Messages for combat level restriction

This commit is contained in:
Jules 2023-03-11 18:32:46 +01:00
parent 5c9b73e3ec
commit b8624733da
4 changed files with 20 additions and 6 deletions

View File

@ -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<PlayerData> 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);
}

View File

@ -48,11 +48,23 @@ 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)) {
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;
}
}
/*
* Check for target's invulnerability BEFORE pvp-mode flag because it can also
* happen when the option pvp_mode.invulnerability.apply_to_pvp_flag is on

View File

@ -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:

View File

@ -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.'