Skip to content

Commit

Permalink
More changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanceSD committed Jul 12, 2024
1 parent 99a206e commit 3d68b26
Show file tree
Hide file tree
Showing 23 changed files with 144 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private String pvpList(final CommandSender sender, final boolean enabled, final
final StringBuilder list = new StringBuilder();
for (final PvPlayer p : ph.getPlayers().values()) {
final Player player = p.getPlayer();
if (enabled == p.hasPvPEnabled() && player != null && (console || ((Player) sender).canSee(player))) {
if (enabled == p.hasPvPEnabled() && (console || ((Player) sender).canSee(player))) {
list.append(p.getName()).append(", ");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
import me.NoChance.PvPManager.Dependencies.Hook;
import me.NoChance.PvPManager.Dependencies.Interfaces.WorldGuardDependency;
import me.NoChance.PvPManager.Managers.PlayerHandler;
import me.NoChance.PvPManager.Player.ProtectionResult;
import me.NoChance.PvPManager.Player.ProtectionType;
import me.NoChance.PvPManager.Settings.Settings;
import me.NoChance.PvPManager.Utils.CombatUtils;
import me.chancesd.pvpmanager.setting.Permissions;
import me.chancesd.sdutils.utils.Log;
import me.NoChance.PvPManager.Utils.MCVersion;
import me.chancesd.sdutils.utils.MCVersion;

public class DebugEntityListener implements Listener {

Expand Down Expand Up @@ -85,7 +86,7 @@ public final void onPlayerDamage(final EntityDamageByEntityEvent event) {

final Player attacker = getAttacker(event.getDamager());
final Player attacked = (Player) event.getEntity();
final ProtectionType result = ph.tryCancel(attacker, attacked);
final ProtectionResult result = ph.checkProtection(attacker, attacked);

if (result.isProtected()) {
event.setCancelled(true);
Expand All @@ -100,7 +101,7 @@ public final void onPlayerDamageOverride(final EntityDamageByEntityEvent event)
if (!CombatUtils.isPvP(event) || CombatUtils.isWorldExcluded(event.getEntity().getWorld().getName()) || !event.isCancelled())
return;

if (ph.tryCancel(getAttacker(event.getDamager()), (Player) event.getEntity()).equals(ProtectionType.FAIL_OVERRIDE)) {
if (ph.checkProtection(getAttacker(event.getDamager()), (Player) event.getEntity()).type() == ProtectionType.FAIL_OVERRIDE) {
event.setCancelled(false);
Log.debug("Force allowing PvP even though a plugin blocked it because a player has override or Vulnerable is enabled");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,23 @@
import me.NoChance.PvPManager.Dependencies.Hook;
import me.NoChance.PvPManager.Dependencies.Interfaces.WorldGuardDependency;
import me.NoChance.PvPManager.Managers.PlayerHandler;
import me.NoChance.PvPManager.Player.ProtectionResult;
import me.NoChance.PvPManager.Player.ProtectionType;
import me.NoChance.PvPManager.Settings.Messages;
import me.NoChance.PvPManager.Settings.Settings;
import me.NoChance.PvPManager.Utils.CombatUtils;
import me.chancesd.pvpmanager.setting.Permissions;
import me.NoChance.PvPManager.Utils.MCVersion;
import me.chancesd.sdutils.utils.MCVersion;

public class EntityListener implements Listener {

private final PlayerHandler ph;
private final PlayerHandler playerHandler;
private final WorldGuardDependency wg;
private final Cache<LightningStrike, Location> lightningCache = CacheBuilder.newBuilder().expireAfterWrite(2, TimeUnit.SECONDS).build();

public EntityListener(final PlayerHandler ph) {
this.ph = ph;
this.playerHandler = ph;
this.wg = (WorldGuardDependency) ph.getPlugin().getDependencyManager().getDependency(Hook.WORLDGUARD);
}

Expand All @@ -63,11 +65,10 @@ public final void onPlayerDamage(final EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player))
return;

final PvPlayer attacked = ph.get((Player) event.getEntity());
final PvPlayer attacked = playerHandler.get((Player) event.getEntity());
if (attacked.isNewbie() && Settings.isNewbieGodMode()) {
event.setCancelled(true);
} else if (event.getDamager() instanceof LightningStrike) {
final LightningStrike lightning = (LightningStrike) event.getDamager();
} else if (event.getDamager() instanceof final LightningStrike lightning) {
if (!lightningCache.asMap().containsKey(lightning))
return;
if (!attacked.hasPvPEnabled() || attacked.isNewbie() || attacked.hasRespawnProtection()) {
Expand All @@ -79,7 +80,7 @@ public final void onPlayerDamage(final EntityDamageByEntityEvent event) {

final Player attacker = getAttacker(event.getDamager());
final Player attacked = (Player) event.getEntity();
final ProtectionType result = ph.tryCancel(attacker, attacked);
final ProtectionResult result = playerHandler.checkProtection(attacker, attacked);

if (result.isProtected()) {
event.setCancelled(true);
Expand All @@ -92,7 +93,7 @@ public final void onPlayerDamageOverride(final EntityDamageByEntityEvent event)
if (!CombatUtils.isPvP(event) || CombatUtils.isWorldExcluded(event.getEntity().getWorld().getName()) || !event.isCancelled())
return;

if (ph.tryCancel(getAttacker(event.getDamager()), (Player) event.getEntity()).equals(ProtectionType.FAIL_OVERRIDE)) {
if (playerHandler.checkProtection(getAttacker(event.getDamager()), (Player) event.getEntity()).type() == ProtectionType.FAIL_OVERRIDE) {
event.setCancelled(false);
}
}
Expand All @@ -112,7 +113,7 @@ public final void onEntityCombust(final EntityCombustByEntityEvent event) {
if (CombatUtils.isWorldExcluded(event.getEntity().getWorld().getName()))
return;
if (!CombatUtils.isPvP(event)) {
if (event.getEntity() instanceof Player && ph.get((Player) event.getEntity()).isNewbie() && Settings.isNewbieGodMode()) {
if (event.getEntity() instanceof final Player player && playerHandler.get(player).isNewbie() && Settings.isNewbieGodMode()) {
event.setCancelled(true);
}
return;
Expand All @@ -121,14 +122,14 @@ public final void onEntityCombust(final EntityCombustByEntityEvent event) {
final Player attacker = getAttacker(event.getCombuster());
final Player attacked = (Player) event.getEntity();

if (!ph.canAttack(attacker, attacked)) {
if (!playerHandler.canAttack(attacker, attacked)) {
event.setCancelled(true);
}
}

public void processDamage(final Player attacker, final Player defender) {
final PvPlayer pvpAttacker = ph.get(attacker);
final PvPlayer pvpDefender = ph.get(defender);
final PvPlayer pvpAttacker = playerHandler.get(attacker);
final PvPlayer pvpDefender = playerHandler.get(defender);

if (Settings.isPvpBlood()) {
defender.getWorld().playEffect(defender.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
Expand Down Expand Up @@ -167,13 +168,13 @@ private void disableActions(final Player attacker, final Player defender, final
attacker.setGameMode(GameMode.SURVIVAL);
}
if (Settings.isDisableDisguise()) {
ph.getPlugin().getDependencyManager().disableDisguise(attacker);
playerHandler.getPlugin().getDependencyManager().disableDisguise(attacker);
}
if (Settings.isDisableInvisibility() && attacker.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
attacker.removePotionEffect(PotionEffectType.INVISIBILITY);
}
if (Settings.isDisableGodMode()) {
ph.getPlugin().getDependencyManager().disableGodMode(attacker);
playerHandler.getPlugin().getDependencyManager().disableGodMode(attacker);
}
}

Expand All @@ -189,7 +190,7 @@ public final void onPotionSplash(final PotionSplashEvent event) {
continue;
}
final Player attacked = (Player) e;
final ProtectionType result = ph.tryCancel(player, attacked);
final ProtectionResult result = playerHandler.checkProtection(player, attacked);

if (result.isProtected()) {
event.setIntensity(attacked, 0);
Expand Down Expand Up @@ -249,11 +250,10 @@ public void onBlockIgnite(final BlockIgniteEvent event) {
return;

final Entity ignitingEntity = event.getIgnitingEntity();
if (ignitingEntity instanceof LightningStrike && lightningCache.asMap().containsKey(ignitingEntity)) {
final LightningStrike lightningStrike = (LightningStrike) ignitingEntity;
if (ignitingEntity instanceof final LightningStrike lightningStrike && lightningCache.asMap().containsKey(ignitingEntity)) {
for (final Entity entity : lightningStrike.getNearbyEntities(2, 2, 2)) {
if (entity instanceof Player) {
final PvPlayer attacked = ph.get((Player) entity);
if (entity instanceof final Player player) {
final PvPlayer attacked = playerHandler.get(player);
if (!attacked.hasPvPEnabled() || attacked.isNewbie() || attacked.hasRespawnProtection()) {
event.setCancelled(true);
return;
Expand All @@ -267,24 +267,23 @@ public void onBlockIgnite(final BlockIgniteEvent event) {
public void onProjectileHitEvent(final ProjectileHitEvent event) {
final Projectile entity = event.getEntity();
final ProjectileSource shooter = entity.getShooter();
if (!Settings.isEnderPearlRenewTag() || entity.getType() != EntityType.ENDER_PEARL || !(shooter instanceof Player))
if (!Settings.isEnderPearlRenewTag() || entity.getType() != EntityType.ENDER_PEARL || !(shooter instanceof final Player player))
return;

final Player player = (Player) shooter;
final PvPlayer pvPlayer = ph.get(player);
final PvPlayer pvPlayer = playerHandler.get(player);

if (pvPlayer.isInCombat()) {
pvPlayer.setTagged(true, pvPlayer);
}
}

private Player getAttacker(final Entity damager) {
if (damager instanceof Player)
return (Player) damager;
if (damager instanceof Projectile)
return (Player) ((Projectile) damager).getShooter();
if (damager instanceof TNTPrimed)
return (Player) ((TNTPrimed) damager).getSource();
if (damager instanceof final Player player)
return player;
if (damager instanceof final Projectile projectile)
return (Player) projectile.getShooter();
if (damager instanceof final TNTPrimed tnt)
return (Player) tnt.getSource();
return (Player) ((AreaEffectCloud) damager).getSource();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.google.common.cache.CacheBuilder;

import me.NoChance.PvPManager.Managers.PlayerHandler;
import me.NoChance.PvPManager.Player.ProtectionType;
import me.NoChance.PvPManager.Player.ProtectionResult;
import me.NoChance.PvPManager.Settings.Messages;
import me.NoChance.PvPManager.Settings.Settings;
import me.NoChance.PvPManager.Utils.CombatUtils;
Expand Down Expand Up @@ -71,7 +71,7 @@ public final void onLingeringPotionSplash(final AreaEffectCloudApplyEvent event)
continue;
}
final Player attacked = (Player) e;
final ProtectionType result = ph.tryCancel(player, attacked);
final ProtectionResult result = ph.checkProtection(player, attacked);

if (result.isProtected()) {
toRemove.add(e);
Expand Down
Loading

0 comments on commit 3d68b26

Please sign in to comment.