Solved 1 Inventory per player

Discussion in 'Plugin Development' started by maxecito, Apr 21, 2015.

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

    maxecito

    Hey guys!
    Im currently working on a "levelup-manager" for each player (RPG-plugin), but my problem is that Im now working with an inventory open to everyone, so when I lvl up something everyone (even other classes) got it.
    Would be GREAT if someone could try to edit the code below to make 1 inventory per player.

    (Sorry, Im a Bukkit/Java noob)
    Code:
    package at.skyblock.main;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.DyeColor;
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    @SuppressWarnings("deprecation")
    public class Elf_levelup {
       public static org.bukkit.inventory.Inventory levelup_elf = Bukkit
           .createInventory(null, 27, ChatColor.DARK_GREEN + ""
               + ChatColor.BOLD + "Levelup-manager");
    
       static {
    
         ItemStack mobility = new ItemStack(Material.HARD_CLAY,
             DyeColor.RED.getData(), (short) 1);
         ItemMeta mobility_meta = mobility.getItemMeta();
         mobility_meta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD
             + "Mobility I");
         ArrayList<String> mobility_desc = new ArrayList<String>();
         mobility_desc.add(ChatColor.AQUA + "Speed I for ");
         mobility_desc.add(ChatColor.AQUA + "2 seconds on hit");
         mobility_meta.setLore(mobility_desc);
         mobility.setItemMeta(mobility_meta);
    
         ItemStack trickshot = new ItemStack(Material.BLAZE_POWDER);
         ItemMeta trickshot_meta = trickshot.getItemMeta();
         trickshot_meta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD
             + "Trickshot I");
         ArrayList<String> trickshot_desc = new ArrayList<String>();
         trickshot_desc.add(ChatColor.AQUA + "10% Chance to apply");
         trickshot_desc.add(ChatColor.AQUA + "Blindness I on hit");
         trickshot_meta.setLore(trickshot_desc);
         trickshot.setItemMeta(trickshot_meta);
    
         ItemStack trickshot2 = new ItemStack(Material.BLAZE_POWDER);
         ItemMeta trickshot2_meta = trickshot2.getItemMeta();
         trickshot2_meta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD
             + "Trickshot II");
         ArrayList<String> trickshot2_desc = new ArrayList<String>();
         trickshot2_desc.add(ChatColor.AQUA + "15% Chance to apply");
         trickshot2_desc.add(ChatColor.AQUA + "Blindness I on hit");
         trickshot2_meta.setLore(trickshot2_desc);
         trickshot2.setItemMeta(trickshot2_meta);
    
         levelup_elf.setItem(0, mobility);
         levelup_elf.setItem(18, trickshot);
         levelup_elf.setItem(19, trickshot2);
       }
    }
    
    
     
  2. Offline

    sgavster

    Instead of null, put player, (of course, define a player object..)
     
  3. Offline

    guitargun

    what abut not making the inventory static?
     
  4. Offline

    maxecito

    @sgavster
    Thanks for the tip, but where should I define the player without having an Event or a Command to receive it...?

    Im using it in 3 other classes.

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

    sgavster

    @maxecito Well; you have to define a player to open the inventory so make a method (public static void open(Player player) { ). Put everything in that class into this method (inventory, and the adding of the items) and put that in the class, then, call it from another class with the player you open the inventory for.
    Also, don't double post, use the 'edit' button.
     
  6. Offline

    Zombie_Striker

    Instead of referencing one inventory and then every player has the inventory open. Name the all inventory the same thing ("RPG MENU") , that way everyone has their own, and you can look to see if the title is "RPG MENU" by using .getTitle();
     
  7. Offline

    maxecito

    @sgavster Possible, but my problem is that I need to edit and set new items from other classes, so I need the Inventory itself static :/
     
  8. Offline

    mythbusterma

    @maxecito

    No, you don't.

    That is not at all what the static keyword is used for, and I'd really appriciate it if everyone stopped saying it is.

    Use getter and setter methods.

    Also, fix your class and variable names, they're very difficult to look at. The only things that get underscores in Java are constants.

    Your efforts would be better focused here:

    The Java™ Tutorials
     
    WinX64 likes this.
  9. Offline

    maxecito

    Alright, solved.
     
Thread Status:
Not open for further replies.

Share This Page