use of com.solinia.solinia.Exceptions.InvalidItemSettingException in project solinia3-core by mixxit.
the class SoliniaItem method editSetting.
@Override
public void editSetting(String setting, String value) throws InvalidItemSettingException, NumberFormatException, CoreStateInitException {
switch(setting.toLowerCase()) {
case "displayname":
if (value.equals(""))
throw new InvalidItemSettingException("Name is empty");
if (value.length() > 36)
throw new InvalidItemSettingException("Name is longer than 36 characters");
setDisplayname(value);
break;
case "worth":
setWorth(Integer.parseInt(value));
break;
case "dye":
setDye(Integer.parseInt(value));
break;
case "allowedclassnames":
String[] allowedclasses = value.split(",");
setAllowedClassNames(Arrays.asList(allowedclasses));
break;
case "color":
setColor(Short.parseShort(value));
break;
case "damage":
setDamage(Integer.parseInt(value));
break;
case "spellscroll":
this.setSpellscroll(Boolean.parseBoolean(value));
break;
case "artifact":
setArtifact(Boolean.parseBoolean(value));
break;
case "baneundead":
setBaneUndead(Integer.parseInt(value));
break;
case "hpregen":
setHpregen(Integer.parseInt(value));
break;
case "mpregen":
setMpregen(Integer.parseInt(value));
break;
case "strength":
setStrength(Integer.parseInt(value));
break;
case "stamina":
setStamina(Integer.parseInt(value));
break;
case "agility":
setAgility(Integer.parseInt(value));
break;
case "dexterity":
setDexterity(Integer.parseInt(value));
break;
case "intelligence":
setIntelligence(Integer.parseInt(value));
break;
case "wisdom":
setWisdom(Integer.parseInt(value));
break;
case "basename":
Material material = Material.valueOf(value.toUpperCase());
setBasename(material.name());
break;
case "charisma":
setCharisma(Integer.parseInt(value));
break;
case "magicresist":
setMagicResist(Integer.parseInt(value));
break;
case "coldresist":
setColdResist(Integer.parseInt(value));
break;
case "fireresist":
setFireResist(Integer.parseInt(value));
break;
case "diseaseresist":
setDiseaseResist(Integer.parseInt(value));
break;
case "poisonresist":
setPoisonResist(Integer.parseInt(value));
break;
case "temporary":
setTemporary(Boolean.parseBoolean(value));
break;
case "abilityid":
setAbilityid(Integer.parseInt(value));
break;
case "weaponabilityid":
setWeaponabilityid(Integer.parseInt(value));
break;
case "petcontrolrod":
setPetControlRod(Boolean.parseBoolean(value));
break;
case "consumable":
setConsumable(Boolean.parseBoolean(value));
break;
case "quest":
setQuest(Boolean.parseBoolean(value));
break;
case "augmentation":
setAugmentation(Boolean.parseBoolean(value));
break;
case "clearallowedclasses":
setAllowedClassNames(new ArrayList<String>());
break;
case "cleardiscoverer":
setDiscoverer("");
break;
case "minlevel":
setMinLevel(Integer.parseInt(value));
break;
case "augmentationfitsslottype":
setAugmentationFitsSlotType(AugmentationSlotType.valueOf(value));
break;
case "ac":
setAC(Integer.parseInt(value));
break;
case "hp":
setHp(Integer.parseInt(value));
break;
case "mana":
setMana(Integer.parseInt(value));
break;
case "experiencebonus":
setExperienceBonus(Boolean.parseBoolean(value));
break;
case "skillmodtype":
setSkillModType(SkillType.valueOf(value));
break;
case "skillmodvalue":
setSkillModValue(Integer.parseInt(value));
break;
case "skillmodtype2":
setSkillModType2(SkillType.valueOf(value));
break;
case "skillmodvalue2":
setSkillModValue2(Integer.parseInt(value));
break;
case "skillmodtype3":
setSkillModType3(SkillType.valueOf(value));
break;
case "skillmodvalue3":
setSkillModValue3(Integer.parseInt(value));
break;
case "skillmodtype4":
setSkillModType4(SkillType.valueOf(value));
break;
case "skillmodvalue4":
setSkillModValue4(Integer.parseInt(value));
break;
case "fingersitem":
setFingersItem(Boolean.parseBoolean(value));
setNeckItem(false);
setShouldersItem(false);
break;
case "neckitem":
setNeckItem(Boolean.parseBoolean(value));
setFingersItem(false);
setShouldersItem(false);
break;
case "shouldersitem":
setShouldersItem(Boolean.parseBoolean(value));
setFingersItem(false);
setNeckItem(false);
break;
default:
throw new InvalidItemSettingException("Invalid Item setting. Valid Options are: displayname,worth,color,damage,hpregen,mpregen,strength,stamina,agility,dexterity,intelligence,wisdom,charisma,abilityid,consumable,crafting,quest,augmentation,cleardiscoverer,clearallowedclasses,ac,hp,mana,experiencebonus,skillmodtype,skillmodvalue,skillmodtype2,skillmodvalue2,skillmodtype3,skillmodvalue3,skillmodtype4,skillmodvalue4,artifact,spellscroll");
}
}
use of com.solinia.solinia.Exceptions.InvalidItemSettingException in project solinia3-core by mixxit.
the class CommandEditItem 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 (!player.isOp() && !player.hasPermission("solinia.edititem")) {
player.sendMessage("You do not have permission to access this command");
return false;
}
}
if (args.length == 0) {
return false;
}
int itemid = Integer.parseInt(args[0]);
if (args.length == 1) {
try {
ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemid);
if (item != null) {
item.sendItemSettingsToSender(sender);
} else {
sender.sendMessage("ITEM ID doesnt exist");
}
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
}
if (args.length < 3) {
sender.sendMessage("Insufficient arguments: itemid setting value");
return false;
}
String setting = args[1];
String value = args[2];
if (args.length > 3 && setting.toLowerCase().contains("lore")) {
value = "";
int current = 0;
for (String entry : args) {
current++;
if (current <= 2)
continue;
value = value + entry + " ";
}
value = value.trim();
}
if (itemid < 1) {
sender.sendMessage("Invalid item id");
return false;
}
value = value.replaceAll("[^A-Za-z0-9_]", "");
try {
ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemid);
if (item == null) {
sender.sendMessage("Cannot locate item id: " + itemid);
return false;
}
if (item.isOperatorCreated() && !sender.isOp()) {
sender.sendMessage("This item was op created and you are not an op. Only ops can edit op items");
return false;
}
StateManager.getInstance().getConfigurationManager().editItem(itemid, setting, value);
sender.sendMessage("Updating setting on item");
} catch (InvalidItemSettingException ne) {
sender.sendMessage("Invalid item setting: " + ne.getMessage());
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
sender.sendMessage(e.getMessage());
}
return true;
}
Aggregations