use of net.minecraft.command.WrongUsageException in project SecurityCraft by Geforce132.
the class CommandSC method execute.
public void execute(ICommandSender sender, String[] par1String) throws CommandException {
if (par1String.length == 0) {
throw new WrongUsageException(StatCollector.translateToLocal("messages.command.sc.usage"));
}
if ((par1String[0].matches("connect") || par1String[0].matches("disconnect") || par1String[0].matches("contact") || par1String[0].matches("bug")) && !mod_SecurityCraft.configHandler.isIrcBotEnabled) {
PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.botDisabled"), EnumChatFormatting.RED);
return;
}
if (par1String.length == 1) {
if (par1String[0].matches("connect")) {
EntityPlayer p = PlayerUtils.getPlayerFromName(sender.getName());
p.openGui(mod_SecurityCraft.instance, GuiHandler.IRC_INFORMATION, p.worldObj, p.chunkCoordX, p.chunkCoordY, p.chunkCoordZ);
try {
mod_SecurityCraft.instance.getIrcBot(sender.getName()).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 (par1String[0].matches("disconnect")) {
if (mod_SecurityCraft.instance.getIrcBot(sender.getName()) != null) {
mod_SecurityCraft.instance.getIrcBot(sender.getName()).disconnect();
}
PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.disconnected"), EnumChatFormatting.RED);
} else if (par1String[0].matches("help")) {
getCommandSenderAsPlayer(sender).inventory.addItemStackToInventory(new ItemStack(mod_SecurityCraft.scManual));
} else if (par1String[0].matches("bug"))
PlayerUtils.sendMessageEndingWithLink(sender, "SecurityCraft", StatCollector.translateToLocal("messages.bugReport"), "http://goo.gl/forms/kfRpvvQzfl", EnumChatFormatting.GOLD);
else if (par1String[0].equals("resume"))
mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(false, sender);
else if (par1String[0].matches("contact")) {
if (mod_SecurityCraft.instance.getIrcBot(sender.getName()) != null) {
mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(true, sender);
} else {
PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.notConnected"), EnumChatFormatting.RED);
}
}
} else if (par1String.length >= 2) {
if (par1String[0].matches("contact")) {
if (mod_SecurityCraft.instance.getIrcBot(sender.getName()) != null) {
mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(true, sender);
} else {
PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.notConnected"), EnumChatFormatting.RED);
}
} else if (par1String[0].matches("bug"))
PlayerUtils.sendMessageEndingWithLink(sender, "SecurityCraft", StatCollector.translateToLocal("messages.bugReport"), "http://goo.gl/forms/kfRpvvQzfl", EnumChatFormatting.GOLD);
else if (par1String[0].equals("resume"))
mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(false, sender);
} else {
throw new WrongUsageException(StatCollector.translateToLocal("messages.command.sc.usage"));
}
}
use of net.minecraft.command.WrongUsageException in project SecurityCraft by Geforce132.
the class CommandSC method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length == 0) {
throw new WrongUsageException(I18n.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", I18n.translateToLocal("messages.irc.botDisabled"), TextFormatting.RED);
return;
}
if (args.length == 1) {
if (args[0].matches("connect")) {
EntityPlayer p = PlayerUtils.getPlayerFromName(sender.getName());
p.openGui(mod_SecurityCraft.instance, GuiHandler.IRC_INFORMATION, p.worldObj, p.chunkCoordX, p.chunkCoordY, p.chunkCoordZ);
try {
mod_SecurityCraft.instance.getIrcBot(sender.getName()).connectToChannel();
} catch (Exception e) {
e.printStackTrace();
PlayerUtils.sendMessageToPlayer(sender, "IRC", I18n.translateToLocal("messages.irc.error"), TextFormatting.RED);
return;
}
PlayerUtils.sendMessageToPlayer(sender, "IRC", I18n.translateToLocal("messages.irc.connected"), TextFormatting.GREEN);
} else if (args[0].matches("disconnect")) {
if (mod_SecurityCraft.instance.getIrcBot(sender.getName()) != null) {
mod_SecurityCraft.instance.getIrcBot(sender.getName()).disconnect();
}
PlayerUtils.sendMessageToPlayer(sender, "IRC", I18n.translateToLocal("messages.irc.disconnected"), TextFormatting.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", I18n.translateToLocal("messages.bugReport"), "http://goo.gl/forms/kfRpvvQzfl", TextFormatting.GOLD);
else if (args[0].equals("resume"))
mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(false, sender);
else if (args[0].matches("contact")) {
if (mod_SecurityCraft.instance.getIrcBot(sender.getName()) != null) {
mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(true, sender);
} else {
PlayerUtils.sendMessageToPlayer(sender, "IRC", I18n.translateToLocal("messages.irc.notConnected"), TextFormatting.RED);
}
}
} else if (args.length >= 2) {
if (args[0].matches("contact")) {
if (mod_SecurityCraft.instance.getIrcBot(sender.getName()) != null) {
mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(true, sender);
} else {
PlayerUtils.sendMessageToPlayer(sender, "IRC", I18n.translateToLocal("messages.irc.notConnected"), TextFormatting.RED);
}
} else if (args[0].matches("bug"))
PlayerUtils.sendMessageEndingWithLink(sender, "SecurityCraft", I18n.translateToLocal("messages.bugReport"), "http://goo.gl/forms/kfRpvvQzfl", TextFormatting.GOLD);
else if (args[0].equals("resume"))
mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(false, sender);
} else {
throw new WrongUsageException(I18n.translateToLocal("messages.command.sc.usage"));
}
}
use of net.minecraft.command.WrongUsageException in project SecurityCraft by Geforce132.
the class CommandModule method processCommand.
@Override
public void processCommand(ICommandSender par1ICommandSender, String[] par2String) throws CommandException {
if (par2String.length == 1) {
if (par2String[0].matches("copy")) {
EntityPlayer player = PlayerUtils.getPlayerFromName(par1ICommandSender.getCommandSenderName());
if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemModule && ((ItemModule) player.getCurrentEquippedItem().getItem()).canNBTBeModified()) {
SecurityCraft.instance.setSavedModule(player.getCurrentEquippedItem().getTagCompound());
PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.saved"), EnumChatFormatting.GREEN);
} else
PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.notHoldingForData"), EnumChatFormatting.RED);
return;
} else if (par2String[0].matches("paste")) {
EntityPlayer player = PlayerUtils.getPlayerFromName(par1ICommandSender.getCommandSenderName());
if (SecurityCraft.instance.getSavedModule() == null) {
PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.nothingSaved"), EnumChatFormatting.RED);
return;
}
if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemModule && ((ItemModule) player.getCurrentEquippedItem().getItem()).canNBTBeModified()) {
player.getCurrentEquippedItem().setTagCompound(SecurityCraft.instance.getSavedModule());
SecurityCraft.instance.setSavedModule(null);
PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.saved"), EnumChatFormatting.GREEN);
}
return;
}
} else if (par2String.length == 2)
if (par2String[0].matches("add")) {
EntityPlayer player = PlayerUtils.getPlayerFromName(par1ICommandSender.getCommandSenderName());
if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemModule && ((ItemModule) player.getCurrentEquippedItem().getItem()).canNBTBeModified()) {
if (player.getCurrentEquippedItem().getTagCompound() == null)
player.getCurrentEquippedItem().setTagCompound(new NBTTagCompound());
for (int i = 1; i <= 10; i++) if (player.getCurrentEquippedItem().getTagCompound().hasKey("Player" + i) && player.getCurrentEquippedItem().getTagCompound().getString("Player" + i).matches(par2String[1])) {
PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.alreadyContained").replace("#", par2String[1]), EnumChatFormatting.RED);
return;
}
player.getCurrentEquippedItem().getTagCompound().setString("Player" + getNextSlot(player.getCurrentEquippedItem().getTagCompound()), par2String[1]);
PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.added").replace("#", par2String[1]), EnumChatFormatting.GREEN);
return;
} else {
PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.notHoldingForModify"), EnumChatFormatting.RED);
return;
}
} else if (par2String[0].matches("remove")) {
EntityPlayer player = PlayerUtils.getPlayerFromName(par1ICommandSender.getCommandSenderName());
if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemModule && ((ItemModule) player.getCurrentEquippedItem().getItem()).canNBTBeModified()) {
if (player.getCurrentEquippedItem().getTagCompound() == null)
player.getCurrentEquippedItem().setTagCompound(new NBTTagCompound());
for (int i = 1; i <= 10; i++) if (player.getCurrentEquippedItem().getTagCompound().hasKey("Player" + i) && player.getCurrentEquippedItem().getTagCompound().getString("Player" + i).matches(par2String[1]))
player.getCurrentEquippedItem().getTagCompound().removeTag("Player" + i);
PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.removed").replace("#", par2String[1]), EnumChatFormatting.GREEN);
return;
} else {
PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.notHoldingForModify"), EnumChatFormatting.RED);
return;
}
}
throw new WrongUsageException(StatCollector.translateToLocal("messages.command.module.usage"));
}
use of net.minecraft.command.WrongUsageException in project Galacticraft by micdoodle8.
the class CommandGCHouston method processCommand.
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
EntityPlayerMP playerBase = null;
MinecraftServer server = MinecraftServer.getServer();
boolean isOp = false;
Entity entitySender = sender.getCommandSenderEntity();
if (entitySender == null) {
isOp = true;
} else if (entitySender instanceof EntityPlayer) {
GameProfile prof = ((EntityPlayer) entitySender).getGameProfile();
isOp = server.getConfigurationManager().canSendCommands(prof);
}
if (args.length < 2) {
try {
if (args.length == 0) {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
if (!playerBase.capabilities.isCreativeMode) {
if (ConfigManagerCore.challengeMode || !(playerBase.worldObj.provider instanceof IGalacticraftWorldProvider)) {
CommandBase.notifyOperators(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.notifyOperators(sender, this, msg);
return;
}
} else {
if (!isOp) {
CommandBase.notifyOperators(sender, this, "commands.gchouston.noop");
return;
}
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[0], true);
}
if (playerBase != null) {
int dimID = ConfigManagerCore.idDimensionOverworld;
WorldServer worldserver = server.worldServerForDimension(dimID);
if (worldserver == null) {
worldserver = server.worldServerForDimension(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(new ItemStack[0]);
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.notifyOperators(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.getCommandUsage(sender)), new Object[0]);
}
}
use of net.minecraft.command.WrongUsageException in project Galacticraft by micdoodle8.
the class CommandSpaceStationChangeOwner method processCommand.
@Override
public void processCommand(ICommandSender icommandsender, String[] astring) throws CommandException {
String oldOwner = null;
String newOwner = "ERROR";
int stationID = -1;
EntityPlayerMP playerAdmin = PlayerUtil.getPlayerBaseServerFromPlayerUsername(icommandsender.getName(), true);
if (astring.length > 1) {
newOwner = astring[1];
try {
stationID = Integer.parseInt(astring[0]);
} catch (final Exception var6) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssnewowner.wrong_usage", this.getCommandUsage(icommandsender)), new Object[0]);
}
if (stationID < 2) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssnewowner.wrong_usage", this.getCommandUsage(icommandsender)), new Object[0]);
}
try {
SpaceStationWorldData stationData = SpaceStationWorldData.getMPSpaceStationData(null, stationID, null);
if (stationData == null) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssnewowner.wrong_usage", this.getCommandUsage(icommandsender)), new Object[0]);
}
oldOwner = stationData.getOwner();
stationData.getAllowedPlayers().remove(oldOwner);
if (stationData.getSpaceStationName().equals("Station: " + oldOwner)) {
stationData.setSpaceStationName("Station: " + newOwner);
}
stationData.getAllowedPlayers().add(newOwner);
stationData.setOwner(newOwner);
final EntityPlayerMP oldPlayer = PlayerUtil.getPlayerBaseServerFromPlayerUsername(oldOwner, true);
final EntityPlayerMP newPlayer = PlayerUtil.getPlayerBaseServerFromPlayerUsername(newOwner, true);
if (oldPlayer != null) {
GCPlayerStats stats = GCPlayerStats.get(oldPlayer);
SpaceStationWorldData.updateSSOwnership(oldPlayer, oldOwner, stats, stationID, stationData);
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_CLIENT_ID, GCCoreUtil.getDimensionID(oldPlayer.worldObj), new Object[] { WorldUtil.spaceStationDataToString(stats.getSpaceStationDimensionData()) }), oldPlayer);
}
if (newPlayer != null) {
GCPlayerStats stats = GCPlayerStats.get(newPlayer);
SpaceStationWorldData.updateSSOwnership(newPlayer, newOwner.replace(".", ""), stats, stationID, stationData);
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_CLIENT_ID, GCCoreUtil.getDimensionID(oldPlayer.worldObj), new Object[] { WorldUtil.spaceStationDataToString(stats.getSpaceStationDimensionData()) }), newPlayer);
}
} catch (final Exception var6) {
throw new CommandException(var6.getMessage(), new Object[0]);
}
} else {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getCommandUsage(icommandsender)), new Object[0]);
}
if (playerAdmin != null) {
playerAdmin.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.changesuccess", oldOwner, newOwner)));
} else // Console
{
System.out.println(GCCoreUtil.translateWithFormat("gui.spacestation.changesuccess", oldOwner, newOwner));
}
}
Aggregations