use of com.solinia.solinia.Exceptions.InvalidNPCEventSettingException in project solinia3-core by mixxit.
the class SoliniaNPCEventHandler method editTriggerEventSetting.
@Override
public void editTriggerEventSetting(String setting, String value) throws InvalidNPCEventSettingException {
switch(setting.toLowerCase()) {
case "randomisedgearsuffix":
setRandomisedGearSuffix(value);
break;
case "title":
setTitle(value);
break;
case "awardstitle":
setAwardsTitle(Boolean.parseBoolean(value));
break;
case "triggerdata":
if (value.equals(""))
throw new InvalidNPCEventSettingException("Triggerdata is empty");
if (value.contains(" "))
throw new InvalidNPCEventSettingException("Triggerdata can only be one value");
setTriggerdata(value.toUpperCase());
break;
case "chatresponse":
if (value.equals(""))
throw new InvalidNPCEventSettingException("Chatresponse is empty");
setChatresponse(value);
break;
case "requiresquest":
int questid = Integer.parseInt(value);
if (questid < 1)
throw new InvalidNPCEventSettingException("Invalid quest id");
try {
ISoliniaQuest quest = StateManager.getInstance().getConfigurationManager().getQuest(questid);
if (quest == null)
throw new InvalidNPCEventSettingException("Invalid quest id");
} catch (CoreStateInitException e) {
throw new InvalidNPCEventSettingException("State not initialised");
}
setRequiresQuest(questid);
break;
case "awardsquest":
int aquestid = Integer.parseInt(value);
if (aquestid < 1)
throw new InvalidNPCEventSettingException("Invalid quest id");
try {
ISoliniaQuest quest = StateManager.getInstance().getConfigurationManager().getQuest(aquestid);
if (quest == null)
throw new InvalidNPCEventSettingException("Invalid quest id");
} catch (CoreStateInitException e) {
throw new InvalidNPCEventSettingException("State not initialised");
}
setAwardsQuest(aquestid);
break;
case "requiresquestflag":
setRequiresQuestFlag(value);
break;
case "awardsquestflag":
setAwardsQuestFlag(value);
break;
case "teleportresponse":
try {
String[] zonedata = value.split(",");
// Dissasemble the value to ensure it is correct
String world = zonedata[0];
double x = Double.parseDouble(zonedata[1]);
double y = Double.parseDouble(zonedata[2]);
double z = Double.parseDouble(zonedata[3]);
setTeleportResponse(world + "," + x + "," + y + "," + z);
break;
} catch (Exception e) {
throw new InvalidNPCEventSettingException("Teleport zone value must be in format: world,x,y,z");
}
case "awardsrandomisedgear":
setAwardsRandomisedGear(Boolean.parseBoolean(value));
break;
case "awardsitem":
int itemId = Integer.parseInt(value);
if (itemId < 1)
throw new InvalidNPCEventSettingException("Invalid item ID");
if (getAwardsQuestFlag() == null || getAwardsQuestFlag().equals(""))
throw new InvalidNPCEventSettingException("You cannot set an awardsitem to a npc event handler unless the npc awards a quest flag - this is to prevent duplicated awards");
try {
ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
if (item == null)
throw new InvalidNPCEventSettingException("Invalid item id");
} catch (CoreStateInitException e) {
throw new InvalidNPCEventSettingException("State not initialised");
}
setAwardsItem(itemId);
break;
default:
throw new InvalidNPCEventSettingException("Invalid NPC Event setting. Valid Options are: triggerdata,chatresponse,interactiontype,requiresquest,awardsquest,requiresquestflag,awardsquestflag,awardsitem");
}
}
use of com.solinia.solinia.Exceptions.InvalidNPCEventSettingException in project solinia3-core by mixxit.
the class CommandEditNpcEvent 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.sendMessage("This is an operator only command");
return false;
}
}
if (args.length == 0) {
return false;
}
int npcid = Integer.parseInt(args[0]);
if (args.length == 1) {
try {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
if (npc != null) {
npc.sendNPCEvents(sender);
} else {
sender.sendMessage("NPC ID doesnt exist");
}
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
}
String triggertext = args[1];
if (args.length == 2) {
try {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
if (npc != null) {
boolean found = false;
for (ISoliniaNPCEventHandler handler : npc.getEventHandlers()) {
if (handler.getTriggerdata().toUpperCase().equals(triggertext.toUpperCase())) {
found = true;
npc.sendNPCEvent(sender, triggertext);
}
}
if (found == false) {
sender.sendMessage("Trigger event doesnt exist on npc");
}
} else {
sender.sendMessage("NPC ID doesnt exist");
}
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
}
if (args.length < 4) {
sender.sendMessage("Insufficient arguments: npcid triggertext setting value");
return false;
}
String setting = args[2];
String value = args[3];
// for 'text' based npc settings like trigger texts etc, get the whole thing as a string
if (args.length > 4 && (setting.toLowerCase().equals("chatresponse") || setting.toLowerCase().equals("title") || setting.toLowerCase().equals("randomisedgearsuffix"))) {
value = "";
int current = 0;
for (String entry : args) {
current++;
if (current <= 3)
continue;
value = value + entry + " ";
}
value = value.trim();
}
if (npcid < 1) {
sender.sendMessage("Invalid NPC id");
return false;
}
try {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
if (npc != null) {
boolean found = false;
for (ISoliniaNPCEventHandler handler : npc.getEventHandlers()) {
if (handler.getTriggerdata().toUpperCase().equals(triggertext.toUpperCase())) {
found = true;
}
}
if (found == false) {
sender.sendMessage("Trigger event doesnt exist on npc");
return false;
}
} else {
sender.sendMessage("NPC ID doesnt exist");
return false;
}
StateManager.getInstance().getConfigurationManager().editNpcTriggerEvent(npcid, triggertext, setting, value);
sender.sendMessage("Updating setting on NPC Event");
} catch (InvalidNPCEventSettingException ne) {
sender.sendMessage("Invalid NPC Event Setting: " + ne.getMessage());
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
sender.sendMessage(e.getMessage());
}
return true;
}
Aggregations