Armour Potion Effect Plugin Not Working

Discussion in 'Plugin Development' started by FlobGaming, Feb 25, 2015.

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

    FlobGaming

    Hello I have recently developed a very small plugin that gives a player who is wearing a full set of gold armour jump boost 2, speed 3 & absorption 1 only while they are wearing the armor. It is not working for some reason. There are no console errors or any errors in my IDE. Help is much appreciated, here is my only class - and yes I did add my plugin.yml correctly:

    Code:
    package me.flobgaming.Classes;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryCloseEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class Classes extends JavaPlugin
      implements Listener
    {
      @Override
      public void onDisable()
      {
      }
    
      @Override
      public void onEnable()
      {
        getServer().getPluginManager().registerEvents(this, this);
      }
      @EventHandler
      public void onInventoryClose(InventoryCloseEvent event) {
          Player player = (Player) event.getView().getPlayer();
          ItemStack[] playerArmor = player.getInventory().getArmorContents();
          if((playerArmor[0] != null && playerArmor[0].getType() == Material.GOLD_HELMET)
                  && (playerArmor[1] != null && playerArmor[1].getType() == Material.GOLD_CHESTPLATE)
                  && (playerArmor[2] != null && playerArmor[2].getType() == Material.GOLD_LEGGINGS)
                  && (playerArmor[3] != null && playerArmor[3].getType() == Material.GOLD_BOOTS)) {
              player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE,1));
              player.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, Integer.MAX_VALUE,0));
              player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE,2));
              player.sendMessage(ChatColor.DARK_GRAY + "> " + ChatColor.DARK_GREEN + "You have equipped the ' " + ChatColor.YELLOW + "Runner " + ChatColor.DARK_GREEN + "' class.");
          }
      }}
    Thanks!
     
  2. Offline

    nj2miami

    Player player = (Player) event.getPlayer();
     
  3. Offline

    FlobGaming

    Still does not work :confused:
     
  4. Offline

    DaanSander

    tried debugging it?
     
  5. Offline

    nj2miami

    Simply add a debug message at the top of your event right after you declare Player player.

    player.sendMessage("Inventory close event triggered");

    If that fires, then at least you know its a logic issue in your IF statements. Try changing the == to .equals() when comparing the Material types.
     
  6. Offline

    FlobGaming

    I have tried adding the debug message but it didn't appear. I have also changed all of my '==' to .equals() statements.
    The error isn't in my if statements.
     
  7. Offline

    nj2miami

    Then you have far greater issues than what you are seeking help on because your event is not being called at all, which means you have a fundamental mistake somewhere in your code.
     
  8. Offline

    redside100

    I'm not sure if InventoryCloseEvent actually gets called when a player closes his/her inventory.
     
  9. Offline

    nj2miami

    I am fairly sure your plugin is not even loading at this point. What does you plugin.yml look like? Do a /plugins and do you see your plugin there?

    Some additional cleanup items:

    implements Listener <- not needed here
    getServer().getPluginManager().registerEvents(this, this); <- also not needed

    It absolutely does, I have many plugins which listen to this event.

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

    FlobGaming

    It does show up in the plugin list and here is my plugin.yml:

    Code:
    name: Classes
    main: me.flobgaming.Classes.Classes
    version: 0.1
    author: Flob
    description: Classes plugin.
     
  11. Offline

    FlobGaming

  12. Offline

    TwerkinCraft

    If you never implement Listener of register the events, the plugin will never try to listen for it...

    And if this is supposed to give potion effects only when the player is wearing the armor, I am going to say, the potion effects are never removed (and there is nothing in there preventing them from taking off the armor). Why check when the inventory is closed, it might be possible that the player logs in already wearing the armor and doesn't get the effects.
     
  13. Offline

    nj2miami

    My mistake here. Its really just bad form to do everything in your main class, so I never do it and thought JavaPlugin already implemented Listener. I always create a class for each listener and register those in a config class. I like my main class clean and simple.

    However, the fact that his plugin is simply not even sending the message I had him put in at the beginning of the event, it is obviously not firing at all, which leads to a larger issue.
     
    TwerkinCraft likes this.
  14. Offline

    Webbeh

    Didn't you invert the armor slots ? Isn't the position 0 for boots, 1 for leggings, 2 for chestplate and 3 for helmet ?

    EDIT: indeed, they're inverted. Try again after having switched those values.
     
  15. Offline

    FlobGaming

    Guys I recoded my methods and altered my variables. The plugin works fine now except when I equip a class the message is displayed so many times in chat. Is this I registered the message event in the Bukkit runnable event? How can I make the message only display once.
     
  16. Offline

    Zombie_Striker

    Code:
    boolean playedOnce = false;
    if(polayedOnce == false){
    sendmessage
    playedOnce = true;
    }
    could also set the boolean to an arraylist if its for multiple people.
     
Thread Status:
Not open for further replies.

Share This Page