Search in sources :

Example 41 with CommandSender

use of org.bukkit.command.CommandSender 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 42 with CommandSender

use of org.bukkit.command.CommandSender 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 43 with CommandSender

use of org.bukkit.command.CommandSender 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 44 with CommandSender

use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.

the class CommandCreateItem 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.createitem")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    ItemStack itemstack = null;
    if (args.length == 0 && sender instanceof Player) {
        Player player = (Player) sender;
        itemstack = player.getInventory().getItemInMainHand();
        if (itemstack.getType().equals(Material.AIR)) {
            player.sendMessage(ChatColor.GRAY + "Empty item in hand. You must hold the item you want to make a new item from");
            return false;
        }
        if (Utils.IsSoliniaItem(itemstack)) {
            player.sendMessage("You can only create a new item from core minecraft items, not solinia items");
            return true;
        }
    } else {
        itemstack = new ItemStack(Material.valueOf(args[0]));
    }
    sender.sendMessage("Building new item based on: " + itemstack.getType().name());
    try {
        ISoliniaItem item = SoliniaItemFactory.CreateItem(itemstack, sender.isOp());
        sender.sendMessage("New Item Created with ID: " + item.getId());
        sender.sendMessage("Use /edititem ID to further edit this item");
    } catch (Exception e) {
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ItemStack(org.bukkit.inventory.ItemStack)

Example 45 with CommandSender

use of org.bukkit.command.CommandSender 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

CommandSender (org.bukkit.command.CommandSender)295 Test (org.junit.Test)171 Player (org.bukkit.entity.Player)94 Matchers.containsString (org.hamcrest.Matchers.containsString)68 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)50 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)43 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)30 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)29 PermissionNode (fr.xephi.authme.permission.PermissionNode)17 BlockCommandSender (org.bukkit.command.BlockCommandSender)16 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)12 Location (org.bukkit.Location)10 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)9 ArrayList (java.util.ArrayList)9 List (java.util.List)9 FoundCommandResult (fr.xephi.authme.command.FoundCommandResult)8 IOException (java.io.IOException)7 Entity (org.bukkit.entity.Entity)7 IEssentialsCommand (com.earth2me.essentials.commands.IEssentialsCommand)6 NoChargeException (com.earth2me.essentials.commands.NoChargeException)6