use util for harmful effects list

This commit is contained in:
2023-06-22 19:06:15 +02:00
parent d859fd0aaa
commit c11c455c53
@@ -4,6 +4,7 @@ import me.youhavetrouble.preventstabby.PreventStabby;
import me.youhavetrouble.preventstabby.players.PlayerManager;
import me.youhavetrouble.preventstabby.util.CombatTimer;
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
import me.youhavetrouble.preventstabby.util.Util;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
@@ -11,6 +12,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
import org.bukkit.potion.PotionEffectType;
import java.util.Iterator;
import java.util.UUID;
@@ -20,21 +22,11 @@ public class AreaEffectCloudApplyListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onCloudEffects(AreaEffectCloudApplyEvent event) {
if (!(event.getEntity().getSource() instanceof Player)) return;
PotionEffectType potionEffectType = event.getEntity().getBasePotionData().getType().getEffectType();
if (potionEffectType == null) return;
if (potionEffectType == null)
return;
if(event.getEntity().getSource() instanceof Player) {
if (potionEffectType.equals(PotionEffectType.BLINDNESS) ||
potionEffectType.equals(PotionEffectType.CONFUSION) ||
potionEffectType.equals(PotionEffectType.HARM) ||
potionEffectType.equals(PotionEffectType.HUNGER) ||
potionEffectType.equals(PotionEffectType.POISON) ||
potionEffectType.equals(PotionEffectType.SLOW_DIGGING) ||
potionEffectType.equals(PotionEffectType.WEAKNESS) ||
potionEffectType.equals(PotionEffectType.SLOW) ||
potionEffectType.equals(PotionEffectType.WITHER)) {
if (!Util.isPotionEffectHarmful(potionEffectType)) return;
PlayerManager playerManager = PreventStabby.getPlugin().getPlayerManager();
@@ -43,10 +35,8 @@ public class AreaEffectCloudApplyListener implements Listener {
while (it.hasNext()) {
LivingEntity entity = it.next();
if (entity instanceof Player) {
UUID victim = entity.getUniqueId();
if (damager == victim)
continue;
if (damager == victim) continue;
if (playerManager.canDamage(damager, victim, true))
CombatTimer.refreshPlayersCombatTime(damager, victim);
@@ -56,12 +46,10 @@ public class AreaEffectCloudApplyListener implements Listener {
} else if (entity instanceof Tameable) {
Tameable tameable = (Tameable) entity;
if (tameable.getOwner() == null)
continue;
if (tameable.getOwner() == null) continue;
UUID victim = tameable.getOwner().getUniqueId();
if (victim == damager)
continue;
if (victim == damager) continue;
if (playerManager.canDamage(damager, victim, true, false))
CombatTimer.refreshPlayersCombatTime(damager, victim);
@@ -71,5 +59,3 @@ public class AreaEffectCloudApplyListener implements Listener {
}
}
}
}
}