Admin GUI

Discussion in 'Plugin Development' started by Jordymt, Feb 25, 2014.

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

    Jordymt

    Hi there,
    For my server I decided to make a Admin GUI menu so we can ban players trough that menu. I wanted to right-click a player with a playerhead and then open the menu for that player so you can only ban that player. The code for getting the playername is already done, but I don't know how to send the playername to my menu(not included here).

    Code for selecting the player:
    Code:java
    1. package me.Opgesnoven.admin;
    2.  
    3. import me.Opgesnoven.sc.Main;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Entity;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.player.PlayerInteractEntityEvent;
    12.  
    13. public class PlayerMenu implements Listener {
    14. public Main plugin;
    15.  
    16. public PlayerMenu(Main instance) {
    17.  
    18. }
    19.  
    20. @EventHandler
    21. public void onInteract(PlayerInteractEntityEvent e) {
    22. Entity entity = e.getRightClicked();
    23. Player p = e.getPlayer();
    24.  
    25. if(e.getRightClicked() instanceof Player) {
    26. if(p.getItemInHand().getType().equals(Material.SKULL_ITEM)) {
    27. String name = ((Player) entity).getName();
    28. Bukkit.broadcastMessage("His name is: " + name);
    29. }
    30. }
    31. }
    32. }


    Please help me out!
    Jordy
     
  2. Offline

    Alshain01

    You can't just pass it in?
     
    yewtree8 likes this.
  3. Offline

    yewtree8

    I have no solution to your problem, but an idea would be to add permissions, therefore players aren't going to go around banning people...
     
  4. Offline

    Jordymt

    Only ops will be able to use it ;-)

    Thats my question, am I able to do it one way or another? I dont think im the first one with this idea.
     
  5. Offline

    Alshain01

    No, I don't think your the first one to come up with passing parameters into methods.
     
    NathanWolf likes this.
  6. Offline

    Jordymt

    Its strange that I didnt find someone else with this kinde of admin menu. It should be possible
     
  7. You could try:

    Code:java
    1. package me.Opgesnoven.admin;
    2.  
    3. import me.Opgesnoven.sc.Main;
    4.  
    5. import me.Opgesnoven.sc.NAMEOFCLASSWITHMENU //Import the class with your menu in
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.Material;
    9. import org.bukkit.entity.Entity;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.player.PlayerInteractEntityEvent;
    14.  
    15. public class PlayerMenu implements Listener {
    16. public Main plugin;
    17.  
    18. public PlayerMenu(Main instance) {
    19.  
    20. }
    21.  
    22. @EventHandler
    23. public void onInteract(PlayerInteractEntityEvent e) {
    24. Entity entity = e.getRightClicked();
    25. Player p = e.getPlayer();
    26.  
    27. if(e.getRightClicked() instanceof Player) {
    28. if(p.getItemInHand().getType().equals(Material.SKULL_ITEM)) {
    29. String name = p.getName();
    30. Bukkit.broadcastMessage("His name is: " + name);
    31. NAMEOFCLASSWITHMENU menu = new NAMEOFCLASSWITHMENU(name);
    32. menu.doStuff();
    33. }
    34. }
    35. }
    36. }

    Code:java
    1.  
    2. package me.Opgesnoven.admin;
    3.  
    4. private String player;
    5. public class NAMEOFCLASSWITHMENU{
    6. public NAMEOFCLASSWITHMENU(String name){
    7. player = name;
    8. }
    9. public doStuff(){
    10. //Inventory code here, using 'name' as the playername, for any lore/commands you need to do.
    11. }
    12. }
    13.  
    14.  


    I think... I can't really test to see if it works because I don't have other code.

    EDIT: I made a small edit to the code so it makes more sense.
     
Thread Status:
Not open for further replies.

Share This Page