Search in sources :

Example 76 with CommandException

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

the class CommandPlanetTeleport method execute.

@Override
public void execute(MinecraftServer server, 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) {
                WorldServer worldserver = server.getWorld(GCCoreUtil.getDimensionID(server.worlds[0]));
                BlockPos spawnPoint = worldserver.getSpawnPoint();
                GCPlayerStats stats = GCPlayerStats.get(playerBase);
                stats.setRocketStacks(NonNullList.withSize(2, ItemStack.EMPTY));
                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.notifyCommandListener(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.getUsage(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.math.BlockPos) CommandException(net.minecraft.command.CommandException) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Example 77 with CommandException

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

the class CommandGCHouston method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    EntityPlayerMP playerBase = null;
    boolean isOp = this.isOp(server, sender);
    if (args.length < 2) {
        try {
            if (args.length == 0) {
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
                if (!playerBase.capabilities.isCreativeMode) {
                    if (ConfigManagerCore.challengeMode || !(playerBase.world.provider instanceof IGalacticraftWorldProvider)) {
                        CommandBase.notifyCommandListener(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.notifyCommandListener(sender, this, msg);
                    return;
                }
            } else {
                if (!isOp) {
                    CommandBase.notifyCommandListener(sender, this, "commands.gchouston.noop");
                    return;
                }
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[0], true);
            }
            if (playerBase != null) {
                int dimID = ConfigManagerCore.idDimensionOverworld;
                WorldServer worldserver = server.getWorld(dimID);
                if (worldserver == null) {
                    worldserver = server.getWorld(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(NonNullList.withSize(0, ItemStack.EMPTY));
                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.notifyCommandListener(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.getUsage(sender)), new Object[0]);
    }
}
Also used : 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) WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos)

Example 78 with CommandException

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

the class CommandGCKit method execute.

@Override
public void execute(MinecraftServer server, 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.notifyCommandListener(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.getUsage(sender)), new Object[0]);
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) ItemStack(net.minecraft.item.ItemStack) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Example 79 with CommandException

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

the class CommandSpaceStationAddOwner method execute.

@Override
public void execute(MinecraftServer server, 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.world, ownedStations.getValue(), playerBase);
                        if (var3.equalsIgnoreCase("+all")) {
                            data.setAllowedAll(true);
                            playerBase.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.spacestation.allow_all_true")));
                            return;
                        }
                        if (var3.equalsIgnoreCase("-all")) {
                            data.setAllowedAll(false);
                            playerBase.sendMessage(new TextComponentString(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.sendMessage(new TextComponentString(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.getUsage(sender)), new Object[0]);
    }
    if (playerBase != null) {
        playerBase.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.spacestation.addsuccess", var3)));
    }
}
Also used : SpaceStationWorldData(micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData) WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TextComponentString(net.minecraft.util.text.TextComponentString) CommandException(net.minecraft.command.CommandException) Map(java.util.Map) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 80 with CommandException

use of net.minecraft.command.CommandException in project BetterQuesting by Funwayguy.

the class QuestCommandEdit method runCommand.

@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
    boolean flag = !QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE);
    if (args.length == 2) {
        try {
            if (args[1].equalsIgnoreCase("on")) {
                flag = true;
            } else if (args[1].equalsIgnoreCase("off")) {
                flag = false;
            } else {
                flag = Boolean.parseBoolean(args[1]);
            }
        } catch (Exception e) {
            throw this.getException(command);
        }
    }
    QuestSettings.INSTANCE.setProperty(NativeProps.EDIT_MODE, flag);
    sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.edit", new TextComponentTranslation(QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE) ? "options.on" : "options.off")));
    SaveLoadHandler.INSTANCE.markDirty();
    NetSettingSync.sendSync(null);
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) CommandException(net.minecraft.command.CommandException)

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