Creatng a "Chat GUI"

Discussion in 'Plugin Development' started by maxben34, Nov 6, 2013.

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

    maxben34

    I'm currently attempting to create a "chat GUI" I wrote this code, but it doesn't seem to be working properly when I left click, because nothing actually happens. PS: I DID REGISTER MY EVENTS


    Code:
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent e){
        e.getPlayer().getInventory().setItem(0, new ItemStack(Material.STONE,1));
        e.getPlayer().getInventory().setItem(1, new ItemStack(Material.GRASS,1));
        e.getPlayer().getInventory().setItem(2, new ItemStack(Material.COBBLESTONE,1));
        e.getPlayer().getInventory().setItem(3, new ItemStack(Material.WOOD,1));
        e.getPlayer().getInventory().setItem(4, new ItemStack(Material.LOG,1));
        e.getPlayer().getInventory().setItem(5, new ItemStack(Material.ICE,1));
        e.getPlayer().getInventory().setItem(6, new ItemStack(Material.SPONGE,1));
        e.getPlayer().getInventory().setItem(7, new ItemStack(Material.MELON_BLOCK,1));
        e.getPlayer().getInventory().setItem(8, new ItemStack(Material.PUMPKIN,1));
        }
     
    public void onItemInteract(final PlayerInteractEvent e){
        if(e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)){
            if(e.getItem().getType().equals(Material.STONE)){
            e.getPlayer().sendMessage("➤How to Play");
            e.getPlayer().sendMessage("Classes");
            e.getPlayer().sendMessage("Team Selection");
            e.getPlayer().sendMessage("Donate");
            e.getPlayer().sendMessage("Scroll down to Move through the Menu. Left Click to Select. Right Click to go Back.");
            if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
                e.getPlayer().sendMessage("There is no previous selection");
                e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.NOTE_PIANO, -10, 3);
                Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                    public void run(){
                        e.getPlayer().sendMessage("➤How to Play");
                        e.getPlayer().sendMessage("Classes");
                        e.getPlayer().sendMessage("Team Selection");
                        e.getPlayer().sendMessage("Donate");
                        e.getPlayer().sendMessage("Scroll down to Move through the Menu. Left Click to Select. Right Click to go Back.");
                    }
                },3*20);
            }
        }
    }
            if(e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)){
                if(e.getItem().getType().equals(Material.STONE)){
                e.getPlayer().sendMessage("Capture is a gamemode where 4 teams compete to hold a capture point for 30 seconds without leaving the position.");
                e.getPlayer().sendMessage("There are many different unique classes that players can select from, as well as donate for!");
                }
            }
            if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
                if(e.getItem().getType().equals(Material.STONE)){
                   
               
                e.getPlayer().sendMessage("➤How to Play");
                e.getPlayer().sendMessage("Classes");
                e.getPlayer().sendMessage("Team Selection");
                e.getPlayer().sendMessage("Donate");
                e.getPlayer().sendMessage("Scroll down to Move through the Menu. Left Click to Select. Right Click to go Back.");
                    }   
                }
            }
        }
     
    
     
  2. Offline

    Blah1

    maxben34 put @EventHandler above playerinteractevent
     
  3. Offline

    maxben34

    OMG. Thanks I guess sometimes no matter how many times you check over your code you can't seem to find a simple problem.

    I'll use this thread for any other issues I come across.

    Blah1
    The issue that i'm currently getting is that I'm having difficulty distinguishing when the player left clicked the stone once, compared to when he left clicked it twice in a row.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
    sgavster and cray_Z like this.
  4. Offline

    Blah1

    There is probably a way to check for double clicking but how I would do it is put the player who hits the block in an arraylist. Before that check if the player is already in the arraylist. If he is, remove him from the "one-hit arraylist" and put him in an arraylist called "doubleclick". The first time the player hits the block you want to set up a delayed task and remove the player after 1 second. From there you will know if its a double click or not

    Btw I know this is confusing but i hope you can make sense of it. And again, there is probably a better way but this is the one i thought of.
     
  5. Offline

    maxben34

    I understand. I'll do this except I don't need the delayed task cuz there is no limit on how long they want till the second click.

    Blah1
    Here's what I have. It isn't working properly. It's supposed to be that if you left clicked once, then if you left click again it sends the how to play message.
    if you right click from there it goes back to the first message. If you right click on the first message, it should tell you that you can't g back any more. It's really complicated and hard to see where I went wrong. Maybe you can point it out for me.

    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent e){
    3. click.add(e.getPlayer());
    4. e.getPlayer().getInventory().setItem(0, new ItemStack(Material.STONE,1));
    5. e.getPlayer().getInventory().setItem(1, new ItemStack(Material.GRASS,1));
    6. e.getPlayer().getInventory().setItem(2, new ItemStack(Material.COBBLESTONE,1));
    7. e.getPlayer().getInventory().setItem(3, new ItemStack(Material.WOOD,1));
    8. e.getPlayer().getInventory().setItem(4, new ItemStack(Material.LOG,1));
    9. e.getPlayer().getInventory().setItem(5, new ItemStack(Material.ICE,1));
    10. e.getPlayer().getInventory().setItem(6, new ItemStack(Material.SPONGE,1));
    11. e.getPlayer().getInventory().setItem(7, new ItemStack(Material.MELON_BLOCK,1));
    12. e.getPlayer().getInventory().setItem(8, new ItemStack(Material.PUMPKIN,1));
    13. }
    14. @EventHandler
    15. public void onItemInteract(final PlayerInteractEvent e){
    16. if(e.getItem().getType().equals(Material.STONE)){
    17. if(e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)){
    18. if(click.contains(e.getPlayer())){
    19. doubleclick.add(e.getPlayer());
    20. click.remove(e.getPlayer());
    21. e.getPlayer().sendMessage(ChatColor.GRAY +"➤How to Play");
    22. e.getPlayer().sendMessage(ChatColor.GRAY +" Classes");
    23. e.getPlayer().sendMessage(ChatColor.GRAY +" Team Selection");
    24. e.getPlayer().sendMessage(ChatColor.GRAY +" Donate");
    25. e.getPlayer().sendMessage(ChatColor.DARK_RED +" Scroll down to Move through the Menu. Left Click to Select. Right Click to go Back.");
    26. }
    27. }
    28. if(e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)){
    29. if(!click.contains(e.getPlayer())){
    30. click.add(e.getPlayer());
    31. e.getPlayer().sendMessage(ChatColor.DARK_PURPLE +"Capture is a gamemode where 4 teams compete to hold a capture point for 30 seconds without leaving the position.");
    32. e.getPlayer().sendMessage(ChatColor.DARK_PURPLE +"There are many different unique classes that players can select from, as well as donate for!");
    33.  
    34. }
    35. }
    36. if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    37. if(doubleclick.contains(e.getPlayer())){
    38. doubleclick.remove(e.getPlayer());
    39. e.getPlayer().sendMessage("There is no previous selection");
    40. e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.NOTE_PIANO, -10, 3);
    41. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    42. public void run(){
    43. click.add(e.getPlayer());
    44. e.getPlayer().sendMessage(ChatColor.GRAY + "➤How to Play");
    45. e.getPlayer().sendMessage(ChatColor.GRAY + " Classes");
    46. e.getPlayer().sendMessage(ChatColor.GRAY + " Team Selection");
    47. e.getPlayer().sendMessage(ChatColor.GRAY + " Donate");
    48. e.getPlayer().sendMessage(ChatColor.DARK_RED + " Scroll down to Move through the Menu. Left Click to Select. Right Click to go Back.");
    49. }
    50. },3*20);
    51. }
    52. }
    53. if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    54. if(doubleclick.contains(e.getPlayer()) && click.contains(e.getPlayer())){
    55. doubleclick.remove(e.getPlayer());
    56. e.getPlayer().sendMessage(ChatColor.GRAY +"➤How to Play");
    57. e.getPlayer().sendMessage(ChatColor.GRAY +" Classes");
    58. e.getPlayer().sendMessage(ChatColor.GRAY +" Team Selection");
    59. e.getPlayer().sendMessage(ChatColor.GRAY +" Donate");
    60. e.getPlayer().sendMessage(ChatColor.DARK_RED + " Scroll down to Move through the Menu. Left Click to Select. Right Click to go Back.");
    61. }
    62. }
    63. }
    64. }
    65. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  6. Offline

    Blah1

    Code:java
    1. public final ArrayList<Player> click = new ArrayList<>();
    2. public final ArrayList<Player> doubleclick = new ArrayList<>();
    3. @EventHandler
    4. public void onPlayerJoin(PlayerJoinEvent e){
    5. click.add(e.getPlayer());
    6. e.getPlayer().getInventory().setItem(0, new ItemStack(Material.STONE,1));
    7. e.getPlayer().getInventory().setItem(1, new ItemStack(Material.GRASS,1));
    8. e.getPlayer().getInventory().setItem(2, new ItemStack(Material.COBBLESTONE,1));
    9. e.getPlayer().getInventory().setItem(3, new ItemStack(Material.WOOD,1));
    10. e.getPlayer().getInventory().setItem(4, new ItemStack(Material.LOG,1));
    11. e.getPlayer().getInventory().setItem(5, new ItemStack(Material.ICE,1));
    12. e.getPlayer().getInventory().setItem(6, new ItemStack(Material.SPONGE,1));
    13. e.getPlayer().getInventory().setItem(7, new ItemStack(Material.MELON_BLOCK,1));
    14. e.getPlayer().getInventory().setItem(8, new ItemStack(Material.PUMPKIN,1));
    15. }
    16. @EventHandler
    17. public void onItemInteract(final PlayerInteractEvent e){
    18. if(e.getItem().getType().equals(Material.STONE)){
    19. // I suggest putting if action == left click block and then check to see if the item is stone.
    20. if(e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)){
    21. if(click.contains(e.getPlayer())){
    22. doubleclick.add(e.getPlayer());
    23. click.remove(e.getPlayer());
    24. e.getPlayer().sendMessage(ChatColor.GRAY +"➤How to Play");
    25. e.getPlayer().sendMessage(ChatColor.GRAY +" Classes");
    26. e.getPlayer().sendMessage(ChatColor.GRAY +" Team Selection");
    27. e.getPlayer().sendMessage(ChatColor.GRAY +" Donate");
    28. e.getPlayer().sendMessage(ChatColor.DARK_RED +" Scroll down to Move through the Menu. Left Click to Select. Right Click to go Back.");
    29. }
    30. if(!(click.contains(e.getPlayer()))){
    31. click.add(e.getPlayer());
    32. e.getPlayer().sendMessage(ChatColor.DARK_PURPLE +"Capture is a gamemode where 4 teams compete to hold a capture point for 30 seconds without leaving the position.");
    33. e.getPlayer().sendMessage(ChatColor.DARK_PURPLE +"There are many different unique classes that players can select from, as well as donate for!");
    34. }
    35. }
    36. // Right click air? You just said if the item is stone do this..
    37. if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    38. // They can only be in one or the other. They should never be in both.
    39. if(doubleclick.contains(e.getPlayer()) && click.contains(e.getPlayer())){
    40. doubleclick.remove(e.getPlayer());
    41. e.getPlayer().sendMessage(ChatColor.GRAY +"➤How to Play");
    42. e.getPlayer().sendMessage(ChatColor.GRAY +" Classes");
    43. e.getPlayer().sendMessage(ChatColor.GRAY +" Team Selection");
    44. e.getPlayer().sendMessage(ChatColor.GRAY +" Donate");
    45. e.getPlayer().sendMessage(ChatColor.DARK_RED + " Scroll down to Move through the Menu. Left Click to Select. Right Click to go Back.");
    46. }
    47. if(doubleclick.contains(e.getPlayer())){
    48. doubleclick.remove(e.getPlayer());
    49. e.getPlayer().sendMessage("There is no previous selection");
    50. e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.NOTE_PIANO, -10, 3);
    51. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    52. public void run(){
    53. click.add(e.getPlayer());
    54. e.getPlayer().sendMessage(ChatColor.GRAY + "➤How to Play");
    55. e.getPlayer().sendMessage(ChatColor.GRAY + " Classes");
    56. e.getPlayer().sendMessage(ChatColor.GRAY + " Team Selection");
    57. e.getPlayer().sendMessage(ChatColor.GRAY + " Donate");
    58. e.getPlayer().sendMessage(ChatColor.DARK_RED + " Scroll down to Move through the Menu. Left Click to Select. Right Click to go Back.");
    59. }
    60. },3*20);
    61. }
    62. }
    63. }
    64. }
     
    maxben34 likes this.
  7. Offline

    maxben34

    Blah1
    Thanks man!

    The code that you gave me doesn't work the way I wanted to when I tested it Blah1.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  8. Offline

    Noxyro

    Just flew over the thread. Could you explain exactly what your plugin is doing?
     
  9. Offline

    Blah1

    maxben34 It's not supposed to work. I put some notes for you to read and fix it.
     
  10. Offline

    maxben34

    Noxyro
    Basically, it's going to be a menu for players to get information about the server within the chat. Left click selects, right click goes back, and scrolling will move the menu up and down. The scrolling isn't in yet because I didn't get the first set of it done yet.
     
  11. Offline

    Noxyro


    So, the items in the action bar are there for scrolling purposes i guess, and you have problems to figure out in wich menu you are at a specific moment and when a menu gets selected or if you go back, right?

    One thing i noticed: You don't need specific items for the scrolling part.
    Code:java
    1. player.getInventory().getHeldItemSlot()
     
  12. Offline

    maxben34

    Ok that's a great idea. You have it right. Any idea on how i can fix my current problem.
     
  13. Offline

    iZanax

    Hey max,

    I got the exact same thing on one of my old popular private plugin.
    I don't got the backup of it on this computer. So I can't help u much.

    For scrolling you have to work with
    PlayerHeldItemEvent
    http://jd.bukkit.org/rb/doxygen/d1/..._1event_1_1player_1_1PlayerItemHeldEvent.htmlAnd gain the previous slot and the new slot. to see which side he scrolls to.
    Keep in mind that there are some exceptions by 8 to 0 and 0 to 8 scroll.
    Goodluck.
     
  14. Offline

    maxben34

    Thanks iZanax. I'll keep that in mind. The hardest part right now is detecting when a player has left clicked once, or twice.
     
Thread Status:
Not open for further replies.

Share This Page