mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 13:26:56 +00:00
use util for harmful effects list
This commit is contained in:
+26
-40
@@ -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,55 +22,39 @@ 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 (!Util.isPotionEffectHarmful(potionEffectType)) 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)) {
|
||||
PlayerManager playerManager = PreventStabby.getPlugin().getPlayerManager();
|
||||
|
||||
PlayerManager playerManager = PreventStabby.getPlugin().getPlayerManager();
|
||||
Iterator<LivingEntity> it = event.getAffectedEntities().iterator();
|
||||
UUID damager = ((Player) event.getEntity().getSource()).getUniqueId();
|
||||
while (it.hasNext()) {
|
||||
LivingEntity entity = it.next();
|
||||
if (entity instanceof Player) {
|
||||
UUID victim = entity.getUniqueId();
|
||||
if (damager == victim) continue;
|
||||
|
||||
Iterator<LivingEntity> it = event.getAffectedEntities().iterator();
|
||||
UUID damager = ((Player) event.getEntity().getSource()).getUniqueId();
|
||||
while(it.hasNext()) {
|
||||
LivingEntity entity = it.next();
|
||||
if(entity instanceof Player) {
|
||||
if (playerManager.canDamage(damager, victim, true))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
it.remove();
|
||||
|
||||
UUID victim = entity.getUniqueId();
|
||||
if (damager == victim)
|
||||
continue;
|
||||
} else if (entity instanceof Tameable) {
|
||||
Tameable tameable = (Tameable) entity;
|
||||
|
||||
if (playerManager.canDamage(damager, victim, true))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
it.remove();
|
||||
if (tameable.getOwner() == null) continue;
|
||||
|
||||
} else if (entity instanceof Tameable) {
|
||||
Tameable tameable = (Tameable) entity;
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
if (victim == damager) continue;
|
||||
|
||||
if (tameable.getOwner() == null)
|
||||
continue;
|
||||
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
if (victim == damager)
|
||||
continue;
|
||||
|
||||
if (playerManager.canDamage(damager, victim, true, false))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
if (playerManager.canDamage(damager, victim, true, false))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user