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);
}
}
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);
}
Aggregations