diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java index b4ab999d..4c9f948f 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -161,7 +161,7 @@ public class MMOCore extends JavaPlugin { if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) { regionHandler = new WorldGuardRegionHandler(); - if (MythicLib.plugin.getConfig().getBoolean("pvp_mode.enabled")) + if (getConfig().getBoolean("pvp_mode.enabled")) Bukkit.getPluginManager().registerEvents(new PvPModeListener(), this); getLogger().log(Level.INFO, "Hooked onto WorldGuard"); } 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 e28e6aa3..3e7f7060 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 @@ -58,45 +58,46 @@ public class PvPModeHandler extends FlagValueChangeHandler { * In that case, put PvP mode to its default setting that is OFF. */ @Override - protected boolean onAbsentValue(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, State lastValue, MoveType moveType) { - return true; + protected boolean onAbsentValue(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, StateFlag.State lastValue, MoveType moveType) { + return onSetValue(player, from, to, toSet, DEFAULT_STATE, lastValue, moveType); } + public static final StateFlag.State DEFAULT_STATE = StateFlag.State.DENY; + /** * Triggered when a player changes region and finds a new value for that flag. * In that case, apply the new setting and display messages if needed. */ @Override - protected boolean onSetValue(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, State currentValue, State lastValue, MoveType moveType) { - - // Do nothing if pvpmode is disabled. - if (isInvalid() || !playerData.getCombat().isInPvpMode()) + protected boolean onSetValue(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, StateFlag.State currentValue, StateFlag.State lastValue, MoveType moveType) { + boolean newPvpMode = toBoolean(currentValue); + boolean lastPvpMode = toBoolean(lastValue); + if (isInvalid()) return true; - final boolean newPvpMode = toBoolean(currentValue); - final boolean lastPvpMode = toBoolean(lastValue); + if (!newPvpMode && lastPvpMode) { - if (!playerData.getCombat().canQuitPvpMode()) { - - // Leaving a custom Pvp zone - if (!newPvpMode && lastPvpMode && canSendMessage()) { + // Send message + if (canSendMessage()) { + 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 - System.currentTimeMillis()) / 1000; - MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.leave", "remaining", MythicLib.plugin.getMMOConfig().decimal.format(remaining)).send(playerData.getPlayer()); + 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()); } - } else if (newPvpMode && !lastPvpMode) { // Apply invulnerability - playerData.getCombat().applyInvulnerability(); + if (playerData.getCombat().isInPvpMode()) + playerData.getCombat().applyInvulnerability(); - // Entering Pvp zone + // Send message if (canSendMessage()) { lastMessage = System.currentTimeMillis(); - MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.enter", "time", MythicLib.plugin.getMMOConfig().decimal.format(MMOCore.plugin.configManager.pvpModeInvulnerability)).send(playerData.getPlayer()); + MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.enter.pvp-mode-" + (playerData.getCombat().isInPvpMode() ? "on" : "off"), new String[]{"time", + (MythicLib.plugin.getMMOConfig()).decimal.format(MMOCore.plugin.configManager.pvpModeInvulnerability)}).send(playerData.getPlayer()); } } - return true; } 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 f98ae4c0..42641ab8 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 @@ -4,6 +4,7 @@ import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.bukkit.protection.events.DisallowedPVPEvent; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.comp.flags.CustomFlag; +import io.lumine.mythic.lib.comp.interaction.InteractionType; import net.Indyuce.mmocore.api.player.PlayerData; import org.apache.commons.lang.Validate; import org.bukkit.event.EventHandler; @@ -16,18 +17,13 @@ public class PvPModeListener implements Listener { @EventHandler(ignoreCancelled = true) public void unblockPvp(DisallowedPVPEvent event) { - final PlayerData defender; - - // Make sure both have PVP mode on + PlayerData defender; if (!PlayerData.get(event.getAttacker()).getCombat().isInPvpMode() || !(defender = PlayerData.get(event.getDefender())).getCombat().isInPvpMode()) return; - // If there are in a PVP zone - if (MythicLib.plugin.getFlags().isFlagAllowed(event.getDefender().getLocation(), CustomFlag.PVP_MODE) && !defender.getCombat().isInvulnerable()) - event.setCancelled(true); - - // If target cannot quit pvp zone yet - else if (!defender.getCombat().canQuitPvpMode()) - event.setCancelled(true); + if (!defender.getCombat().canQuitPvpMode() || + (!defender.getCombat().isInvulnerable() && MythicLib.plugin.getFlags().isFlagAllowed(event.getDefender().getLocation(), CustomFlag.PVP_MODE))) + if (MythicLib.plugin.getEntities().canInteract(event.getAttacker(), event.getDefender(), InteractionType.OFFENSE_ACTION, true)) + event.setCancelled(true); } } diff --git a/MMOCore-Dist/src/main/resources/default/messages.yml b/MMOCore-Dist/src/main/resources/default/messages.yml index 387f6636..d79602a4 100644 --- a/MMOCore-Dist/src/main/resources/default/messages.yml +++ b/MMOCore-Dist/src/main/resources/default/messages.yml @@ -34,8 +34,12 @@ pvp-mode: cooldown: '&cPlease wait {remaining} seconds to use this command again.' toggle-on: '&aPvP Mode on.' toggle-off: '&cPvP Mode off.' - leave: '&cYou left a PVP zone but are still vulnerable for {remaining} seconds!' - enter: '&aYou entered a PVP zone and gained invulnerability for {time} seconds!' + leave: + pvp-allowed: '&cYou left a PVP zone but are still vulnerable for {remaining} seconds!' + pvp-denied: '&cYou left the PVP zone.' + enter: + pvp-mode-on: '&aYou entered a PVP zone and gained invulnerability for {time} seconds!' + pvp-mode-off: '&aYou entered a PVP zone. You may use /pvpmode to fight other players.' # Fishing Profession caught-fish: '&cYou caught a fish!' @@ -69,7 +73,7 @@ casting: no-longer: '%&cYou cancelled skill casting.' no-mana: '&cYou do not have enough {mana}, {mana-required} more required!' no-stamina: '&cYou do not have enough stamina!' - on-cooldown: '&cThis skill is on a {cooldown} cooldown.' + on-cooldown: '&cThis skill is on a {cooldown}s cooldown.' # Combat Log now-in-combat: '%&cYou are now in combat!'