Added invulnerability when using /pvpmode inside of region

This commit is contained in:
Jules 2023-02-21 14:56:25 +01:00
parent 9bd830efb7
commit 07a61b900e
3 changed files with 24 additions and 7 deletions

View File

@ -1,6 +1,7 @@
package net.Indyuce.mmocore.command; package net.Indyuce.mmocore.command;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.comp.flags.CustomFlag;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.api.RegisteredCommand; import net.Indyuce.mmocore.command.api.RegisteredCommand;
@ -39,7 +40,17 @@ public class PvpModeCommand extends RegisteredCommand {
playerData.getCombat().setPvpMode(!playerData.getCombat().isInPvpMode()); playerData.getCombat().setPvpMode(!playerData.getCombat().isInPvpMode());
playerData.getCooldownMap().applyCooldown(COOLDOWN_KEY, playerData.getCombat().isInPvpMode() ? MMOCore.plugin.configManager.pvpModeToggleOnCooldown : MMOCore.plugin.configManager.pvpModeToggleOffCooldown); 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; return true;
} }
} }

View File

@ -82,8 +82,8 @@ public class PvPModeHandler extends FlagValueChangeHandler<State> {
final String msgPath = (playerData.getCombat().isInPvpMode() && !playerData.getCombat().canQuitPvpMode()) ? "allowed" : "denied"; final String msgPath = (playerData.getCombat().isInPvpMode() && !playerData.getCombat().canQuitPvpMode()) ? "allowed" : "denied";
lastMessage = System.currentTimeMillis(); lastMessage = System.currentTimeMillis();
final double remaining = (playerData.getCombat().getLastHit() + MMOCore.plugin.configManager.pvpModeCombatTimeout * 1000.0D - System.currentTimeMillis()) / 1000.0D; 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", MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.leave.pvp-" + msgPath, "remaining",
(MythicLib.plugin.getMMOConfig()).decimal.format(remaining)}).send(playerData.getPlayer()); (MythicLib.plugin.getMMOConfig()).decimal.format(remaining)).send(playerData.getPlayer());
} }
} else if (newPvpMode && !lastPvpMode) { } else if (newPvpMode && !lastPvpMode) {
@ -95,8 +95,8 @@ public class PvPModeHandler extends FlagValueChangeHandler<State> {
// Send message // Send message
if (canSendMessage()) { if (canSendMessage()) {
lastMessage = System.currentTimeMillis(); lastMessage = System.currentTimeMillis();
MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.enter.pvp-mode-" + (applyInvulnerability ? "on" : "off"), new String[]{"time", 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()); MythicLib.plugin.getMMOConfig().decimal.format(MMOCore.plugin.configManager.pvpModeInvulnerability)).send(playerData.getPlayer());
} }
} }
return true; return true;

View File

@ -32,8 +32,14 @@ booster-expired: '&cExpired!'
# PvP Mode # PvP Mode
pvp-mode: pvp-mode:
cooldown: '&cPlease wait {remaining} seconds to use this command again.' 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: leave:
pvp-allowed: '&cYou left a PVP zone but are still vulnerable for {remaining} seconds!' pvp-allowed: '&cYou left a PVP zone but are still vulnerable for {remaining} seconds!'
pvp-denied: '&cYou left the PVP zone.' pvp-denied: '&cYou left the PVP zone.'