diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Commands/PvPList.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Commands/PvPList.java index 9dbbe14ad..b2d886aa7 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Commands/PvPList.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Commands/PvPList.java @@ -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(", "); } } diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/DebugEntityListener.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/DebugEntityListener.java index 8af01e06c..7ed461965 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/DebugEntityListener.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/DebugEntityListener.java @@ -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 { @@ -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); @@ -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 { diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/EntityListener.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/EntityListener.java index 4ae920c3b..fd4f48d46 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/EntityListener.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/EntityListener.java @@ -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 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); } @@ -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()) { @@ -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); @@ -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); } } @@ -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; @@ -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); @@ -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); } } @@ -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); @@ -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; @@ -267,11 +267,10 @@ 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); @@ -279,12 +278,12 @@ public void onProjectileHitEvent(final ProjectileHitEvent event) { } 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(); } diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/EntityListener1_9.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/EntityListener1_9.java index d4b2e6418..ef21680fb 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/EntityListener1_9.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/EntityListener1_9.java @@ -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; @@ -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); diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/PlayerListener.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/PlayerListener.java index e1493a109..13fa27faa 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/PlayerListener.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/PlayerListener.java @@ -2,6 +2,8 @@ import me.chancesd.pvpmanager.world.CombatWorld; import me.chancesd.sdutils.utils.Log; +import me.chancesd.sdutils.utils.MCVersion; + import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -41,24 +43,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.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; import me.chancesd.pvpmanager.setting.Permissions; import me.chancesd.pvpmanager.utils.ScheduleUtils; -import me.NoChance.PvPManager.Utils.MCVersion; @SuppressWarnings("deprecation") public class PlayerListener implements Listener { - private final PlayerHandler ph; + private final PlayerHandler playerHandler; private final WorldGuardDependency wg; private Material mushroomSoup; private final Cache msgCooldown = CacheBuilder.newBuilder().weakValues().expireAfterWrite(800, TimeUnit.MILLISECONDS).build(); public PlayerListener(final PlayerHandler ph) { - this.ph = ph; + this.playerHandler = ph; this.wg = (WorldGuardDependency) ph.getPlugin().getDependencyManager().getDependency(Hook.WORLDGUARD); if (MCVersion.isAtLeast(MCVersion.V1_13)) { mushroomSoup = Material.MUSHROOM_STEW; @@ -72,7 +73,7 @@ public final void onBlockPlace(final BlockPlaceEvent event) { if (!Settings.isBlockPlaceBlocks() && !Settings.isBlockPlaceBlocksNewbie()) return; - final PvPlayer combatPlayer = ph.get(event.getPlayer()); + final PvPlayer combatPlayer = playerHandler.get(event.getPlayer()); if (Settings.isBlockPlaceBlocks() && combatPlayer.isInCombat() || Settings.isBlockPlaceBlocksNewbie() && combatPlayer.isNewbie()) { event.setCancelled(true); combatPlayer.sendActionBar(Messages.getBlockPlaceBlockedInCombat(), 1000); @@ -81,7 +82,7 @@ public final void onBlockPlace(final BlockPlaceEvent event) { @EventHandler(ignoreCancelled = true) public final void onToggleFlight(final PlayerToggleFlightEvent event) { - if (Settings.isDisableFly() && event.isFlying() && ph.get(event.getPlayer()).isInCombat()) { + if (Settings.isDisableFly() && event.isFlying() && playerHandler.get(event.getPlayer()).isInCombat()) { event.setCancelled(true); } } @@ -89,10 +90,10 @@ public final void onToggleFlight(final PlayerToggleFlightEvent event) { @EventHandler(ignoreCancelled = true) public final void onPlayerEat(final PlayerItemConsumeEvent event) { final Material type = event.getItem().getType(); - final PvPlayer player = ph.get(event.getPlayer()); + final PvPlayer player = playerHandler.get(event.getPlayer()); if (Settings.isBlockEat() && player.isInCombat() && type.isEdible()) { event.setCancelled(true); - ph.get(event.getPlayer()).sendActionBar(Messages.getEatBlockedInCombat(), 1000); + playerHandler.get(event.getPlayer()).sendActionBar(Messages.getEatBlockedInCombat(), 1000); } if (Settings.getItemCooldowns().containsKey(type)) { if (player.hasItemCooldown(type)) { @@ -108,11 +109,11 @@ public final void onPlayerEat(final PlayerItemConsumeEvent event) { public final void onPlayerKick(final PlayerKickEvent event) { final Player player = event.getPlayer(); Log.debugLazy(() -> player.getName() + " was kicked with reason: " + event.getReason() + " | Leave message: " + event.getLeaveMessage() - + " - In combat: " + ph.get(player).isInCombat()); + + " - In combat: " + playerHandler.get(player).isInCombat()); if (Settings.punishOnKick() && (!Settings.matchKickReason() || Settings.getPunishKickReasons().contains(event.getReason()))) return; - final PvPlayer pvPlayer = ph.get(player); + final PvPlayer pvPlayer = playerHandler.get(player); if (pvPlayer.isInCombat()) { pvPlayer.unTag(); } @@ -121,20 +122,20 @@ public final void onPlayerKick(final PlayerKickEvent event) { @EventHandler // normal priority to avoid conflict with griefprevention public final void onPlayerLogout(final PlayerQuitEvent event) { final Player player = event.getPlayer(); - final PvPlayer pvPlayer = ph.get(player); + final PvPlayer pvPlayer = playerHandler.get(player); Log.debug(player.getName() + " quit with reason: " + event.getQuitMessage() + " - In combat: " + pvPlayer.isInCombat()); if (pvPlayer.isInCombat() && !pvPlayer.hasPerm(Permissions.EXEMPT_COMBAT_LOG)) { if (Settings.isLogToFile()) { - ph.getConfigManager().getLog().log(player.getName() + " tried to escape combat!"); + playerHandler.getConfigManager().getLog().log(player.getName() + " tried to escape combat!"); } CombatUtils.executeCommands(Settings.getCommandsOnPvPLog(), player, player.getName()); - ph.applyPunishments(pvPlayer); + playerHandler.applyPunishments(pvPlayer); } } @EventHandler(priority = EventPriority.MONITOR) public final void onPlayerLogoutMonitor(final PlayerQuitEvent event) { - ph.removeUser(ph.get(event.getPlayer())); + playerHandler.removeUser(playerHandler.get(event.getPlayer())); } @EventHandler(priority = EventPriority.HIGH) @@ -143,12 +144,12 @@ public final void onPlayerDeath(final PlayerDeathEvent event) { if (CombatUtils.isWorldExcluded(player.getWorld().getName())) return; - final PvPlayer pvPlayer = ph.get(player); + final PvPlayer pvPlayer = playerHandler.get(player); final Player killer = player.getKiller(); // Player died in combat, process that if (killer != null && !killer.equals(player)) { - final PvPlayer pKiller = ph.get(killer); + final PvPlayer pKiller = playerHandler.get(killer); handlePvPDeath(player, pvPlayer, killer, pKiller); } @@ -162,11 +163,11 @@ public final void onPlayerDeath(final PlayerDeathEvent event) { // Let's process player's inventory/exp according to config file if (pvPlayer.hasPvPLogged()) { - ph.handleCombatLogDrops(event, player); + playerHandler.handleCombatLogDrops(event, player); return; } - ph.handlePlayerDrops(event, player, killer); + playerHandler.handlePlayerDrops(event, player, killer); } private void handlePvPDeath(final Player player, final PvPlayer pvPlayer, final Player killer, final PvPlayer pKiller) { @@ -209,7 +210,7 @@ public final void onPlayerUseSoup(final PlayerInteractEvent e) { i.setType(Material.BOWL); } } - final PvPlayer pvplayer = ph.get(player); + final PvPlayer pvplayer = playerHandler.get(player); if ((e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) && Settings.getItemCooldowns().containsKey(type)) { if (pvplayer.hasItemCooldown(type)) { final String msg = Messages.getItemCooldown(pvplayer.getItemCooldown(type)); @@ -219,7 +220,7 @@ public final void onPlayerUseSoup(final PlayerInteractEvent e) { } e.setCancelled(true); } else if (!type.isEdible()) { - Bukkit.getScheduler().runTask(ph.getPlugin(), () -> pvplayer.setItemCooldown(type, Settings.getItemCooldowns().get(type))); + Bukkit.getScheduler().runTask(playerHandler.getPlugin(), () -> pvplayer.setItemCooldown(type, Settings.getItemCooldowns().get(type))); } } } @@ -231,7 +232,7 @@ public final void onPlayerInteract(final PlayerInteractEvent e) { return; final ItemStack i = player.getItemInHand(); - final PvPlayer pvplayer = ph.get(player); + final PvPlayer pvplayer = playerHandler.get(player); final Block clickedBlock = e.getClickedBlock(); if (clickedBlock == null) return; @@ -241,7 +242,7 @@ public final void onPlayerInteract(final PlayerInteractEvent e) { if (player.equals(p) || !clickedBlock.getWorld().equals(p.getWorld()) || !player.canSee(p)) { continue; } - final PvPlayer target = ph.get(p); + final PvPlayer target = playerHandler.get(p); if ((!target.hasPvPEnabled() || !pvplayer.hasPvPEnabled()) && clickedBlock.getLocation().distanceSquared(p.getLocation()) < 9) { pvplayer.message(Messages.pvpDisabledOther(target.getName())); e.setCancelled(true); @@ -264,7 +265,7 @@ public final void onPlayerInteract(final PlayerInteractEvent e) { @EventHandler(ignoreCancelled = true) public final void onPlayerPickup(final PlayerPickupItemEvent e) { if (Settings.isNewbieProtectionEnabled() && Settings.isBlockPickNewbies()) { - final PvPlayer player = ph.get(e.getPlayer()); + final PvPlayer player = playerHandler.get(e.getPlayer()); if (player.isNewbie()) { e.setCancelled(true); player.sendActionBar(Messages.getNewbiePickupItemBlocked(), 1000); @@ -275,7 +276,7 @@ public final void onPlayerPickup(final PlayerPickupItemEvent e) { @EventHandler public final void onPlayerJoin(final PlayerJoinEvent event) { final Player player = event.getPlayer(); - final PvPlayer pvPlayer = ph.get(player); + final PvPlayer pvPlayer = playerHandler.get(player); ScheduleUtils.runAsync(() -> { if (player.isOp() || pvPlayer.hasPerm(Permissions.ADMIN)) { Messages.sendQueuedMsgs(pvPlayer); @@ -289,7 +290,7 @@ public final void onPlayerTeleport(final PlayerTeleportEvent event) { if (CombatUtils.isNPC(player)) // Citizens seems to teleport NPCs very often so let's avoid creating new PvPlayer instances return; - final PvPlayer pvplayer = ph.get(player); + final PvPlayer pvplayer = playerHandler.get(player); if (!Settings.isInCombatEnabled() || !pvplayer.isInCombat()) return; @@ -309,7 +310,7 @@ public final void onPlayerTeleport(final PlayerTeleportEvent event) { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public final void onCommand(final PlayerCommandPreprocessEvent event) { if (Settings.isInCombatEnabled() && Settings.isStopCommands() || Settings.isNewbieProtectionEnabled()) { - final PvPlayer player = ph.get(event.getPlayer()); + final PvPlayer player = playerHandler.get(event.getPlayer()); final String[] givenCommand = event.getMessage().substring(1).split(" ", 3); if (player.isInCombat() && !player.hasPerm(Permissions.EXEMPT_BLOCK_COMMANDS)) { @@ -332,9 +333,8 @@ public final void onPlayerFish(final PlayerFishEvent event) { if (CombatUtils.isWorldExcluded(player.getWorld().getName())) return; - if (event.getState() == State.CAUGHT_ENTITY && event.getCaught() instanceof Player) { - final Player caught = (Player) event.getCaught(); - final ProtectionType result = ph.tryCancel(player, caught); + if (event.getState() == State.CAUGHT_ENTITY && event.getCaught() instanceof final Player caught) { + final ProtectionResult result = playerHandler.checkProtection(player, caught); if (result.isProtected()) { event.setCancelled(true); Messages.messageProtection(result, player, caught); @@ -347,7 +347,7 @@ public final void onPlayerRespawn(final PlayerRespawnEvent event) { if (CombatUtils.isWorldExcluded(event.getPlayer().getWorld().getName())) return; if (Settings.isKillAbuseEnabled() && Settings.getRespawnProtection() != 0) { - final PvPlayer player = ph.get(event.getPlayer()); + final PvPlayer player = playerHandler.get(event.getPlayer()); player.setRespawnTime(System.currentTimeMillis()); } } @@ -356,7 +356,7 @@ public final void onPlayerRespawn(final PlayerRespawnEvent event) { public final void onInventoryOpen(final InventoryOpenEvent event) { if (!Settings.isBlockInventoryOpen()) return; - final PvPlayer combatPlayer = ph.get((Player) event.getPlayer()); + final PvPlayer combatPlayer = playerHandler.get((Player) event.getPlayer()); if (combatPlayer.isInCombat()) { event.setCancelled(true); combatPlayer.sendActionBar(Messages.getInventoryBlockedInCombat(), 1000); @@ -366,8 +366,8 @@ public final void onInventoryOpen(final InventoryOpenEvent event) { @EventHandler public void onChangeWorld(final PlayerChangedWorldEvent event) { final Player player = event.getPlayer(); - final PvPlayer pvPlayer = ph.get(player); - final CombatWorld combatWorld = ph.getPlugin().getWorldManager().getWorld(player.getWorld()); + final PvPlayer pvPlayer = playerHandler.get(player); + final CombatWorld combatWorld = playerHandler.getPlugin().getWorldManager().getWorld(player.getWorld()); pvPlayer.setCombatWorld(combatWorld); final CombatWorld.WorldOptionState optionState = pvPlayer.getCombatWorld().isPvPForced(); diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/WGListener.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/WGListener.java index b42940f4c..ee37fb3b7 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/WGListener.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/WGListener.java @@ -21,7 +21,7 @@ public WGListener(final PlayerHandler ph) { public final void onWGPvPCancel(final DisallowedPVPEvent event) { // NO_UCD if (event.getAttacker().hasMetadata("NPC") || event.getDefender().hasMetadata("NPC")) return; - if (ph.tryCancel(event.getAttacker(), event.getDefender()) == ProtectionType.FAIL_OVERRIDE) { + if (ph.checkProtection(event.getAttacker(), event.getDefender()).type() == ProtectionType.FAIL_OVERRIDE) { event.setCancelled(true); Log.debug("Force allowing PvP even though WorldGuard blocked it because a player has override or Vulnerable is enabled"); } diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/WGListenerLegacy.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/WGListenerLegacy.java index ff242e35e..a3e2b7fe8 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/WGListenerLegacy.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Listeners/WGListenerLegacy.java @@ -21,7 +21,7 @@ public WGListenerLegacy(final PlayerHandler ph) { public final void onWGPvPCancel(final DisallowedPVPEvent event) { // NO_UCD if (event.getAttacker().hasMetadata("NPC") || event.getDefender().hasMetadata("NPC")) return; - if (ph.tryCancel(event.getAttacker(), event.getDefender()) == ProtectionType.FAIL_OVERRIDE) { + if (ph.checkProtection(event.getAttacker(), event.getDefender()).type() == ProtectionType.FAIL_OVERRIDE) { event.setCancelled(true); Log.debug("Force allowing PvP even though WorldGuard blocked it because a player has override or Vulnerable is enabled"); } diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Managers/DependencyManager.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Managers/DependencyManager.java index f0db8ef31..0a382d26d 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Managers/DependencyManager.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Managers/DependencyManager.java @@ -16,18 +16,10 @@ import me.NoChance.PvPManager.Dependencies.AFKDependency; import me.NoChance.PvPManager.Dependencies.BaseDependency; import me.NoChance.PvPManager.Dependencies.DependencyException; -import me.NoChance.PvPManager.Dependencies.DisguiseDependency; -import me.NoChance.PvPManager.Dependencies.GodDependency; import me.NoChance.PvPManager.Dependencies.Hook; import me.NoChance.PvPManager.Dependencies.GroupDependency; -import me.NoChance.PvPManager.Dependencies.RegionDependency; import me.NoChance.PvPManager.Dependencies.ForceToggleDependency; -import me.NoChance.PvPManager.Dependencies.WorldGuardHook; -import me.NoChance.PvPManager.Dependencies.ForceToggleDependency; -import me.NoChance.PvPManager.Dependencies.Hook; -import me.NoChance.PvPManager.Dependencies.Hooks.CooldownsXHook; import me.NoChance.PvPManager.Dependencies.Hooks.EssentialsHook; -import me.NoChance.PvPManager.Dependencies.Hooks.KingdomsXHook; import me.NoChance.PvPManager.Dependencies.Hooks.GriefPreventionHook; import me.NoChance.PvPManager.Dependencies.Hooks.LibsDisguisesHook; import me.NoChance.PvPManager.Dependencies.Hooks.PlaceHolderAPIHook; @@ -39,7 +31,6 @@ import me.NoChance.PvPManager.Dependencies.Interfaces.Dependency; import me.NoChance.PvPManager.Dependencies.Interfaces.DisguiseDependency; import me.NoChance.PvPManager.Dependencies.Interfaces.GodDependency; -import me.NoChance.PvPManager.Dependencies.Interfaces.PvPDependency; import me.NoChance.PvPManager.Dependencies.Interfaces.RegionDependency; import me.NoChance.PvPManager.Dependencies.Interfaces.WorldGuardDependency; import me.NoChance.PvPManager.Listeners.MoveListener; @@ -48,8 +39,9 @@ import me.NoChance.PvPManager.Settings.Settings; import me.NoChance.PvPManager.Utils.CombatUtils; import me.chancesd.pvpmanager.utils.ScheduleUtils; -import me.NoChance.PvPManager.Utils.MCVersion; import me.chancesd.sdutils.utils.Log; +import me.chancesd.sdutils.utils.MCVersion; +import me.chancesd.sdutils.utils.Utils; import net.milkbowl.vault.economy.Economy; public class DependencyManager { @@ -113,42 +105,30 @@ private List setupHooks(final Hook... hooks) { return failedHooks; } - private void attemptHookingInto(final Hook hook) { + private boolean attemptHookingInto(final Hook hook) { switch (hook) { case SIMPLECLANS: - registerDependency(new SimpleClansHook(hook)); - break; + return registerDependency(new SimpleClansHook(hook)); case VAULT: - registerDependency(new VaultHook(hook)); - break; + return registerDependency(new VaultHook(hook)); case WORLDGUARD: - if (CombatUtils.isVersionAtLeast(CombatUtils.stripTags(hook.getVersion()), "7.0")) { - registerDependency(new WorldGuardModernHook(hook)); + if (Utils.isVersionAtLeast(Utils.stripTags(hook.getVersion()), "7.0")) { + return registerDependency(new WorldGuardModernHook(hook)); } else { - registerDependency(new WorldGuardLegacyHook(hook)); + return registerDependency(new WorldGuardLegacyHook(hook)); } - break; case ESSENTIALS: - registerDependency(new EssentialsHook(hook)); - break; + return registerDependency(new EssentialsHook(hook)); case PLACEHOLDERAPI: - registerDependency(new PlaceHolderAPIHook(hook)); - break; + return registerDependency(new PlaceHolderAPIHook(hook)); case LIBSDISGUISES: - registerDependency(new LibsDisguisesHook(hook)); - break; + return registerDependency(new LibsDisguisesHook(hook)); case TOWNY: - registerDependency(new TownyHook(hook)); - break; - case KINGDOMSX: - registerDependency(new KingdomsXHook(hook)); - break; + return registerDependency(new TownyHook(hook)); case GRIEFPREVENTION: - registerDependency(new GriefPreventionHook(hook)); - break; + return registerDependency(new GriefPreventionHook(hook)); default: - registerDependency(new BaseDependency(hook)); - break; + return registerDependency(new BaseDependency(hook)); } } @@ -223,32 +203,27 @@ public Dependency getDependency(final Hook h) { return dependencies.get(h); } - public void registerDependency(final Dependency dep) { + public boolean registerDependency(final Dependency dep) { dependencies.put(dep.getHook(), dep); - if (dep instanceof GroupDependency) { - attackChecks.add((GroupDependency) dep); + if (dep instanceof final GroupDependency pvpHook) { + attackChecks.add(pvpHook); } - if (dep instanceof RegionDependency) { - regionChecks.add((RegionDependency) dep); + if (dep instanceof final RegionDependency regionHook) { + regionChecks.add(regionHook); } - if (dep instanceof GodDependency) { - godChecks.add((GodDependency) dep); + if (dep instanceof final GodDependency godHook) { + godChecks.add(godHook); } - if (dep instanceof DisguiseDependency) { - disguiseChecks.add((DisguiseDependency) dep); + if (dep instanceof final DisguiseDependency disguiseHook) { + disguiseChecks.add(disguiseHook); } - if (dep instanceof ForceToggleDependency) { - final ForceToggleDependency togglePvPHook = (ForceToggleDependency) dep; - if (togglePvPHook.shouldDisableProtection()) { - togglePvPChecks.add(togglePvPHook); - } + if (dep instanceof final ForceToggleDependency togglePvPHook && togglePvPHook.shouldDisableProtection()) { + togglePvPChecks.add(togglePvPHook); } - if (dep instanceof AFKDependency) { - final AFKDependency afkHook = (AFKDependency) dep; - if (afkHook.shouldProtectAFK()) { - afkChecks.add(afkHook); - } + if (dep instanceof final AFKDependency afkHook && afkHook.shouldProtectAFK()) { + afkChecks.add(afkHook); } + return true; } public void unregisterDependency(final Dependency dep) { diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Managers/PlayerHandler.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Managers/PlayerHandler.java index 60fbe7a55..9f8484b99 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Managers/PlayerHandler.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Managers/PlayerHandler.java @@ -61,7 +61,7 @@ public PlayerHandler(final PvPManager plugin) { addOnlinePlayers(); } - public final ProtectionResult tryCancel(final Player damager, final Player defender) { + public final ProtectionResult checkProtection(final Player damager, final Player defender) { final PvPlayer attacker = get(damager); final PvPlayer attacked = get(defender); @@ -90,7 +90,7 @@ public final ProtectionResult tryCancel(final Player damager, final Player defen } /** - * Use this method to check PvP instead of using {@link PlayerHandler#tryCancel(Player, Player)} + * Use this method to check PvP instead of using {@link PlayerHandler#checkProtection(Player, Player)} * This method will not be changed while the previous might change at any time. * * @param attacker @@ -101,7 +101,7 @@ public final ProtectionResult tryCancel(final Player damager, final Player defen * @return true if the attack didn't get blocked or if it got override, otherwise false */ public final boolean canAttack(final Player attacker, final Player defender) { - return tryCancel(attacker, defender).canAttack(); + return checkProtection(attacker, defender).isVulnerable(); } private boolean canAttackHooks(final PvPlayer attacker, final PvPlayer defender) { diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Player/BasePlayer.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Player/BasePlayer.java index 06f293a3a..caa8eb596 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Player/BasePlayer.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Player/BasePlayer.java @@ -4,11 +4,12 @@ import me.chancesd.pvpmanager.setting.Permissions; import me.chancesd.pvpmanager.world.CombatWorld; +import me.chancesd.sdutils.utils.MCVersion; + import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import me.NoChance.PvPManager.Utils.CombatUtils; -import me.NoChance.PvPManager.Utils.MCVersion; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Player/ProtectionResult.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Player/ProtectionResult.java index 727b525b2..ae73bec62 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Player/ProtectionResult.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Player/ProtectionResult.java @@ -6,4 +6,12 @@ public ProtectionResult(final ProtectionType type) { this(type, false); } + public boolean isProtected() { + return !type.canAttack(); + } + + public boolean isVulnerable() { + return type.canAttack(); + } + } diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Player/ProtectionType.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Player/ProtectionType.java index a473c8e1d..e52a88ceb 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Player/ProtectionType.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Player/ProtectionType.java @@ -5,16 +5,11 @@ public enum ProtectionType { public boolean canAttack() { switch (this) { - case FAIL_PLUGIN_HOOK: - case FAIL_OVERRIDE: - case FAIL: + case FAIL_PLUGIN_HOOK, FAIL_OVERRIDE, FAIL: return true; default: return false; } } - public boolean isProtected() { - return !canAttack(); - } } diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/PvPManager.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/PvPManager.java index 4e3ff2b4d..bfca14917 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/PvPManager.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/PvPManager.java @@ -1,11 +1,11 @@ package me.NoChance.PvPManager; -import me.chancesd.pvpmanager.managers.WorldManager; import org.bukkit.ChatColor; import org.bukkit.command.CommandExecutor; import org.bukkit.command.PluginCommand; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; + import me.NoChance.PvPManager.Commands.Announce; import me.NoChance.PvPManager.Commands.Newbie; import me.NoChance.PvPManager.Commands.PM; @@ -27,12 +27,13 @@ import me.NoChance.PvPManager.Managers.DisplayManager; import me.NoChance.PvPManager.Managers.PlayerHandler; import me.NoChance.PvPManager.Settings.Messages; -import me.chancesd.sdutils.library.PluginLibraries; -import me.chancesd.sdutils.utils.Log; import me.chancesd.pvpmanager.managers.StorageManager; import me.chancesd.pvpmanager.managers.UpdateManager; +import me.chancesd.pvpmanager.managers.WorldManager; import me.chancesd.pvpmanager.utils.ScheduleUtils; -import me.NoChance.PvPManager.Utils.MCVersion; +import me.chancesd.sdutils.library.PluginLibraries; +import me.chancesd.sdutils.utils.Log; +import me.chancesd.sdutils.utils.MCVersion; public class PvPManager extends JavaPlugin { diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/PvPlayer.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/PvPlayer.java index bd1ce1f81..9d2b03a8f 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/PvPlayer.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/PvPlayer.java @@ -26,7 +26,6 @@ import me.NoChance.PvPManager.Settings.Settings; import me.NoChance.PvPManager.Tasks.NewbieTask; import me.NoChance.PvPManager.Utils.CombatUtils; -import me.NoChance.PvPManager.Utils.MCVersion; import me.chancesd.pvpmanager.player.nametag.BukkitNameTag; import me.chancesd.pvpmanager.player.nametag.NameTag; import me.chancesd.pvpmanager.setting.Permissions; @@ -34,6 +33,7 @@ import me.chancesd.pvpmanager.utils.ScheduleUtils; import me.chancesd.pvpmanager.world.CombatWorld; import me.chancesd.sdutils.utils.Log; +import me.chancesd.sdutils.utils.MCVersion; /** * @deprecated Will be renamed to CombatPlayer and moved to another package when v4 is released. diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Settings/Messages.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Settings/Messages.java index 5bb0997f7..1634b04f3 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Settings/Messages.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Settings/Messages.java @@ -21,7 +21,7 @@ import me.NoChance.PvPManager.PvPManager; import me.NoChance.PvPManager.PvPlayer; -import me.NoChance.PvPManager.Player.ProtectionType; +import me.NoChance.PvPManager.Player.ProtectionResult; import me.NoChance.PvPManager.Utils.ChatUtils; import me.NoChance.PvPManager.Utils.TimeUtil; import me.chancesd.sdutils.utils.Log; @@ -269,20 +269,20 @@ private static void addMessage(final String a) { } } - public static void messageProtection(final ProtectionType result, final Player player, final Player attacked) { + public static void messageProtection(final ProtectionResult result, final Player player, final Player attacked) { final String message = getProtectionMessage(result, attacked); final PvPlayer receiver = plugin.getPlayerHandler().get(player); receiver.message(message); } - public static String getProtectionMessage(final ProtectionType result, final Player attacked) { - switch (result) { + public static String getProtectionMessage(final ProtectionResult result, final Player attacked) { + switch (result.type()) { case NEWBIE: - return result.attackerCaused() ? newbieBlocked() : newbieBlockedOther(attacked.getName()); + return result.isAttacker() ? newbieBlocked() : newbieBlockedOther(attacked.getName()); case PVPDISABLED: - return result.attackerCaused() ? pvpDisabled() : pvpDisabledOther(attacked.getName()); + return result.isAttacker() ? pvpDisabled() : pvpDisabledOther(attacked.getName()); case RESPAWN_PROTECTION: - return result.attackerCaused() ? respawnProtSelf() : respawnProtOther(attacked.getName()); + return result.isAttacker() ? respawnProtSelf() : respawnProtOther(attacked.getName()); case WORLD_PROTECTION: return worldProtection(); case AFK_PROTECTION: diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Settings/Settings.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Settings/Settings.java index 1d02fa6f5..f6914a89a 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Settings/Settings.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Settings/Settings.java @@ -8,7 +8,6 @@ import java.util.Map.Entry; import java.util.Set; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarStyle; @@ -20,7 +19,7 @@ import me.NoChance.PvPManager.Utils.ChatUtils; import me.chancesd.sdutils.utils.Log; -import me.NoChance.PvPManager.Utils.MCVersion; +import me.chancesd.sdutils.utils.MCVersion; public final class Settings { @@ -162,7 +161,6 @@ private static void assignSections(final YamlConfiguration config) { public static void initizalizeVariables(final YamlConfiguration c) { assignSections(c); - minecraftVersion = MCVersion.getMCVersion(Bukkit.getBukkitVersion().isEmpty() ? "0" : Bukkit.getBukkitVersion().replaceAll("-.+", "")); locale = generalSection.getString("Locale", "en").toUpperCase(); defaultPvp = generalSection.getBoolean("Default PvP", true); pvpBlood = generalSection.getBoolean("PvP Blood", true); diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Utils/CombatUtils.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Utils/CombatUtils.java index 235c75476..f93b4f09d 100644 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Utils/CombatUtils.java +++ b/pvpmanager/src/main/java/me/NoChance/PvPManager/Utils/CombatUtils.java @@ -33,6 +33,7 @@ import me.chancesd.sdutils.utils.Log; import me.chancesd.sdutils.utils.MCVersion; import me.chancesd.sdutils.utils.ReflectionUtil; +import me.chancesd.sdutils.utils.MCVersion; public final class CombatUtils { @@ -118,8 +119,7 @@ public static final boolean isPvP(final EntityDamageByEntityEvent event) { return !Settings.isIgnoreNoDamageHits() || event.getDamage() != 0; } } - if (attacker instanceof TNTPrimed) { - final TNTPrimed tnt = (TNTPrimed) attacker; + if (attacker instanceof final TNTPrimed tnt) { final Entity tntAttacker = tnt.getSource(); if (tntAttacker instanceof Player && (Settings.isSelfTag() || !tntAttacker.equals(defender))) { return true; @@ -138,8 +138,8 @@ public static final boolean isPvP(final EntityCombustByEntityEvent event) { if (attacker instanceof Player && !isNPC(attacker)) return true; - if (attacker instanceof Projectile) { - final ProjectileSource projSource = ((Projectile) attacker).getShooter(); + if (attacker instanceof final Projectile projectile) { + final ProjectileSource projSource = projectile.getShooter(); if (projSource instanceof Player) { final Entity shooter = (Entity) projSource; return !shooter.equals(defender) && !isNPC(shooter); @@ -244,39 +244,13 @@ public static boolean recursiveContainsCommand(final String[] givenCommand, fina return contains; } - public static final boolean isVersionAtLeast(final String v1, final String v2) { - if (v1.equals(v2)) - return true; - - final String[] v1Array = v1.split("\\."); - final String[] v2Array = v2.split("\\."); - final int length = Math.max(v2Array.length, v1Array.length); - try { - for (int i = 0; i < length; i++) { - final int x = i < v2Array.length ? Integer.parseInt(v2Array[i]) : 0; - final int y = i < v1Array.length ? Integer.parseInt(v1Array[i]) : 0; - if (y > x) - return true; - if (y < x) - return false; - } - } catch (final NumberFormatException ex) { - Log.severe("Error reading version number! Comparing " + v1 + " to " + v2); - } - return true; - } - - public static String stripTags(final String version) { - return version.replaceAll("[-;+].+", ""); - } - public static String truncateString(final String text, final int size) { return text.substring(0, Math.min(text.length(), size)); } private static ProjectileSource getSource(final Entity entity) { - if (entity instanceof Projectile) - return ((Projectile) entity).getShooter(); + if (entity instanceof final Projectile projectile) + return projectile.getShooter(); else return ((AreaEffectCloud) entity).getSource(); } diff --git a/pvpmanager/src/main/java/me/NoChance/PvPManager/Utils/MCVersion.java b/pvpmanager/src/main/java/me/NoChance/PvPManager/Utils/MCVersion.java deleted file mode 100644 index 1e4e42552..000000000 --- a/pvpmanager/src/main/java/me/NoChance/PvPManager/Utils/MCVersion.java +++ /dev/null @@ -1,55 +0,0 @@ -package me.NoChance.PvPManager.Utils; - -import me.NoChance.PvPManager.Settings.Settings; - -/** - * Utility class to get and compare MC versions - * - * @author ChanceSD - */ -public enum MCVersion { - OLD, V1_8, V1_9, V1_10, V1_11, V1_11_2, V1_12, V1_13, V1_13_1, V1_14, V1_15, V1_16, V1_16_5, V1_17, V1_18, V1_19; - - public static MCVersion getMCVersion(final String version) { - if (CombatUtils.isVersionAtLeast(version, "1.19")) - return MCVersion.V1_19; - else if (CombatUtils.isVersionAtLeast(version, "1.18")) - return MCVersion.V1_18; - else if (CombatUtils.isVersionAtLeast(version, "1.17")) - return MCVersion.V1_17; - else if (CombatUtils.isVersionAtLeast(version, "1.16.5")) - return MCVersion.V1_16_5; - else if (CombatUtils.isVersionAtLeast(version, "1.16")) - return MCVersion.V1_16; - else if (CombatUtils.isVersionAtLeast(version, "1.15")) - return MCVersion.V1_15; - else if (CombatUtils.isVersionAtLeast(version, "1.14")) - return MCVersion.V1_14; - else if (CombatUtils.isVersionAtLeast(version, "1.13.1")) - return MCVersion.V1_13_1; - else if (CombatUtils.isVersionAtLeast(version, "1.13")) - return MCVersion.V1_13; - else if (CombatUtils.isVersionAtLeast(version, "1.12")) - return MCVersion.V1_12; - else if (CombatUtils.isVersionAtLeast(version, "1.11.2")) - return MCVersion.V1_11_2; - else if (CombatUtils.isVersionAtLeast(version, "1.11")) - return MCVersion.V1_11; - else if (CombatUtils.isVersionAtLeast(version, "1.10")) - return MCVersion.V1_10; - else if (CombatUtils.isVersionAtLeast(version, "1.9")) - return MCVersion.V1_9; - else if (CombatUtils.isVersionAtLeast(version, "1.8")) - return MCVersion.V1_8; - return MCVersion.OLD; - } - - public static final boolean isAtLeast(final MCVersion version) { - return Settings.getMinecraftVersion().ordinal() >= version.ordinal(); - } - - public static final boolean isLessThan(final MCVersion version) { - return Settings.getMinecraftVersion().ordinal() < version.ordinal(); - } - -} diff --git a/pvpmanager/src/main/java/me/chancesd/pvpmanager/managers/UpdateManager.java b/pvpmanager/src/main/java/me/chancesd/pvpmanager/managers/UpdateManager.java index 614025562..20bf091ac 100644 --- a/pvpmanager/src/main/java/me/chancesd/pvpmanager/managers/UpdateManager.java +++ b/pvpmanager/src/main/java/me/chancesd/pvpmanager/managers/UpdateManager.java @@ -15,6 +15,7 @@ import me.chancesd.sdutils.updater.Updater.UpdateResult; import me.chancesd.sdutils.updater.Updater.UpdateType; import me.chancesd.sdutils.utils.Log; +import me.chancesd.sdutils.utils.Utils; public class UpdateManager { @@ -44,8 +45,8 @@ public void checkForUpdates() { + Messages.getCurrentversion(); Messages.queueAdminMsg(updateMsg); Bukkit.broadcast(updateMsg, Permissions.ADMIN.getPermission()); - if (Settings.isAutoUpdate() && CombatUtils.isVersionAtLeast(Messages.getNewVersion(), "4.0") - && !CombatUtils.isVersionAtLeast(Messages.getNewVersion(), "4.1")) { + if (Settings.isAutoUpdate() && Utils.isVersionAtLeast(Messages.getNewVersion(), "4.0") + && !Utils.isVersionAtLeast(Messages.getNewVersion(), "4.1")) { final String v4message = Messages.PREFIXMSG + " §aSince §b§lv4.0 is a huge update§a, it changes a lot of the config and messages file. " + "This makes it unable to be automatically updated. " diff --git a/pvpmanager/src/main/java/me/chancesd/pvpmanager/player/nametag/BukkitNameTag.java b/pvpmanager/src/main/java/me/chancesd/pvpmanager/player/nametag/BukkitNameTag.java index d6901d9c2..495ac48a9 100644 --- a/pvpmanager/src/main/java/me/chancesd/pvpmanager/player/nametag/BukkitNameTag.java +++ b/pvpmanager/src/main/java/me/chancesd/pvpmanager/player/nametag/BukkitNameTag.java @@ -11,7 +11,7 @@ import me.NoChance.PvPManager.PvPlayer; import me.NoChance.PvPManager.Settings.Settings; import me.chancesd.sdutils.utils.Log; -import me.NoChance.PvPManager.Utils.MCVersion; +import me.chancesd.sdutils.utils.MCVersion; public class BukkitNameTag extends NameTag { diff --git a/pvpmanager/src/main/java/me/chancesd/pvpmanager/storage/Database.java b/pvpmanager/src/main/java/me/chancesd/pvpmanager/storage/Database.java index a21802749..507224357 100644 --- a/pvpmanager/src/main/java/me/chancesd/pvpmanager/storage/Database.java +++ b/pvpmanager/src/main/java/me/chancesd/pvpmanager/storage/Database.java @@ -24,8 +24,8 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import me.NoChance.PvPManager.Utils.MCVersion; import me.chancesd.pvpmanager.storage.DatabaseConfigBuilder.DatabaseType; +import me.chancesd.sdutils.utils.MCVersion; public class Database { diff --git a/pvpmanager/src/test/java/me/NoChance/PvPManager/Listeners/EntityListenerTest.java b/pvpmanager/src/test/java/me/NoChance/PvPManager/Listeners/EntityListenerTest.java index 028c9818c..33a1818c7 100644 --- a/pvpmanager/src/test/java/me/NoChance/PvPManager/Listeners/EntityListenerTest.java +++ b/pvpmanager/src/test/java/me/NoChance/PvPManager/Listeners/EntityListenerTest.java @@ -184,7 +184,7 @@ final void cancelNewbie() { ph.get(attacker).setNewbie(true); createAttack(false); - assertEquals(ProtectionType.NEWBIE, ph.tryCancel(attacker, defender)); + assertEquals(ProtectionType.NEWBIE, ph.checkProtection(attacker, defender).type()); verify(attacker, times(2)).sendMessage(Messages.newbieBlocked()); verify(mockEvent).setCancelled(true); @@ -196,7 +196,7 @@ final void cancelPvPDisabled() { ph.get(defender).setPvP(false); createAttack(false); - assertEquals(ProtectionType.PVPDISABLED, ph.tryCancel(attacker, defender)); + assertEquals(ProtectionType.PVPDISABLED, ph.checkProtection(attacker, defender).type()); verify(attacker, times(2)).sendMessage(Messages.pvpDisabledOther(defender.getName())); verify(mockEvent).setCancelled(true); @@ -210,7 +210,7 @@ final void failCancel() { when(attacker.isFlying()).thenReturn(true); when(defender.isFlying()).thenReturn(true); - assertEquals(ProtectionType.FAIL, ph.tryCancel(attacker, defender)); + assertEquals(ProtectionType.FAIL, ph.checkProtection(attacker, defender).type()); createAttack(false); assertTrue(ph.get(attacker).isInCombat()); assertTrue(ph.get(defender).isInCombat()); @@ -226,7 +226,7 @@ final void overrideCancel() { ph.get(attacker).toggleOverride(); createAttack(false); - assertEquals(ProtectionType.FAIL_OVERRIDE, ph.tryCancel(attacker, defender)); + assertEquals(ProtectionType.FAIL_OVERRIDE, ph.checkProtection(attacker, defender).type()); assertTrue(ph.get(attacker).isInCombat()); assertTrue(ph.get(defender).isInCombat()); @@ -239,7 +239,7 @@ final void overrideCancelled() { ph.get(attacker).toggleOverride(); createAttack(true); - assertEquals(ProtectionType.FAIL_OVERRIDE, ph.tryCancel(attacker, defender)); + assertEquals(ProtectionType.FAIL_OVERRIDE, ph.checkProtection(attacker, defender).type()); assertTrue(ph.get(attacker).isInCombat()); assertTrue(ph.get(defender).isInCombat()); diff --git a/pvpmanager/src/test/java/me/NoChance/PvPManager/Managers/DependencyTest.java b/pvpmanager/src/test/java/me/NoChance/PvPManager/Managers/DependencyTest.java index dad62f6cd..949501734 100644 --- a/pvpmanager/src/test/java/me/NoChance/PvPManager/Managers/DependencyTest.java +++ b/pvpmanager/src/test/java/me/NoChance/PvPManager/Managers/DependencyTest.java @@ -1,7 +1,6 @@ package me.NoChance.PvPManager.Managers; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -18,7 +17,7 @@ import me.NoChance.PvPManager.InstanceCreator; import me.NoChance.PvPManager.PluginTest; -import me.NoChance.PvPManager.Utils.CombatUtils; +import me.chancesd.sdutils.utils.Utils; @ExtendWith(InstanceCreator.class) public class DependencyTest { @@ -43,9 +42,9 @@ void allEnabled() { @Test void versionTags() { - final String v1 = CombatUtils.stripTags("1.0.2-SNAPSHOT"); - final String v2 = CombatUtils.stripTags("1.0.2;1994-9adac4f"); - final String v3 = CombatUtils.stripTags("1.0.2+9adac4f"); + final String v1 = Utils.stripTags("1.0.2-SNAPSHOT"); + final String v2 = Utils.stripTags("1.0.2;1994-9adac4f"); + final String v3 = Utils.stripTags("1.0.2+9adac4f"); assertEquals("1.0.2", v1); assertEquals("1.0.2", v2); assertEquals("1.0.2", v3);