From b8624733da2ef94ff108af7c1fc4c5fc3f4d2723 Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 11 Mar 2023 18:32:46 +0100 Subject: [PATCH] Messages for combat level restriction --- .../Indyuce/mmocore/api/player/PlayerData.java | 4 ++-- .../comp/region/pvpmode/PvPModeListener.java | 18 +++++++++++++++--- MMOCore-Dist/src/main/resources/config.yml | 2 +- .../src/main/resources/default/messages.yml | 2 ++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 193ac142..3705daeb 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -786,7 +786,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc } // Splitting exp through party members - AbstractParty party; + final AbstractParty party; if (splitExp && (party = getParty()) != null && MMOCore.plugin.configManager.splitMainExp) { final List nearbyMembers = party.getOnlineMembers().stream() .filter(pd -> { @@ -841,7 +841,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc if (level > oldLevel) { Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(this, null, oldLevel, level)); if (isOnline()) { - new ConfigMessage("level-up").addPlaceholders("level", "" + level).send(getPlayer()); + new ConfigMessage("level-up").addPlaceholders("level", String.valueOf(level)).send(getPlayer()); MMOCore.plugin.soundManager.getSound(SoundEvent.LEVEL_UP).playTo(getPlayer()); new SmallParticleEffect(getPlayer(), Particle.SPELL_INSTANT); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/region/pvpmode/PvPModeListener.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/region/pvpmode/PvPModeListener.java index 19e0fba6..126b7c85 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/region/pvpmode/PvPModeListener.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/region/pvpmode/PvPModeListener.java @@ -48,9 +48,21 @@ public class PvPModeListener implements Listener { final Player target = (Player) event.getEntity(); final PlayerData targetData = PlayerData.get(target), sourceData = PlayerData.get(source); final int minLevel = MMOCore.plugin.configManager.minCombatLevel; - if (minLevel > 0 && (targetData.getLevel() < minLevel || sourceData.getLevel() < minLevel)) { - event.setCancelled(true); - return; + if (minLevel > 0) { + + if (targetData.getLevel() < minLevel) { + event.setCancelled(true); + if (event.getDamage() > 0) + MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.cannot-hit.low-level-target").send(source); + return; + } + + if (sourceData.getLevel() < minLevel) { + event.setCancelled(true); + if (event.getDamage() > 0) + MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.cannot-hit.low-level-self").send(source); + return; + } } /* diff --git a/MMOCore-Dist/src/main/resources/config.yml b/MMOCore-Dist/src/main/resources/config.yml index 98ab5040..e30e3bac 100644 --- a/MMOCore-Dist/src/main/resources/config.yml +++ b/MMOCore-Dist/src/main/resources/config.yml @@ -312,7 +312,7 @@ pvp_mode: # When enabled, leaving a no-PVP zone and entering a # PVP zone will apply the SAME invulnerability time. # Requires /reload when changed - apply_to_pvp_flag: false + apply_to_pvp_flag: true cooldown: diff --git a/MMOCore-Dist/src/main/resources/default/messages.yml b/MMOCore-Dist/src/main/resources/default/messages.yml index 84864417..1fa73d39 100644 --- a/MMOCore-Dist/src/main/resources/default/messages.yml +++ b/MMOCore-Dist/src/main/resources/default/messages.yml @@ -35,6 +35,8 @@ pvp-mode: # When you cannot hit another player cannot-hit: + low-level-target: '&cYou cannot fight this player as their level is too low.' + low-level-self: '&cYour level is too low to fight other players.' pvp-mode-disabled-target: '&cThis player has not toggled on PvP.' pvp-mode-disabled-self: '&cYou have not toggled on PvP.' invulnerable-self: '&cYou are still out of combat for {left} seconds.'