Linking classes to certain items into a GUI

Discussion in 'Plugin Development' started by DatCookiez, Jan 18, 2014.

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

    DatCookiez

    Hello guys,

    I am developing a plugin and I am just about done, all I need to do now is link certain classes in my plugin to another class. In one of my classes I have set up a GUI with items in it and in other classes I have made pvp kits and I am wanting to link them towards items in the GUI. When someone clicks on a certain item in that GUI I want them to receive all of the things that are listed in that class.

    Sorry if this doesn't make sense :/

    Thanks,
    DatCookiez
     
  2. Offline

    Aperx

    You could have a method that puts on the armour and gives whatever items come with the kit, like

    Code:java
    1. public void setKitTest(String player){
    2. //Itemstacks here
    3.  
    4. //Set armour
    5.  
    6. //Set inventory
    7. }
     
  3. Offline

    DatCookiez



    I need more help :O I am noob at using other classes
     
  4. Offline

    Gater12

    DatCookiez Then you have missed the point Java being an Object Orientated Programming language.
     
    Aperx likes this.
  5. Offline

    Aperx

    So with your kits, make that method for each one. Then,in the GUI class, do whateveryourclassnameisforthekit.setKit(then us a listener, InventoryClick listener, to get the player who clicked the gui item meant to give them the kit, and this will give the the armour and set their inventory

    so

    Code:
    YourClass.setKit(event.getWhoClicked());
    or something like that
     
  6. Offline

    DatCookiez


    I can't add items to a players inventory in the method? I can't find a way to call a player into the method so i can add items

    Also, I have special abilities in each class like one of them right click blaze powder to light people on fire, how would I make it so ONLY that kit gets that ability? (the ability is in the class according the the kit)

    Aperx
    Is this correct?
    Code:java
    1. public void setKitTest(String player){
    2.  
    3. Player p = Bukkit.getServer().getPlayer(player);
    4.  
    5. ItemStack dhelm = new ItemStack(Material.DIAMOND_HELMET);
    6. ItemStack dboot = new ItemStack(Material.DIAMOND_BOOTS);
    7. ItemStack dchest = new ItemStack(Material.DIAMOND_CHESTPLATE);
    8. ItemStack dleg = new ItemStack(Material.DIAMOND_LEGGINGS);
    9. ItemStack ssword = new ItemStack(Material.STONE_SWORD);
    10.  
    11. p.getInventory().addItem(ssword);
    12. p.getInventory().setHelmet(dhelm);
    13. p.getInventory().setChestplate(dchest);
    14. p.getInventory().setLeggings(dleg);
    15. p.getInventory().setBoots(dboot);
    16.  
    17. }


    And this is my click event
    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent e) {
    3. Player p = (Player) e.getWhoClicked();
    4. if (!e.getInventory().getName().equalsIgnoreCase(inv.getName())) return;
    5. if (e.getCurrentItem().getItemMeta() == null) return;
    6. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Mentalist")) {
    7. BlazeRod.setKitTest(e.getWhoClicked());
    8. e.setCancelled(true);
    9. p.sendMessage(ChatColor.GREEN + "You have chosen Mentalist!");
    10. e.getWhoClicked().closeInventory();
    11. }


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

    Aperx


    use
    Code:
    public void whatever(Player player){
     
    }
    Dunno why i wrote string :p
    The rest should be pretty straight forward, you could use itemmeta to make the effects to stick with that kit, but i don't want to feed you so, that should be easy enough for you to work out
     
  8. Offline

    DatCookiez

    Aperx
    Doesn't seem to be giving my players the items :/

    Aperx

    Code:java
    1. public void setKitTest(Player p){
    2.  
    3. ItemStack gchest = new ItemStack(Material.GOLD_CHESTPLATE);
    4. ItemStack gleg = new ItemStack(Material.GOLD_LEGGINGS);
    5. ItemStack gboot = new ItemStack(Material.GOLD_BOOTS);
    6. ItemStack dsword = new ItemStack(Material.DIAMOND_SWORD);
    7. ItemStack blazerod = new ItemStack(Material.BLAZE_ROD);
    8.  
    9. org.bukkit.inventory.meta.ItemMeta meta17 = blazerod.getItemMeta();
    10. meta17.setDisplayName(ChatColor.DARK_AQUA + "Teleporter");
    11. meta17.setLore(Arrays.asList(ChatColor.DARK_PURPLE + "Right click to teleport to", "the nearest player!"));
    12. blazerod.setItemMeta(meta17);
    13.  
    14. gchest.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    15. gleg.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    16. gboot.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    17. dsword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 2);
    18.  
    19. p.getInventory().addItem(dsword);
    20. p.getInventory().setChestplate(gchest);
    21. p.getInventory().setLeggings(gleg);
    22. p.getInventory().setBoots(gboot);
    23.  
    24. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page