Search in sources :

Example 46 with CommandException

use of net.minecraft.command.CommandException 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]);
    }
}
Also used : Entity(net.minecraft.entity.Entity) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) WorldServer(net.minecraft.world.WorldServer) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) CommandException(net.minecraft.command.CommandException) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException) MinecraftServer(net.minecraft.server.MinecraftServer) WrongUsageException(net.minecraft.command.WrongUsageException) GameProfile(com.mojang.authlib.GameProfile) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.BlockPos)

Example 47 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 48 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 49 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 50 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)

Aggregations

CommandException (net.minecraft.command.CommandException)82 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)33 WrongUsageException (net.minecraft.command.WrongUsageException)31 MinecraftServer (net.minecraft.server.MinecraftServer)22 TextComponentString (net.minecraft.util.text.TextComponentString)19 ICommandSender (net.minecraft.command.ICommandSender)18 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)16 RCConfig (ivorius.reccomplex.RCConfig)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 BlockPos (net.minecraft.util.math.BlockPos)13 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)12 ItemStack (net.minecraft.item.ItemStack)12 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 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)7 Collectors (java.util.stream.Collectors)7