use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.
the class CommandSpaceStationAddOwner method processCommand.
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
String var3 = null;
EntityPlayerMP playerBase = null;
if (args.length > 0) {
var3 = args[0];
try {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
if (playerBase != null) {
GCPlayerStats stats = GCPlayerStats.get(playerBase);
if (stats.getSpaceStationDimensionData().isEmpty()) {
throw new WrongUsageException(GCCoreUtil.translate("commands.ssinvite.not_found"), new Object[0]);
} else {
for (Map.Entry<Integer, Integer> ownedStations : stats.getSpaceStationDimensionData().entrySet()) {
final SpaceStationWorldData data = SpaceStationWorldData.getStationData(playerBase.worldObj, ownedStations.getValue(), playerBase);
if (var3.equalsIgnoreCase("+all")) {
data.setAllowedAll(true);
playerBase.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.allow_all_true")));
return;
}
if (var3.equalsIgnoreCase("-all")) {
data.setAllowedAll(false);
playerBase.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.allow_all_false", var3)));
return;
}
if (!data.getAllowedPlayers().contains(var3)) {
data.getAllowedPlayers().add(var3);
data.markDirty();
}
}
}
final EntityPlayerMP playerToAdd = PlayerUtil.getPlayerBaseServerFromPlayerUsername(var3, true);
if (playerToAdd != null) {
playerToAdd.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.added", PlayerUtil.getName(playerBase))));
}
}
} catch (final Exception var6) {
throw new CommandException(var6.getMessage(), new Object[0]);
}
} else {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getCommandUsage(sender)), new Object[0]);
}
if (playerBase != null) {
playerBase.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.addsuccess", var3)));
}
}
use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.
the class CommandGCKit method processCommand.
@Override
public void processCommand(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) {
ItemHandlerHelper.giveItemToPlayer(playerBase, new ItemStack(GCItems.emergencyKit), 0);
CommandBase.notifyOperators(sender, this, "commands.emergencykit", 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.getCommandUsage(sender)), new Object[0]);
}
}
use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.
the class CommandGCInv method processCommand.
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
if (CommandGCInv.firstuse) {
CommandGCInv.firstuse = false;
CommandGCInv.initialise();
}
if (args.length == 2) {
try {
EntityPlayerMP thePlayer = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[1], true);
if (thePlayer != null && !thePlayer.isDead && thePlayer.worldObj != null) {
GCPlayerStats stats = GCPlayerStats.get(thePlayer);
if (args[0].equalsIgnoreCase("drop")) {
InventoryExtended gcInventory = stats.getExtendedInventory();
gcInventory.dropExtendedItems(thePlayer);
} else if (args[0].equalsIgnoreCase("save")) {
InventoryExtended gcInventory = stats.getExtendedInventory();
ItemStack[] saveinv = new ItemStack[gcInventory.getSizeInventory()];
for (int i = 0; i < gcInventory.getSizeInventory(); i++) {
saveinv[i] = gcInventory.getStackInSlot(i);
gcInventory.setInventorySlotContents(i, null);
}
CommandGCInv.savedata.put(args[1].toLowerCase(), saveinv);
CommandGCInv.dontload.add(args[1].toLowerCase());
CommandGCInv.writefile();
System.out.println("[GCInv] Saving and clearing GC inventory slots of " + PlayerUtil.getName(thePlayer));
} else if (args[0].equalsIgnoreCase("restore")) {
ItemStack[] saveinv = CommandGCInv.savedata.get(args[1].toLowerCase());
CommandGCInv.dontload.remove(args[1].toLowerCase());
if (saveinv == null) {
System.out.println("[GCInv] Tried to restore but player " + PlayerUtil.getName(thePlayer) + " had no saved GC inventory items.");
return;
}
CommandGCInv.doLoad(thePlayer);
} else if (args[0].equalsIgnoreCase("clear")) {
InventoryExtended gcInventory = stats.getExtendedInventory();
for (int i = 0; i < gcInventory.getSizeInventory(); i++) {
gcInventory.setInventorySlotContents(i, null);
}
} else {
throw new WrongUsageException("Invalid GCInv command. Usage: " + this.getCommandUsage(sender), new Object[0]);
}
} else {
// inventory already)
if (args[0].equalsIgnoreCase("restore")) {
ItemStack[] saveinv = CommandGCInv.savedata.get(args[1].toLowerCase());
if (saveinv != null) {
System.out.println("[GCInv] Restore command for offline player " + args[1] + ", setting to restore GCInv on next login.");
CommandGCInv.dontload.remove(args[1].toLowerCase());
// Now it can autoload on next player logon
return;
}
}
// No player found, and not a 'restore' command
if (args[0].equalsIgnoreCase("clear") || args[0].equalsIgnoreCase("save") || args[0].equalsIgnoreCase("drop")) {
System.out.println("GCInv command: player " + args[1] + " not found.");
} else {
throw new WrongUsageException("Invalid GCInv command. Usage: " + this.getCommandUsage(sender), new Object[0]);
}
}
} catch (final Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
} else {
throw new WrongUsageException("Not enough command arguments! Usage: " + this.getCommandUsage(sender), new Object[0]);
}
}
use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.
the class CommandSpaceStationRemoveOwner method processCommand.
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
String var3 = null;
EntityPlayerMP playerBase = null;
if (args.length > 0) {
var3 = args[0];
try {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), false);
if (playerBase != null) {
GCPlayerStats stats = GCPlayerStats.get(playerBase);
if (stats.getSpaceStationDimensionData().isEmpty()) {
throw new WrongUsageException(GCCoreUtil.translate("commands.ssinvite.not_found"), new Object[0]);
} else {
for (Map.Entry<Integer, Integer> e : stats.getSpaceStationDimensionData().entrySet()) {
final SpaceStationWorldData data = SpaceStationWorldData.getStationData(playerBase.worldObj, e.getValue(), playerBase);
String str = null;
for (String name : data.getAllowedPlayers()) {
if (name.equalsIgnoreCase(var3)) {
str = name;
break;
}
}
if (str != null) {
data.getAllowedPlayers().remove(str);
data.markDirty();
} else {
throw new CommandException(GCCoreUtil.translateWithFormat("commands.ssuninvite.no_player", "\"" + var3 + "\""), new Object[0]);
}
}
}
}
} catch (final Exception var6) {
throw new CommandException(var6.getMessage(), new Object[0]);
}
} else {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getCommandUsage(sender)), new Object[0]);
}
if (playerBase != null) {
playerBase.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.removesuccess", var3)));
}
}
use of net.minecraft.command.CommandException in project DynamicSurroundings by OreCruncher.
the class CommandCalc method execute.
@Override
public void execute(final MinecraftServer server, final ICommandSender sender, final String[] parms) throws CommandException {
try {
boolean showHelp = false;
if (parms.length == 0) {
showHelp = true;
} else if (COMMAND_OPTION_HELP.compareToIgnoreCase(parms[0]) == 0) {
showHelp = true;
} else if (COMMAND_OPTION_FUNCS.compareToIgnoreCase(parms[0]) == 0) {
final Expression exp = new Expression("0");
for (final String line : exp.getDeclaredFunctions()) sender.sendMessage(new TextComponentString(line));
} else if (COMMAND_OPTION_VARS.compareToIgnoreCase(parms[0]) == 0) {
final Expression exp = new Expression("0");
for (final String line : exp.getDeclaredVariables()) sender.sendMessage(new TextComponentString(line));
} else if (COMMAND_OPTION_OPS.compareToIgnoreCase(parms[0]) == 0) {
final Expression exp = new Expression("0");
for (final String line : exp.getDeclaredOperators()) sender.sendMessage(new TextComponentString(line));
} else {
try {
final Expression exp = new Expression(buildString(parms, 0));
final Variant result = exp.eval();
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "-> " + result.asString()));
} catch (final ExpressionException t) {
sender.sendMessage(new TextComponentString(TextFormatting.RED + t.getMessage()));
} catch (final Throwable t) {
sender.sendMessage(new TextComponentString(TextFormatting.RED + "Internal error"));
showHelp = true;
}
}
if (showHelp) {
for (final String line : HELP) sender.sendMessage(new TextComponentString(line));
}
} catch (final Exception ex) {
ex.printStackTrace();
}
}
Aggregations