Solved How do i check if a player has a book so it won't give him or her another one?

Discussion in 'Plugin Development' started by winitro, Sep 13, 2014.

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

    winitro

    Code:java
    1. [SIZE=2]@EventHandler[/SIZE]
    2.  
    3.  
    4.  
    5.  
    6. [B][COLOR=#7f0055][SIZE=2][B][COLOR=#7f0055][SIZE=2]public[/SIZE][/COLOR][/B][/SIZE][/COLOR][/B][B][COLOR=#7f0055][SIZE=2][B][COLOR=#7f0055][SIZE=2]void[/SIZE][/COLOR][/B][/SIZE][/COLOR][/B]
    7. [SIZE=2] onPlayerJoin(PlayerJoinEvent event) {[/SIZE]
    8. [B][COLOR=#7f0055][SIZE=2][B][COLOR=#7f0055][SIZE=2]if[/SIZE][/COLOR][/B][/SIZE][/COLOR][/B][SIZE=2]([/SIZE][I][COLOR=#0000c0][SIZE=2][I][COLOR=#0000c0][SIZE=2]KeeperofThings[/SIZE][/COLOR][/I][/SIZE][/COLOR][/I][SIZE=2].contains(event.getPlayer().getName())) [/SIZE][B][COLOR=#7f0055][SIZE=2][B][COLOR=#7f0055][SIZE=2]return[/SIZE][/COLOR][/B][/SIZE][/COLOR][/B]
    9. [SIZE=2];[/SIZE]
    10. Player player = event.getPlayer();
    11. ItemStack newItem = setMeta(
    12. [B][COLOR=#7f0055][SIZE=2][B][COLOR=#7f0055][SIZE=2]new[/SIZE][/COLOR][/B][/SIZE][/COLOR][/B][SIZE=2] ItemStack(Material.[/SIZE][I][COLOR=#0000c0][SIZE=2][I][COLOR=#0000c0][SIZE=2]BOOK[/SIZE][/COLOR][/I][/SIZE][/COLOR][/I][SIZE=2]), [/SIZE][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff][SIZE=2]"§2["[/SIZE][/COLOR][/SIZE][/COLOR][SIZE=2] + [/SIZE][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff][SIZE=2]"§a"[/SIZE][/COLOR][/SIZE][/COLOR][SIZE=2] + player.getName() + [/SIZE][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff][SIZE=2]"§2]"[/SIZE][/COLOR][/SIZE][/COLOR][SIZE=2] + [/SIZE][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff][SIZE=2]" §bKit selector"[/SIZE][/COLOR][/SIZE][/COLOR][SIZE=2], Arrays.[I]asList[/I]([/SIZE][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff][SIZE=2]"§cPick your kit here!"[/SIZE][/COLOR][/SIZE][/COLOR][SIZE=2], [/SIZE][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff][SIZE=2]"§bPlugin made by: §awinitro"[/SIZE][/COLOR][/SIZE][/COLOR]
    13. [SIZE=2]));[/SIZE]
    14.  
    15. player.getInventory().addItem(newItem);
    16.  
    17. }
    18. [SIZE=2] [/SIZE]
    19. syntax]
     
  2. Offline

    Mysticate

    1: Woah... that's a lot of formatting errors...
    2:
    Code:java
    1. if (!(player.getInventory().contains(new ItemStack(Material.BOOK))){
    2. //Give the player a book
    3. }
     
  3. Offline

    16davidjm6

    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent event) {
    3. if(KeeperofThings.contains(event.getPlayer().getName())){
    4. return;
    5. }
    6.  
    7. Player player = event.getPlayer();
    8.  
    9. ItemStack newItem = setMeta(new ItemStack(Material.BOOK), "§2[" + "§a" + player.getName() + "§2]" +
    10. " §bKit selector", Arrays.asList("§cPick your kit here!", "§bPlugin made by: §awinitro"));
    11.  
    12. player.getInventory().addItem(newItem);
    13.  
    14. }
    15.  


    reposting the original code to make it actually readable. No idea what the heck was up with those format tags, but I highly suggest not putting them in when you need help with code again. The less readability something has, the less likely you are to get help.
     
  4. Offline

    winitro

    Ok thanks
     
Thread Status:
Not open for further replies.

Share This Page