So ist mein Code:Jede andere Möglichkeit, dies zu optimieren?
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);
}
Ich würde gerne wissen, ob mehr Art und Weise gibt es diese zu optimieren? Ich habe in Bukkit und Spigot herumgefragt, aber niemand hat mir wirklich irgendwelche Tipps gegeben, also bin ich hergekommen. Bevor der Effekt erneut angewendet wird, lässt er den Trankeffekt zuerst auslaufen, anstatt ihn jede halbe Sekunde erneut anzuwenden.
Bei Fragen zum Optimieren von Code, der bereits funktioniert, können Sie nach [codereview.se] (https://codereview.stackexchange.com) fragen. Ich möchte Sie jedoch dazu ermutigen, [this] (http://meta.codereview.stackexchange.com/questions/5777/a-guide-to-code-review-for-stack-overflow-users) zuerst zu lesen. – bcsb1001