use of com.solinia.solinia.Exceptions.InvalidGodSettingException in project solinia3-core by mixxit.
the class CommandEditGod method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player) && !(sender instanceof CommandSender))
return false;
if (sender instanceof Player) {
Player player = (Player) sender;
if (!sender.isOp() && !sender.hasPermission("solinia.editgod")) {
player.sendMessage("This is an operator only command");
return false;
}
}
if (args.length == 0) {
return false;
}
int godid = Integer.parseInt(args[0]);
if (args.length == 1) {
try {
ISoliniaGod solgod = StateManager.getInstance().getConfigurationManager().getGod(godid);
if (solgod != null) {
solgod.sendGodSettingsToSender(sender);
} else {
sender.sendMessage("ID doesnt exist");
}
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
}
if (args.length < 3) {
sender.sendMessage("Insufficient arguments: godid setting value");
return false;
}
String setting = args[1];
String value = args[2];
// a string
if (args.length > 3 && setting.toLowerCase().contains("description")) {
value = "";
int current = 0;
for (String entry : args) {
current++;
if (current <= 2)
continue;
value = value + entry + " ";
}
value = value.trim();
}
if (godid < 1) {
sender.sendMessage("Invalid god id");
return false;
}
try {
if (StateManager.getInstance().getConfigurationManager().getGod(godid) == null) {
sender.sendMessage("Cannot locate god id: " + godid);
return false;
}
StateManager.getInstance().getConfigurationManager().editGod(godid, setting, value);
sender.sendMessage("Updating setting on god");
} catch (InvalidGodSettingException ne) {
sender.sendMessage("Invalid god setting: " + ne.getMessage());
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
sender.sendMessage(e.getMessage());
}
return true;
}
use of com.solinia.solinia.Exceptions.InvalidGodSettingException in project solinia3-core by mixxit.
the class SoliniaGod method editSetting.
@Override
public void editSetting(String setting, String value) throws InvalidGodSettingException, NumberFormatException, CoreStateInitException {
switch(setting.toLowerCase()) {
case "name":
if (value.equals(""))
throw new InvalidGodSettingException("Name is empty");
setName(value);
break;
case "description":
setDescription(value);
break;
case "alignment":
if (!value.toUpperCase().equals("EVIL") && !value.toUpperCase().equals("NEUTRAL") && !value.toUpperCase().equals("GOOD"))
throw new InvalidGodSettingException("Invalid Alignment (GOOD,NEUTRAL,EVIL)");
setAlignment(value.toUpperCase());
break;
case "passiveabilityid":
int abilityid = Integer.parseInt(value);
if (abilityid < 1) {
setPassiveAbilityId(0);
break;
}
try {
ISoliniaSpell ability = StateManager.getInstance().getConfigurationManager().getSpell(abilityid);
if (ability == null)
throw new InvalidGodSettingException("Invalid id");
if (!ability.isBuffSpell() || !SpellUtils.getSpellTargetType(ability.getTargettype()).equals(SpellTargetType.Self))
throw new InvalidGodSettingException("Only Self only buff type spells can be set as a passive spell");
} catch (CoreStateInitException e) {
throw new InvalidGodSettingException("State not initialised");
}
setPassiveAbilityId(abilityid);
break;
default:
throw new InvalidGodSettingException("Invalid setting. Valid Options are: name,description");
}
}
Aggregations