Search in sources :

Example 81 with CommandException

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

the class QuestCommandLives method runCommand.

@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
    String action = args[1];
    int value;
    UUID playerID = null;
    try {
        value = Integer.parseInt(args[2]);
    } catch (Exception e) {
        throw getException(command);
    }
    if (args.length >= 4) {
        playerID = this.findPlayerID(server, sender, args[3]);
        if (playerID == null) {
            throw getException(command);
        }
    }
    String pName = playerID == null ? "NULL" : NameCache.INSTANCE.getName(playerID);
    if (action.equalsIgnoreCase("set")) {
        value = Math.max(1, value);
        if (playerID != null) {
            LifeDatabase.INSTANCE.setLives(playerID, value);
            EntityPlayerMP target = server.getPlayerList().getPlayerByUUID(playerID);
            // noinspection ConstantConditions
            if (target != null)
                NetLifeSync.sendSync(new EntityPlayerMP[] { target }, new UUID[] { playerID });
            sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.lives.set_player", pName, value));
        } else {
            for (// TODO: Make this work for offline players
            EntityPlayerMP p : // TODO: Make this work for offline players
            server.getPlayerList().getPlayers()) {
                UUID uuid = QuestingAPI.getQuestingUUID(p);
                LifeDatabase.INSTANCE.setLives(uuid, value);
                NetLifeSync.sendSync(new EntityPlayerMP[] { p }, new UUID[] { uuid });
            }
            sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.lives.set_all", value));
        }
    } else if (action.equalsIgnoreCase("add")) {
        if (playerID != null) {
            int lives = LifeDatabase.INSTANCE.getLives(playerID) + value;
            LifeDatabase.INSTANCE.setLives(playerID, lives);
            EntityPlayerMP target = server.getPlayerList().getPlayerByUUID(playerID);
            // noinspection ConstantConditions
            if (target != null)
                NetLifeSync.sendSync(new EntityPlayerMP[] { target }, new UUID[] { playerID });
            if (value >= 0) {
                sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.lives.add_player", value, pName, lives));
            } else {
                sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.lives.remove_player", Math.abs(value), pName, lives));
            }
        } else {
            for (EntityPlayerMP p : server.getPlayerList().getPlayers()) {
                UUID uuid = QuestingAPI.getQuestingUUID(p);
                int lives = LifeDatabase.INSTANCE.getLives(uuid);
                LifeDatabase.INSTANCE.setLives(uuid, lives + value);
                NetLifeSync.sendSync(new EntityPlayerMP[] { p }, new UUID[] { uuid });
            }
            if (value >= 0) {
                sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.lives.add_all", value));
            } else {
                sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.lives.remove_all", Math.abs(value)));
            }
        }
    } else if (action.equalsIgnoreCase("max")) {
        value = Math.max(1, value);
        QuestSettings.INSTANCE.setProperty(NativeProps.LIVES_MAX, value);
        // TODO: Sync this for display purposes client side
        sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.lives.max", value));
    } else if (action.equalsIgnoreCase("default")) {
        value = Math.max(1, value);
        QuestSettings.INSTANCE.setProperty(NativeProps.LIVES_DEF, value);
        // TODO: Sync this for display purposes client side
        sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.lives.default" + value));
    } else {
        throw getException(command);
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) UUID(java.util.UUID) CommandException(net.minecraft.command.CommandException)

Example 82 with CommandException

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

the class QuestCommandHardcore method runCommand.

@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
    boolean flag = !QuestSettings.INSTANCE.getProperty(NativeProps.HARDCORE);
    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.HARDCORE, flag);
    SaveLoadHandler.INSTANCE.markDirty();
    sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.hardcore", new TextComponentTranslation(QuestSettings.INSTANCE.getProperty(NativeProps.HARDCORE) ? "options.on" : "options.off")));
    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