Search in sources :

Example 46 with CommandSender

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

the class CommandCreateQuest 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 < 1) {
        sender.sendMessage("Insufficient arguments: name");
        return false;
    }
    String questname = args[0];
    if (questname.equals("")) {
        sender.sendMessage("Invalid quest name");
        return false;
    }
    try {
        for (ISoliniaQuest quest : StateManager.getInstance().getConfigurationManager().getQuests()) {
            if (quest.getName().toUpperCase().equals(questname.toUpperCase())) {
                sender.sendMessage("That quest already exists");
                return false;
            }
        }
        SoliniaQuest quest = new SoliniaQuest();
        quest.setId(StateManager.getInstance().getConfigurationManager().getNextQuestId());
        quest.setName(questname);
        StateManager.getInstance().getConfigurationManager().addQuest(quest);
        sender.sendMessage("Quest created! [" + quest.getId() + "]");
    } catch (CoreStateInitException e) {
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : ISoliniaQuest(com.solinia.solinia.Interfaces.ISoliniaQuest) Player(org.bukkit.entity.Player) ISoliniaQuest(com.solinia.solinia.Interfaces.ISoliniaQuest) SoliniaQuest(com.solinia.solinia.Models.SoliniaQuest) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 47 with CommandSender

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

the class CommandEditFaction 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.editfaction")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length == 0) {
        return false;
    }
    int factionid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaFaction solfaction = StateManager.getInstance().getConfigurationManager().getFaction(factionid);
            if (solfaction != null) {
                solfaction.sendFactionSettingsToSender(sender);
            } else {
                sender.sendMessage("FACTION ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: factionid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    // a string
    if (args.length > 3 && (setting.toLowerCase().contains("description") || setting.toLowerCase().contains("factionentry") || setting.toLowerCase().contains("allygrants") || setting.toLowerCase().contains("title"))) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 2)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (factionid < 1) {
        sender.sendMessage("Invalid faction id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getFaction(factionid) == null) {
            sender.sendMessage("Cannot locate faction id: " + factionid);
            return false;
        }
        if (StateManager.getInstance().getConfigurationManager().getFaction(factionid).isOperatorCreated() && !sender.isOp()) {
            sender.sendMessage("This faction was op created and you are not an op. Only ops can faction op items");
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editFaction(factionid, setting, value);
        sender.sendMessage("Updating setting on faction");
    } catch (InvalidFactionSettingException ne) {
        sender.sendMessage("Invalid faction setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        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) InvalidFactionSettingException(com.solinia.solinia.Exceptions.InvalidFactionSettingException) IOException(java.io.IOException)

Example 48 with CommandSender

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

the class CommandEditClass 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 classid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaClass solclass = StateManager.getInstance().getConfigurationManager().getClassObj(classid);
            if (solclass != null) {
                solclass.sendClassSettingsToSender(sender);
            } else {
                sender.sendMessage("CLASS ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: classid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    // a string
    if (args.length > 3 && (setting.toLowerCase().contains("text") || setting.toLowerCase().contains("description") || setting.toLowerCase().contains("title"))) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 2)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (classid < 1) {
        sender.sendMessage("Invalid class id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getClassObj(classid) == null) {
            sender.sendMessage("Cannot locate class id: " + classid);
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editClass(classid, setting, value);
        sender.sendMessage("Updating setting on class");
    } catch (InvalidClassSettingException ne) {
        sender.sendMessage("Invalid class setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : ISoliniaClass(com.solinia.solinia.Interfaces.ISoliniaClass) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) InvalidClassSettingException(com.solinia.solinia.Exceptions.InvalidClassSettingException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 49 with CommandSender

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

the class CommandCreateLootDrop 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.createlootdrop")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length < 1) {
        sender.sendMessage("Insufficient arguments: name");
        return false;
    }
    String lootdropname = "";
    int count = 0;
    for (String entry : args) {
        lootdropname += entry;
        count++;
    }
    if (lootdropname.equals("")) {
        sender.sendMessage("Blank name not allowed when creating lootdrop");
        return false;
    }
    lootdropname = lootdropname.replace(" ", "_").toUpperCase();
    if (lootdropname.length() > 25) {
        sender.sendMessage("Lootdrop name cannot be longer than 25 characters");
        return true;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getLootDrop(lootdropname) != null) {
            sender.sendMessage("LootDrop already exists with the same name");
            return true;
        }
        SoliniaLootFactory.CreateLootDrop(lootdropname, sender.isOp());
        sender.sendMessage("LootDrop created as " + StateManager.getInstance().getConfigurationManager().getLootDrop(lootdropname).getId());
    } catch (CoreStateInitException e) {
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 50 with CommandSender

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

the class CommandCreateMerchantList 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 < 1) {
        sender.sendMessage("Insufficient arguments: name");
        return false;
    }
    String merchantlistname = "";
    for (String entry : args) {
        merchantlistname += entry;
    }
    if (merchantlistname.equals("")) {
        sender.sendMessage("Blank name not allowed when creating merchant list");
        return false;
    }
    merchantlistname.replace(" ", "_");
    try {
        if (StateManager.getInstance().getConfigurationManager().getNPCMerchant(merchantlistname.toUpperCase()) != null) {
            sender.sendMessage("MerchantList already exists with the same name");
            return true;
        }
        SoliniaNPCMerchantFactory.CreateNPCMerchant(merchantlistname);
        sender.sendMessage("MerchantList created");
    } catch (CoreStateInitException e) {
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) 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