use of net.minecraft.command.WrongUsageException in project Galacticraft by micdoodle8.
the class CommandGCAstroMiner method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length > 2) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.dimensiontp.too_many", this.getUsage(sender)), new Object[0]);
}
if (args.length < 1) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getUsage(sender)), new Object[0]);
}
int type = 0;
int newvalue = 0;
if (args[0].equalsIgnoreCase("show")) {
type = 1;
} else if (args[0].equalsIgnoreCase("reset")) {
type = 2;
} else if (args[0].length() > 3 && args[0].substring(0, 3).equalsIgnoreCase("set")) {
String number = args[0].substring(3);
try {
newvalue = Integer.parseInt(number);
if (newvalue > 0) {
type = 3;
}
} catch (NumberFormatException ex) {
}
}
// Proceed if syntax of show|reset|set<number> was correct
if (type > 0) {
EntityPlayerMP playerBase = null;
try {
if (args.length == 2) {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[1], true);
} else {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
}
if (playerBase != null) {
GCPlayerStats stats = GCPlayerStats.get(playerBase);
switch(type) {
case 1:
sender.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + stats.getAstroMinerCount())));
break;
case 2:
stats.setAstroMinerCount(0);
sender.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + 0)));
break;
case 3:
stats.setAstroMinerCount(newvalue);
sender.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + newvalue)));
break;
}
} else {
throw new Exception("Could not find player with name: " + args[1]);
}
} catch (final Exception e) {
throw new CommandException(e.getMessage(), new Object[0]);
}
return;
}
}
use of net.minecraft.command.WrongUsageException in project MinecraftForge by MinecraftForge.
the class ClientCommandHandler method executeCommand.
/**
* @return 1 if successfully executed, -1 if no permission or wrong usage,
* 0 if it doesn't exist or it was canceled (it's sent to the server)
*/
@Override
public int executeCommand(ICommandSender sender, String message) {
message = message.trim();
if (message.startsWith("/")) {
message = message.substring(1);
}
String[] temp = message.split(" ");
String[] args = new String[temp.length - 1];
String commandName = temp[0];
System.arraycopy(temp, 1, args, 0, args.length);
ICommand icommand = getCommands().get(commandName);
try {
if (icommand == null) {
return 0;
}
if (icommand.checkPermission(this.getServer(), sender)) {
CommandEvent event = new CommandEvent(icommand, sender, args);
if (MinecraftForge.EVENT_BUS.post(event)) {
if (event.getException() != null) {
throw event.getException();
}
return 0;
}
this.tryExecute(sender, args, icommand, message);
return 1;
} else {
sender.sendMessage(format(RED, "commands.generic.permission"));
}
} catch (WrongUsageException wue) {
sender.sendMessage(format(RED, "commands.generic.usage", format(RED, wue.getMessage(), wue.getErrorObjects())));
} catch (CommandException ce) {
sender.sendMessage(format(RED, ce.getMessage(), ce.getErrorObjects()));
} catch (Throwable t) {
sender.sendMessage(format(RED, "commands.generic.exception"));
t.printStackTrace();
}
return -1;
}
use of net.minecraft.command.WrongUsageException in project SecurityCraft by Geforce132.
the class CommandSCHelp method processCommand.
public void processCommand(ICommandSender icommandsender, String[] par1String) {
if (par1String.length == 0) {
throw new WrongUsageException(usage);
}
if ((par1String[0].matches("connect") || par1String[0].matches("disconnect") || par1String[0].matches("contact") || par1String[0].matches("bug")) && !mod_SecurityCraft.instance.configHandler.isIrcBotEnabled) {
sendMessageToPlayer("The SecurityCraft IRC bot is disabled from the config file. Please enable to it to use this feature.", icommandsender);
return;
}
if (par1String[0].matches("changePasscode") && par1String.length == 6) {
int[] positions = { Integer.parseInt(par1String[1]), Integer.parseInt(par1String[2]), Integer.parseInt(par1String[3]) };
World world = icommandsender.getEntityWorld();
if (world.getBlock(positions[0], positions[1], positions[2]) == mod_SecurityCraft.Keypad && ((TileEntityKeypad) world.getTileEntity(positions[0], positions[1], positions[2])).getKeypadCode().matches(par1String[4])) {
((TileEntityKeypad) world.getTileEntity(positions[0], positions[1], positions[2])).setKeypadCode(par1String[5]);
HelpfulMethods.sendMessage(icommandsender, "Changed keypad's (at X:" + positions[0] + " Y:" + positions[1] + " Z:" + positions[2] + ") code from " + Integer.parseInt(par1String[4]) + " to " + Integer.parseInt(par1String[5]) + ".", EnumChatFormatting.GREEN);
} else if ((world.getBlock(positions[0], positions[1], positions[2]) == mod_SecurityCraft.Keypad && !((TileEntityKeypad) world.getTileEntity(positions[0], positions[1], positions[2])).getKeypadCode().matches(par1String[4])) || (world.getBlock(positions[0], positions[1], positions[2]) == mod_SecurityCraft.keypadChest && !((TileEntityKeypadChest) world.getTileEntity(positions[0], positions[1], positions[2])).getKeypadCode().matches(par1String[4]))) {
HelpfulMethods.sendMessage(icommandsender, par1String[3] + " is not the passcode for this block.", EnumChatFormatting.RED);
} else if (world.getBlock(positions[0], positions[1], positions[2]) != mod_SecurityCraft.Keypad && world.getBlock(positions[0], positions[1], positions[2]) != mod_SecurityCraft.keypadChest) {
HelpfulMethods.sendMessage(icommandsender, "There is no accessable block at the specifed coordinates!", EnumChatFormatting.RED);
}
return;
}
if (par1String.length == 1) {
if (par1String[0].matches("connect")) {
mod_SecurityCraft.instance.setIrcBot(new SCIRCBot("SCUser_" + icommandsender.getCommandSenderName()));
try {
mod_SecurityCraft.instance.getIrcBot().connectToChannel();
} catch (Exception e) {
e.printStackTrace();
sendMessageToPlayer("Error occurred when connecting to IRC. Do you have internet access, and access to the IRC server 'irc.esper.net'?", icommandsender);
return;
}
sendMessageToPlayer("Bot connected successfully. You may now report bugs using '/sc bug <bug to report>' or contact me using '/sc contact <message>", icommandsender);
} else if (par1String[0].matches("disconnect")) {
if (mod_SecurityCraft.instance.getIrcBot() != null) {
mod_SecurityCraft.instance.getIrcBot().disconnect();
}
mod_SecurityCraft.instance.setIrcBot(null);
sendMessageToPlayer("Bot disconnected from EsperNet successfully.", icommandsender);
}
} else if (par1String.length >= 2) {
if (par1String[0].matches("bug")) {
if (mod_SecurityCraft.instance.getIrcBot() != null) {
mod_SecurityCraft.instance.getIrcBot().sendMessage("#GeforceMods", "[SecurityCraft " + mod_SecurityCraft.getVersion() + " bug] Geforce: " + getMessageFromArray(par1String, 1));
sendMessageToPlayer(EnumChatFormatting.GRAY + "<" + icommandsender.getCommandSenderName() + " --> IRC> " + getMessageFromArray(par1String, 1) + ".", icommandsender);
} else {
sendMessageToPlayer("Bot is not connected to EsperNet. Use '/sc connect' to connect to IRC.", icommandsender);
}
} else if (par1String[0].matches("contact")) {
if (mod_SecurityCraft.instance.getIrcBot() != null) {
mod_SecurityCraft.instance.getIrcBot().sendMessage("#GeforceMods", "[SecurityCraft " + mod_SecurityCraft.getVersion() + "] Geforce: " + getMessageFromArray(par1String, 1));
sendMessageToPlayer(EnumChatFormatting.GRAY + "<" + icommandsender.getCommandSenderName() + " --> IRC> " + getMessageFromArray(par1String, 1) + ".", icommandsender);
} else {
sendMessageToPlayer("Bot is not connected to EsperNet. Use '/sc connect' to connect to IRC.", icommandsender);
}
} else if (par1String[0].matches("help")) {
if (par1String[1] == null || par1String[1].isEmpty()) {
throw new WrongUsageException(usage);
}
String par1 = getHelpInfo(par1String[1]);
if (!par1.isEmpty()) {
sendMessageToPlayer("[SCHelp] " + par1, icommandsender);
}
} else if (par1String[0].matches("recipe")) {
String itemname = par1String[1].toLowerCase();
if (itemname.matches("level1keycard") && !mod_SecurityCraft.configHandler.ableToCraftKeycard1) {
sendMessageToPlayer("[Recipe currently disabled in config file] " + getRecipe(itemname)[0], icommandsender);
sendMessageToPlayer(getRecipe(itemname)[1], icommandsender);
sendMessageToPlayer(getRecipe(itemname)[2], icommandsender);
sendMessageToPlayer(getRecipe(itemname)[3], icommandsender);
sendMessageToPlayer(getRecipe(itemname)[4], icommandsender);
} else if (itemname.matches("level2keycard") && !mod_SecurityCraft.configHandler.ableToCraftKeycard2) {
sendMessageToPlayer("[Recipe currently disabled in config file] " + getRecipe(itemname)[0], icommandsender);
sendMessageToPlayer(getRecipe(itemname)[1], icommandsender);
sendMessageToPlayer(getRecipe(itemname)[2], icommandsender);
sendMessageToPlayer(getRecipe(itemname)[3], icommandsender);
sendMessageToPlayer(getRecipe(itemname)[4], icommandsender);
} else if (itemname.matches("level3keycard") && !mod_SecurityCraft.configHandler.ableToCraftKeycard3) {
sendMessageToPlayer("[Recipe currently disabled in config file] " + getRecipe(itemname)[0], icommandsender);
sendMessageToPlayer(getRecipe(par1String[1])[1], icommandsender);
sendMessageToPlayer(getRecipe(par1String[1])[2], icommandsender);
sendMessageToPlayer(getRecipe(par1String[1])[3], icommandsender);
sendMessageToPlayer(getRecipe(par1String[1])[4], icommandsender);
} else {
sendMessageToPlayer(getRecipe(par1String[1])[0], icommandsender);
sendMessageToPlayer(getRecipe(par1String[1])[1], icommandsender);
sendMessageToPlayer(getRecipe(par1String[1])[2], icommandsender);
sendMessageToPlayer(getRecipe(par1String[1])[3], icommandsender);
sendMessageToPlayer(getRecipe(par1String[1])[4], icommandsender);
}
}
} else {
throw new WrongUsageException(usage);
}
}
use of net.minecraft.command.WrongUsageException in project SecurityCraft by Geforce132.
the class CommandSCLog method processCommand.
public void processCommand(ICommandSender icommandsender, String[] par1String) {
if (par1String.length >= 1) {
if (par1String[0].matches("clear")) {
File file = new File("changelog.txt");
if (file.exists()) {
file.delete();
File file2 = new File("changelog.txt");
try {
file2.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
return;
}
}
try {
String string = "";
for (int i = 0; i < par1String.length; i++) {
if (i >= 1) {
string += " " + par1String[i];
} else {
string += "-" + par1String[i];
}
}
File file = new File("changelog.txt");
if (!file.exists()) {
file.createNewFile();
}
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("changelog.txt", true)));
out.println(string);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
} else {
throw new WrongUsageException("/log <changeToLog>");
}
}
use of net.minecraft.command.WrongUsageException in project SecurityCraft by Geforce132.
the class CommandSC method processCommand.
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
if (args.length == 0) {
throw new WrongUsageException(StatCollector.translateToLocal("messages.command.sc.usage"));
}
if ((args[0].matches("connect") || args[0].matches("disconnect") || args[0].matches("contact") || args[0].matches("bug")) && !mod_SecurityCraft.configHandler.isIrcBotEnabled) {
PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.botDisabled"), EnumChatFormatting.RED);
return;
}
if (args.length == 1) {
if (args[0].matches("connect")) {
EntityPlayer p = PlayerUtils.getPlayerFromName(sender.getCommandSenderName());
p.openGui(mod_SecurityCraft.instance, GuiHandler.IRC_INFORMATION, p.worldObj, p.chunkCoordX, p.chunkCoordY, p.chunkCoordZ);
try {
mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()).connectToChannel();
} catch (Exception e) {
e.printStackTrace();
PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.error"), EnumChatFormatting.RED);
return;
}
PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.connected"), EnumChatFormatting.GREEN);
} else if (args[0].matches("disconnect")) {
if (mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()) != null) {
mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()).disconnect();
}
PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.disconnected"), EnumChatFormatting.RED);
} else if (args[0].matches("help")) {
getCommandSenderAsPlayer(sender).inventory.addItemStackToInventory(new ItemStack(mod_SecurityCraft.scManual));
} else if (args[0].matches("bug"))
PlayerUtils.sendMessageEndingWithLink(sender, "SecurityCraft", StatCollector.translateToLocal("messages.bugReport"), "http://goo.gl/forms/kfRpvvQzfl", EnumChatFormatting.GOLD);
else if (args[0].equals("resume"))
mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()).setMessageMode(false, sender);
else if (args[0].matches("contact")) {
if (mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()) != null) {
mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()).setMessageMode(true, sender);
} else {
PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.notConnected"), EnumChatFormatting.RED);
}
}
} else if (args.length >= 2) {
if (args[0].matches("contact")) {
if (mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()) != null) {
mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()).setMessageMode(true, sender);
} else {
PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.notConnected"), EnumChatFormatting.RED);
}
} else if (args[0].matches("bug"))
PlayerUtils.sendMessageEndingWithLink(sender, "SecurityCraft", StatCollector.translateToLocal("messages.bugReport"), "http://goo.gl/forms/kfRpvvQzfl", EnumChatFormatting.GOLD);
else if (args[0].equals("resume"))
mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()).setMessageMode(false, sender);
} else {
throw new WrongUsageException(StatCollector.translateToLocal("messages.command.sc.usage"));
}
}
Aggregations