Solved Inventory Manipulation

Discussion in 'Plugin Development' started by justin_393, Mar 12, 2014.

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

    justin_393

    Code:java
    1. package jjbat_000.servermenu;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.EventPriority;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.player.PlayerLoginEvent;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.inventory.ItemStack;
    10. import org.bukkit.inventory.meta.ItemMeta;
    11. import org.bukkit.ChatColor;
    12.  
    13.  
    14. public class Login implements Listener {
    15. @EventHandler(priority = EventPriority.HIGH)
    16. public void onLogin(PlayerLoginEvent event) {
    17. Player player = event.getPlayer();
    18. player.getInventory().addItem(new ItemStack(Material.COMPASS));
    19. /*
    20.   String myDisplayName = ChatColor.GREEN + "Server Selector";
    21.   ItemStack Compass = new ItemStack(Material.COMPASS);
    22.   ItemMeta im = Compass.getItemMeta();
    23.   im.setDisplayName(myDisplayName);
    24.   Compass.setItemMeta(im);*/ // Will be worked on later.
    25. }
    26.  
    27. }


    Hi, I'm trying to make a plugin to where when a player logs in they receive a compass. This is my listener class. For some reason I do not receive the compass when I test the plugin. I get an error when I do player.getInventory().addItem(Material.COMPASS); so I used player.getInventory().addItem(new ItemStack(Material.COMPASS));
     
  2. Offline

    Heirteir

    justin_393
    change PlayerLoginEvent to PlayerJoinEvent and that should fix your error if it doesn't let me know
     
  3. Offline

    justin_393

    Heirteir
    Yep, that works thanks. I never knew there was a difference between PlayerLoginEvent and PlayerJoinEvent Mind clarifying?
     
  4. Offline

    Heirteir

    justin_393
    This event is used when the player first presses the connect button to login to the server. You usually check here if a player is banned, etc

    PlayerJoinEvent

    This event is called when a player has successfully logged onto the server.
    This is the event you use if you want to have a motd. Or just a welcome message.

    Got this from another post because to be honest I didn't know the difference either but this pretty much tells you the
    difference!
     
  5. Offline

    justin_393

    Alright, thanks!
     
Thread Status:
Not open for further replies.

Share This Page