Solved Join Event not doing anything

Discussion in 'Plugin Development' started by FletchTech90, Jun 18, 2014.

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

    FletchTech90

    Hi, I'm trying to give a compass to the player and send a message on join, but nothing, absolutely nothing, happens. This is urgent!
    My code:
    Code:java
    1. @EventHandler
    2. public void onJoin(PlayerJoinEvent e){
    3. Player p = e.getPlayer();
    4. PlayerInventory i = p.getInventory();
    5. ItemStack compass = new ItemStack(Material.COMPASS, 1);
    6. ItemMeta im = compass.getItemMeta();
    7. List<String> lore = new ArrayList<String>();
    8. lore.add(ChatColor.YELLOW + "Right Click with");
    9. lore.add(ChatColor.YELLOW + "me to teleport");
    10. lore.add(ChatColor.YELLOW + "around the server!");
    11. im.setLore(lore);
    12. im.setDisplayName(ChatColor.GOLD + "Warp Compass");
    13. p.sendMessage(ChatColor.YELLOW + "You can use your compass to teleport!");
    14. if(!(i.contains(Material.COMPASS))){
    15. i.addItem(compass);
    16. }
    17. }
     
  2. Offline

    Gater12

  3. Offline

    FletchTech90

    Can you please clarify a little? I'm a derp. Sorry about that. ;)
     
  4. Offline

    MCMatters

    Full class please
     
  5. Offline

    FletchTech90


    Code:java
    1. package me.FletchTech90.AstroRealms;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.player.PlayerJoinEvent;
    11. import org.bukkit.inventory.ItemStack;
    12. import org.bukkit.inventory.PlayerInventory;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class Main extends JavaPlugin {
    17.  
    18. public void onEnable(){
    19. this.getLogger().info("Enabled " + this.getDescription().getName() + " v" + this.getDescription().getVersion());
    20. }
    21.  
    22. public void onDisable(){
    23. this.getLogger().info("Disabled " + this.getDescription().getName() + " v" + this.getDescription().getVersion());
    24. }
    25.  
    26. @EventHandler
    27. public void onJoin(PlayerJoinEvent e){
    28. Player p = e.getPlayer();
    29. PlayerInventory i = p.getInventory();
    30. ItemStack compass = new ItemStack(Material.COMPASS, 1);
    31. ItemMeta im = compass.getItemMeta();
    32. List<String> lore = new ArrayList<String>();
    33. lore.add(ChatColor.YELLOW + "Right Click with");
    34. lore.add(ChatColor.YELLOW + "me to teleport");
    35. lore.add(ChatColor.YELLOW + "around the server!");
    36. im.setLore(lore);
    37. im.setDisplayName(ChatColor.GOLD + "Warp Compass");
    38. p.sendMessage(ChatColor.YELLOW + "You can use your compass to teleport!");
    39. if(!(i.contains(Material.COMPASS))){
    40. i.addItem(compass);
    41. }
    42. }
    43.  
    44. }
    45.  
     
  6. Offline

    MCMatters

    Ah in onenqble do FletchTech90
    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(this, this);
     
  7. Offline

    FletchTech90

    Oh! Thanks so much, MCMatters! You saved my plugin! You sir, just earned a follow. ;)
     
Thread Status:
Not open for further replies.

Share This Page