Search in sources :

Example 6 with ClickEvent

use of net.md_5.bungee.api.chat.ClickEvent 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)

Example 7 with ClickEvent

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

the class FriendsMenu method onOptionClick.

@Override
public boolean onOptionClick(OptionClickEvent event) {
    UPlayer player = new UPlayer(event);
    Material item = event.getItemStack().getType();
    if (item == Material.SPECKLED_MELON) {
        if (player.getSetting(Setting.FRIENDS_SHOW_HEALTH)) {
            player.setSetting(Setting.FRIENDS_SHOW_HEALTH, false);
            player.sendMessage(Message.FRIEND_HEALTH_DISABLED);
        } else {
            player.setSetting(Setting.FRIENDS_SHOW_HEALTH, true);
            player.sendMessage(Message.FRIEND_HEALTH_ENABLED);
        }
        return false;
    } else if (player.getFriends().isEmpty()) {
        return false;
    } else {
        // Clicked item is a player
        // OfflinePlayer friend = Ublisk.getOfflinePlayer(event.getName());
        OfflinePlayer offlineFriend = player.getFriends().get(event.getPosition());
        if (offlineFriend == null)
            player.sendMessage("error");
        UPlayer friend = new UPlayer(offlineFriend);
        player.sendMessage(friend.getDisplayName(ChatColor.DARK_AQUA, true), new ComponentBuilder(" - ").color(ChatColor.DARK_GRAY).bold(true).create(), new ComponentBuilder("Remove friend").color(ChatColor.RED).italic(true).event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/friend remove " + friend.getName())).create());
        return true;
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) OfflinePlayer(org.bukkit.OfflinePlayer) Material(org.bukkit.Material) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 8 with ClickEvent

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

the class Guild method invitePlayer.

public synchronized void invitePlayer(final UPlayer source, final UPlayer target) {
    if (!this.exists())
        throw new UnsupportedOperationException("Cannot invite player to non-existent guild.");
    final GuildInvite invite = new GuildInvite(this, source);
    // Add invite to list of invites, and remove it after 60 seconds (if it hasn't been accepted)
    GUILD_INVITES.put(target.getName(), invite);
    new BukkitRunnable() {

        public void run() {
            if (GUILD_INVITES.containsKey(target.getName())) {
                GUILD_INVITES.remove(target.getName());
            }
        }
    }.runTaskLater(Main.getInstance(), 60 * 20);
    TextComponent inviteMessage = new TextComponent(source.getName() + " has invited you to join " + this.getName() + ". ");
    inviteMessage.setColor(ChatColor.DARK_AQUA);
    inviteMessage.setBold(true);
    BaseComponent[] hoverText = new ComponentBuilder("Click me!").color(ChatColor.YELLOW).create();
    TextComponent clickToAccept = new TextComponent("Click here to accept.");
    clickToAccept.setColor(ChatColor.AQUA);
    clickToAccept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText));
    clickToAccept.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/guild accept"));
    BaseComponent[] components = new BaseComponent[] { inviteMessage, clickToAccept };
    target.sendMessage(components);
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 9 with ClickEvent

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

the class CommandSetTitle method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (sender instanceof Player) {
        Player player = (Player) sender;
        try {
            ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
            if (args.length == 0) {
                player.sendMessage("Available titles:");
                for (String title : solplayer.getAvailableTitles()) {
                    TextComponent tc = new TextComponent();
                    tc.setText("- " + title);
                    TextComponent tc2 = new TextComponent();
                    tc2.setText(ChatColor.GRAY + "Click here to set this title" + ChatColor.RESET);
                    tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/settitle " + title));
                    tc.addExtra(tc2);
                    sender.spigot().sendMessage(tc);
                }
                player.sendMessage("/settitle none to remove your current title");
                return true;
            }
            String targetTitle = args[0];
            if (args.length > 0) {
                targetTitle = "";
                int current = 0;
                for (String entry : args) {
                    current++;
                    targetTitle = targetTitle + entry + " ";
                }
                targetTitle = targetTitle.trim();
            }
            if (!targetTitle.equals("none")) {
                boolean found = false;
                for (String title : solplayer.getAvailableTitles()) {
                    if (targetTitle.toUpperCase().equals(title.toUpperCase())) {
                        targetTitle = title;
                        found = true;
                        break;
                    }
                }
                if (found == false) {
                    player.sendMessage("You do not have this title");
                    return true;
                }
                solplayer.setTitle(targetTitle);
            } else {
                solplayer.setTitle("");
            }
            System.out.println("* [" + player.getName() + "] Title set to: " + "'" + solplayer.getTitle() + "'");
            player.sendMessage("* Title set to: '" + solplayer.getTitle() + "'");
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            player.sendMessage(e.getMessage());
        }
    }
    return true;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 10 with ClickEvent

use of net.md_5.bungee.api.chat.ClickEvent 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)

Aggregations

ClickEvent (net.md_5.bungee.api.chat.ClickEvent)30 TextComponent (net.md_5.bungee.api.chat.TextComponent)21 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)15 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)10 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)7 Player (org.bukkit.entity.Player)7 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)4 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 UPlayer (xyz.derkades.ublisk.utils.UPlayer)3 OwnedLand (biz.princeps.landlord.util.OwnedLand)2 ConfirmationGUI (biz.princeps.lib.gui.ConfirmationGUI)2 ArrayList (java.util.ArrayList)2 ChatColor (net.md_5.bungee.api.ChatColor)2 Material (org.bukkit.Material)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 World (org.bukkit.World)2 Landlord (biz.princeps.landlord.Landlord)1 Options (biz.princeps.landlord.api.Options)1 LandPostClaimEvent (biz.princeps.landlord.api.events.LandPostClaimEvent)1