Search in sources :

Example 16 with ComponentBuilder

use of net.md_5.bungee.api.chat.ComponentBuilder in project DiscordBot by LXGaming.

the class DiscordChatCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    StringBuilder stringBuilder = new StringBuilder();
    for (String arg : args) {
        stringBuilder.append(arg + " ");
    }
    if (stringBuilder.toString().trim().length() == 0) {
        sender.sendMessage(new ComponentBuilder("Message cannot be blank!").color(ChatColor.RED).create());
        return;
    }
    Message message = new Message().setChannel(DiscordBotCore.getInstance().getConfiguration().getChannels().get(this.name).getChannel()).setFormat(DiscordBotCore.getInstance().getConfiguration().getChannelFormat().get(this.name)).setName(sender.getName()).setNick("").setServer("Unknown").setMessage(stringBuilder.toString().trim()).setDiscord(true).setMinecraft(true).setConsole(true).setRedis(true);
    if (sender instanceof ProxiedPlayer) {
        ProxiedPlayer player = (ProxiedPlayer) sender;
        if (DiscordBotCore.getInstance().getDatabaseManager().checkDatabase(player.getUniqueId())) {
            player.sendMessage(new ComponentBuilder("DiscordChat disabled. '/DiscordBot Toggle' to enable").color(ChatColor.RED).create());
            return;
        }
        message.setName(player.getName()).setNick(player.getDisplayName());
        if (player.getServer() != null && player.getServer().getInfo() != null) {
            message.setServer(player.getServer().getInfo().getName());
        }
    }
    DiscordBotCore.getInstance().getMessageSender().sendMessage(message);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Message(io.github.lxgaming.discordbot.entries.Message) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 17 with ComponentBuilder

use of net.md_5.bungee.api.chat.ComponentBuilder in project DiscordBot by LXGaming.

the class DiscordBotListener method onMessageMinecraft.

@Override
public void onMessageMinecraft(Message message) {
    if (message.sendRedis() && DiscordBot.getInstance().getRedisBungee() != null) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("message", message.getMessage());
        jsonObject.addProperty("permission", message.getData().get("Permission"));
        DiscordBot.getInstance().getRedisBungee().sendChannelMessage("DiscordBot", new Gson().toJson(jsonObject));
    }
    for (Iterator<ProxiedPlayer> iterator = ProxyServer.getInstance().getPlayers().iterator(); iterator.hasNext(); ) {
        ProxiedPlayer proxiedPlayer = iterator.next();
        if (DiscordBotCore.getInstance().getDatabaseManager().checkDatabase(proxiedPlayer.getUniqueId())) {
            return;
        }
        if (message.getData().get("Permission").equals("*") || proxiedPlayer.hasPermission(message.getData().get("Permission"))) {
            proxiedPlayer.sendMessage(new ComponentBuilder(message.getMessage()).create());
        }
    }
    return;
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 18 with ComponentBuilder

use of net.md_5.bungee.api.chat.ComponentBuilder in project FireAPI by FireBlade-Serv.

the class FireFriends method sendFriendsMessageResquest.

public void sendFriendsMessageResquest(ProxiedPlayer pp, String name) {
    TextComponent accept = new TextComponent("§a§l✔ Accepter§r ");
    accept.setClickEvent(new ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.RUN_COMMAND, "/amis accept " + name));
    accept.setHoverEvent(new HoverEvent(net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aCliquez ici pour accepter sa demande").create()));
    TextComponent base = new TextComponent(this.pre + "§e" + name + "§r vous demande en ami ! ");
    base.addExtra(accept);
    pp.sendMessage(base);
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 19 with ComponentBuilder

use of net.md_5.bungee.api.chat.ComponentBuilder 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();
                            tc.setText(ChatColor.LIGHT_PURPLE + aaAbility.getName() + " Rank " + aarank.getPosition() + ChatColor.RESET + " Cost: " + ChatColor.YELLOW + aarank.getCost() + ChatColor.RESET + " AA points /aa buy " + aarank.getId());
                            String details = ChatColor.GOLD + aaAbility.getName() + " Rank: " + aarank.getPosition() + ChatColor.RESET + "\n" + 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();
                            tc.setText(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 + "\n" + 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();
                        tc.setText(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 + "\n" + 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().getAARank(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.getMaxHealth() < 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 : ISoliniaAARank(com.solinia.solinia.Interfaces.ISoliniaAARank) 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) 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 20 with ComponentBuilder

use of net.md_5.bungee.api.chat.ComponentBuilder 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().size());
                for (SoliniaAccountClaim claim : solplayer.getAccountClaims()) {
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(claim.getItemid());
                    if (item == null)
                        continue;
                    TextComponent tc = new TextComponent();
                    tc.setText(ChatColor.LIGHT_PURPLE + item.getDisplayname() + " /claim claim " + claim.getId());
                    tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(item.asJsonString()).create()));
                    sender.spigot().sendMessage(tc);
                }
                return true;
            case "give":
                if (!sender.isOp())
                    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());
                SoliniaAccountClaim newclaim = new SoliniaAccountClaim();
                newclaim.setId(StateManager.getInstance().getConfigurationManager().getNextAccountClaimId());
                newclaim.setMcname(mcaccountname);
                newclaim.setItemid(itemId);
                newclaim.setClaimed(false);
                StateManager.getInstance().getConfigurationManager().addAccountClaim(newclaim);
                sender.sendMessage("Account claim added!");
                return true;
            case "claim":
                if (!(sender instanceof Player))
                    return false;
                Player claimPlayer = (Player) sender;
                ISoliniaPlayer solClaimPlayer = SoliniaPlayerAdapter.Adapt(claimPlayer);
                sender.sendMessage("Current Claims: " + solClaimPlayer.getAccountClaims().size());
                if (args.length < 2) {
                    sender.sendMessage("That is not a claim id - /claim claim claimid (see /claim list)");
                    return true;
                }
                int seekClaimId = Integer.parseInt(args[1].toUpperCase());
                System.out.println("Looking up claims for player name: " + claimPlayer.getName() + " for claim ID: " + seekClaimId);
                SoliniaAccountClaim claim = StateManager.getInstance().getConfigurationManager().getAccountClaim(claimPlayer.getName().toUpperCase(), seekClaimId);
                if (claim == null) {
                    sender.sendMessage("That is not a valid claim - /claim claim claimid (see /claim list)");
                    return true;
                }
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(claim.getItemid());
                if (item == null) {
                    sender.sendMessage("That is not a valid claim item - /claim claim claimid (see /claim list)");
                    return true;
                }
                claimPlayer.getWorld().dropItemNaturally(claimPlayer.getLocation(), item.asItemStack());
                sender.sendMessage("Claim item dropped at your feet - ID: " + claim.getId());
                StateManager.getInstance().getConfigurationManager().removeClaim(claim.getId());
                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) 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) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Aggregations

ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)24 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)13 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)12 TextComponent (net.md_5.bungee.api.chat.TextComponent)9 Player (org.bukkit.entity.Player)9 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)6 UPlayer (xyz.derkades.ublisk.utils.UPlayer)5 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)4 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)4 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)3 EventHandler (org.bukkit.event.EventHandler)3 OwnedLand (biz.princeps.landlord.util.OwnedLand)2 ConfirmationGUI (biz.princeps.lib.gui.ConfirmationGUI)2 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)2 UUID (java.util.UUID)2 Material (org.bukkit.Material)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 World (org.bukkit.World)2 ArmorStand (org.bukkit.entity.ArmorStand)2 ItemStack (org.bukkit.inventory.ItemStack)2