Created
July 18, 2021 12:42
-
-
Save John-Paul-R/7e09987dbd7b64f0801ce946b491de0c to your computer and use it in GitHub Desktop.
Cursed Entrypoints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fibermc.essentialcommands.mixin; | |
import com.fibermc.essentialcommands.EssentialCommands; | |
import com.fibermc.essentialcommands.access.CommandNodeAccess; | |
import com.mojang.brigadier.Command; | |
import com.mojang.brigadier.tree.ArgumentCommandNode; | |
import com.mojang.brigadier.tree.CommandNode; | |
import com.mojang.brigadier.tree.LiteralCommandNode; | |
import com.mojang.brigadier.tree.RootCommandNode; | |
import org.apache.log4j.LogManager; | |
import org.apache.log4j.Logger; | |
import org.spongepowered.asm.mixin.Mixin; | |
import org.spongepowered.asm.mixin.Shadow; | |
import java.util.LinkedHashMap; | |
import java.util.Map; | |
@Mixin(CommandNode.class) | |
public class CommandNodeMixin<S> implements CommandNodeAccess<S> { | |
@Shadow | |
private Map<String, CommandNode<S>> children = new LinkedHashMap<>(); | |
@Shadow | |
private Map<String, LiteralCommandNode<S>> literals = new LinkedHashMap<>(); | |
@Shadow | |
private Map<String, ArgumentCommandNode<S, ?>> arguments = new LinkedHashMap<>(); | |
private static final Logger LOGGER = LogManager.getLogger("CommandNodeLog"); | |
@Shadow | |
private Command<S> command; | |
/** | |
* Overwrites existing method in CommandNode. | |
* Remove some sorting that breaks ability to deal with | |
* command node ambiguity via registration order. | |
* (essentially a fix from brigadier 1.0.18 | |
* | |
* @param node | |
* @author John-Paul-R (JP7) | |
*/ | |
public void addChild(final CommandNode<S> node) { | |
if (node instanceof RootCommandNode) { | |
throw new UnsupportedOperationException("Cannot add a RootCommandNode as a child to any other CommandNode"); | |
} | |
final CommandNode<S> child = children.get(node.getName()); | |
if (child != null) { | |
// We've found something to merge onto | |
if (node.getCommand() != null) { | |
((CommandNodeAccess<S>) child).setCommand(node.getCommand()); | |
} | |
for (final CommandNode<S> grandchild : node.getChildren()) { | |
child.addChild(grandchild); | |
} | |
} else { | |
children.put(node.getName(), node); | |
if (node instanceof LiteralCommandNode) { | |
literals.put(node.getName(), (LiteralCommandNode<S>) node); | |
} else if (node instanceof ArgumentCommandNode) { | |
arguments.put(node.getName(), (ArgumentCommandNode<S, ?>) node); | |
} | |
} | |
LOGGER.info("EC MIXIN WORKING"); | |
} | |
@Override | |
public void setCommand(Command<S> command) { | |
this.command = command; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fibermc.essentialcommands; | |
import net.devtech.grossfabrichacks.entrypoints.PrePreLaunch; | |
import net.devtech.grossfabrichacks.instrumentation.InstrumentationApi; | |
import org.apache.log4j.LogManager; | |
public class GFHEntrypoint implements PrePreLaunch { | |
@Override | |
public void onPrePreLaunch() { | |
InstrumentationApi.pipeClassThroughTransformerBootstrap("com.mojang.brigadier.tree.CommandNode"); | |
LogManager.getLogger("ECPreLaunch").info("Completed Essential Commands pre-pre-launch tasks!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment