Clear Armor on Join.

Discussion in 'Plugin Development' started by MaxNatural, Jul 4, 2014.

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

    MaxNatural

    The main problem on my class is the
    Code:java
    1. new ItemStack(Material.AIR
    And i can't figure out the problem.

    Code:java
    1. package me.max;
    2.  
    3. import net.minecraft.server.v1_7_R1.Material;
    4.  
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerJoinEvent;
    9. import org.bukkit.inventory.ItemStack;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class Armor extends JavaPlugin implements Listener {
    13.  
    14. @EventHandler
    15. public void onJoin(PlayerJoinEvent e) {
    16. Player player = e.getPlayer();
    17. player.getInventory().setHelmet(new ItemStack(Material.AIR));
    18. player.getInventory().setChestplate(new ItemStack(Material.AIR));
    19. player.getInventory().setLeggings(new ItemStack(Material.AIR));
    20. player.getInventory().setBoots(new ItemStack(Material.AIR));
    21. }
    22. }
    23.  
     
  2. Offline

    tommyhoogstra

    Set the armour pieces to null, not air.

    This is a snippet of a working clear I have:

    Code:java
    1. public void clearArmor(Player p){
    2. p.getInventory().setHelmet(null);
    3. p.getInventory().setChestplate(null);
    4. p.getInventory().setLeggings(null);
    5. p.getInventory().setBoots(null);
    6. }
     
  3. Offline

    MaxNatural

  4. Offline

    tommyhoogstra

    You haven't registered your events in that class?
     
  5. Offline

    MaxNatural

    Code:java
    1. package me.max;
    2.  
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.PlayerJoinEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class Armor extends JavaPlugin implements Listener {
    10.  
    11. @EventHandler
    12. public void onJoin(PlayerJoinEvent event) {
    13. Player player = event.getPlayer();
    14. player.getInventory().setHelmet(null);
    15. player.getInventory().setChestplate(null);
    16. player.getInventory().setLeggings(null);
    17. player.getInventory().setBoots(null);
    18. }
    19. }
    20.  


    Not 100% sure what you mean sorry.

    tommyhoogstra

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

    MordorKing78

    If you did register the event in the Main Class. And it still does not work.
    Maybe,
    Code:java
    1. @EventHandler
    2. public void onJoin(PlayerJoinEvent event) {
    3. Player player = event.getPlayer();
    4. player.getInventory().setHelmet(Material.AIR);
    5. player.getInventory().setChestplate(Material.AIR);
    6. player.getInventory().setLeggings(Material.AIR);
    7. player.getInventory().setBoots(Material.AIR);


    Its the same as null but... I Think you did not register it in the main class.
    If you did are there any errors?
     
  7. Offline

    MaxNatural

  8. Offline

    hankered

    Add
    Code:java
    1. player.sendMessage("hi")
    2.  

    and tell us if you get the message when you join
     
  9. Offline

    CynutsBR

    MaxNatural You need to register event in onEnable, and create a plugin.yml!
     
  10. Offline

    Twistt

    Instead doing each piece of armour one after the other you can do p/player.setArmorContents(null).
    I'll leave some code below as this may be confusing to you or anyone and I will fix your code aswell
    Code:java
    1.  
    2. import org.bukkit.Bukkit;
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.player.PlayerJoinEvent;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class Armor extends JavaPlugin implements Listener {
    9.  
    10. public void onEnable() {
    11. Bukkit.getPluginManager().registerEvents(this, this); // This gets the plugin manager and tells it to register all events in this class.
    12. }
    13.  
    14. public void onJoin(PlayerJoinEvent event) {
    15. Player player = event.getPlayer();
    16. player.getInventory().setArmorContents(null); // << This gets there armor and sets it to nothing
    17. }
    18.  
    19. }


    This is as much as I could help you the rest is for you to figure out but I have given you all the code you need and shorted it a little too.
     
    iiHeroo likes this.
  11. Offline

    MaxNatural

    Twistt thanks i fixed it!
     
  12. Offline

    Twistt

    Your welcome! :)
     
  13. Offline

    MordorKing78

    Great, You can solve your post now ;)
     
Thread Status:
Not open for further replies.

Share This Page