use of com.solinia.solinia.Exceptions.InvalidLootDropSettingException in project solinia3-core by mixxit.
the class CommandEditLootDrop 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.editlootdrop")) {
player.sendMessage("You do not have permission to access this command");
return false;
}
}
if (args.length < 1) {
sender.sendMessage("Insufficient arguments: lootdropid");
return false;
}
if (args.length == 0) {
return false;
}
int LootDropid = Integer.parseInt(args[0]);
if (args.length == 1) {
try {
ISoliniaLootDrop LootDrop = StateManager.getInstance().getConfigurationManager().getLootDrop(LootDropid);
if (LootDrop != null) {
LootDrop.sendLootDropSettingsToSender(sender);
} else {
sender.sendMessage("LootDrop ID doesnt exist");
}
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
}
if (args.length < 3) {
sender.sendMessage("Insufficient arguments: LootDropid setting value");
return false;
}
String setting = args[1];
String value = args[2];
if (LootDropid < 1) {
sender.sendMessage("Invalid LootDrop id");
return false;
}
try {
if (StateManager.getInstance().getConfigurationManager().getLootDrop(LootDropid) == null) {
sender.sendMessage("Cannot locate LootDrop id: " + LootDropid);
return false;
}
if (StateManager.getInstance().getConfigurationManager().getLootDrop(LootDropid).isOperatorCreated() && !sender.isOp()) {
sender.sendMessage("This lootdrop was op created and you are not an op. Only ops can edit op lootdrop items");
return false;
}
StateManager.getInstance().getConfigurationManager().editLootDrop(LootDropid, setting, value);
sender.sendMessage("Updating setting on LootDrop");
} catch (InvalidLootDropSettingException ne) {
sender.sendMessage("Invalid LootDrop setting: " + ne.getMessage());
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
sender.sendMessage(e.getMessage());
}
return true;
}
use of com.solinia.solinia.Exceptions.InvalidLootDropSettingException in project solinia3-core by mixxit.
the class SoliniaLootDrop method editSetting.
@Override
public void editSetting(String setting, String value) throws InvalidLootDropSettingException, NumberFormatException, CoreStateInitException {
switch(setting.toLowerCase()) {
case "name":
if (value.equals(""))
throw new InvalidLootDropSettingException("Name is empty");
if (value.length() > 25)
throw new InvalidLootDropSettingException("Name is longer than 25 characters");
setName(value);
break;
case "remove":
int itemIdToRemove = Integer.parseInt(value);
if (itemIdToRemove < 1)
throw new InvalidLootDropSettingException("Invalid item id to remove");
for (int i = 0; i < getEntries().size(); i++) {
if (getEntries().get(i).getLootdropid() == itemIdToRemove)
getEntries().remove(i);
}
break;
case "setallchance":
int newChance = Integer.parseInt(value);
for (int i = 0; i < getEntries().size(); i++) {
getEntries().get(i).setChance(newChance);
}
break;
case "setallitemminlevel":
int minLevel = Integer.parseInt(value);
if (minLevel < 1 || minLevel > Utils.getMaxLevel())
throw new InvalidLootDropSettingException("Invalid minlevel");
for (int i = 0; i < getEntries().size(); i++) {
int itemId = getEntries().get(i).getItemid();
StateManager.getInstance().getConfigurationManager().getItem(itemId).setMinLevel(minLevel);
}
break;
case "setallitemfireresist":
int fireresist = Integer.parseInt(value);
if (fireresist < 0 || fireresist > ((Utils.getMaxLevel() / 10) * 5))
throw new InvalidLootDropSettingException("Invalid fireresist value is it too low or too high?");
for (int i = 0; i < getEntries().size(); i++) {
int itemId = getEntries().get(i).getItemid();
StateManager.getInstance().getConfigurationManager().getItem(itemId).setFireResist(fireresist);
}
break;
case "setallitemcoldresist":
int coldresist = Integer.parseInt(value);
if (coldresist < 0 || coldresist > ((Utils.getMaxLevel() / 10) * 5))
throw new InvalidLootDropSettingException("Invalid coldresist value is it too low or too high?");
for (int i = 0; i < getEntries().size(); i++) {
int itemId = getEntries().get(i).getItemid();
StateManager.getInstance().getConfigurationManager().getItem(itemId).setColdResist(coldresist);
}
break;
case "setallitemmagicresist":
int magicresist = Integer.parseInt(value);
if (magicresist < 0 || magicresist > ((Utils.getMaxLevel() / 10) * 5))
throw new InvalidLootDropSettingException("Invalid magicresist value is it too low or too high?");
for (int i = 0; i < getEntries().size(); i++) {
int itemId = getEntries().get(i).getItemid();
StateManager.getInstance().getConfigurationManager().getItem(itemId).setMagicResist(magicresist);
}
break;
case "setallitempoisonresist":
int poisonresist = Integer.parseInt(value);
if (poisonresist < 0 || poisonresist > ((Utils.getMaxLevel() / 10) * 5))
throw new InvalidLootDropSettingException("Invalid poisonresist value is it too low or too high?");
for (int i = 0; i < getEntries().size(); i++) {
int itemId = getEntries().get(i).getItemid();
StateManager.getInstance().getConfigurationManager().getItem(itemId).setPoisonResist(poisonresist);
}
break;
case "setallitemdiseaseresist":
int diseaseresist = Integer.parseInt(value);
if (diseaseresist < 0 || diseaseresist > ((Utils.getMaxLevel() / 10) * 5))
throw new InvalidLootDropSettingException("Invalid diseaseresist value is it too low or too high?");
for (int i = 0; i < getEntries().size(); i++) {
int itemId = getEntries().get(i).getItemid();
StateManager.getInstance().getConfigurationManager().getItem(itemId).setDiseaseResist(diseaseresist);
}
break;
case "setallitemchance":
int chance = Integer.parseInt(value);
if (chance < 1 || chance > 100)
throw new InvalidLootDropSettingException("Invalid chance");
for (ISoliniaLootDropEntry entry : getEntries()) {
entry.setChance(chance);
}
break;
case "setallcount":
int count = Integer.parseInt(value);
if (count < 0 || count > 100)
throw new InvalidLootDropSettingException("Invalid count");
for (ISoliniaLootDropEntry entry : getEntries()) {
entry.setCount(count);
}
break;
default:
throw new InvalidLootDropSettingException("Invalid LootDrop setting. Valid Options are: name,remove,setallchance,setallitemchance,setallcount,setallitemminlevel,setallitemfireresist,setallitemcoldresist,setallitemmagicresist,setallitempoisonresist,setallitemdiseaseresist");
}
}
Aggregations