Search in sources :

Example 1 with CoreStateInitException

use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.

the class CommandEditLootTable 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.editloottable")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length < 1) {
        sender.sendMessage("Insufficient arguments: LootTableid");
        return false;
    }
    if (args.length == 0) {
        return false;
    }
    int LootTableid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaLootTable LootTable = StateManager.getInstance().getConfigurationManager().getLootTable(LootTableid);
            if (LootTable != null) {
                LootTable.sendLootTableSettingsToSender(sender);
            } else {
                sender.sendMessage("LootTable ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: LootTableid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    if (LootTableid < 1) {
        sender.sendMessage("Invalid LootTable id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getLootTable(LootTableid) == null) {
            sender.sendMessage("Cannot locate LootTable id: " + LootTableid);
            return false;
        }
        if (StateManager.getInstance().getConfigurationManager().getLootTable(LootTableid).isOperatorCreated() && !sender.isOp()) {
            sender.sendMessage("This loottable was op created and you are not an op. Only ops can edit op loottable items");
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editLootTable(LootTableid, setting, value);
        sender.sendMessage("Updating setting on LootTable");
    } catch (InvalidLootTableSettingException ne) {
        sender.sendMessage("Invalid LootTable setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) InvalidLootTableSettingException(com.solinia.solinia.Exceptions.InvalidLootTableSettingException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ISoliniaLootTable(com.solinia.solinia.Interfaces.ISoliniaLootTable)

Example 2 with CoreStateInitException

use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.

the class CommandEditNpc 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.editnpc")) {
            player.sendMessage("You do not have permission to access this 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.sendNpcSettingsToSender(sender);
            } else {
                sender.sendMessage("NPC ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: npcid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    // for 'text' based npc settings like trigger texts etc, get the whole thing as a string
    if (args.length > 3 && (setting.toLowerCase().contains("text") || setting.toLowerCase().contains("title"))) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 2)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (npcid < 1) {
        sender.sendMessage("Invalid npc id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getNPC(npcid) == null) {
            sender.sendMessage("Cannot locate npc id: " + npcid);
            return false;
        }
        if (StateManager.getInstance().getConfigurationManager().getNPC(npcid).isOperatorCreated() && !sender.isOp()) {
            sender.sendMessage("This npc was op created and you are not an op. Only ops can edit op npcs");
            return false;
        }
        try {
            StateManager.getInstance().getConfigurationManager().editNPC(npcid, setting, value);
            sender.sendMessage("Updating setting on npc");
        } catch (java.io.IOException e) {
            sender.sendMessage("Failed to update NPC - If this was a request to change custom head data, the mojang servers may be unable to fetch the player skin, try the same command again in a few moments");
        }
    } catch (InvalidNpcSettingException ne) {
        sender.sendMessage("Invalid NPC setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) InvalidNpcSettingException(com.solinia.solinia.Exceptions.InvalidNpcSettingException)

Example 3 with CoreStateInitException

use of com.solinia.solinia.Exceptions.CoreStateInitException 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)

Example 4 with CoreStateInitException

use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.

the class CommandCreateFaction method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    try {
        if (sender instanceof Player) {
            Player player = (Player) sender;
            if (!player.isOp() && !player.hasPermission("solinia.createfaction")) {
                player.sendMessage("You do not have permission to access this command");
                return false;
            }
        }
        if (args.length < 2) {
            sender.sendMessage("Insufficient arguments: basestandingvalue name");
            return false;
        }
        // args
        // defaultnpcid
        // spawngroupname
        int base = Integer.parseInt(args[0]);
        String factionname = "";
        int count = 0;
        for (String entry : args) {
            if (count == 0) {
                count++;
                continue;
            }
            factionname += entry;
            count++;
        }
        if (factionname.equals("")) {
            sender.sendMessage("Blank name not allowed when creating faction");
            return false;
        }
        factionname = factionname.replace(" ", "_").toUpperCase();
        if (StateManager.getInstance().getConfigurationManager().getFaction(factionname) != null) {
            sender.sendMessage("Faction already exists");
            return true;
        }
        ISoliniaFaction faction = SoliniaFactionFactory.CreateFaction(factionname, base, sender.isOp());
        sender.sendMessage("Created faction: " + faction.getId());
        return true;
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 5 with CoreStateInitException

use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.

the class CommandCreateNpcCopy 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.createnpccopy")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length < 2) {
        sender.sendMessage("Insufficient arguments: sourcenpcid npcname");
        return false;
    }
    int npcid = Integer.parseInt(args[0]);
    if (npcid < 1) {
        sender.sendMessage("Invalid npc id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getNPC(npcid) == null) {
            sender.sendMessage("Cannot locate npc id: " + npcid);
            return false;
        }
        String name = "";
        int i = 0;
        for (String element : args) {
            if (i <= 0) {
                i++;
                continue;
            }
            name += element;
            i++;
        }
        if (name.equals("")) {
            sender.sendMessage("Name of NPC cannot be null");
            return false;
        }
        if (name.length() > 16) {
            sender.sendMessage("Name of NPC cannot exceed 16 characters");
            return false;
        }
        name = name.replace(" ", "_");
        ISoliniaNPC npc = SoliniaNPCFactory.CreateNPCCopy(npcid, name, sender.isOp());
        sender.sendMessage("Created NPC Copy: " + npc.getId());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) 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)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