forked from Upstream/mmocore
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
d847049e90
@ -213,7 +213,14 @@
|
||||
<dependency>
|
||||
<groupId>de.erethon</groupId>
|
||||
<artifactId>DungeonsXL</artifactId>
|
||||
<version>0.18-PRE-02</version>
|
||||
<version>0.18-SNAPSHOT-1149</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>de.erethon</groupId>
|
||||
<artifactId>Bedrock</artifactId>
|
||||
<version>1.2.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@ -262,7 +269,7 @@
|
||||
<dependency>
|
||||
<groupId>me.ulrich</groupId>
|
||||
<artifactId>UltimateClans</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>6.0.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@ -276,7 +283,7 @@
|
||||
<dependency>
|
||||
<groupId>org.kingdoms.main</groupId>
|
||||
<artifactId>Kingdoms</artifactId>
|
||||
<version>1.11.15.0.0.0.1.1</version>
|
||||
<version>1.15.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -208,6 +208,7 @@ public class MMOCore extends JavaPlugin {
|
||||
PartyModuleType moduleType = PartyModuleType.valueOf(partyPluginName);
|
||||
Validate.isTrue(moduleType.isValid(), "Plugin '" + moduleType.name() + "' is not installed");
|
||||
partyModule = moduleType.provideModule();
|
||||
getLogger().log(Level.WARNING, "Hooked parties onto " + moduleType.getPluginName());
|
||||
} catch (RuntimeException exception) {
|
||||
getLogger().log(Level.WARNING, "Could not initialize party module: " + exception.getMessage());
|
||||
partyModule = new MMOCorePartyModule();
|
||||
@ -219,6 +220,7 @@ public class MMOCore extends JavaPlugin {
|
||||
GuildModuleType moduleType = GuildModuleType.valueOf(pluginName);
|
||||
Validate.isTrue(moduleType.isValid(), "Plugin '" + moduleType.name() + "' is not installed");
|
||||
guildModule = moduleType.provideModule();
|
||||
getLogger().log(Level.WARNING, "Hooked guilds onto " + moduleType.getPluginName());
|
||||
} catch (RuntimeException exception) {
|
||||
getLogger().log(Level.WARNING, "Could not initialize guild module: " + exception.getMessage());
|
||||
guildModule = new MMOCoreGuildModule();
|
||||
|
@ -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().setInvulnerable(MMOCore.plugin.configManager.pvpModeInvulnerabilityTimeCommand);
|
||||
MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.toggle.on-invulnerable", "time",
|
||||
MythicLib.plugin.getMMOConfig().decimal.format(MMOCore.plugin.configManager.pvpModeInvulnerabilityTimeCommand)).send(playerData.getPlayer());
|
||||
|
||||
// Just send message otherwise
|
||||
} else
|
||||
MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.toggle." + (playerData.getCombat().isInPvpMode() ? "on" : "off") + "-safe").send((Player) sender);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -95,6 +95,9 @@ public class RPGPlaceholders extends PlaceholderExpansion {
|
||||
else if (identifier.equals("in_combat"))
|
||||
return String.valueOf(playerData.isInCombat());
|
||||
|
||||
else if (identifier.equals("pvp_mode"))
|
||||
return String.valueOf(playerData.getCombat().isInPvpMode());
|
||||
|
||||
else if (identifier.startsWith("since_enter_combat"))
|
||||
return playerData.isInCombat() ? MythicLib.plugin.getMMOConfig().decimal.format((System.currentTimeMillis() - playerData.getCombat().getFirstHit()) / 1000) : "-1";
|
||||
|
||||
|
@ -0,0 +1,66 @@
|
||||
package net.Indyuce.mmocore.comp.region.pvpmode;
|
||||
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.session.MoveType;
|
||||
import com.sk89q.worldguard.session.Session;
|
||||
import com.sk89q.worldguard.session.handler.FlagValueChangeHandler;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class MMOCoreFlagHandler extends FlagValueChangeHandler<StateFlag.State> {
|
||||
|
||||
@NotNull
|
||||
protected PlayerData playerData;
|
||||
|
||||
protected long lastMessage;
|
||||
|
||||
protected static final long MESSAGE_TIMEOUT = 3 * 1000;
|
||||
|
||||
public MMOCoreFlagHandler(Session session, Flag<StateFlag.State> flag) {
|
||||
super(session, flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered when WorldGuard initializes the value for the first time,
|
||||
* on player login or world change for instance.
|
||||
*/
|
||||
@Override
|
||||
protected void onInitialValue(LocalPlayer player, ApplicableRegionSet set, StateFlag.State value) {
|
||||
try {
|
||||
playerData = PlayerData.get(player.getUniqueId());
|
||||
|
||||
// Things get done here
|
||||
onSetValue(player, player.getLocation(), player.getLocation(), set, value, StateFlag.State.DENY, MoveType.TELEPORT);
|
||||
} catch (Exception exception) {
|
||||
// Citizens.
|
||||
}
|
||||
}
|
||||
|
||||
public abstract StateFlag.State getDefaultState();
|
||||
|
||||
/**
|
||||
* Triggered when WorldGuard does not find a region setting the value of the flag.
|
||||
* 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, StateFlag.State lastValue, MoveType moveType) {
|
||||
return onSetValue(player, from, to, toSet, getDefaultState(), lastValue, moveType);
|
||||
}
|
||||
|
||||
protected boolean isInvalid() {
|
||||
return playerData == null;
|
||||
}
|
||||
|
||||
protected boolean toBoolean(@Nullable StateFlag.State state) {
|
||||
return state == StateFlag.State.ALLOW;
|
||||
}
|
||||
|
||||
protected boolean canSendMessage() {
|
||||
return System.currentTimeMillis() > lastMessage + MESSAGE_TIMEOUT;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package net.Indyuce.mmocore.comp.region.pvpmode;
|
||||
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.session.MoveType;
|
||||
import com.sk89q.worldguard.session.Session;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
|
||||
public class PvPFlagHandler extends MMOCoreFlagHandler {
|
||||
|
||||
public static final Factory FACTORY = new Factory() {
|
||||
|
||||
@Override
|
||||
public PvPFlagHandler create(Session session) {
|
||||
return new PvPFlagHandler(session, Flags.PVP);
|
||||
}
|
||||
};
|
||||
|
||||
public PvPFlagHandler(Session session, StateFlag flag) {
|
||||
super(session, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public State getDefaultState() {
|
||||
return State.ALLOW;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (isInvalid())
|
||||
return true;
|
||||
|
||||
boolean newPvp = toBoolean(currentValue);
|
||||
boolean lastPvp = toBoolean(lastValue);
|
||||
|
||||
if (newPvp && !lastPvp) {
|
||||
|
||||
// Apply invulnerability
|
||||
playerData.getCombat().setInvulnerable(MMOCore.plugin.configManager.pvpModeInvulnerabilityTimeRegionChange);
|
||||
|
||||
// Send message
|
||||
if (canSendMessage()) {
|
||||
lastMessage = System.currentTimeMillis();
|
||||
MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.enter.pvp-mode-on", "time",
|
||||
MythicLib.plugin.getMMOConfig().decimal.format(MMOCore.plugin.configManager.pvpModeInvulnerabilityTimeRegionChange)).send(playerData.getPlayer());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -3,32 +3,23 @@ package net.Indyuce.mmocore.comp.region.pvpmode;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.session.MoveType;
|
||||
import com.sk89q.worldguard.session.Session;
|
||||
import com.sk89q.worldguard.session.handler.FlagValueChangeHandler;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.comp.flags.CustomFlag;
|
||||
import io.lumine.mythic.lib.comp.flags.WorldGuardFlags;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import net.Indyuce.mmocore.command.PvpModeCommand;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class PvPModeHandler extends FlagValueChangeHandler<State> {
|
||||
|
||||
@NotNull
|
||||
private PlayerData playerData;
|
||||
|
||||
private long lastMessage;
|
||||
|
||||
private static final long MESSAGE_TIMEOUT = 3 * 1000;
|
||||
public class PvPModeHandler extends MMOCoreFlagHandler {
|
||||
|
||||
public static final Factory FACTORY = new Factory() {
|
||||
public final WorldGuardFlags wgFlags = Objects.requireNonNull(MythicLib.plugin.getFlags().getHandler(WorldGuardFlags.class), "Could not reach ML compatibility class for WG");
|
||||
final WorldGuardFlags wgFlags = Objects.requireNonNull(MythicLib.plugin.getFlags().getHandler(WorldGuardFlags.class), "Could not reach ML compatibility class for WG");
|
||||
|
||||
@Override
|
||||
public PvPModeHandler create(Session session) {
|
||||
@ -40,29 +31,10 @@ public class PvPModeHandler extends FlagValueChangeHandler<State> {
|
||||
super(session, flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered when WorldGuard initializes the value for the first time,
|
||||
* on player login or world change for instance.
|
||||
*/
|
||||
@Override
|
||||
protected void onInitialValue(LocalPlayer player, ApplicableRegionSet set, State value) {
|
||||
try {
|
||||
playerData = PlayerData.get(player.getUniqueId());
|
||||
} catch (Exception exception) {
|
||||
// Citizens.
|
||||
public State getDefaultState() {
|
||||
return State.ALLOW;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered when WorldGuard does not find a region setting the value of the flag.
|
||||
* 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, 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.
|
||||
@ -70,47 +42,48 @@ public class PvPModeHandler extends FlagValueChangeHandler<State> {
|
||||
*/
|
||||
@Override
|
||||
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;
|
||||
|
||||
boolean newPvpMode = toBoolean(currentValue);
|
||||
boolean lastPvpMode = toBoolean(lastValue);
|
||||
|
||||
if (!newPvpMode && lastPvpMode) {
|
||||
|
||||
// Apply cooldown
|
||||
playerData.getMMOPlayerData().getCooldownMap().applyCooldown(PvpModeCommand.COOLDOWN_KEY, MMOCore.plugin.configManager.pvpModeRegionLeaveCooldown);
|
||||
|
||||
// Send message
|
||||
if (canSendMessage()) {
|
||||
final String msgPath = (playerData.getCombat().isInPvpMode() && !playerData.getCombat().canQuitPvpMode()) ? "allowed" : "denied";
|
||||
|
||||
// Leave combat when joining safe zone
|
||||
final boolean pvpFlag = toSet.queryState(null, Flags.PVP) != StateFlag.State.DENY;
|
||||
if (playerData.getCombat().isInPvpMode() && !pvpFlag)
|
||||
playerData.getCombat().close();
|
||||
|
||||
final boolean pvpEnabled = playerData.getCombat().isInPvpMode() && !playerData.getCombat().canQuitPvpMode() && pvpFlag;
|
||||
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-" + (pvpEnabled ? "allowed" : "denied"), "remaining",
|
||||
(MythicLib.plugin.getMMOConfig()).decimal.format(remaining)).send(playerData.getPlayer());
|
||||
}
|
||||
} else if (newPvpMode && !lastPvpMode) {
|
||||
|
||||
// Apply cooldown
|
||||
playerData.getMMOPlayerData().getCooldownMap().applyCooldown(PvpModeCommand.COOLDOWN_KEY, MMOCore.plugin.configManager.pvpModeRegionEnterCooldown);
|
||||
|
||||
// Apply invulnerability
|
||||
final boolean applyInvulnerability = playerData.getCombat().isInPvpMode() && playerData.getCombat().canQuitPvpMode();
|
||||
if (applyInvulnerability)
|
||||
playerData.getCombat().applyInvulnerability();
|
||||
playerData.getCombat().setInvulnerable(MMOCore.plugin.configManager.pvpModeInvulnerabilityTimeRegionChange);
|
||||
|
||||
// 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.pvpModeInvulnerabilityTimeRegionChange)).send(playerData.getPlayer());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isInvalid() {
|
||||
return playerData == null;
|
||||
}
|
||||
|
||||
private boolean toBoolean(@Nullable State state) {
|
||||
return state == State.ALLOW;
|
||||
}
|
||||
|
||||
private boolean canSendMessage() {
|
||||
return System.currentTimeMillis() > lastMessage + MESSAGE_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,89 @@
|
||||
package net.Indyuce.mmocore.comp.region.pvpmode;
|
||||
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.protection.events.DisallowedPVPEvent;
|
||||
import com.sk89q.worldguard.session.handler.Handler;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.UtilityMethods;
|
||||
import io.lumine.mythic.lib.comp.flags.CustomFlag;
|
||||
import io.lumine.mythic.lib.comp.interaction.InteractionType;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class PvPModeListener implements Listener {
|
||||
public PvPModeListener() {
|
||||
Validate.isTrue(WorldGuard.getInstance().getPlatform().getSessionManager().registerHandler(PvPModeHandler.FACTORY, null), "Could not register WG handler for PvP mode");
|
||||
Validate.isTrue(registerHandler(PvPModeHandler.FACTORY), "Could not register WG handler for PvP mode");
|
||||
if (MMOCore.plugin.getConfig().getBoolean("pvp_mode.invulnerability.apply_to_pvp_flag"))
|
||||
Validate.isTrue(registerHandler(PvPFlagHandler.FACTORY), "Could not register WG handler for PvP");
|
||||
}
|
||||
|
||||
private boolean registerHandler(Handler.Factory factory) {
|
||||
return WorldGuard.getInstance().getPlatform().getSessionManager().registerHandler(factory, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs after MythicLib interaction checks. This listener
|
||||
* takes care of PVP inside of PvP-mode regions.
|
||||
* <p>
|
||||
* Only send messages when damage is greater than 0 to support
|
||||
* Bukkit events-based checks just like in recent ML builds.
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void unblockPvp(DisallowedPVPEvent event) {
|
||||
PlayerData defender;
|
||||
if (PlayerData.get(event.getAttacker()).getCombat().isInPvpMode() || !(defender = PlayerData.get(event.getDefender())).getCombat().isInPvpMode())
|
||||
public void a(EntityDamageByEntityEvent event) {
|
||||
if (!UtilityMethods.isRealPlayer(event.getEntity()))
|
||||
return;
|
||||
|
||||
if (!defender.getCombat().canQuitPvpMode() ||
|
||||
(!defender.getCombat().isInvulnerable() && MythicLib.plugin.getFlags().isFlagAllowed(event.getDefender().getLocation(), CustomFlag.PVP_MODE)))
|
||||
if (MythicLib.plugin.getEntities().checkPvpInteractionRules(event.getAttacker(), event.getDefender(), InteractionType.OFFENSE_ACTION, true))
|
||||
final @Nullable Player source = UtilityMethods.getPlayerDamager(event);
|
||||
if (source == null)
|
||||
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
|
||||
final Player target = (Player) event.getEntity();
|
||||
final PlayerData targetData = PlayerData.get(target);
|
||||
if (targetData.getCombat().isInvulnerable()) {
|
||||
if (event.getDamage() > 0) {
|
||||
final long left = targetData.getCombat().getInvulnerableTill() - System.currentTimeMillis();
|
||||
MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.cannot-hit.invulnerable-target",
|
||||
"left", MythicLib.plugin.getMMOConfig().decimal.format(left / 1000d)).send(source);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// If attacker is still invulnerable and cannot deal damage
|
||||
final PlayerData sourceData = PlayerData.get(source);
|
||||
if (!MMOCore.plugin.configManager.pvpModeInvulnerabilityCanDamage && sourceData.getCombat().isInvulnerable()) {
|
||||
if (event.getDamage() > 0) {
|
||||
final long left = sourceData.getCombat().getInvulnerableTill() - System.currentTimeMillis();
|
||||
MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.cannot-hit.invulnerable-self",
|
||||
"left", MythicLib.plugin.getMMOConfig().decimal.format(left / 1000d)).send(source);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Checks for PvP mode on target location
|
||||
if (!MythicLib.plugin.getFlags().isFlagAllowed(target.getLocation(), CustomFlag.PVP_MODE))
|
||||
return;
|
||||
|
||||
// Defender has not enabled PvP mode
|
||||
if (!targetData.getCombat().isInPvpMode()) {
|
||||
event.setCancelled(true);
|
||||
if (event.getDamage() > 0)
|
||||
MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.cannot-hit.pvp-mode-disabled-target").send(source);
|
||||
}
|
||||
|
||||
// Attacker has not enabled PvP mode
|
||||
else if (!sourceData.getCombat().isInPvpMode()) {
|
||||
event.setCancelled(true);
|
||||
if (event.getDamage() > 0)
|
||||
MMOCore.plugin.configManager.getSimpleMessage("pvp-mode.cannot-hit.pvp-mode-disabled-self").send(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package net.Indyuce.mmocore.guild;
|
||||
import io.lumine.mythic.lib.comp.interaction.relation.Relationship;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface GuildModule {
|
||||
@ -10,5 +11,6 @@ public interface GuildModule {
|
||||
@Nullable
|
||||
public AbstractGuild getGuild(PlayerData playerData);
|
||||
|
||||
@NotNull
|
||||
public Relationship getRelationship(Player player, Player target);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public enum GuildModuleType {
|
||||
// Useless since MythicLib already supports FactionBridge
|
||||
// FACTIONS("Factions", FactionsGuildModule::new),
|
||||
GUILDS("Guilds", GuildsGuildModule::new),
|
||||
KINGDOMSX("KingdomsX", KingdomsXGuildModule::new),
|
||||
KINGDOMSX("Kingdoms", KingdomsXGuildModule::new),
|
||||
MMOCORE("MMOCore", MMOCoreGuildModule::new),
|
||||
ULTIMATE_CLANS("UltimateClans", UltimateClansGuildModule::new),
|
||||
;
|
||||
@ -25,6 +25,10 @@ public enum GuildModuleType {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return Bukkit.getPluginManager().getPlugin(pluginName) != null;
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import net.Indyuce.mmocore.guild.AbstractGuild;
|
||||
import net.Indyuce.mmocore.guild.GuildModule;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.kingdoms.constants.kingdom.Kingdom;
|
||||
import org.kingdoms.constants.kingdom.model.KingdomRelation;
|
||||
import org.kingdoms.constants.group.Kingdom;
|
||||
import org.kingdoms.constants.group.model.relationships.KingdomRelation;
|
||||
import org.kingdoms.constants.player.KingdomPlayer;
|
||||
import org.kingdoms.main.Kingdoms;
|
||||
|
||||
@ -30,7 +30,7 @@ public class KingdomsXGuildModule implements GuildModule {
|
||||
|
||||
final KingdomPlayer player1 = Kingdoms.get().getDataHandlers().getKingdomPlayerManager().getData(player.getUniqueId());
|
||||
if (player1 == null)
|
||||
return null;
|
||||
return Relationship.GUILD_NEUTRAL;
|
||||
|
||||
final Kingdom kingdom1 = player1.getKingdom();
|
||||
if (kingdom1 == null)
|
||||
@ -38,7 +38,7 @@ public class KingdomsXGuildModule implements GuildModule {
|
||||
|
||||
final KingdomPlayer player2 = Kingdoms.get().getDataHandlers().getKingdomPlayerManager().getData(target.getUniqueId());
|
||||
if (player2 == null)
|
||||
return null;
|
||||
return Relationship.GUILD_NEUTRAL;
|
||||
|
||||
final Kingdom kingdom2 = player2.getKingdom();
|
||||
if (kingdom2 == null)
|
||||
|
@ -3,7 +3,7 @@ package net.Indyuce.mmocore.guild.compat;
|
||||
import io.lumine.mythic.lib.comp.interaction.relation.Relationship;
|
||||
import me.ulrich.clans.data.ClanData;
|
||||
import me.ulrich.clans.data.ClanRivalAlly;
|
||||
import me.ulrich.clans.packets.interfaces.UClans;
|
||||
import me.ulrich.clans.interfaces.UClans;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.guild.AbstractGuild;
|
||||
import net.Indyuce.mmocore.guild.GuildModule;
|
||||
|
@ -27,11 +27,13 @@ import java.util.logging.Level;
|
||||
public class ConfigManager {
|
||||
public final CommandVerbose commandVerbose = new CommandVerbose();
|
||||
|
||||
public boolean overrideVanillaExp, canCreativeCast, passiveSkillNeedBound, cobbleGeneratorXP, saveDefaultClassInfo, attributesAsClassInfo, splitProfessionExp, disableQuestBossBar, pvpModeEnabled;
|
||||
public boolean overrideVanillaExp, canCreativeCast, passiveSkillNeedBound, cobbleGeneratorXP, saveDefaultClassInfo, attributesAsClassInfo, splitProfessionExp, disableQuestBossBar,
|
||||
pvpModeEnabled, pvpModeInvulnerabilityCanDamage;
|
||||
public String partyChatPrefix, noSkillBoundPlaceholder;
|
||||
public ChatColor staminaFull, staminaHalf, staminaEmpty;
|
||||
public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown;
|
||||
public double lootChestsChanceWeight, dropItemsChanceWeight, fishingDropsChanceWeight, partyMaxExpSplitRange, pvpModeToggleOnCooldown, pvpModeToggleOffCooldown, pvpModeCombatCooldown, pvpModeCombatTimeout, pvpModeInvulnerability;
|
||||
public double lootChestsChanceWeight, dropItemsChanceWeight, fishingDropsChanceWeight, partyMaxExpSplitRange, pvpModeToggleOnCooldown, pvpModeToggleOffCooldown, pvpModeCombatCooldown,
|
||||
pvpModeCombatTimeout, pvpModeInvulnerabilityTimeRegionChange, pvpModeInvulnerabilityTimeCommand, pvpModeRegionEnterCooldown, pvpModeRegionLeaveCooldown;
|
||||
public int maxPartyLevelDifference, maxBoundActiveSkills, maxBoundPassiveSkills;
|
||||
public final List<EntityDamageEvent.DamageCause> combatLogDamageCauses = new ArrayList<>();
|
||||
|
||||
@ -136,8 +138,12 @@ public class ConfigManager {
|
||||
pvpModeToggleOnCooldown = config.getDouble("pvp_mode.cooldown.toggle_on");
|
||||
pvpModeToggleOffCooldown = config.getDouble("pvp_mode.cooldown.toggle_off");
|
||||
pvpModeCombatCooldown = config.getDouble("pvp_mode.cooldown.combat");
|
||||
pvpModeRegionEnterCooldown = config.getDouble("pvp_mode.cooldown.region_enter");
|
||||
pvpModeRegionLeaveCooldown = config.getDouble("pvp_mode.cooldown.region_leave");
|
||||
pvpModeCombatTimeout = config.getDouble("pvp_mode.combat_timeout");
|
||||
pvpModeInvulnerability = config.getDouble("pvp_mode.invulnerability");
|
||||
pvpModeInvulnerabilityTimeCommand = config.getDouble("pvp_mode.invulnerability.time.command");
|
||||
pvpModeInvulnerabilityTimeRegionChange = config.getDouble("pvp_mode.invulnerability.time.region_change");
|
||||
pvpModeInvulnerabilityCanDamage = config.getBoolean("pvp_mode.invulnerability.can_damage");
|
||||
|
||||
// Resources
|
||||
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
|
||||
|
@ -24,6 +24,10 @@ public enum PartyModuleType {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return Bukkit.getPluginManager().getPlugin(pluginName) != null;
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ public class CombatHandler implements Closable {
|
||||
private final PlayerData player;
|
||||
private final long firstHit = System.currentTimeMillis();
|
||||
|
||||
private long lastHit = System.currentTimeMillis();
|
||||
private long lastInvulnerabilityApplication;
|
||||
private long lastHit = System.currentTimeMillis(), invulnerableTill;
|
||||
|
||||
private boolean pvpMode;
|
||||
|
||||
@ -28,6 +27,7 @@ public class CombatHandler implements Closable {
|
||||
|
||||
public void update() {
|
||||
lastHit = System.currentTimeMillis();
|
||||
invulnerableTill = 0;
|
||||
player.getMMOPlayerData().getCooldownMap().applyCooldown(PvpModeCommand.COOLDOWN_KEY, MMOCore.plugin.configManager.pvpModeCombatCooldown);
|
||||
|
||||
// Simply refreshing
|
||||
@ -58,6 +58,10 @@ public class CombatHandler implements Closable {
|
||||
return firstHit;
|
||||
}
|
||||
|
||||
public long getInvulnerableTill() {
|
||||
return invulnerableTill;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply checks if there is a scheduled task.
|
||||
*
|
||||
@ -68,17 +72,18 @@ public class CombatHandler implements Closable {
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used for PvP mode invulnerability when a player
|
||||
* joins a region while he still has PvP mode toggled on.
|
||||
* This is used for PvP mode inactivity when a player
|
||||
* joins a region with PvP mode toggled on, OR toggles on
|
||||
* PvP mode using the command when standing in a PvP region.
|
||||
*
|
||||
* @return If the player is invulnerable
|
||||
* @return If the player is inert i.e if he CAN hit/take damage
|
||||
*/
|
||||
public boolean isInvulnerable() {
|
||||
return System.currentTimeMillis() < lastInvulnerabilityApplication + MMOCore.plugin.configManager.pvpModeInvulnerability * 1000;
|
||||
return System.currentTimeMillis() < invulnerableTill;
|
||||
}
|
||||
|
||||
public void applyInvulnerability() {
|
||||
lastInvulnerabilityApplication = System.currentTimeMillis();
|
||||
public void setInvulnerable(double time) {
|
||||
invulnerableTill = System.currentTimeMillis() + (long) (time * 1000);
|
||||
}
|
||||
|
||||
public boolean canQuitPvpMode() {
|
||||
@ -107,5 +112,10 @@ public class CombatHandler implements Closable {
|
||||
public void close() {
|
||||
if (isInCombat())
|
||||
quit(true);
|
||||
|
||||
// Necessary steps when entering a town.
|
||||
lastHit = 0;
|
||||
invulnerableTill = 0;
|
||||
player.getMMOPlayerData().getCooldownMap().resetCooldown(PvpModeCommand.COOLDOWN_KEY);
|
||||
}
|
||||
}
|
||||
|
@ -293,19 +293,45 @@ command-verbose:
|
||||
pvp_mode:
|
||||
|
||||
# Requires /reload when changed
|
||||
enabled: true
|
||||
enabled: false
|
||||
|
||||
# Delay after any attack during which the player will stay in PvP Mode (seconds)
|
||||
# Has to be lower than 'cooldown.combat'
|
||||
combat_timeout: 30
|
||||
|
||||
# Invulnerability when entering a pvp-mode region when your PvP mode is toggled on.
|
||||
invulnerability: 60
|
||||
# Invulnerability triggered when:
|
||||
# - entering a PvP region with PvP mode turned on.
|
||||
# - using the /pvpmode command inside of a PvP region.
|
||||
invulnerability:
|
||||
time:
|
||||
region_change: 60
|
||||
command: 30
|
||||
|
||||
# When enabled, players can damage other players
|
||||
# to end this invulnerable time period.
|
||||
can_damage: false
|
||||
|
||||
# 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
|
||||
|
||||
cooldown:
|
||||
# Delay before being able to use /pvpmode after being in combat (seconds)
|
||||
# Has to be greater than the combat timeout for it to make sense
|
||||
|
||||
# Cooldown before being able to use the /pvpmode
|
||||
# command when entering a PvP mode region.
|
||||
region_enter: 20
|
||||
|
||||
# Cooldown before being able to use the /pvpmode
|
||||
# command when entering a PvP mode region.
|
||||
region_leave: 20
|
||||
|
||||
# Delay before being able to use /pvpmode after being in combat (seconds).
|
||||
# Has to be greater than the 'combat_timeout'
|
||||
combat: 45
|
||||
|
||||
# Cooldown when toggling on PvP mode, before being able to toggle it off (seconds)
|
||||
toggle_on: 5
|
||||
|
||||
# Cooldown when toggling off PvP mode (seconds)
|
||||
toggle_off: 3
|
@ -32,8 +32,21 @@ 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 you cannot hit another player
|
||||
cannot-hit:
|
||||
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.'
|
||||
invulnerable-target: '&cThis player is out of combat for {left} seconds.'
|
||||
|
||||
# When using /pvpmode
|
||||
toggle:
|
||||
on-safe: '&aYou will now be able to fight other players in dedicated areas.'
|
||||
on-invulnerable: '&aYou will be able to fight other players in {time} seconds.'
|
||||
off-safe: '&cYou can no longer fight other players.'
|
||||
|
||||
# Entering/leaving regions
|
||||
leave:
|
||||
pvp-allowed: '&cYou left a PVP zone but are still vulnerable for {remaining} seconds!'
|
||||
pvp-denied: '&cYou left the PVP zone.'
|
||||
|
Loading…
Reference in New Issue
Block a user