Search in sources :

Example 41 with CommandException

use of net.minecraft.command.CommandException 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));
    }
}
Also used : SpaceStationWorldData(micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData) WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) ChatComponentText(net.minecraft.util.ChatComponentText) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Example 42 with CommandException

use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.

the class CommandPlanetTeleport 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) {
                MinecraftServer server = MinecraftServer.getServer();
                WorldServer worldserver = server.worldServerForDimension(GCCoreUtil.getDimensionID(server.worldServers[0]));
                BlockPos spawnPoint = worldserver.getSpawnPoint();
                GCPlayerStats stats = GCPlayerStats.get(playerBase);
                stats.setRocketStacks(new ItemStack[2]);
                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.notifyOperators(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.getCommandUsage(sender)), new Object[0]);
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.BlockPos) CommandException(net.minecraft.command.CommandException) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 43 with CommandException

use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.

the class CommandJoinSpaceRace method processCommand.

@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
    MinecraftServer server = MinecraftServer.getServer();
    EntityPlayerMP playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(server, sender.getName(), true);
    if (args.length == 0) {
        try {
            if (playerBase != null) {
                GCPlayerStats stats = GCPlayerStats.get(playerBase);
                if (stats.getSpaceRaceInviteTeamID() > 0) {
                    SpaceRaceManager.sendSpaceRaceData(server, playerBase, SpaceRaceManager.getSpaceRaceFromID(stats.getSpaceRaceInviteTeamID()));
                    GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_OPEN_JOIN_RACE_GUI, GCCoreUtil.getDimensionID(playerBase.worldObj), new Object[] { stats.getSpaceRaceInviteTeamID() }), playerBase);
                } else {
                    throw new Exception("You haven't been invited to a space race team!");
                }
            } 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.joinrace.no_team", this.getCommandUsage(sender)), new Object[0]);
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 44 with CommandException

use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.

the class CommandGCAstroMiner method processCommand.

@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
    if (args.length > 2) {
        throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.dimensiontp.too_many", this.getCommandUsage(sender)), new Object[0]);
    }
    if (args.length < 1) {
        throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getCommandUsage(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.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + stats.getAstroMinerCount())));
                        break;
                    case 2:
                        stats.setAstroMinerCount(0);
                        sender.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + 0)));
                        break;
                    case 3:
                        stats.setAstroMinerCount(newvalue);
                        sender.addChatMessage(new ChatComponentText(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;
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) ChatComponentText(net.minecraft.util.ChatComponentText) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Example 45 with CommandException

use of net.minecraft.command.CommandException in project BiomeTweaker by superckl.

the class CommandReloadScript method execute.

@Override
public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) throws CommandException {
    if (args.length != 1) {
        sender.sendMessage(new TextComponentTranslation("biometweaker.msg.reloadscript.usage.text").setStyle(new Style().setColor(TextFormatting.RED)));
        return;
    }
    try {
        final File operateIn = BiomeTweaker.getInstance().getConfig().getBtConfigFolder();
        final File scriptFile = new File(operateIn, args[0]);
        if (!scriptFile.exists() || !scriptFile.isFile()) {
            sender.sendMessage(new TextComponentTranslation("biometweaker.msg.reloadscript.nofile.text", scriptFile.getName()).setStyle(new Style().setColor(TextFormatting.RED)));
            return;
        }
        BiomeTweaker.getInstance().parseScript(scriptFile);
        sender.sendMessage(new TextComponentTranslation("biometweaker.msg.reloadscript.success.text", scriptFile.getName()).setStyle(new Style().setColor(TextFormatting.AQUA)));
    } catch (final Exception e) {
        sender.sendMessage(new TextComponentTranslation("biometweaker.msg.reloadscript.failure.text", args[0]).setStyle(new Style().setColor(TextFormatting.RED)));
        LogHelper.error(String.format("Failed to reload script %s!", args[0]));
        e.printStackTrace();
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Style(net.minecraft.util.text.Style) File(java.io.File) CommandException(net.minecraft.command.CommandException)

Aggregations

CommandException (net.minecraft.command.CommandException)70 WrongUsageException (net.minecraft.command.WrongUsageException)22 MinecraftServer (net.minecraft.server.MinecraftServer)22 ICommandSender (net.minecraft.command.ICommandSender)18 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)18 RCConfig (ivorius.reccomplex.RCConfig)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)15 TextComponentString (net.minecraft.util.text.TextComponentString)15 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)12 BlockPos (net.minecraft.util.math.BlockPos)11 CommandExpecting (ivorius.mcopts.commands.CommandExpecting)10 Expect (ivorius.mcopts.commands.parameters.expect.Expect)10 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)10 RCCommands (ivorius.reccomplex.commands.RCCommands)9 RCP (ivorius.reccomplex.commands.parameters.RCP)8 List (java.util.List)8 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)8 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)7 Collectors (java.util.stream.Collectors)7 Parameters (ivorius.mcopts.commands.parameters.Parameters)6