Search in sources :

Example 81 with CoreStateInitException

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
    }
}
Also used : ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ArrayList(java.util.ArrayList) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 82 with CoreStateInitException

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;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) InvalidNPCEventSettingException(com.solinia.solinia.Exceptions.InvalidNPCEventSettingException)

Example 83 with CoreStateInitException

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;
}
Also used : ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) UUID(java.util.UUID)

Example 84 with CoreStateInitException

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;
}
Also used : ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 85 with CoreStateInitException

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;
}
Also used : Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Aggregations

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)216 Player (org.bukkit.entity.Player)114 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)99 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)43 CommandSender (org.bukkit.command.CommandSender)42 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)41 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)36 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)36 LivingEntity (org.bukkit.entity.LivingEntity)32 ArrayList (java.util.ArrayList)31 Entity (org.bukkit.entity.Entity)21 ItemStack (org.bukkit.inventory.ItemStack)20 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)17 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)16 EventHandler (org.bukkit.event.EventHandler)16 Timestamp (java.sql.Timestamp)13 TextComponent (net.md_5.bungee.api.chat.TextComponent)12 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)11 CraftLivingEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity)11 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)10