event handler for wearing armor

Discussion in 'Plugin Development' started by youtube037, Sep 6, 2014.

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

    youtube037

    im making a custom plugin for a server and they want you to make the right armor and when u wear that armor it will give u potion effects. it will use vanilla armor and normal crafting recipes i cant get an event handler when u wear the full set it will give u the potion effects i need help
     
  2. Offline

    BananaBitchs

    Enjoy youtube037
    Code:java
    1. public void onEnable() {
    2. ArmorPotion():
    3. }
    4. public void ArmorPotion(){
    5.  
    6. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    7.  
    8. public void run(){
    9. for(Player all : Bukkit.getOnlinePlayers()){
    10. Player p = all.getPlayer();
    11. if(p.getInventory().getHelmet().getType() == Material.DIAMOND_HELMET && p.getInventory().getChestplate().getType() == Material.DIAMOND_CHESTPLATE && p.getInventory().getLeggings().getType() == Material.DIAMOND_LEGGINGS && p.getInventory().getBoots().getType() == Material.DIAMOND_BOOTS){
    12. if(!p.hasPotionEffect(PotionEffectType.REGENERATION)){
    13. p.sendMessage("You have now Reginaration potion!");
    14. p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION , 100,2));
    15. }
    16. }
    17. }
    18. }
    19. }, 0, 10L);
    20. }
     
  3. Offline

    LCastr0

    Wrong section...
     
  4. Offline

    AoH_Ruthless

    BananaBitchs Your spoonfeed also has some minor flaws..
    • Why use #getPlayer() on an object that is known to be a player??
    • Why would you loop every 10 ticks to add a potion for 100 ticks? Keep it consistent.
    • (Convention) Fix your naming of methods and loop variable.
     
  5. Offline

    ChipDev

    Did you report?
     
  6. Offline

    LCastr0

    Shh
     
Thread Status:
Not open for further replies.

Share This Page