Hot Summer Deals are Here!
Celebrate with up to 99% off on 17,700 resources
01
Days
05
Hours
05
Mins
37
Secs

Help

Status
This thread has been locked.

HuskyGG

Banned
Feedback score
3
Posts
79
Reactions
16
Resources
0
Sorry, i know ive made a few of these but i cannot find anywhere.
How can i add it so on my gui i can perform a command if one of the items are clicked.
Here is the code :
Code:
                ItemStack bo = new ItemStack(Material.REDSTONE, 1);
                ItemMeta bometa = bo.getItemMeta();
                bometa.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&d&lSet a bounty on " + recieved.getName()));
                bo.setItemMeta(bometa);
                ArrayList<String> lore7 = new ArrayList<String>();
                lore7.add(ChatColor.translateAlternateColorCodes('&', "&d&l* &7&lCurrently viewing settings for &d&l" + recieved.getName()));
                meta.setLore(lore7);
               
               
                //Row 1
                i.setItem(0,empty);
                i.setItem(1,empty);
                i.setItem(2,empty);
                i.setItem(3,empty);
                i.setItem(4,skull);
                i.setItem(5,empty);
                i.setItem(6,empty);
                i.setItem(7,empty);
                i.setItem(8,empty);
               
                //Row 2
                i.setItem(9,empty);
                i.setItem(10,al);
                i.setItem(11,report);
                i.setItem(12,msg);
                i.setItem(13,tp);
                i.setItem(14,fi);
                i.setItem(15,ig);
                i.setItem(16,bo);
                i.setItem(17,empty);
               
                //Row3
                i.setItem(18,empty);
                i.setItem(19,empty);
                i.setItem(20,empty);
                i.setItem(21,empty);
                i.setItem(22,empty);
                i.setItem(23,empty);
                i.setItem(24,empty);
                i.setItem(25,empty);
                i.setItem(26,empty);
               
                player.openInventory(i);

Thats not all of it.
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Tig3ax

Feedback score
3
Posts
196
Reactions
41
Resources
0
Use the inventoryclickevent.
Check if the name of the inventory is your inventory name.
After that check the itemtype, name or slot and then do something.
 

HuskyGG

Banned
Feedback score
3
Posts
79
Reactions
16
Resources
0
Use the inventoryclickevent.
Check if the name of the inventory is your inventory name.
After that check the itemtype, name or slot and then do something.
Thanks but i dont know how to implement this :/
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/huskygg-scam-report.282658/)

Tig3ax

Feedback score
3
Posts
196
Reactions
41
Resources
0
Code:
public class onPlayerInventoryClick implements Listener {

    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {

        Player player = (Player) event.getWhoClicked();
        String itemname = event.getCurrentItem().getItemMeta().getDisplayName();

        if (ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Admin Menu")) {
            event.setCancelled(true);

            if (itemname.contains("Change Gamemode")) {
                // do something
            }
            }
        }
    }
Example on some of my code.
 

sores

MineBOI
Premium
Feedback score
5
Posts
305
Reactions
210
Resources
0
Code:
public class onPlayerInventoryClick implements Listener {

    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {

        Player player = (Player) event.getWhoClicked();
        String itemname = event.getCurrentItem().getItemMeta().getDisplayName();

        if (ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Admin Menu")) {
            event.setCancelled(true);

            if (itemname.contains("Change Gamemode")) {
                // do something
            }
            }
        }
    }
Example on some of my code.
Pretty good example. From there if you wanted to perform a command simply use player.performCommand("YourCommandHere");
 

HuskyGG

Banned
Feedback score
3
Posts
79
Reactions
16
Resources
0
Code:
public class onPlayerInventoryClick implements Listener {

    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {

        Player player = (Player) event.getWhoClicked();
        String itemname = event.getCurrentItem().getItemMeta().getDisplayName();

        if (ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Admin Menu")) {
            event.setCancelled(true);

            if (itemname.contains("Change Gamemode")) {
                // do something
            }
            }
        }
    }
Example on some of my code.
Thanks, but how would i get this linked with the gui as its in a separate class?
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/huskygg-scam-report.282658/)

Tig3ax

Feedback score
3
Posts
196
Reactions
41
Resources
0

This might help you.
There are tons more video's and treads that also explain this.
 

felldownstairs

Gypsy Boy | Java Developer
Supreme
Feedback score
4
Posts
783
Reactions
144
Resources
0
https://gyazo.com/ba759d87fb08c997d954e89b2be2bd57
Tig3ax is right. It would help to make your code more organize and use an object. So basically each object would have a list of commands, An item to go along with it, and a slot for that item. Notice how In my screenshot. I have a Party class. Every party will have an Array list of members and a party leader. You need to do something like that. Loop through all your items and more each item. Make a new instance of an object class and add it to a Hashmap then do what Tig3ax said and just compare the items. Once you have a match. Loop through the commands in the object and there you go.
damn what was that sexy font in intellij
 
Status
This thread has been locked.
Top