-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);
}
私はこれを最適化するために、任意のより多くの方法がありますかどうかを知りたいのですが?私はバキットとスピゴットで尋ねましたが、誰も本当に私にヒントをくれませんでしたので、ここに来ました。 また、効果を再適用する前に、効果を1秒ごとに再適用するのではなく、最初に使い果たすことができます。
すでに動作しているコードの最適化については、[codereview.se](https://codereview.stackexchange.com)でお尋ねください。しかし、最初に[this](http://meta.codereview.stackexchange.com/questions/5777/a-guide-to-code-review-for-stack-overflow-users)を読むことをお勧めします。 – bcsb1001