mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-11 21:06:55 +00:00
use util for harmful effects list
This commit is contained in:
+10
-24
@@ -4,6 +4,7 @@ import me.youhavetrouble.preventstabby.PreventStabby;
|
|||||||
import me.youhavetrouble.preventstabby.players.PlayerManager;
|
import me.youhavetrouble.preventstabby.players.PlayerManager;
|
||||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||||
|
import me.youhavetrouble.preventstabby.util.Util;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
@@ -11,6 +12,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -20,33 +22,21 @@ public class AreaEffectCloudApplyListener implements Listener {
|
|||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onCloudEffects(AreaEffectCloudApplyEvent event) {
|
public void onCloudEffects(AreaEffectCloudApplyEvent event) {
|
||||||
|
|
||||||
|
if (!(event.getEntity().getSource() instanceof Player)) return;
|
||||||
PotionEffectType potionEffectType = event.getEntity().getBasePotionData().getType().getEffectType();
|
PotionEffectType potionEffectType = event.getEntity().getBasePotionData().getType().getEffectType();
|
||||||
|
if (potionEffectType == null) return;
|
||||||
|
|
||||||
if (potionEffectType == null)
|
if (!Util.isPotionEffectHarmful(potionEffectType)) return;
|
||||||
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();
|
Iterator<LivingEntity> it = event.getAffectedEntities().iterator();
|
||||||
UUID damager = ((Player) event.getEntity().getSource()).getUniqueId();
|
UUID damager = ((Player) event.getEntity().getSource()).getUniqueId();
|
||||||
while(it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
LivingEntity entity = it.next();
|
LivingEntity entity = it.next();
|
||||||
if(entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
|
|
||||||
UUID victim = entity.getUniqueId();
|
UUID victim = entity.getUniqueId();
|
||||||
if (damager == victim)
|
if (damager == victim) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (playerManager.canDamage(damager, victim, true))
|
if (playerManager.canDamage(damager, victim, true))
|
||||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||||
@@ -56,12 +46,10 @@ public class AreaEffectCloudApplyListener implements Listener {
|
|||||||
} else if (entity instanceof Tameable) {
|
} else if (entity instanceof Tameable) {
|
||||||
Tameable tameable = (Tameable) entity;
|
Tameable tameable = (Tameable) entity;
|
||||||
|
|
||||||
if (tameable.getOwner() == null)
|
if (tameable.getOwner() == null) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
UUID victim = tameable.getOwner().getUniqueId();
|
UUID victim = tameable.getOwner().getUniqueId();
|
||||||
if (victim == damager)
|
if (victim == damager) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (playerManager.canDamage(damager, victim, true, false))
|
if (playerManager.canDamage(damager, victim, true, false))
|
||||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||||
@@ -70,6 +58,4 @@ public class AreaEffectCloudApplyListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user