Solved How to create an inventory with player heads

Discussion in 'Plugin Development' started by sgavster, Aug 15, 2013.

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

    Xx_LeetGamer_xX

    Then just remove all the arena stuff, and change this for loop:

    Code:
    for(Player px: SurvivalGames.getInstance().games[arena].players){
    To this:

    Code:
    for(Player px: <your array list>){
     
  2. Offline

    sgavster

    Xx_LeetGamer_xX Okay, so what about these?
    Code:
        int arena = SpectateHandler.GetArena(p);
    Code:
      int size = SurvivalGames.getInstance().games[arena].players.size();
    Code:
     if(SurvivalGames.getInstance().games[SpectateHandler.GetArena(p)].players.contains(px)){
    Code:
          if(SpectateHandler.spectators.contains(p)){
    I'm guessing most of them are ArrayList's, but I'm just making sure.
     
  3. Offline

    Xx_LeetGamer_xX

    You can delete all of that, that's just to make sure the player is spectating on the SG plugin.

    However, you do want to keep the size variable, but you can just make it the size of your array list.
     
  4. Offline

    sgavster

    Xx_LeetGamer_xX So would I do this:
    Code:
    int size = <array_list_name>.size();
     
  5. Offline

    Xx_LeetGamer_xX

    That's correct.
     
    sgavster likes this.
  6. Offline

    sgavster

    Xx_LeetGamer_xX One last thing, sorry, but what should I put here:
    Code:java
    1. Inventory inv = Bukkit.createInventory(p, GetSize(arena), ChatColor.BOLD + "Spectator Teleporter");

    in the GetSize(arena) part?
     
  7. Offline

    Xx_LeetGamer_xX

    You can find that method on the bottom of the PlayerInteract class. That basically just sizes the inventory because it must be a multiple of 9.
     
    sgavster likes this.
  8. Offline

    sgavster

    Xx_LeetGamer_xX okay. Just confused about 1 more thing, which is
    Code:
     [FONT=Consolas][COLOR=#141414]for(Player px: SurvivalGames.getInstance().games[arena].players){[/COLOR][/FONT]
    if I change it to int size = playing.size(); (playing being the arraylist) it doesn't work.. Is there something I am missing?
     
  9. Offline

    Xx_LeetGamer_xX

    What is the error?
     
  10. Offline

    sgavster

    Xx_LeetGamer_xX Type mismatch: cannot convert from element type String to Player
    Also, I get an error on this code:
    Code:
    private static int GetSize(int arena){
    for The method GetSize(int) from the type UltimumStans is never used locally
     
  11. Offline

    xCyanide

    sgavster
    This is the code I use for my sg plugin(I am using the icon menu because I feel it makes thing so much easier)
    Code:java
    1. public void getSpecatoryInventory(Player p) {
    2. String title = GameMOTD.motdPrefix + ChatColor.DARK_RED + "Players:";
    3. int i = 0;
    4. IconMenu spectatorMenu = new IconMenu(title, 27, new IconMenu.OptionClickEventHandler(){
    5. public void onOptionClick(OptionClickEvent event) {
    6. event.setWillClose(true);
    7. event.setWillDestroy(true);
    8.  
    9. event.getPlayer().teleport(Bukkit.getPlayer(event.getName()).getLocation());
    10. }
    11. }, plugin);
    12. for(Player player : plugin.sgplayers) {
    13. if(i< 27){
    14. ItemStack head = new ItemStack(397, 1, (byte) 3);
    15. spectatorMenu.setOption(i, head, player.getName());
    16. i = i+1;
    17. }
    18. }
    19. spectatorMenu.open(p);
    20. }
     
    sgavster likes this.
  12. Offline

    sgavster

    xCyanide How do you access it? And that's it? That's all the code? :eek:
     
  13. Offline

    xCyanide

    sgavster
    Access the method? and that is it :)
     
  14. Offline

    sgavster

    xCyanide That's well, very impressive :eek: new like for you :p

    xCyanide I'm not sure what to put here:
    Code:
    }, plugin);
    , and these
    Code:
    OptionClickEvent
    Code:
    IconMenu
    can't be resolved as a type, and I can't import them.
    Any help would be great.. I really want to get this done. :(

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

    xCyanide

    sgavster likes this.
  16. Offline

    sgavster

    xCyanide I put it in my main class, but it doesn't work for some reason :/ the only error is 'plugin'

    xCyanide Nevermind. :p Thank you!

    Ugh, I'm sorry to bug you, but I'm getting a huge error in the console..:
    [​IMG]
    [​IMG]

    I'm still new to Java, and I'm not sure what's causing this, again sorry for bugging you :(

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

    xCyanide

  18. Offline

    sgavster

    xCyanide
    Code:
                        ItemStack head = new ItemStack(397, 1, (byte) 3);
     
  19. Offline

    xCyanide

    sgavster
    Are you positive that is line 223?
     
  20. Offline

    sgavster

    xCyanide Oops, that was line 233, sorry! This is line 223
    Code:
            IconMenu spectatorMenu = new IconMenu(this.prefix, 27, new IconMenu.OptionClickEventHandler(){
     
  21. Offline

    xCyanide

    sgavster
    Post your entire player interact event and is this event in the main class or a different class?
     
  22. Offline

    sgavster

    xCyanide The event is in Main. Also, I removed some un-needed code, and this is the error: [​IMG]
    and this is the code
    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled=true)
    2. public void playerInteract1(PlayerInteractEvent e)
    3. {
    4. Player p = e.getPlayer();
    5. if(p.getItemInHand().getType() == Material.COMPASS){
    6. if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
    7. }
    8. int i = 0;
    9. IconMenu spectatorMenu = new IconMenu(this.prefix, 27, new IconMenu.OptionClickEventHandler(){
    10. public void onOptionClick(OptionClickEvent event) {
    11. event.setWillClose(true);
    12. event.setWillDestroy(true);
    13.  
    14. event.getPlayer().teleport(Bukkit.getPlayer(event.getName()).getLocation());
    15. }
    16. }, plugin);
    17. for(Player player : Bukkit.getOnlinePlayers()) {
    18. if(i< 27){
    19. ItemStack head = new ItemStack(397, 1, (byte) 3);
    20. spectatorMenu.setOption(i, head, player.getName());
    21. i = i+1;
    22. }
    23. }
    24. spectatorMenu.open(p);
    25. }
    26. }
    27. }
     
  23. Offline

    xCyanide

    sgavster
    Change plugin to this(I was expecting that to be your problem when you told me what line 223 was)
     
  24. Offline

    artish1

    sgavster
    I don't really know much about IconMenu (What you are using), Because i use my own sort of GUI in inventories, but it seems as though i've come across alot of errors and most of those causes are through IconMenu, I really haven't ever used this resource but i would suggest you report this problem to the person who made that.
     
Thread Status:
Not open for further replies.

Share This Page