disco armour in GUI

Discussion in 'Plugin Development' started by Glass_Eater84, Jun 26, 2014.

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

    Glass_Eater84

    Hey everyone!
    Today, I am trying to accomplish putting disco armour inside a GUI.
    What I mean is when someone clicks a inc sack, it will open a gui for disco armour. I am very confused about how I would go about this.
    Here is my code:
    Code:java
    1. package me.glasseater.discoarmour;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Color;
    7. import org.bukkit.Material;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.inventory.ItemStack;
    10. import org.bukkit.inventory.meta.LeatherArmorMeta;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Main extends JavaPlugin {
    14.  
    15. public void onEnable() {
    16. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    17. private Random r = new Random();
    18.  
    19. public void run() {
    20. Color c = Color.fromRGB(r.nextInt(255), r.nextInt(255), r.nextInt(255));
    21.  
    22. for (Player p : Bukkit.getServer().getOnlinePlayers()) {
    23. if (p.getInventory().getHelmet() != null && p.getInventory().getHelmet().getType() == Material.LEATHER_HELMET) {
    24. p.getInventory().setHelmet(getColorArmor(Material.LEATHER_HELMET, c));
    25. }
    26.  
    27. if (p.getInventory().getChestplate() != null && p.getInventory().getChestplate().getType() == Material.LEATHER_CHESTPLATE) {
    28. p.getInventory().setChestplate(getColorArmor(Material.LEATHER_CHESTPLATE, c));
    29. }
    30.  
    31. if (p.getInventory().getLeggings() != null && p.getInventory().getLeggings().getType() == Material.LEATHER_LEGGINGS) {
    32. p.getInventory().setLeggings(getColorArmor(Material.LEATHER_LEGGINGS, c));
    33. }
    34.  
    35. if (p.getInventory().getBoots() != null && p.getInventory().getBoots().getType() == Material.LEATHER_BOOTS) {
    36. p.getInventory().setBoots(getColorArmor(Material.LEATHER_BOOTS, c));
    37. }
    38. }
    39. }
    40. }, 0, 1);
    41. }
    42.  
    43. public ItemStack getColorArmor(Material m, Color c) {
    44. ItemStack i = new ItemStack(m, 1);
    45. LeatherArmorMeta meta = (LeatherArmorMeta) i.getItemMeta();
    46. meta.setColor(c);
    47. i.setItemMeta(meta);
    48. return i;
    49. }
    50. }

    Any help would be much appreciated!
    Best Regards,
    Glass
     
  2. Offline

    NoLiver92

    Glass_Eater84 What exactly is disco armour?

    You need a listener for the event inventoryclickevent, you get the player of the inventory then apply whatever it is to make them have disco armour.
     
  3. Offline

    Glass_Eater84

    NoLiver92 This is disco armour:

    I want to make it so when you click a inc sack it will open a gui and you can select it and it will auto equip.
     
  4. Offline

    NoLiver92

    Glass_Eater84 Im with you, looks good but potentially laggy.

    You have the runnable in the on enable, what you need to do is create a listener in the inventoryclickevent to listen for when they click the inksack, then add them to a list. Now in the runnable get all the players in the list and then apply the effect to them.

    P.S. only people in the list are people with disco armour enabled.
     
  5. Offline

    Glass_Eater84

    NoLiver92 Ok I understand what you mean (I think) Do you mean if you click on the inksack you will have the disco armour?
     
  6. Offline

    NoLiver92

    yes but I was saying a way of doing it
     
  7. Offline

    HeadGam3z

    Glass_Eater84
    You need to register your event in your onEnable and implement Listener.
     
  8. Offline

    Gater12

    Glass_Eater84
    1. PlayerJoinEvent

    2. InventoryClickEvent but check if they are in the List then disable it.
     
  9. Offline

    HeadGam3z

    Glass_Eater84
    Any stack-traces?
    EDIT: Isn't that the exact same code, but this time with the event registration?

    Glass_Eater84
    When/where are you ever stating that something needs to happen when you have an ink sac in your code?

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

    Glass_Eater84

    HeadGam3z
    *facepalm* didn't realize that :p
    What would I have to add for it to work?
    -Glass
     
  11. Offline

    HeadGam3z

    You could get the item you're holding and test if it's an ink sac, then on action right click, you run your disco armor code (same event btw)
     
  12. Offline

    FabeGabeMC

    Make a list of strings storing the player's name rather than a list of players storing literally all their possible/accessible data (logins, kills, deaths, blocks ran, time on server...)
    ex:
    Code:java
    1. //The list
    2. List<String> disco = new ArrayList<String>();
    3. //How to use it
    4. //Example event
    5. @EventHandler
    6. public void onClick(PlayerInteractEvent e) {
    7. Player p = e.getPlayer();
    8. //You needed to add these too :P
    9. Action a = e.getAction();
    10. if(a == Action.RIGHT_CLICK_AIR &&
    11. p.getItemInHand().getType() == Material.INK_SACK) {
    12. disco.add(p.getName());
    13. }
    14. }
    15.  
    16. //Removing them
    17. disco.remove(p.getName());
     
Thread Status:
Not open for further replies.

Share This Page