List of usage examples for net.minecraftforge.fml.common ObfuscationReflectionHelper setPrivateValue
public static <T, E> void setPrivateValue(@Nonnull final Class<? super T> classToAccess, @Nonnull final T instance, @Nullable final E value, @Nonnull final String fieldName)
From source file:info.servertools.core.command.CommandManager.java
License:Apache License
private void registerCommand(final STCommand command, final Command commandAnnotation) { log.trace("registerCommand {}", command); CommentedConfigurationNode commandNode = node.getNode(command.getClass().getName()); CommentedConfigurationNode enableNode = commandNode.getNode("enable-command"); CommentedConfigurationNode nameNode = commandNode.getNode("command-name"); CommentedConfigurationNode permNode = commandNode.getNode("op-required"); if (enableNode.isVirtual() || enableNode.getValue() == null) { enableNode.setValue(true);/*from w w w.ja v a 2 s .co m*/ } if (nameNode.isVirtual() || nameNode.getValue() == null) { nameNode.setValue(commandAnnotation.name()); } if (permNode.isVirtual() || permNode.getValue() == null) { permNode.setValue(commandAnnotation.opRequired()); } enableNode.setComment("Set to false to disable this command"); nameNode.setComment("Default name: " + commandAnnotation.name()); permNode.setComment("If server operator status is needed to execute the command"); final String name = nameNode.getString(); if (!validCommandPattern.matcher(name).matches()) { throw new RuntimeException( String.format("Command %s was configured with an invald name: %s", command, name)); } ReflectionHelper.setPrivateValue(STCommand.class, command, name, "name"); if (!commandAnnotation.name().equals(name)) { log.info("Command {} was renamed from {} to {}", command, commandAnnotation.name(), command.getCommandName()); } final boolean opRequired = permNode.getBoolean(commandAnnotation.opRequired()); ObfuscationReflectionHelper.setPrivateValue(STCommand.class, command, opRequired, "opRequired"); if (enableNode.getBoolean(true)) { commands.add(command); } else { log.info("Command {} was disabled via configuration"); } saveConfig(); }