use of net.minecraft.command.CommandException in project BetterQuesting by Funwayguy.
the class QuestCommandDelete method runCommand.
@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
if (args[1].equalsIgnoreCase("all")) {
QuestDatabase.INSTANCE.reset();
QuestLineDatabase.INSTANCE.reset();
PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.delete.all"));
} else {
try {
int id = Integer.parseInt(args[1].trim());
IQuest quest = QuestDatabase.INSTANCE.getValue(id);
QuestDatabase.INSTANCE.removeKey(id);
PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.delete.single", new TextComponentTranslation(quest.getUnlocalisedName())));
} catch (Exception e) {
throw getException(command);
}
}
}
use of net.minecraft.command.CommandException in project BetterQuesting by Funwayguy.
the class QuestCommandReset method runCommand.
@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
String action = args[1];
UUID uuid = null;
if (args.length == 3) {
uuid = this.findPlayerID(server, sender, args[2]);
if (uuid == null) {
throw this.getException(command);
}
}
String pName = uuid == null ? "NULL" : NameCache.INSTANCE.getName(uuid);
if (action.equalsIgnoreCase("all")) {
for (IQuest quest : QuestDatabase.INSTANCE.getAllValues()) {
if (uuid != null) {
// Clear progress and state
quest.resetUser(uuid, true);
} else {
quest.resetAll(true);
}
}
if (uuid != null) {
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.player_all", pName));
} else {
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.all_all"));
}
} else {
try {
int id = Integer.parseInt(action.trim());
IQuest quest = QuestDatabase.INSTANCE.getValue(id);
if (uuid != null) {
// Clear progress and state
quest.resetUser(uuid, true);
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.player_single", new TextComponentTranslation(quest.getUnlocalisedName()), pName));
} else {
quest.resetAll(true);
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.all_single", new TextComponentTranslation(quest.getUnlocalisedName())));
}
} catch (Exception e) {
throw getException(command);
}
}
PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
}
use of net.minecraft.command.CommandException in project BetterRain by OreCruncher.
the class CommandRain method processCommand.
@Override
public void processCommand(final ICommandSender sender, final String[] parms) {
try {
final EntityPlayerMP player = getCommandSenderAsPlayer(sender);
final World world = player.worldObj;
final DimensionEffectData data = DimensionEffectData.get(world);
if (parms.length == 1) {
if ("status".compareToIgnoreCase(parms[0]) == 0) {
// Dump out some diagnostics for the currentAurora dimension
player.addChatMessage(new ChatComponentText(statusOutput(world, data)));
} else if ("reset".compareToIgnoreCase(parms[0]) == 0) {
world.provider.resetRainAndThunder();
player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("msg.RainReset")));
} else if ("reload".compareToIgnoreCase(parms[0]) == 0) {
BiomeRegistry.initialize();
BlockRegistry.initialize();
player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("msg.BiomeReload")));
} else {
final double d = parseDouble(parms[0], 0.0D, 100.0D) / 100.0D;
data.setRainIntensity((float) d);
player.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("msg.RainIntensitySet", FORMATTER.format(data.getRainIntensity() * 100))));
}
} else if (parms.length == 2) {
if ("setmin".compareToIgnoreCase(parms[0]) == 0) {
final double d = parseDouble(parms[1], 0.0D, 100.0D) / 100.0D;
data.setMinRainIntensity((float) d);
player.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("msg.MinRainIntensitySet", FORMATTER.format(data.getMinRainIntensity() * 100))));
} else if ("setmax".compareToIgnoreCase(parms[0]) == 0) {
final double d = parseDouble(parms[1], 0.0D, 100.0D) / 100.0D;
data.setMaxRainIntensity((float) d);
player.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("msg.MaxRainIntensitySet", FORMATTER.format(data.getMaxRainIntensity() * 100))));
} else {
throw new CommandException(getCommandUsage(sender));
}
} else {
player.addChatMessage(new ChatComponentText(getCommandUsage(sender)));
}
} catch (final Exception ex) {
ex.printStackTrace();
}
}
use of net.minecraft.command.CommandException in project Kingdom-Keys-Re-Coded by Wehavecookies56.
the class CommandLevelUp method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (sender.getCommandSenderEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) sender.getCommandSenderEntity();
if (args.length == 0 || args.length > 2)
TextHelper.sendFormattedChatMessage("Invalid arguments, usage: " + getUsage(sender), TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
else if (args.length == 1) {
int level = 1;
try {
if (Integer.parseInt(args[0]) < 1 || Integer.parseInt(args[0]) > 100) {
TextHelper.sendFormattedChatMessage("Invalid level, it must be a number between 1 - 100", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
return;
} else
level = Integer.parseInt(args[0]);
} catch (Exception e) {
TextHelper.sendFormattedChatMessage("Invalid level, it must be a number between 1 - 100", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
return;
}
PlayerStatsCapability.IPlayerStats STATS = player.getCapability(ModCapabilities.PLAYER_STATS, null);
STATS.setLevel(1);
STATS.setExperience(0);
if (STATS.getChoice1().equals(Strings.Choice_Sword))
STATS.setStrength(3);
else
STATS.setStrength(1);
if (STATS.getChoice1().equals(Strings.Choice_Shield))
STATS.setDefense(3);
else
STATS.setDefense(1);
if (STATS.getChoice1().equals(Strings.Choice_Staff))
STATS.setMagic(3);
else
STATS.setMagic(1);
STATS.setHP(20);
player.setHealth(20);
while (STATS.getLevel() < level) STATS.addExperience(player, STATS.getExpNeeded(level - 1, STATS.getExperience()));
player.heal(STATS.getHP());
TextHelper.sendFormattedChatMessage("Your level is now " + args[0], TextFormatting.YELLOW, (EntityPlayer) sender.getCommandSenderEntity());
PacketDispatcher.sendTo(new SyncLevelData(player.getCapability(ModCapabilities.PLAYER_STATS, null)), (EntityPlayerMP) player);
} else if (args.length == 2) {
int level = 1;
try {
if (Integer.parseInt(args[0]) < 1 || Integer.parseInt(args[0]) > 100) {
TextHelper.sendFormattedChatMessage("Invalid level, it must be a number between 1 - 100", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
return;
} else
level = Integer.parseInt(args[0]);
} catch (Exception e) {
TextHelper.sendFormattedChatMessage("Invalid level, it must be a number between 1 - 100", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
return;
}
EntityPlayerMP entityplayermp = args.length == 2 ? (EntityPlayerMP) getPlayerFromUsername(args[1]) : getCommandSenderAsPlayer(sender);
PlayerStatsCapability.IPlayerStats STATS = entityplayermp.getCapability(ModCapabilities.PLAYER_STATS, null);
STATS.setLevel(1);
STATS.setExperience(0);
if (STATS.getChoice1().equals(Strings.Choice_Sword))
STATS.setStrength(3);
else
STATS.setStrength(1);
if (STATS.getChoice1().equals(Strings.Choice_Shield))
STATS.setDefense(3);
else
STATS.setDefense(1);
if (STATS.getChoice1().equals(Strings.Choice_Staff))
STATS.setMagic(3);
else
STATS.setMagic(1);
STATS.setHP(20);
entityplayermp.setHealth(20);
while (STATS.getLevel() < level) STATS.addExperience(entityplayermp, STATS.getExpNeeded(level - 1, STATS.getExperience()));
entityplayermp.heal(STATS.getHP());
TextHelper.sendFormattedChatMessage(args[1] + "'s level is now " + args[0], TextFormatting.YELLOW, (EntityPlayer) sender.getCommandSenderEntity());
TextHelper.sendFormattedChatMessage("Your level is now " + args[0], TextFormatting.YELLOW, (EntityPlayer) entityplayermp);
PacketDispatcher.sendTo(new SyncLevelData(entityplayermp.getCapability(ModCapabilities.PLAYER_STATS, null)), (EntityPlayerMP) entityplayermp);
} else
TextHelper.sendFormattedChatMessage("Invalid arguments, usage: " + getUsage(sender), TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
}
}
use of net.minecraft.command.CommandException in project Kingdom-Keys-Re-Coded by Wehavecookies56.
the class CommandDriveLevel method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (sender.getCommandSenderEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) sender.getCommandSenderEntity();
if (args.length == 0 || args.length > 3)
TextHelper.sendFormattedChatMessage("Invalid arguments, usage: " + getUsage(sender), TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
else if (args.length >= 2 && args.length <= 3) {
if (args.length == 3) {
if (getPlayerFromUsername(args[2]) != null) {
player = getPlayerFromUsername(args[2]);
}
}
int level = 1;
try {
// Parse the given level
if (Integer.parseInt(args[1]) < 1 || Integer.parseInt(args[1]) > 7) {
TextHelper.sendFormattedChatMessage("Invalid level, it must be a number between 1 - 7", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
return;
} else
level = Integer.parseInt(args[1]);
} catch (Exception e) {
TextHelper.sendFormattedChatMessage("Invalid level, it must be a number between 1 - 7", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
return;
}
IDriveState DRIVE = player.getCapability(ModCapabilities.DRIVE_STATE, null);
String form = null;
int oldLevel = DRIVE.getDriveLevel("form." + args[0].toLowerCase());
int newLevel = Integer.parseInt(args[1].toString());
switch(args[0].toLowerCase()) {
case "valor":
DRIVE.setDriveLevel(Strings.Form_Valor, newLevel);
form = Utils.translateToLocal(Strings.Form_Valor);
break;
case "wisdom":
DRIVE.setDriveLevel(Strings.Form_Wisdom, Integer.parseInt(args[1].toString()));
form = Utils.translateToLocal(Strings.Form_Wisdom);
break;
case "limit":
DRIVE.setDriveLevel(Strings.Form_Limit, Integer.parseInt(args[1].toString()));
form = Utils.translateToLocal(Strings.Form_Limit);
break;
case "master":
DRIVE.setDriveLevel(Strings.Form_Master, Integer.parseInt(args[1].toString()));
form = Utils.translateToLocal(Strings.Form_Master);
break;
case "final":
DRIVE.setDriveLevel(Strings.Form_Final, Integer.parseInt(args[1].toString()));
form = Utils.translateToLocal(Strings.Form_Final);
break;
}
DRIVE.displayLevelUpMessage(player, "form." + args[0].toLowerCase());
if (oldLevel != 7 && newLevel == 7) {
// Increase
player.getCapability(ModCapabilities.DRIVE_STATE, null).setDriveGaugeLevel(player.getCapability(ModCapabilities.DRIVE_STATE, null).getDriveGaugeLevel() + 1);
player.getCapability(ModCapabilities.DRIVE_STATE, null).setDP(player.getCapability(ModCapabilities.DRIVE_STATE, null).getMaxDP());
PacketDispatcher.sendTo(new SyncDriveData(player.getCapability(ModCapabilities.DRIVE_STATE, null)), (EntityPlayerMP) player);
} else if (oldLevel == 7 && newLevel != 7) {
// Decrease
player.getCapability(ModCapabilities.DRIVE_STATE, null).setDriveGaugeLevel(player.getCapability(ModCapabilities.DRIVE_STATE, null).getDriveGaugeLevel() - 1);
player.getCapability(ModCapabilities.DRIVE_STATE, null).setDP(player.getCapability(ModCapabilities.DRIVE_STATE, null).getMaxDP());
PacketDispatcher.sendTo(new SyncDriveData(player.getCapability(ModCapabilities.DRIVE_STATE, null)), (EntityPlayerMP) player);
}
if (form != null) {
if (args.length == 3)
TextHelper.sendFormattedChatMessage("Succesfully leveled up " + form + " to level " + args[1] + " for player " + args[2], TextFormatting.YELLOW, (EntityPlayer) sender.getCommandSenderEntity());
else
TextHelper.sendFormattedChatMessage("Succesfully leveled up " + form + " to level " + args[1], TextFormatting.YELLOW, (EntityPlayer) sender.getCommandSenderEntity());
} else {
TextHelper.sendFormattedChatMessage("Unknown form " + args[0], TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
}
} else {
TextHelper.sendFormattedChatMessage("Invalid arguments, usage: " + getUsage(sender), TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
}
}
}
Aggregations