Search in sources :

Example 56 with CommandSender

use of net.md_5.bungee.api.CommandSender in project VotingPlugin by Ben12345rocks.

the class AdminVoteHelp method adminHelpText.

/**
 * Admin help text.
 *
 * @param sender the sender
 * @return the array list
 */
public ArrayList<TextComponent> adminHelpText(CommandSender sender) {
    ArrayList<TextComponent> msg = new ArrayList<TextComponent>();
    HashMap<String, TextComponent> unsorted = new HashMap<String, TextComponent>();
    boolean requirePerms = plugin.getConfigFile().getFormatCommandsVoteHelpRequirePermission();
    for (CommandHandler cmdHandle : plugin.getAdminVoteCommand()) {
        if (!requirePerms || cmdHandle.hasPerm(sender)) {
            unsorted.put(cmdHandle.getHelpLineCommand("/adminvote"), cmdHandle.getHelpLine("/adminvote"));
        }
    }
    ArrayList<String> unsortedList = new ArrayList<String>();
    unsortedList.addAll(unsorted.keySet());
    Collections.sort(unsortedList, String.CASE_INSENSITIVE_ORDER);
    for (String cmd : unsortedList) {
        msg.add(unsorted.get(cmd));
    }
    return msg;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CommandHandler(com.bencodez.advancedcore.api.command.CommandHandler)

Example 57 with CommandSender

use of net.md_5.bungee.api.CommandSender in project VotingPlugin by Ben12345rocks.

the class VoteHelp method helpText.

public ArrayList<TextComponent> helpText(CommandSender sender) {
    ArrayList<TextComponent> msg = new ArrayList<TextComponent>();
    HashMap<String, TextComponent> unsorted = new HashMap<String, TextComponent>();
    boolean requirePerms = plugin.getConfigFile().getFormatCommandsVoteHelpRequirePermission();
    String colorStr = plugin.getConfigFile().getFormatCommandsVoteHelpHoverColor();
    ChatColor hoverColor = null;
    try {
        hoverColor = ChatColor.of(colorStr);
    } catch (Exception e) {
        plugin.getLogger().warning("Failed to get color for hover help message");
        e.printStackTrace();
        hoverColor = ChatColor.AQUA;
    }
    for (CommandHandler cmdHandle : plugin.getVoteCommand()) {
        if (!requirePerms || cmdHandle.hasPerm(sender)) {
            unsorted.put(cmdHandle.getHelpLineCommand("/vote"), cmdHandle.getHelpLine("/vote", plugin.getConfigFile().getFormatCommandsVoteHelpLine(), hoverColor));
        }
    }
    ArrayList<String> unsortedList = new ArrayList<String>();
    unsortedList.addAll(unsorted.keySet());
    Collections.sort(unsortedList, String.CASE_INSENSITIVE_ORDER);
    for (String cmd : unsortedList) {
        msg.add(unsorted.get(cmd));
    }
    return msg;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CommandHandler(com.bencodez.advancedcore.api.command.CommandHandler) ChatColor(net.md_5.bungee.api.ChatColor)

Example 58 with CommandSender

use of net.md_5.bungee.api.CommandSender in project solinia3-core by mixxit.

the class CommandClaim method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    try {
        if (args.length < 1) {
            sender.sendMessage(ChatColor.GRAY + "Insufficient arguments (list,claim)");
            return true;
        }
        switch(args[0]) {
            case "list":
                if (!(sender instanceof Player))
                    return false;
                Player player = (Player) sender;
                ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
                sender.sendMessage("Current Claims: " + solplayer.getAccountClaims().stream().filter(claim -> claim.getItemid() > 0).collect(Collectors.toList()).size());
                for (SoliniaAccountClaim claim : solplayer.getAccountClaims().stream().filter(claim -> claim.getItemid() > 0).collect(Collectors.toList())) {
                    // sender.sendMessage("Item: " + claim.getItemid());
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(claim.getItemid());
                    if (item == null)
                        continue;
                    TextComponent tc = new TextComponent();
                    tc.setText(ChatColor.LIGHT_PURPLE + item.getDisplayname() + ChatColor.AQUA + " [ Click here to remove ]");
                    tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim claim " + claim.getId()));
                    tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(item.asJsonString()).create()));
                    sender.spigot().sendMessage(tc);
                }
                sender.sendMessage("Use /claim claim all - to claim all your items");
                return true;
            case "give":
                if (!sender.isOp() && !sender.hasPermission("solinia.claim.give"))
                    return false;
                if (args.length < 3) {
                    sender.sendMessage("That is not a claim id - /claim give mcaccountname itemid");
                    return true;
                }
                String mcaccountname = args[1];
                int itemId = Integer.parseInt(args[2].toUpperCase());
                if (PlayerUtils.AddAccountClaim(mcaccountname, itemId))
                    sender.sendMessage("Account claim added!");
                Player targetplayer = Bukkit.getPlayer(mcaccountname);
                if (targetplayer != null && targetplayer.isOnline()) {
                    targetplayer.sendMessage(ChatColor.YELLOW + "* You seem to have received an item in your /claims");
                }
                return true;
            case "claim":
                if (!(sender instanceof Player))
                    return false;
                Player claimPlayer = (Player) sender;
                ISoliniaPlayer solClaimPlayer = SoliniaPlayerAdapter.Adapt(claimPlayer);
                if (args.length < 2) {
                    sender.sendMessage("That is not a claim id or the word all - /claim claim claimid (see /claim list) or /claim claim all");
                    return true;
                }
                if (args[1].toUpperCase().equals("ALL")) {
                    for (SoliniaAccountClaim claim : StateManager.getInstance().getConfigurationManager().getAccountClaims(claimPlayer.getName().toUpperCase())) {
                        getClaim(claimPlayer, claim.getId());
                    }
                } else {
                    int seekClaimId = Integer.parseInt(args[1].toUpperCase());
                    getClaim(claimPlayer, seekClaimId);
                }
                return true;
            default:
                sender.sendMessage(ChatColor.GRAY + "Invalid arguments (list,claim)");
                return true;
        }
    } catch (CoreStateInitException e) {
    }
    return true;
}
Also used : SoliniaAccountClaim(com.solinia.solinia.Models.SoliniaAccountClaim) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) CommandSender(org.bukkit.command.CommandSender) SoliniaAccountClaim(com.solinia.solinia.Models.SoliniaAccountClaim) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) PlayerUtils(com.solinia.solinia.Utils.PlayerUtils) Player(org.bukkit.entity.Player) StateManager(com.solinia.solinia.Managers.StateManager) ChatMessageType(net.md_5.bungee.api.ChatMessageType) Collectors(java.util.stream.Collectors) CommandExecutor(org.bukkit.command.CommandExecutor) TextComponent(net.md_5.bungee.api.chat.TextComponent) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) SoliniaPlayerAdapter(com.solinia.solinia.Adapters.SoliniaPlayerAdapter) Command(org.bukkit.command.Command) Bukkit(org.bukkit.Bukkit) ChatColor(net.md_5.bungee.api.ChatColor) TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 59 with CommandSender

use of net.md_5.bungee.api.CommandSender in project solinia3-core by mixxit.

the class CommandAA method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player))
        return false;
    Player player = (Player) sender;
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
        player.sendMessage("Current AA Points: " + solplayer.getAAPoints());
        if (args.length < 1) {
            player.sendMessage(ChatColor.GRAY + "Insufficient arguments (list,buy)");
            return true;
        }
        switch(args[0]) {
            case "list":
                int pageno = 1;
                if (args.length > 1)
                    pageno = Integer.parseInt(args[1]);
                pageno = pageno - 1;
                int sizePerPage = 8;
                List<ISoliniaAARank> fullaaranks = solplayer.getBuyableAARanks();
                List<ISoliniaAARank> aaranks = fullaaranks.stream().skip(pageno * sizePerPage).limit(sizePerPage).collect(Collectors.toCollection(ArrayList::new));
                for (ISoliniaAARank aarank : aaranks) {
                    ISoliniaAAAbility aaAbility = StateManager.getInstance().getConfigurationManager().getAAAbility(aarank.getAbilityid());
                    if (aaAbility != null)
                        if (!aaAbility.isEnabled())
                            continue;
                    if (aarank.getCost() <= solplayer.getAAPoints()) {
                        if (solplayer.canPurchaseAlternateAdvancementRank(aaAbility, aarank)) {
                            TextComponent tc = new TextComponent(TextComponent.fromLegacyText(ChatColor.LIGHT_PURPLE + aaAbility.getName() + " Rank " + aarank.getPosition() + ChatColor.RESET + " Cost: " + ChatColor.YELLOW + aarank.getCost() + ChatColor.RESET + " AA " + ChatColor.LIGHT_PURPLE + "[Click to Buy]" + ChatColor.RESET));
                            tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/aa buy " + aarank.getId()));
                            String details = ChatColor.GOLD + aaAbility.getName() + " Rank: " + aarank.getPosition() + ChatColor.RESET + System.lineSeparator() + aarank.getDescription() + ChatColor.RESET + System.lineSeparator() + "Cost: " + aarank.getCost() + " AA points";
                            tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
                            sender.spigot().sendMessage(tc);
                        } else {
                            if (aarank.getLevel_req() <= solplayer.getActualLevel()) {
                                TextComponent tc = new TextComponent(TextComponent.fromLegacyText(ChatColor.GRAY + "NB " + aaAbility.getName() + " Rank " + aarank.getPosition() + ChatColor.GRAY + " Cost: " + ChatColor.GRAY + aarank.getCost() + ChatColor.GRAY + " Cannot purchase yet"));
                                String details = ChatColor.GOLD + aaAbility.getName() + " Rank: " + aarank.getPosition() + ChatColor.RESET + System.lineSeparator() + aarank.getDescription() + ChatColor.RESET;
                                tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
                                sender.spigot().sendMessage(tc);
                            }
                        }
                    } else {
                        TextComponent tc = new TextComponent(TextComponent.fromLegacyText(ChatColor.GRAY + "NA " + aaAbility.getName() + " Rank " + aarank.getPosition() + ChatColor.GRAY + " Cost: " + ChatColor.RED + aarank.getCost() + ChatColor.GRAY + " Insufficient AA points"));
                        String details = ChatColor.GOLD + aaAbility.getName() + " Rank: " + aarank.getPosition() + ChatColor.RESET + System.lineSeparator() + aarank.getDescription() + ChatColor.RESET;
                        tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
                        sender.spigot().sendMessage(tc);
                    }
                }
                player.sendMessage("Displayed Page " + ChatColor.GOLD + (pageno + 1) + ChatColor.RESET + "/" + ChatColor.GOLD + Math.ceil((float) fullaaranks.size() / (float) sizePerPage) + ChatColor.RESET + " (See /aa list <pageno>");
                player.sendMessage("More items may appear when you have more AA points available to spend");
                break;
            case "give":
                if (args.length < 3) {
                    player.sendMessage("That is not a valid player name and amount /aa give playername amount");
                    return true;
                }
                if (!player.isOp()) {
                    player.sendMessage("Op only command");
                    return true;
                }
                Player targetplayer = Bukkit.getPlayer(args[1]);
                if (targetplayer == null) {
                    player.sendMessage("Cannot find player");
                    return true;
                }
                int newpoints = Integer.parseInt(args[2]);
                if (newpoints < 1) {
                    player.sendMessage("Too few points never give them less than 1");
                    return true;
                }
                if (newpoints > 5) {
                    player.sendMessage("Too many points man.... never give them more than 5, its supposed to be hard to achieve");
                    return true;
                }
                ISoliniaPlayer targetsolplayer = SoliniaPlayerAdapter.Adapt(targetplayer);
                targetsolplayer.setAAPoints(targetsolplayer.getAAPoints() + newpoints);
                player.sendMessage("* Granted player " + newpoints + " aa points");
                targetplayer.sendMessage("* You have been granted " + newpoints + " AA points by Operator " + player.getName());
                break;
            case "buy":
                if (args.length < 2) {
                    player.sendMessage("That is not a valid AA rank id - /aa buy aaabilityrankid (see /aa list)");
                    return true;
                }
                int seekRankId = Integer.parseInt(args[1].toUpperCase());
                ISoliniaAARank aarank = StateManager.getInstance().getConfigurationManager().getAARankCache(seekRankId);
                if (aarank == null) {
                    player.sendMessage("That is not a valid AA rank id - /aa buy aaabilityrankid (see /aa list)");
                    return true;
                }
                ISoliniaAAAbility aa = StateManager.getInstance().getConfigurationManager().getAAAbility(aarank.getAbilityid());
                if (aa == null) {
                    player.sendMessage("That is not a valid AA rank id - /aa buy aaabilityrankid (see /aa list)");
                    return true;
                }
                if (!solplayer.canPurchaseAlternateAdvancementRank(aa, aarank)) {
                    player.sendMessage("You cannot buy that AA");
                    return true;
                }
                solplayer.purchaseAlternateAdvancementRank(aa, aarank);
                try {
                    ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt(player);
                    if (player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() < solentity.getMaxHP()) {
                        solplayer.updateMaxHp();
                    }
                } catch (CoreStateInitException e) {
                }
                return true;
            default:
                player.sendMessage(ChatColor.GRAY + "Invalid arguments (list,buy)");
                return true;
        }
    } catch (CoreStateInitException e) {
    }
    return true;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ISoliniaAARank(com.solinia.solinia.Interfaces.ISoliniaAARank) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaAAAbility(com.solinia.solinia.Interfaces.ISoliniaAAAbility) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 60 with CommandSender

use of net.md_5.bungee.api.CommandSender in project solinia3-core by mixxit.

the class CommandListCrafts 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.isOp() && !sender.hasPermission("solinia.listcrafts")) {
        sender.sendMessage("You do not have permission to access this command");
        return false;
    }
    try {
        if (args.length == 0) {
            // Return all
            for (SoliniaCraft entity : StateManager.getInstance().getConfigurationManager().getCrafts()) {
                TextComponent textComponent = new TextComponent();
                String title = "CraftID: " + ChatColor.GOLD + entity.getId() + ChatColor.RESET + " - " + entity.getRecipeName() + " outputId: " + entity.getOutputItem();
                textComponent.setText(title);
                String transfertext = "/editcraft " + entity.getId() + "";
                textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, transfertext));
                sender.spigot().sendMessage(textComponent);
            }
            return true;
        }
        if (args.length > 0 && args[0].equals(".criteria")) {
            try {
                ChatUtils.sendFilterByCriteria(StateManager.getInstance().getConfigurationManager().getCrafts(), sender, args, SoliniaCraft.class);
                return true;
            } catch (CoreStateInitException e) {
                // TODO Auto-generated catch block
                sender.sendMessage(e.getMessage());
                e.printStackTrace();
            }
        }
        // Filter for name
        for (SoliniaCraft entity : StateManager.getInstance().getConfigurationManager().getCrafts()) {
            if (entity.getRecipeName().toUpperCase().contains(args[0].toUpperCase())) {
                TextComponent textComponent = new TextComponent();
                String title = "CraftID: " + ChatColor.GOLD + entity.getId() + ChatColor.RESET + " - " + entity.getRecipeName() + " outputId: " + entity.getOutputItem();
                textComponent.setText(title);
                String transfertext = "/editcraft " + entity.getId() + "";
                textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, transfertext));
                sender.spigot().sendMessage(textComponent);
            }
        }
    } catch (CoreStateInitException e) {
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) SoliniaCraft(com.solinia.solinia.Models.SoliniaCraft) CommandSender(org.bukkit.command.CommandSender)

Aggregations

TextComponent (net.md_5.bungee.api.chat.TextComponent)44 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)24 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)23 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)21 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)18 Player (org.bukkit.entity.Player)17 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)15 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)10 CommandSender (net.md_5.bungee.api.CommandSender)9 ArrayList (java.util.ArrayList)7 ChatColor (net.md_5.bungee.api.ChatColor)6 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)6 CommandSender (org.bukkit.command.CommandSender)5 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)4 ISoliniaRace (com.solinia.solinia.Interfaces.ISoliniaRace)4 HashMap (java.util.HashMap)4 ISoliniaClass (com.solinia.solinia.Interfaces.ISoliniaClass)3 ChatSender (at.pcgamingfreaks.Bungee.Message.Sender.ChatSender)2 SendMethod (at.pcgamingfreaks.Bungee.Message.Sender.SendMethod)2 CommandHandler (com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)2