Simple thing isnt working :(

Discussion in 'Plugin Development' started by 15987632, Aug 31, 2014.

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

    15987632

    When a player joins and his first inv slot in empty it will give him a wood sword same goes for all his armor slots with leather armor. Why wont this work :(

    Code:java
    1. import org.bukkit.Bukkit;
    2. import org.bukkit.Material;
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.player.PlayerJoinEvent;
    6. import org.bukkit.inventory.Inventory;
    7. import org.bukkit.inventory.ItemStack;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10.  
    11. public class main extends JavaPlugin implements Listener {
    12.  
    13. public void onEnable() {
    14. getLogger().info("is started");
    15. Bukkit.getPluginManager().registerEvents(this, this);
    16. }
    17.  
    18. public void onPlayerJoin(PlayerJoinEvent e) {
    19. Player p = e.getPlayer();
    20. Inventory i = p.getInventory();
    21. if (i.getItem(1) == null) {
    22. i.getItem(1).setType(Material.WOOD_SWORD);
    23. }
    24. if (p.getEquipment().getHelmet() == null){
    25. ItemStack item = new ItemStack(Material.LEATHER_HELMET, 1);
    26. p.getEquipment().setHelmet(item);
    27. }
    28. if (p.getEquipment().getChestplate() == null){
    29. ItemStack item = new ItemStack(Material.LEATHER_CHESTPLATE);
    30. p.getEquipment().setChestplate(item);
    31. }
    32. if (p.getEquipment().getLeggings() == null){
    33. ItemStack item = new ItemStack(Material.LEATHER_LEGGINGS, 1);
    34. p.getEquipment().setLeggings(item);
    35. }
    36. if (p.getEquipment().getBoots() == null){
    37. ItemStack item = new ItemStack(Material.LEATHER_BOOTS, 1);
    38. p.getEquipment().setLeggings(item);
    39. }
    40. }
    41.  
    42. }
     
  2. Offline

    Gater12

    15987632
    You have forgotten the @EventHandler annotation above your event method.
     
  3. Offline

    Skye

  4. Offline

    15987632

    Skye Im stupid xD thanks
     
  5. Offline

    hintss

    You should probably setItem to a new itemstack with a sword instead of what you're doing now. Also, btw, slot 1 is the second hotbar slot, slot 0 is the first.
     
Thread Status:
Not open for further replies.

Share This Page