Adding potion effects when equipped with full set of armor

Discussion in 'Plugin Development' started by porkchopelite, May 22, 2013.

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

    porkchopelite

    I'm trying to add potion effects and change weapon damage outputs(player who gets hit will receive slowness etc.)when a player equips a full set of leather armor, i'm making my first every plugin and i'm new to java as well so i have no idea what i'm doing. This is what I've got so far.

    Code:
    import org.bukkit.Material;
    import org.bukkit.entity.HumanEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryCloseEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.command.CommandSender;
     
    public class main implements Listener  {
        public void onInventoryClose(InventoryCloseEvent event){
            HumanEntity human = event.getView().getPlayer();
            if(human instanceof Player){
                human.getInventory().getHelmet();
                Material helmet = human.getInventory().getHelmet().getType();
                human.getInventory().getChestplate();
                Material chestplate = human.getInventory().getChestplate().getType();
                human.getInventory().getLeggings();
                Material leggings = human.getInventory().getLeggings().getType();
                human.getInventory().getBoots();
                Material boots = human.getInventory().getBoots().getType();
                if(helmet == Material.LEATHER_HELMET)if (chestplate == Material.LEATHER_CHESTPLATE)if(leggings == Material.LEATHER_LEGGINGS)if (boots == Material.LEATHER_BOOTS) {
                    Player player = (Player) human;
                    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE,0));
                    Player.sendMessage("You have equipped the Assassin class.");
                }else {
                   
                    
     
  2. Offline

    chasechocolate

    You need to have the @EventHandler annotation above your method.
     
  3. Offline

    Rhino390

    Just an observation, but
    Code:java
    1.  
    2. [SIZE=13px][FONT=Consolas]if(helmet == Material.LEATHER_HELMET)if(chestplate == Material.LEATHER_CHESTPLATE)if(leggings == Material.LEATHER_LEGGINGS)if(boots == Material.LEATHER_BOOTS){[/FONT][/SIZE]
    3.  



    doesn't make any sense. You would need to use:
    Code:java
    1.  
    Code:java
    1.  
    2. [FONT=Consolas]if(leggings == Material.LEATHER_LEGGINGS && chestplate == Material.LEATHER_CHESTPLATE && boots == Material.LEATHER_BOOTS && helmet == Material.LEATHER_HELMET){[/FONT]
    3. //Do code here
    4. }
    5. [FONT=Consolas][/FONT]
     
  4. Offline

    bitWolfy

    Rhino390 It'll actually work. Really bad coding, but it'll work.

    porkchopelite I sincerely hope that this is NOT your only class in the plugin. Here, I re-wrote the listener for you:

    Code:
    @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.LEATHER_HELMET)
                && (playerArmor[1] != null && playerArmor[1].getType() == Material.LEATHER_CHESTPLATE)
                && (playerArmor[2] != null && playerArmor[2].getType() == Material.LEATHER_LEGGINGS)
                && (playerArmor[3] != null && playerArmor[3].getType() == Material.LEATHER_BOOTS)) {
            player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE,0));
            player.sendMessage("You have equipped the Assassin class.");
        }
    }
     
  5. Offline

    porkchopelite

    bitWolfy It actually is, the listener class is the only class i have in my plugin, i have no idea what to do with my main class. Like i said im really new to java and have no idea what im doing. Anyways can you help me finish this part of my plugin and get it working ? The idea is that once you've equipped the full set of armour you'll get speed 2 constantly unless you take one part of the armor off. How do i achieve that , with scheduler ? Cheers :D
     
  6. Offline

    Rhino390

    If that is your only class then it will never work, you need a main class that extends JavaPlugin, with an onEnable() and onDisable(), and you have to register the event in the onEnable().
     
Thread Status:
Not open for further replies.

Share This Page