From 07a61b900ef2042ca3395d189884aa990df13780 Mon Sep 17 00:00:00 2001 From: Jules Date: Tue, 21 Feb 2023 14:56:25 +0100 Subject: [PATCH] Added invulnerability when using /pvpmode inside of region --- .../net/Indyuce/mmocore/command/PvpModeCommand.java | 13 ++++++++++++- .../mmocore/comp/region/pvpmode/PvPModeHandler.java | 8 ++++---- .../src/main/resources/default/messages.yml | 10 ++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PvpModeCommand.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PvpModeCommand.java index 7cc99d7a..a0394d95 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PvpModeCommand.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PvpModeCommand.java @@ -1,6 +1,7 @@ package net.Indyuce.mmocore.command; import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.comp.flags.CustomFlag; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.command.api.RegisteredCommand; @@ -39,7 +40,17 @@ public class PvpModeCommand extends RegisteredCommand { playerData.getCombat().setPvpMode(!playerData.getCombat().isInPvpMode()); playerData.getCooldownMap().applyCooldown(COOLDOWN_KEY, playerData.getCombat().isInPvpMode() ? MMOCore.plugin.configManager.pvpModeToggleOnCooldown : MMOCore.plugin.configManager.pvpModeToggleOffCooldown); - MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.toggle-" + (playerData.getCombat().isInPvpMode() ? "on" : "off")).send((Player) sender); + + // Toggling on when in PVP region + if (playerData.getCombat().isInPvpMode() && + MythicLib.plugin.getFlags().isFlagAllowed(playerData.getPlayer(), CustomFlag.PVP_MODE)) { + playerData.getCombat().applyInvulnerability(); + MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.toggle.on-invulnerable", "time", + MythicLib.plugin.getMMOConfig().decimal.format(MMOCore.plugin.configManager.pvpModeInvulnerability)).send(playerData.getPlayer()); + + // Just send message otherwise + } else + MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.toggle." + (playerData.getCombat().isInPvpMode() ? "on" : "off")).send((Player) sender); return true; } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/region/pvpmode/PvPModeHandler.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/region/pvpmode/PvPModeHandler.java index 60bdb26f..d0620a24 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/region/pvpmode/PvPModeHandler.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/region/pvpmode/PvPModeHandler.java @@ -82,8 +82,8 @@ public class PvPModeHandler extends FlagValueChangeHandler { final String msgPath = (playerData.getCombat().isInPvpMode() && !playerData.getCombat().canQuitPvpMode()) ? "allowed" : "denied"; lastMessage = System.currentTimeMillis(); final double remaining = (playerData.getCombat().getLastHit() + MMOCore.plugin.configManager.pvpModeCombatTimeout * 1000.0D - System.currentTimeMillis()) / 1000.0D; - MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.leave.pvp-" + msgPath, new String[]{"remaining", - (MythicLib.plugin.getMMOConfig()).decimal.format(remaining)}).send(playerData.getPlayer()); + MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.leave.pvp-" + msgPath, "remaining", + (MythicLib.plugin.getMMOConfig()).decimal.format(remaining)).send(playerData.getPlayer()); } } else if (newPvpMode && !lastPvpMode) { @@ -95,8 +95,8 @@ public class PvPModeHandler extends FlagValueChangeHandler { // Send message if (canSendMessage()) { lastMessage = System.currentTimeMillis(); - MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.enter.pvp-mode-" + (applyInvulnerability ? "on" : "off"), new String[]{"time", - (MythicLib.plugin.getMMOConfig()).decimal.format(MMOCore.plugin.configManager.pvpModeInvulnerability)}).send(playerData.getPlayer()); + MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.enter.pvp-mode-" + (applyInvulnerability ? "on" : "off"), "time", + MythicLib.plugin.getMMOConfig().decimal.format(MMOCore.plugin.configManager.pvpModeInvulnerability)).send(playerData.getPlayer()); } } return true; diff --git a/MMOCore-Dist/src/main/resources/default/messages.yml b/MMOCore-Dist/src/main/resources/default/messages.yml index d79602a4..e6ec39c2 100644 --- a/MMOCore-Dist/src/main/resources/default/messages.yml +++ b/MMOCore-Dist/src/main/resources/default/messages.yml @@ -32,8 +32,14 @@ booster-expired: '&cExpired!' # PvP Mode pvp-mode: cooldown: '&cPlease wait {remaining} seconds to use this command again.' - toggle-on: '&aPvP Mode on.' - toggle-off: '&cPvP Mode off.' + + # When using /pvpmode + toggle: + on: '&aPvP Mode on.' + on-invulnerable: '&aPvP Mode on. You are now invulnerable for {time} seconds.' + off: '&cPvP Mode off.' + + # Entering/leaving regions with specific flag value leave: pvp-allowed: '&cYou left a PVP zone but are still vulnerable for {remaining} seconds!' pvp-denied: '&cYou left the PVP zone.'