2016-07-19 4 views
-4

그래서 내 코드는 다음과 같습니다 다른 방법으로이를 최적화 할 수 있습니까?

public void checkArmor() { 
    Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { 
     public void run() { 
      for (Player p : Bukkit.getOnlinePlayers()) { 
       if (p.getInventory().getBoots().getType() == Material.CHAINMAIL_BOOTS 
         && p.getInventory().getLeggings().getType() == Material.CHAINMAIL_LEGGINGS 
         && p.getInventory().getChestplate().getType() == Material.CHAINMAIL_CHESTPLATE 
         && p.getInventory().getHelmet().getType() == Material.CHAINMAIL_HELMET) { 
        p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 20, 0)); 
        p.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 20, 1)); 
        p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20, 0)); 
       } 
       if (p.getInventory().getBoots().getType() == Material.LEATHER_BOOTS 
         && p.getInventory().getLeggings().getType() == Material.LEATHER_LEGGINGS 
         && p.getInventory().getChestplate().getType() == Material.LEATHER_CHESTPLATE 
         && p.getInventory().getHelmet().getType() == Material.LEATHER_HELMET) { 
        p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20, 1)); 
        p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20, 1)); 
        p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20, 1)); 
       } 
       if (p.getInventory().getBoots().getType() == Material.IRON_BOOTS 
         && p.getInventory().getLeggings().getType() == Material.IRON_LEGGINGS 
         && p.getInventory().getChestplate().getType() == Material.IRON_CHESTPLATE 
         && p.getInventory().getHelmet().getType() == Material.IRON_HELMET) { 
        p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 20, 0)); 
        p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20, 1)); 
        p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 20, 1)); 
       } 
       if (p.getInventory().getBoots().getType() == Material.GOLD_BOOTS 
         && p.getInventory().getLeggings().getType() == Material.GOLD_LEGGINGS 
         && p.getInventory().getChestplate().getType() == Material.GOLD_CHESTPLATE 
         && p.getInventory().getHelmet().getType() == Material.GOLD_HELMET) { 
        p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 20, 2)); 
        p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 140, 0)); 
        p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 20, 1)); 
        p.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 20, 1)); 
       } 
      } 
     } 
    }, 0, 10); 
} 

내가이 최적화 더 이상 방법이 있는지 알고 싶습니다

? 나는 부킷 킷 (bukkit)과 스피 곳 (spigot)에서 물어 보았지만, 아무도 나에게 어떤 조언도주지 않았으므로 여기에왔다. 또한 효과를 다시 적용하기 전에 물방울 효과가 0.5 초마다 다시 적용되는 대신 먼저 실행됩니다.

+0

이미 작동하는 코드 최적화에 대한 질문은 [codereview.se] (https://codereview.stackexchange.com)에서 문의하십시오. 그러나 먼저 [this] (http://meta.codereview.stackexchange.com/questions/5777/a-guide-to-code-review-for-stack-overflow-users)를 읽어보십시오. – bcsb1001

답변

0

같은 방법을 반복해서 호출하고 있습니다. 왜 한 번만 전화를하고 난 정말이 엄청난 성능 차이가 있다고 생각하지 않는다

leggingsType = p.getInventory().getLeggings().getType(); 

과 같은 몇 가지 변수에 결과를 할당하지만 코드를 읽기 쉽게 만들 수 없습니다.