Need some help with my plugin.

Discussion in 'Spigot Plugin Development' started by ProGaming848, Jun 24, 2016.

Thread Status:
Not open for further replies.
  1. I am trying to make a AdminTool plugin. This means that when a admin right clicks a player, i brings up a admin menu to kick/ban the player, to view information about the player etc.

    Code (Text):
        @EventHandler
        public void onInvClick(InventoryClickEvent event) {
            if ((event.getInventory().getName().equals(ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "AdminTool"))) {
                if (event.getCurrentItem().getType() == Material.BARRIER && event.getCurrentItem().getItemMeta()
                        .getDisplayName().equals(ChatColor.RED + "Kick this player..")) {
                   
                } else {
                    return;
                }
            }
        }
    This is my code that i am trying to make the way that when i right click the barrier in the admin menu, it kicks the player i right clicked on before, but i don't actually know how to make the part it kicks the right clicked player, and not me..
     
  2. MiniDigger

    Supporter

    you need to save what player you clicked before. just have a map<uuid,uuid> where you put the player you clicked and the clicked player in so that you can access it in your other eventhandler.
     
  3. And how can i do that??
     
  4. Its Easy. Just open an Inventory with the Name of the Player. then u can easy access to that player.
     
  5. With this you can save the players name / uuid in the ItemStack of the inventory and then handle it.
     
  6. @Syranda omg. WHY USE APIS. They are so useless. u need to put them ON the server. thats not nice.

    @ProGaming848

    PlayerInteractAtEntiyEvent

    Open an inventory and name the Title as the UUID or the Playername of the Clicked Player.

    Now u can add certain Items for example. a barrier to ban this person. Just do on Inventory Klick
    Check if the Barriers name starts with "Ban" and then you get a player.
    Player target = Bukkit.getPlayer(Inventory.getTitle());
    if(target != null) target.kickPlayer("Kicked");
     
  7. Why APIs? Because you don't have to reinvent the wheel. You only have to know how it works.
     
  8. well ? java is an api , spigot is an api , etc and not all are useless if you meant custom coded by anyone then you have to be precise.
     
    • Agree Agree x 1
  9. good point but back to the topic read carefully it doesn't need another API.
     
    • Agree Agree x 1
  10. You're right @MadMaxCookie. I just told him how I would do it... Because I personally don't like to have e.g. a players name in a item lore or inventory title as identifier because it's odd to work with them.
     
  11. MiniDigger

    Supporter

    thats why I suggested to use a simple map to store the clicked player ^^
     
    • Like Like x 1
  12. Yeahr but that would lead to an error if the server reloads while in the inventory. (Unusual but may occur)
     
  13. Just set the Players name as Title. Easy and Simple.
     
  14. MiniDigger

    Supporter

    *shrugs*
    no support for reloads ;)
     
    • Funny Funny x 1
  15. MiniDigger

    Supporter

    easy. simple. ugly ;)
     
  16. Can someone just edit my code a bit so i can understand it? I am a person who learns from visual things..

    Code (Text):
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            if ((event.getInventory().getName().equals(ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "AdminTool"))) {
                if (event.getCurrentItem().getType() == Material.BARRIER && event.getCurrentItem().getItemMeta()
                        .getDisplayName().equals(ChatColor.RED + "Kick this player..")) {
                   
                   
                } else {
                    return;
                }
            }
        }
     
  17. Inventory titles are not unique.. So it's a bit odd to work with
     
  18. Code (Text):
     @EventHandler
                public void onInventoryClick(InventoryClickEvent event) {
                    if ((event.getInventory().getName().equals(ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "AdminTool"))) {
                        if (event.getCurrentItem().getType() == Material.BARRIER && event.getCurrentItem().getItemMeta()
                                .getDisplayName().equals(ChatColor.RED + "Kick this player..")) {
                           
                            Player p = Bukkit.getPlayer(event.getClickedInventory().getTitle());
                            if(p != null)
                                p.kickPlayer("Kicked by an Operator");
                           
                           
                        } else {
                            return;
                        }
                    }
                }
     
  19. MiniDigger

    Supporter

    you got multiple suggestion in this thread now. we are not here to spoonfeed you. if you did not understand a suggesting as the user to clarify it.
     
Thread Status:
Not open for further replies.