Search in sources :

Example 1 with ComponentBuilder

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

the class Solinia3CoreItemPickupListener method PickupItem.

@EventHandler
public void PickupItem(PlayerPickupItemEvent e) {
    ItemStack pickedUpItemStack = e.getItem().getItemStack();
    // Replace oxygen items with durability items
    if (pickedUpItemStack.getEnchantmentLevel(Enchantment.OXYGEN) > 999) {
        e.getPlayer().sendMessage("Detected an item in the old format, converting to the new format. Please drop all your old items and pick them up if you are having problems with them");
        try {
            ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItemByOxygen(pickedUpItemStack);
            if (pickedUpItemStack != null) {
                if (latestitem != null) {
                    ItemStack latestitemstack = latestitem.asItemStack();
                    pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
                } else {
                    // this is an item that is broken
                    e.getPlayer().sendMessage("This item is no longer implemented");
                    Utils.CancelEvent(e);
                    e.getItem().remove();
                }
            }
        } catch (CoreStateInitException eOxy) {
        }
    }
    String temporaryGuid = null;
    Integer augmentationItemId = null;
    try {
        if (Utils.IsSoliniaItem(pickedUpItemStack) && pickedUpItemStack.getType().equals(Material.ENCHANTED_BOOK)) {
            e.getPlayer().sendMessage(ChatColor.GRAY + "You have picked up an ability! To use it, hold it in your hand and right click!");
            ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItem(pickedUpItemStack);
            if (pickedUpItemStack != null) {
                if (latestitem != null) {
                    ItemStack latestitemstack = latestitem.asItemStack();
                    pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
                } else {
                    // this is an item that is broken
                    e.getPlayer().sendMessage("This item is no longer implemented");
                    Utils.CancelEvent(e);
                    e.getItem().remove();
                }
            }
            if (latestitem.getDiscoverer() == null || latestitem.getDiscoverer().equals("")) {
                latestitem.setDiscoverer(e.getPlayer().getCustomName());
                e.getPlayer().getServer().broadcastMessage(ChatColor.YELLOW + "* " + latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
                StateManager.getInstance().getChannelManager().sendToDiscordMC(null, StateManager.getInstance().getChannelManager().getDefaultDiscordChannel(), latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
            }
        }
        if (Utils.IsSoliniaItem(pickedUpItemStack) && !(pickedUpItemStack.getType().equals(Material.ENCHANTED_BOOK))) {
            Map<Enchantment, Integer> oldenchantments = pickedUpItemStack.getEnchantments();
            ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItem(pickedUpItemStack);
            if (latestitem.getDiscoverer() == null || latestitem.getDiscoverer().equals("")) {
                latestitem.setDiscoverer(e.getPlayer().getCustomName());
                e.getPlayer().getServer().broadcastMessage(ChatColor.YELLOW + "* " + latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
                StateManager.getInstance().getChannelManager().sendToDiscordMC(null, StateManager.getInstance().getChannelManager().getDefaultDiscordChannel(), latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
            }
            if (pickedUpItemStack != null) {
                ItemStack latestitemstack = latestitem.asItemStack();
                // We need to store this information before we change the itemmeta, so we can update it afterwards
                if (latestitem.isTemporary()) {
                    temporaryGuid = ItemStackUtils.getTemporaryItemGuid(pickedUpItemStack);
                }
                augmentationItemId = ItemStackUtils.getAugmentationItemId(pickedUpItemStack);
                // Now go and replace the itemmeta
                pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
                // Now re-apply enchantments that it had before
                for (Map.Entry<Enchantment, Integer> entry : oldenchantments.entrySet()) {
                    Enchantment key = entry.getKey();
                    Integer value = entry.getValue();
                    if (value < 1000) {
                        pickedUpItemStack.addUnsafeEnchantment(key, value);
                    }
                }
                // Since the item is temporary, attempt to apply the temporary timestamp it had prior to this
                if (latestitem.isTemporary()) {
                    pickedUpItemStack.setItemMeta(ItemStackUtils.applyTemporaryStamp(pickedUpItemStack, temporaryGuid));
                }
                if (augmentationItemId != null && augmentationItemId != 0) {
                    pickedUpItemStack.setItemMeta(ItemStackUtils.applyAugmentationToItemStack(pickedUpItemStack, augmentationItemId));
                }
            }
        }
        // group messages
        if (Utils.IsSoliniaItem(pickedUpItemStack)) {
            ISoliniaItem item;
            try {
                item = SoliniaItemAdapter.Adapt(pickedUpItemStack);
                if (item.getAllowedClassNames().size() > 0) {
                    ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(e.getPlayer());
                    if (solPlayer.getGroup() != null && solPlayer.getGroup().getMembers() != null)
                        for (UUID playerUuid : solPlayer.getGroup().getMembers()) {
                            if (playerUuid.equals(e.getPlayer().getUniqueId()))
                                continue;
                            Player groupMember = Bukkit.getPlayer(playerUuid);
                            ISoliniaPlayer groupSolPlayer = SoliniaPlayerAdapter.Adapt(groupMember);
                            if (groupSolPlayer != null) {
                                if (groupSolPlayer.getClassObj() != null)
                                    if (item.getAllowedClassNames().contains(groupSolPlayer.getClassObj().getName().toUpperCase())) {
                                        TextComponent tc = new TextComponent();
                                        tc.setText("* " + groupSolPlayer.getFullName() + " picked up an item of interest to your class: [" + ChatColor.AQUA + item.getDisplayname() + ChatColor.RESET + "]");
                                        tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(item.asJsonString()).create()));
                                        groupSolPlayer.getBukkitPlayer().spigot().sendMessage(tc);
                                    }
                            }
                        }
                }
            } catch (SoliniaItemException e1) {
            }
        }
    } catch (CoreStateInitException coreException) {
    // do nothing
    }
}
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) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) UUID(java.util.UUID) Map(java.util.Map) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ComponentBuilder

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

the class CommandCharacter 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);
        if (args.length == 0) {
            player.sendMessage("Your Characters: ");
            String main = "ALT";
            if (solplayer.isMain()) {
                main = "MAIN";
            }
            player.sendMessage("- " + ChatColor.LIGHT_PURPLE + solplayer.getFullNameWithTitle() + ChatColor.RESET + " " + main + " - " + ChatColor.GREEN + "ACTIVE" + ChatColor.RESET);
            for (ISoliniaPlayer character : StateManager.getInstance().getPlayerManager().getCharactersByPlayerUUID(player.getUniqueId())) {
                if (character.getCharacterId().equals(solplayer.getCharacterId()))
                    continue;
                if (character.isMain()) {
                    main = "MAIN";
                } else {
                    main = "ALT";
                }
                TextComponent tc = new TextComponent();
                tc.setText("- " + ChatColor.LIGHT_PURPLE + character.getFullNameWithTitle() + ChatColor.RESET + " " + main + " - ");
                String details = ChatColor.GOLD + character.getFullNameWithTitle() + " Level: " + character.getLevel() + ChatColor.RESET;
                TextComponent tc2 = new TextComponent();
                String changetext = "/character load " + character.getCharacterId().toString();
                if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
                    tc2.setText(ChatColor.RED + "Already changed this session" + ChatColor.RESET);
                } else {
                    tc2.setText(ChatColor.AQUA + "[Click to Switch]" + ChatColor.RESET);
                    tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, changetext));
                }
                tc.addExtra(tc2);
                tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
                sender.spigot().sendMessage(tc);
            }
            player.sendMessage("Note, new characters may not be visible for up to 15 minutes");
            player.sendMessage("Use '/character new' to create a new character");
        } else {
            switch(args[0].toUpperCase()) {
                case "NEW":
                    if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
                        player.sendMessage("You can only change your character once per server session. Please wait for the next 4 hourly restart");
                        return true;
                    }
                    ISoliniaPlayer newPlayer = StateManager.getInstance().getPlayerManager().createNewPlayerAlt(plugin, player);
                    if (newPlayer != null) {
                        player.sendMessage("Your character has been stored and a new character created");
                        player.sendMessage("Please check you have not dropped any items due to your character change");
                    } else {
                        player.sendMessage("Problem creating your new character");
                    }
                    break;
                case "LOAD":
                    if (args.length < 2) {
                        player.sendMessage("You must provide the character UUID");
                        return true;
                    }
                    if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
                        player.sendMessage("You can only change your character once per server session. Please wait for the next 4 hourly restart");
                        return true;
                    }
                    UUID characterUUID = UUID.fromString(args[1]);
                    ISoliniaPlayer loadedPlayer = StateManager.getInstance().getPlayerManager().loadPlayerAlt(plugin, player, characterUUID);
                    if (loadedPlayer != null) {
                        player.sendMessage("Your character has been stored and your new character loaded");
                        player.sendMessage("Please check you have not dropped any items due to your character change");
                    } else {
                        player.sendMessage("Problem loading requested character");
                    }
                    break;
                default:
                    player.sendMessage("Unknown character subcommand");
                    break;
            }
        }
    } 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) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) UUID(java.util.UUID) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 3 with ComponentBuilder

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

the class Utils method sendRaceInfo.

public static void sendRaceInfo(CommandSender sender) throws CoreStateInitException {
    List<ISoliniaClass> classes = StateManager.getInstance().getConfigurationManager().getClasses();
    for (ISoliniaRace race : StateManager.getInstance().getConfigurationManager().getRaces()) {
        if (race.isAdmin())
            continue;
        String classBuilder = "";
        for (ISoliniaClass solclass : classes) {
            if (solclass.getValidRaces().contains(race.getId()))
                classBuilder += solclass.getName() + " ";
        }
        TextComponent tc = new TextComponent();
        tc.setText(ChatColor.RED + "~ RACE: " + ChatColor.GOLD + race.getName().toUpperCase() + ChatColor.GRAY + " [" + race.getId() + "] - " + ChatColor.RESET);
        TextComponent tc2 = new TextComponent();
        tc2.setText("Hover for more details");
        String details = ChatColor.GOLD + race.getName() + ChatColor.RESET + "\nRecommended Alignment: " + ChatColor.GOLD + race.getAlignment() + ChatColor.RESET + "\n" + race.getDescription() + "\nSTR: " + ChatColor.GOLD + race.getStrength() + ChatColor.RESET + " STA: " + ChatColor.GOLD + race.getStamina() + ChatColor.RESET + " AGI: " + ChatColor.GOLD + race.getAgility() + ChatColor.RESET + " DEX: " + ChatColor.GOLD + race.getDexterity() + ChatColor.RESET + " INT: " + ChatColor.GOLD + race.getIntelligence() + ChatColor.RESET + " WIS: " + ChatColor.GOLD + race.getWisdom() + ChatColor.RESET + " CHA: " + ChatColor.GOLD + race.getCharisma() + ChatColor.GOLD + " \nClasses: " + ChatColor.RESET + classBuilder;
        tc2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
        tc.addExtra(tc2);
        sender.spigot().sendMessage(tc);
    }
}
Also used : ISoliniaClass(com.solinia.solinia.Interfaces.ISoliniaClass) TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) ISoliniaRace(com.solinia.solinia.Interfaces.ISoliniaRace) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 4 with ComponentBuilder

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

the class SelectorMenu method onOptionClick.

@Override
public boolean onOptionClick(OptionClickEvent event) {
    int slot = event.getPosition();
    Player player = event.getPlayer();
    String action = config.getString("menu." + slot + ".action");
    if (action == null) {
        // If the action is null (so 'slot' is not found in the config) it is probably a wildcard
        action = config.getString("menu.-1.action");
        if (action == null) {
            // If it is still null it must be missing
            action = "msg:Action missing";
        }
    }
    if (action.startsWith("url:")) {
        // Send url message
        String url = action.substring(4);
        String message = Colors.parseColors(config.getString("url-message", "&3&lClick here"));
        player.spigot().sendMessage(new ComponentBuilder(message).event(new ClickEvent(ClickEvent.Action.OPEN_URL, url)).create());
        return true;
    } else if (action.startsWith("cmd:")) {
        // Execute command
        String command = action.substring(4);
        // Send command 2 ticks later to let the GUI close first (for commands that open a GUI)
        Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(), () -> {
            Bukkit.dispatchCommand(player, Main.PLACEHOLDER_API.parsePlaceholders(player, command));
        }, 2);
        return true;
    } else if (action.startsWith("bungeecmd:")) {
        // BungeeCord command
        String command = action.substring(10);
        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), String.format("sync player bungee %s %s", player.getName(), Main.PLACEHOLDER_API.parsePlaceholders(player, command)));
        return true;
    } else if (action.startsWith("sel:")) {
        // Open selector
        String configName = action.substring(4);
        FileConfiguration config = Main.getConfigurationManager().getByName(configName);
        if (config == null) {
            player.sendMessage(ChatColor.RED + "This server selector does not exist.");
            return true;
        } else {
            new SelectorMenu(player, config).open();
            return false;
        }
    } else if (action.startsWith("world:")) {
        // Teleport to world
        String worldName = action.substring(6);
        World world = Bukkit.getWorld(worldName);
        if (world == null) {
            player.sendMessage(ChatColor.RED + "A world with the name " + worldName + " does not exist.");
            return true;
        } else {
            player.teleport(world.getSpawnLocation());
            return true;
        }
    } else if (action.startsWith("srv:")) {
        // Teleport to server
        String serverName = action.substring(4);
        Main.teleportPlayerToServer(player, serverName);
        return true;
    } else if (action.startsWith("msg:")) {
        // Send message
        String message = action.substring(4);
        player.sendMessage(Main.PLACEHOLDER_API.parsePlaceholders(player, message));
        return true;
    } else if (action.equals("close")) {
        // Return true = close
        return true;
    } else {
        // Return false = stay open
        return false;
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Player(org.bukkit.entity.Player) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) World(org.bukkit.World) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 5 with ComponentBuilder

use of net.md_5.bungee.api.chat.ComponentBuilder in project Ublisk by Derkades.

the class PlayerInteractEntity method onPlayerInteractEntityEvent.

@EventHandler
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (event.getHand() != EquipmentSlot.HAND)
        return;
    Entity entity = event.getRightClicked();
    final UPlayer player = new UPlayer(event);
    if (entity instanceof ArmorStand && player.getGameMode() != GameMode.CREATIVE) {
        event.setCancelled(true);
    }
    if (entity instanceof Player && player.isSneaking()) {
        UPlayer target = new UPlayer(entity);
        BaseComponent[] stats = new ComponentBuilder("View statistics").bold(true).color(DARK_AQUA).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to open website").color(GOLD).create())).event(new ClickEvent(ClickEvent.Action.OPEN_URL, "http://ublisk.robinmc.com/stats/player.php?player=" + target.getName())).create();
        BaseComponent[] addAsFriend = new ComponentBuilder("Add as friend").bold(true).color(DARK_AQUA).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to run /friend add " + target.getName()).color(GOLD).create())).event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/friend add " + target.getName())).create();
        BaseComponent[] inviteToGuild = new ComponentBuilder("Invite to guild").bold(true).color(DARK_AQUA).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to run /guild invite " + target.getName()).color(GOLD).create())).event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/guild invite " + target.getName())).create();
        player.sendSpacers(2);
        player.sendMessage(stats);
        player.sendMessage(addAsFriend);
        player.sendMessage(inviteToGuild);
    }
}
Also used : Entity(org.bukkit.entity.Entity) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) UPlayer(xyz.derkades.ublisk.utils.UPlayer) Player(org.bukkit.entity.Player) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) UPlayer(xyz.derkades.ublisk.utils.UPlayer) ArmorStand(org.bukkit.entity.ArmorStand) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) EventHandler(org.bukkit.event.EventHandler)

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