PlayerInteractEvent - Ranking of players on the title

Discussion in 'Plugin Development' started by BlaquuTM, Feb 14, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    BlaquuTM

    Hello, I have a question about the PlayerInteractEvent class. Namely, I want to do something on my server, that when a player clicks right on another player in Subitle, his nickname and ranking will appear. With what I can send everything, every class etc. I do not send them now because I do not know what to send. I count on help and thank you very much to those who help me.
     
    Last edited: Feb 16, 2018
  2. Offline

    Shmunx

    May I see your code? With that, I may be able to help.
     
  3. Offline

    BlaquuTM

    Do you mean PlayerInteractEvent class code? He will send a code of this class for now, and if you want another one, write what you would like to do then.

    Code:
     package pl.blaquutm.mhcore.listeners;
    
    import org.bukkit. *;
    import org.bukkit.block.Biome;
    import org.bukkit.block.Block;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.CraftItemEvent;
    import org.bukkit.event.inventory.InventoryType;
    import org.bukkit.event.player.PlayerDropItemEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerItemConsumeEvent;
    import org.bukkit.event.player.PlayerPickupItemEvent;
    import org.bukkit.event.player.PlayerTeleportEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.material.Button;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    importuj pl.blaquutm.api.Config;
    importuj pl.blaquutm.mhcore.data.base.guild.Guild;
    importuj pl.blaquutm.mhcore.data.base.user.User;
    importuj pl.blaquutm.mhcore.managers.GuildManager;
    importuj pl.blaquutm.mhcore.managers.UserManager;
    importuj pl.blaquutm.mhcore.utils.ChatUtil;
    importuj pl.blaquutm.mhcore.utils.DataUtil;
    importuj pl.blaquutm.mhcore.utils.ItemBuilder;
    importuj pl.blaquutm.mhcore.utils.PolishItemNames;
    importuj pl.blaquutm.mhcore.utils.RandomUtil;
    importuj pl.blaquutm.mhcore.utils.SniezkaUtil;
    import pl.blaquutm.mhcore.utils.ZdrapkaUtil;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Random;
    import java.util.UUID;
    
    public class PlayerInteractListener implements Listener
    {
        @SuppressWarnings("unused")
        private static final HashMap<UUID, Long> times;
        public static final HashMap <UUID, String> chuj;
    
        static {
            times = new HashMap<UUID, Long>();
            chuj = new HashMap<UUID, String>();
        }
    
    
        @EventHandler
        public void PlayerItemConsume(PlayerItemConsumeEvent e) {
            Player p = e.getPlayer();
            User u = UserManager.getUser(p);
            ItemStack is = e.getItem();
            if (!is.getType().equals((Object) Material.GOLDEN_APPLE)) {
                return;
            }
            if (is.getDurability() == 1) {
                p.removePotionEffect(PotionEffectType.SPEED);
                p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 270, 1));
    
                p.removePotionEffect(PotionEffectType.ABSORPTION);
                p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 2410, 1));
           
                u.addKoxeat(1);
                u.save();
           
            } else {
                p.removePotionEffect(PotionEffectType.REGENERATION);
                p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 120, 2));
    
                p.removePotionEffect(PotionEffectType.ABSORPTION);
                p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 2410, 1));
           
                u.addRefileat(1);
                u.save();
           
            }
        }
        @EventHandler(priority = EventPriority.MONITOR)
        public void onRandomTp(final PlayerInteractEvent event) {
            if (!event.hasBlock()) {
                return;
            }
            final Block clicked = event.getClickedBlock();
            if (clicked.getType() == Material.STONE_BUTTON) {
                final Button btn = (Button)clicked.getState().getData();
                final Block base = clicked.getRelative(btn.getAttachedFace());
                if (base.getType() != Material.JUKEBOX) {
                    return;
                }
                randomTp(event.getPlayer());
            }
        }
    
        @EventHandler(priority = EventPriority.MONITOR)
        public void interact(PlayerInteractEvent e) {
            if (e.isCancelled()) {
                return;
            }
            final Guild g = GuildManager.getGuild(e.getClickedBlock().getLocation());
            if (g != null && e.getClickedBlock().getType() == Material.DRAGON_EGG) {
                e.setCancelled(true);
                return;
            }
            if (g != null && e.getPlayer().getItemInHand().getType() == Material.BOAT) {
                e.setCancelled(true);
            }
        }
    
        @EventHandler
        public void onVanish(final PlayerPickupItemEvent e) {
            final Player p = e.getPlayer();
            final User u = UserManager.getUser(p);
            if (u.isVanish()) {
                e.setCancelled(true);
            }
        }
    
        @EventHandler
        public void onVanish(final PlayerDropItemEvent e) {
            final Player p = e.getPlayer();
            final User u = UserManager.getUser(p);
            if (u.isVanish()) {
                e.setCancelled(true);
            }
        }
    
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onJajo(final PlayerInteractEvent event) {
            final ItemStack s = event.getItem();
            final Player p = event.getPlayer();
            if (s == null) {
                return;
            }
            if (s.getType() == Material.DRAGON_EGG && s.getItemMeta().equals(SniezkaUtil.drop.build().getItemMeta())) {
                if (!p.hasPermission("core.cmd.admin") && !Config.ENABLE_JAJO) {
                    ChatUtil.sendMessage(p, "&8» &cPandora jest tymczasowo wylaczone!");
                    event.setCancelled(true);
                    return;
                }
                    event.setCancelled(true);
                    final ItemStack is = SniezkaUtil.drops.get(RandomUtil.getRandInt(0, SniezkaUtil.drops.size() - 1));
                    ChatUtil.giveItems(p, is);
                    event.setCancelled(true);
                    p.getInventory().removeItem(SniezkaUtil.drop.build());
                    p.updateInventory();
                    p.playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 10);
                    p.playSound(p.getLocation(), Sound.EXPLODE, 20.0f, 20.0f);
                    final User user = UserManager.getUser(p);
                    user.addCoins(50);
                    user.addJajopen(1);
                    user.save();
                    for (final Player po : Bukkit.getOnlinePlayers()) {
                        final User u = UserManager.getUser(po);
                        if (u.isEggsMessages()) {;
                            ChatUtil.sendMessage((CommandSender)po, "&8» &7Gracz &9" + p.getName() + " &7otworzyl &2&lPierozek &7i wylosowal: &6" + PolishItemNames.getPolishName(is.getType(), is.getData().getData()) + (is.getAmount() <= 1 ? "" : "&8 &6x" + is.getAmount()) + "&7!");
                            return;
                        }
                    }
            }
        }
        @EventHandler
        public void onPerla(final PlayerInteractEvent event) {
            final ItemStack s = event.getItem();
            final Player p = event.getPlayer();
            final User u = UserManager.getUser(p);
            if (s == null) {
                return;
            }
            if (s.getType() == Material.ENDER_PEARL) {
                u.addPerlycyk(1);
                u.save();
            }
        }
        public static boolean randomTp(final Player player) {
            final int x = RandomUtil.getRandInt(-2000, 2000);
            final int z = RandomUtil.getRandInt(-2000, 2000);
            final double y = player.getWorld().getHighestBlockYAt(x, z) + 1.5f;
            final Location loc = new Location(player.getWorld(), (double)x, y, (double)z);
            final Biome biome = loc.getBlock().getBiome();
            if (biome == Biome.OCEAN || biome == Biome.DEEP_OCEAN || GuildManager.getGuild(loc) != null) {
                return randomTp(player);
            }
            player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
            ChatUtil.giveItems(player, new ItemStack(Material.COOKED_BEEF, 64));
            player.updateInventory();
            return true;
        }
    
        public List<Player> getPlayersInRadius(final Location location, final int size) {
            final List<Player> players = new ArrayList<Player>();
            for (final Player p : location.getWorld().getPlayers()) {
                if (location.distance(p.getLocation()) <= size) {
                    players.add(p);
                }
            }
            return players;
        }
    
        @EventHandler
        public void onCraft(final CraftItemEvent e) {
            if (e.getInventory().getType().equals((Object)InventoryType.WORKBENCH) && e.getSlotType().toString().equalsIgnoreCase("RESULT") && e.getCurrentItem().getType().name().equalsIgnoreCase("JUKEBOX")) {
                e.setCancelled(true);
            }
        }
    
        @EventHandler
        public void onAntyNogi(PlayerInteractEvent e) {
            Action ea = e.getAction();
            Player p = e.getPlayer();
            if((ea.equals(Action.RIGHT_CLICK_AIR)) || (ea.equals(Action.RIGHT_CLICK_BLOCK))){
                if(e.getMaterial().equals(Material.NAME_TAG)){
                    //ItemBuilder anty = new ItemBuilder(Material.NAME_TAG).setTitle(Util.fix("&6&lAnty Nogi")).addLore(ChatUtil.fixColor("")).addLore(ChatUtil.fixColor("&8» &2Kliknij PPM, aby uratowac czlonka gildii!")).addEnchantment(Enchantment.DURABILITY, 2);
                    if(e.getItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatUtil.fixColor("&6&lAnty Nogi"))){
                        User u = UserManager.getUser(p);
                        if(u.isLastPearl()){
                            p.sendMessage(ChatUtil.fixColor("&8» &7Anty nozki bedziesz mogl uzyc dopiero za &6" + DataUtil.secondsToString(u.getLastPearl()) + "&7!"));
                            return;
                        }
                        Guild g = GuildManager.getGuild(p);
                        if(g == null){
                            p.sendMessage(ChatUtil.fixColor("&8» &cNie posiadasz gildi!"));
                            return;
                        }
                        Guild gcub = GuildManager.getGuildByLoc(p.getLocation());
                        if(gcub == null){
                            p.sendMessage(ChatUtil.fixColor("&8» &cNie ma tutaj zadnego cuboida!"));
                            return;
                        }
                        if(gcub.getTag().equalsIgnoreCase(g.getTag())){
                            p.sendMessage(ChatUtil.fixColor("&8» &cNie mozesz tego zrobic na swoim cuboidzie!"));
                            return;
                        }
                        ArrayList<Player> gra = new ArrayList<Player>();
                        for(Player w : getPlayersInRadius(p.getLocation(), 20)){
                            Guild gw = GuildManager.getGuild(w);
                            if(gw == null){
                                continue;
                            }
                            if(!(g == gw)){
                                continue;
                            }
                            if(p.getName() == w.getName()){
                                continue;
                            }
                            gra.add(w);
                        }
                        if(gra.size() == 0){
                            p.sendMessage(ChatUtil.fixColor("&8» &cAby uwolnic kolege z nozek musisz stac od niego 20 kratek!"));
                            return;
                        }
                        Inventory inv = Bukkit.createInventory(p, 27, (ChatUtil.fixColor("&7Gracze do uratowania")));
                        for(int i = 0; i < gra.size(); i++){
                            ItemBuilder gracz = new ItemBuilder(Material.SKULL_ITEM, (short) 3).setTitle(ChatUtil.fixColor("&6" + gra.get(i).getName())).addLore(ChatUtil.fixColor("&8» &7Aby uratowac tego gracz musisz kliknac w jego glowe!"));
                            inv.setItem(i, gracz.build());
                        }
                        p.openInventory(inv);
                    }
                }
                if(e.getMaterial().equals(Material.PAPER)){
                    //ItemBuilder anty = new ItemBuilder(Material.NAME_TAG).setTitle(Util.fix("&6&LANTY NOZKI")).addEnchantment(Enchantment.DURABILITY, 2);
                    if(e.getItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatUtil.fixColor("&6Zdrapka"))){
                        ZdrapkaUtil.zdrapka(p, 0);
                        return;
                    }
                }
            }
        }
        @EventHandler
        public void onInteract(final PlayerInteractEvent e) {
            if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock().getType() == Material.WOOD_BUTTON) {
                final Location block = e.getClickedBlock().getLocation().add(1.0, 0.0, 0.0);
                final Location block2 = e.getClickedBlock().getLocation().add(-1.0, 0.0, 0.0);
                final Location block3 = e.getClickedBlock().getLocation().add(0.0, 0.0, 1.0);
                final Location block4 = e.getClickedBlock().getLocation().add(0.0, 0.0, -1.0);
                if (block.getBlock().getType() == Material.JUKEBOX || block2.getBlock().getType() == Material.JUKEBOX || block3.getBlock().getType() == Material.JUKEBOX || block4.getBlock().getType() == Material.JUKEBOX) {
                    new Random();
                    final int x = RandomUtil.getRandInt(-2000, 2000);
                    final int z = RandomUtil.getRandInt(-2000, 2000);
                    for (final Player players : this.getPlayersInRadius(e.getClickedBlock().getLocation(), 3)) {
                        final Location loc = new Location(e.getPlayer().getWorld(), x, (double)e.getPlayer().getWorld().getHighestBlockYAt((int)x, (int)z), z);
                        final Biome biome = loc.getBlock().getBiome();
                        if (biome == Biome.OCEAN || biome == Biome.DEEP_OCEAN || GuildManager.getGuild(loc) != null) {
                            ChatUtil.sendMessage((CommandSender)players, "&8» &cTrafiles na gildie lub ocean!");
                            return;
                        }
                        e.getPlayer().teleport(loc);
                        final Lokalizacja ploc = new Lokalizacja (e.getPlayer (). getWorld (), e.getPlayer (). getLocation (). getX (), e.getPlayer (). getLocation (). getY (), e.getPlayer () .getLocation (). getZ ());
                        ploc.setY (e.getPlayer (). getLocation (). getY () + 5.0);
                        e.getPlayer (). teleport (ploc);
                        players.teleport (e.getPlayer (). getLocation ());
                        ChatUtil.giveItems (gracze, nowy ItemStack (Material.GRILLED_PORK, 64));
                        players.updateInventory ();
                    }
                }
            }
        }
        public static int randInt () {
            final Random r = new Random ();
            return r.nextInt (14) + 1;
        }
    }
     
    Last edited: Feb 16, 2018
  4. Offline

    Shmunx

    Sorry for getting to you late, can you please elaborate on how you want the ranking and information show up?

    By the way, i'm not here to give you the code, i'm here to help you and give you ideas, since most of the other good coders aren't responding to this thread.
     
Thread Status:
Not open for further replies.

Share This Page