use of net.minecraft.command.WrongUsageException in project watson by totemo.
the class ClientCommandManager method executeCommand.
// --------------------------------------------------------------------------
/**
* @see net.minecraft.src.ICommandManager#executeCommand(net.minecraft.src.ICommandSender,
* java.lang.String)
*
* The JavaDocs for the interface don't currently describe the exact
* meaning of the return value. Looking at the code for
* {@link net.minecraft.src.CommandHandler} it contains a loop that
* applies a command for all players who match a particular name pattern.
* The returned value is the number of times that the command was
* successfully executed by that loop. Therefore in the case of this
* class, it returns 1 on success and 0 on error.
*/
@Override
public int executeCommand(ICommandSender sender, String commandLine) {
try {
String[] tokens = getTokens(commandLine);
String verb = tokens[0];
ICommand command = getCommand(verb);
if (command == null) {
throw new CommandNotFoundException();
}
tokens = Arrays.copyOfRange(tokens, 1, tokens.length);
if (command.canCommandSenderUseCommand(sender)) {
command.processCommand(sender, tokens);
return 1;
} else {
sendError(sender, new ChatComponentTranslation("commands.generic.permission", new Object[0]));
}
} catch (WrongUsageException ex) {
sendError(sender, new ChatComponentTranslation("commands.generic.usage", new Object[] { new ChatComponentTranslation(ex.getMessage(), ex.getErrorObjects()) }));
} catch (CommandException ex) {
sendError(sender, new ChatComponentTranslation(ex.getMessage(), ex.getErrorObjects()));
} catch (Throwable throwable) {
sendError(sender, new ChatComponentTranslation("commands.generic.exception", new Object[0]));
Log.exception(Level.WARNING, "error processing command", throwable);
}
return 0;
}
use of net.minecraft.command.WrongUsageException in project RecurrentComplex by Ivorforce.
the class CommandSearchStructure method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
List<ToDoubleFunction<String>> ranks = new ArrayList<>();
consider(ranks, parameters.get(0), Parameter::varargsList, (s, t) -> StructureSearch.searchRank(t, StructureSearch.keywords(StructureRegistry.INSTANCE.id(s), s)));
consider(ranks, parameters.get("containing"), e -> RCP.expression(e, new BlockExpression(RecurrentComplex.specialRegistry)), StructureSearch::containedBlocks);
consider(ranks, parameters.get("biome"), MCP::biome, StructureSearch::biome);
consider(ranks, parameters.get("dimension"), MCP.dimension(server, sender), StructureSearch::dimension);
consider(ranks, parameters.get("maze"), p -> p, StructureSearch::maze);
consider(ranks, parameters.get("list"), p -> p, StructureSearch::list);
consider(ranks, parameters.get("author"), p -> p, StructureSearch::author);
boolean all = parameters.has("all");
if (ranks.stream().noneMatch(Objects::nonNull))
throw new WrongUsageException(getUsage(sender));
postResultMessage("Results: ", sender, RCTextStyle::structure, search(all ? StructureRegistry.INSTANCE.ids() : StructureRegistry.INSTANCE.activeIDs(), name -> ranks.stream().filter(Objects::nonNull).mapToDouble(f -> f.applyAsDouble(name)).reduce(1, (a, b) -> a * b)));
}
use of net.minecraft.command.WrongUsageException in project AppleCore by squeek502.
the class CommandHunger method execute.
@Override
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender commandSender, @Nonnull String[] args) throws CommandException {
if (args.length > 0) {
EntityPlayerMP playerToActOn = args.length >= 2 ? getPlayer(server, commandSender, args[0]) : getCommandSenderAsPlayer(commandSender);
int maxHunger = AppleCoreAPI.accessor.getMaxHunger(playerToActOn);
int newHunger = args.length >= 2 ? parseInt(args[1], 0, maxHunger) : parseInt(args[0], 0, maxHunger);
AppleCoreAPI.mutator.setHunger(playerToActOn, newHunger);
if (playerToActOn.getFoodStats().getSaturationLevel() > newHunger)
AppleCoreAPI.mutator.setSaturation(playerToActOn, newHunger);
notifyCommandListener(commandSender, this, 1, "applecore.commands.hunger.set.hunger.to", playerToActOn.getDisplayName(), newHunger);
} else {
throw new WrongUsageException(getUsage(commandSender));
}
}
use of net.minecraft.command.WrongUsageException in project Galacticraft by micdoodle8.
the class CommandPlanetTeleport method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
EntityPlayerMP playerBase = null;
if (args.length < 2) {
try {
if (args.length == 1) {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[0], true);
} else {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
}
if (playerBase != null) {
WorldServer worldserver = server.getWorld(GCCoreUtil.getDimensionID(server.worlds[0]));
BlockPos spawnPoint = worldserver.getSpawnPoint();
GCPlayerStats stats = GCPlayerStats.get(playerBase);
stats.setRocketStacks(NonNullList.withSize(2, ItemStack.EMPTY));
stats.setRocketType(IRocketType.EnumRocketType.DEFAULT.ordinal());
stats.setRocketItem(GCItems.rocketTier1);
stats.setFuelLevel(1000);
stats.setCoordsTeleportedFromX(spawnPoint.getX());
stats.setCoordsTeleportedFromZ(spawnPoint.getZ());
try {
WorldUtil.toCelestialSelection(playerBase, stats, Integer.MAX_VALUE);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
CommandBase.notifyCommandListener(sender, this, "commands.dimensionteleport", new Object[] { String.valueOf(EnumColor.GREY + "[" + playerBase.getName()), "]" });
} else {
throw new Exception("Could not find player with name: " + args[0]);
}
} catch (final Exception var6) {
throw new CommandException(var6.getMessage(), new Object[0]);
}
} else {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.dimensiontp.too_many", this.getUsage(sender)), new Object[0]);
}
}
use of net.minecraft.command.WrongUsageException in project Galacticraft by micdoodle8.
the class CommandGCHouston method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
EntityPlayerMP playerBase = null;
boolean isOp = this.isOp(server, sender);
if (args.length < 2) {
try {
if (args.length == 0) {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
if (!playerBase.capabilities.isCreativeMode) {
if (ConfigManagerCore.challengeMode || !(playerBase.world.provider instanceof IGalacticraftWorldProvider)) {
CommandBase.notifyCommandListener(sender, this, "commands.gchouston.fail");
return;
}
}
if (timerList.contains(playerBase)) {
timerList.remove(playerBase);
} else {
timerList.add(playerBase);
TickHandlerServer.timerHoustonCommand = 250;
String msg = EnumColor.YELLOW + GCCoreUtil.translate("commands.gchouston.confirm.1") + " " + EnumColor.WHITE + GCCoreUtil.translate("commands.gchouston.confirm.2");
CommandBase.notifyCommandListener(sender, this, msg);
return;
}
} else {
if (!isOp) {
CommandBase.notifyCommandListener(sender, this, "commands.gchouston.noop");
return;
}
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[0], true);
}
if (playerBase != null) {
int dimID = ConfigManagerCore.idDimensionOverworld;
WorldServer worldserver = server.getWorld(dimID);
if (worldserver == null) {
worldserver = server.getWorld(0);
if (worldserver == null) {
throw new Exception("/gchouston could not find Overworld.");
}
dimID = 0;
}
BlockPos spawnPoint = null;
BlockPos bedPos = playerBase.getBedLocation(dimID);
if (bedPos != null) {
spawnPoint = EntityPlayer.getBedSpawnLocation(worldserver, bedPos, false);
}
if (spawnPoint == null) {
spawnPoint = worldserver.getTopSolidOrLiquidBlock(worldserver.getSpawnPoint());
}
GCPlayerStats stats = GCPlayerStats.get(playerBase);
stats.setRocketStacks(NonNullList.withSize(0, ItemStack.EMPTY));
stats.setRocketType(IRocketType.EnumRocketType.DEFAULT.ordinal());
stats.setRocketItem(null);
stats.setFuelLevel(0);
stats.setCoordsTeleportedFromX(spawnPoint.getX());
stats.setCoordsTeleportedFromZ(spawnPoint.getZ());
stats.setUsingPlanetSelectionGui(false);
playerBase.closeScreen();
Vector3 spawnPos = new Vector3(spawnPoint.getX() + 0.5D, spawnPoint.getY() + 0.25D, spawnPoint.getZ() + 0.5D);
try {
WorldUtil.teleportEntitySimple(worldserver, dimID, playerBase, spawnPos);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
CommandBase.notifyCommandListener(sender, this, "commands.gchouston.success", new Object[] { String.valueOf(EnumColor.GREY + "" + playerBase.getName()) });
} else {
throw new Exception("Could not find player with name: " + args[0]);
}
} catch (final Exception var6) {
throw new CommandException(var6.getMessage(), new Object[0]);
}
} else {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.dimensiontp.too_many", this.getUsage(sender)), new Object[0]);
}
}
Aggregations