use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class CommandLoot method sendLootListToSender.
private void sendLootListToSender(CommandSender sender, String itemMatch) {
try {
if (itemMatch.length() < 3) {
sender.sendMessage("Item search must be at least 3 characters: " + itemMatch);
return;
}
List<ISoliniaItem> items = StateManager.getInstance().getConfigurationManager().getItemsByPartialName(itemMatch);
int itemIdLookup = 0;
try {
itemIdLookup = Integer.parseInt(itemMatch);
ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemIdLookup);
items.add(item);
} catch (Exception e) {
}
if (items.size() < 1) {
sender.sendMessage("Could not find item: " + itemMatch);
return;
}
if (items.size() > 1) {
sender.sendMessage("More than one item found with this string, please be more specific: " + itemMatch);
return;
}
String itemname = "";
for (ISoliniaItem item : items) {
itemname = item.getDisplayname();
List<Integer> lootDropIds = StateManager.getInstance().getConfigurationManager().getLootDropIdsWithItemId(item.getId());
if (lootDropIds.size() < 1) {
sender.sendMessage("Item [" + itemname + "] not found in any loot drops");
return;
}
List<Integer> lootTableIds = StateManager.getInstance().getConfigurationManager().getLootTablesWithLootDrops(lootDropIds);
if (lootTableIds.size() < 1) {
sender.sendMessage("Item [" + itemname + "] not found in any loot tables");
return;
}
List<String> matchingNpcList = new ArrayList<String>();
String currentLine = "";
for (ISoliniaNPC npc : StateManager.getInstance().getConfigurationManager().getNPCs()) {
if (!lootTableIds.contains(npc.getLoottableid()))
continue;
if ((currentLine + npc.getName() + " ").length() > 2000) {
matchingNpcList.add(currentLine);
currentLine = "";
}
currentLine += npc.getName() + " ";
}
if (!currentLine.equals("")) {
matchingNpcList.add(currentLine);
}
for (String line : matchingNpcList) {
sender.sendMessage("Item [" + itemname + "] found on: " + line);
}
}
} catch (CoreStateInitException e) {
// ignore it
}
}
use of com.solinia.solinia.Exceptions.CoreStateInitException 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;
}
use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class CommandGroup method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// TODO Auto-generated method stub
if (!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
try {
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
String groupname = "You have no group";
if (solplayer.getGroup() != null) {
UUID ownerid = solplayer.getGroup().getOwner();
Player owner = Bukkit.getPlayer(ownerid);
if (owner != null) {
groupname = owner.getDisplayName() + "'s group";
}
}
if (args.length == 0) {
player.sendMessage("Your group: " + groupname);
player.sendMessage("Valid commands are: /group invite <name>, /group list, /group accept, /group decline, /group leave,/g <msg>");
return true;
}
if (args[0].equals("invite")) {
if (args.length == 2) {
Player target = Bukkit.getPlayer(args[1]);
if (target != null) {
if (!target.equals(player)) {
StateManager.getInstance().invitePlayerToGroup(player, target);
} else {
player.sendMessage("You cannot invite yourself to a group");
}
} else {
player.sendMessage(args[1] + " is not online");
}
return true;
} else {
player.sendMessage("Incorrect arguments [" + args.length + "] for group invite - see /group");
return true;
}
}
if (args[0].equals("leave")) {
if (solplayer.getGroup() == null)
return true;
solplayer.getGroup().removePlayer(player);
return true;
}
if (args[0].equals("list")) {
if (solplayer.getGroup() == null)
return true;
solplayer.getGroup().sendGroupList(player);
return true;
}
if (args[0].equals("accept")) {
StateManager.getInstance().acceptGroupInvite(player);
return true;
}
if (args[0].equals("decline")) {
StateManager.getInstance().declineGroupInvite(player);
return true;
}
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
return true;
}
use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class CommandHideOoc method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player) {
try {
ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt((Player) sender);
if (solPlayer.isOocEnabled() == false) {
solPlayer.setOocEnabled(true);
sender.sendMessage("Ooc enabled");
} else {
solPlayer.setOocEnabled(false);
sender.sendMessage("Ooc disabled");
}
} catch (CoreStateInitException e) {
return false;
}
return true;
}
return false;
}
use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class CommandForename method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("This is a Player only command");
return false;
}
Player player = (Player) sender;
try {
player.sendMessage("Old Forename: " + SoliniaPlayerAdapter.Adapt(player).getForename());
if (args.length == 0)
return false;
if (!StateManager.getInstance().getPlayerManager().IsNewNameValid(args[0], SoliniaPlayerAdapter.Adapt(player).getLastname())) {
player.sendMessage("Forename + Lastname length must be between 3 and 14 characters and not in use by other players");
String newname = args[0];
if (!SoliniaPlayerAdapter.Adapt(player).getLastname().equals(""))
newname = args[0] + "_" + SoliniaPlayerAdapter.Adapt(player).getLastname();
player.sendMessage("Target name [" + newname + "] length: " + newname.length());
return false;
}
SoliniaPlayerAdapter.Adapt(player).setForename(args[0]);
sender.sendMessage("* Forename set");
SoliniaPlayerAdapter.Adapt(player).updateDisplayName();
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
return false;
}
Aggregations