Search in sources :

Example 1 with SoliniaNPCEventHandler

use of com.solinia.solinia.Models.SoliniaNPCEventHandler in project solinia3-core by mixxit.

the class CommandCreateNPCEvent 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 < 4) {
        sender.sendMessage("Insufficient arguments: npcid eventtype trigger response");
        return false;
    }
    String response = "";
    int counter = 0;
    for (String entry : args) {
        counter++;
        if (counter < 4)
            continue;
        response += entry + " ";
    }
    if (response.length() > 0) {
        response = response.trim();
    }
    if (response.equals("")) {
        sender.sendMessage("Blank responses not allowed when creating an npc event");
        return false;
    }
    Integer npcid = Integer.parseInt(args[0]);
    String eventtype = args[1];
    String trigger = args[2];
    if (npcid < 1) {
        sender.sendMessage("NPC does not exist");
        return false;
    }
    try {
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
        if (npc == null) {
            sender.sendMessage("NPC does not exist");
            return false;
        }
        boolean foundtype = false;
        InteractionType interactiontype = null;
        for (InteractionType type : InteractionType.values()) {
            if (!type.name().toUpperCase().equals(eventtype))
                continue;
            foundtype = true;
            interactiontype = type;
            break;
        }
        if (foundtype == false) {
            sender.sendMessage("Cannot find interaction type specified");
            return false;
        }
        if (trigger == null || trigger.equals("")) {
            sender.sendMessage("Trigger provided is empty");
            return false;
        }
        boolean exists = false;
        for (ISoliniaNPCEventHandler seek : npc.getEventHandlers()) {
            if (!seek.getInteractiontype().equals(interactiontype))
                continue;
            if (!seek.getTriggerdata().toUpperCase().equals(trigger))
                continue;
            exists = true;
        }
        if (exists) {
            sender.sendMessage("Event handler already exists");
            return false;
        }
        SoliniaNPCEventHandler eventhandler = new SoliniaNPCEventHandler();
        eventhandler.setNpcId(npc.getId());
        eventhandler.setInteractiontype(interactiontype);
        eventhandler.setTriggerdata(trigger.toUpperCase());
        eventhandler.setChatresponse(response);
        npc.addEventHandler(eventhandler);
        sender.sendMessage("New EventHandler added to NPC");
    } catch (CoreStateInitException e) {
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : InteractionType(com.solinia.solinia.Models.InteractionType) SoliniaNPCEventHandler(com.solinia.solinia.Models.SoliniaNPCEventHandler) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) 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)

Aggregations

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)1 ISoliniaNPCEventHandler (com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler)1 InteractionType (com.solinia.solinia.Models.InteractionType)1 SoliniaNPCEventHandler (com.solinia.solinia.Models.SoliniaNPCEventHandler)1 CommandSender (org.bukkit.command.CommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1