Search in sources :

Example 56 with CommandSender

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

the class CommandForceLevel 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 < 2) {
        sender.sendMessage("Insufficient arguments (<mcname> <level>)");
        return false;
    }
    String name = args[0];
    int level = Integer.parseInt(args[1]);
    if (level < 1) {
        sender.sendMessage("Level must be greater than 0");
    }
    boolean found = false;
    Double experience = Utils.getExperienceRequirementForLevel(level);
    for (Player currentplayer : Bukkit.getServer().getOnlinePlayers()) {
        if (!currentplayer.getName().toUpperCase().equals(name.toUpperCase()))
            continue;
        try {
            ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(currentplayer);
            found = true;
            if (found) {
                solplayer.setExperience(experience);
                sender.sendMessage("* Player " + name + " set to " + level);
                solplayer.updateMaxHp();
                return true;
            } else {
                sender.sendMessage("Force level command failed. Is that a valid level and a valid online mcaccount?");
                return false;
            }
        } catch (CoreStateInitException e) {
            e.printStackTrace();
            sender.sendMessage(e.getMessage());
        }
    }
    if (found == false) {
        sender.sendMessage("Failed to find player by that minecraft username");
        return false;
    }
    return true;
}
Also used : ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 57 with CommandSender

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

the class CommandListSpells 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) {
        sender.sendMessage("You must provide some text to filter the spells by");
        return true;
    }
    // Filter for name
    int found = 0;
    try {
        for (ISoliniaSpell spell : StateManager.getInstance().getConfigurationManager().getSpells()) {
            found++;
            if (spell.getName().toUpperCase().contains(args[0].toUpperCase())) {
                String spellmessage = spell.getId() + " - " + spell.getName();
                sender.sendMessage(spellmessage);
            }
        }
        if (found == 0) {
            sender.sendMessage("Spell could not be located by search string");
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
        e.printStackTrace();
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 58 with CommandSender

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

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

the class CommandGrantTitle method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender)) {
        sender.sendMessage("This is a Player/Console only command");
        return false;
    }
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp()) {
            player.sendMessage("This is an operator only command");
            return true;
        }
    }
    if (args.length < 2)
        return false;
    if (Bukkit.getPlayer(args[0]) == null) {
        sender.sendMessage("Cannot find player");
        return true;
    }
    String targetTitle = "";
    int current = 0;
    for (String entry : args) {
        current++;
        if (current < 2)
            continue;
        targetTitle = targetTitle + entry + " ";
    }
    targetTitle = targetTitle.trim();
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(Bukkit.getPlayer(args[0]));
        boolean success = solplayer.grantTitle(targetTitle);
        if (success)
            sender.sendMessage("Player title granted: " + targetTitle);
        else
            sender.sendMessage("Player already has title: " + targetTitle);
        return true;
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        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) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 60 with CommandSender

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

the class CommandListItems 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.listitems")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length == 0) {
        sender.sendMessage("You must provide some text to filter the item name by");
        return true;
    }
    // Filter for name
    int found = 0;
    try {
        for (ISoliniaItem item : StateManager.getInstance().getConfigurationManager().getItems()) {
            found++;
            if (item.getDisplayname().toUpperCase().contains(args[0].toUpperCase())) {
                String itemmessage = item.getId() + " - " + item.getDisplayname();
                sender.sendMessage(itemmessage);
            }
        }
        if (found == 0) {
            sender.sendMessage("Item could not be located by search string");
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
        e.printStackTrace();
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) 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