use of net.minecraft.command.CommandHandler in project SpongeCommon by SpongePowered.
the class MinecraftCommandWrapper method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (!testPermission(source)) {
throw new CommandPermissionException(Text.of(SpongeImpl.getGame().getRegistry().getTranslationById(TRANSLATION_NO_PERMISSION).get()));
}
CommandHandler handler = (CommandHandler) SpongeImpl.getServer().getCommandManager();
final ICommandSender mcSender = WrapperICommandSender.of(source);
final String[] splitArgs = splitArgs(arguments);
int usernameIndex = 0;
try {
usernameIndex = handler.getUsernameIndex(this.command, splitArgs);
} catch (net.minecraft.command.CommandException e) {
throw new RuntimeException(e);
}
int successCount = 0;
if (!throwEvent(mcSender, splitArgs)) {
return CommandResult.empty();
}
// Below this is copied from CommandHandler.execute. This might need to be updated between versions.
int affectedEntities = 1;
if (usernameIndex > -1) {
List<Entity> list = null;
try {
list = EntitySelector.matchEntities(mcSender, splitArgs[usernameIndex], Entity.class);
} catch (net.minecraft.command.CommandException e) {
throw new RuntimeException(e);
}
String previousNameVal = splitArgs[usernameIndex];
affectedEntities = list.size();
((IMixinCommandHandler) handler).setExpandedSelector(true);
for (Entity entity : list) {
splitArgs[usernameIndex] = entity.getCachedUniqueIdString();
if (tryExecute(handler, mcSender, splitArgs, arguments)) {
++successCount;
}
}
splitArgs[usernameIndex] = previousNameVal;
((IMixinCommandHandler) handler).setExpandedSelector(false);
} else {
if (tryExecute(handler, mcSender, splitArgs, arguments)) {
++successCount;
}
}
return CommandResult.builder().affectedEntities(affectedEntities).successCount(successCount).build();
}
use of net.minecraft.command.CommandHandler in project MinecraftForge by MinecraftForge.
the class FMLServerStartingEvent method registerServerCommand.
public void registerServerCommand(ICommand command) {
CommandHandler ch = (CommandHandler) getServer().getCommandManager();
ch.registerCommand(command);
}
use of net.minecraft.command.CommandHandler in project AppleCore by squeek502.
the class Commands method init.
public static void init(MinecraftServer server) {
CommandHandler commandHandler = (CommandHandler) server.getCommandManager();
commandHandler.registerCommand(new CommandHunger());
}
use of net.minecraft.command.CommandHandler in project Railcraft by Railcraft.
the class Railcraft method serverStarting.
@Mod.EventHandler
public void serverStarting(FMLServerStartingEvent event) {
CommandHandler commandManager = (CommandHandler) event.getServer().getCommandManager();
commandManager.registerCommand(ROOT_COMMAND);
}
Aggregations