WG Hardcore penalty flag 'mcmmo-hardcore'

This commit is contained in:
nossr50 2019-06-17 08:25:37 -07:00
parent 38bc60ba86
commit 2cecc91026
4 changed files with 34 additions and 0 deletions

View File

@ -1,4 +1,5 @@
Version 2.1.82
Added new WG flag 'mcmmo-hardcore' if set to negative players will not be penalized by hardcore mode (if hardcore mode is enabled) it defaults to true
Added proper error handling when loading parties file
Fixed an error that could occur when using mcrank on an offline player
You can now use mcrank on offline players by default

View File

@ -6,6 +6,8 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.worldguard.WorldGuardManager;
import com.gmail.nossr50.worldguard.WorldGuardUtils;
import org.bukkit.entity.Player;
import java.util.HashMap;
@ -14,6 +16,12 @@ public final class HardcoreManager {
private HardcoreManager() {}
public static void invokeStatPenalty(Player player) {
if(WorldGuardUtils.isWorldGuardLoaded()) {
if(!WorldGuardManager.getInstance().hasHardcoreFlag(player))
return;
}
double statLossPercentage = Config.getInstance().getHardcoreDeathStatPenaltyPercentage();
int levelThreshold = Config.getInstance().getHardcoreDeathStatPenaltyLevelThreshold();
@ -59,6 +67,12 @@ public final class HardcoreManager {
}
public static void invokeVampirism(Player killer, Player victim) {
if(WorldGuardUtils.isWorldGuardLoaded()) {
if(!WorldGuardManager.getInstance().hasHardcoreFlag(killer) || !WorldGuardManager.getInstance().hasHardcoreFlag(victim))
return;
}
double vampirismStatLeechPercentage = Config.getInstance().getHardcoreVampirismStatLeechPercentage();
int levelThreshold = Config.getInstance().getHardcoreVampirismLevelThreshold();

View File

@ -6,4 +6,5 @@ public class WorldGuardFlags {
// StateFlag with the name "my-custom-flag", which defaults to "allow"
public static final StateFlag MCMMO_ENABLE_WG_FLAG = new StateFlag("mcmmo", true);
public static final StateFlag MCMMO_XP_WG_FLAG = new StateFlag("mcmmo-xp", true);
public static final StateFlag MCMMO_HARDCORE_WG_FLAG = new StateFlag("mcmmo-hardcore", true);
}

View File

@ -64,6 +64,23 @@ public class WorldGuardManager {
return query.testState(loc, WorldGuardPlugin.inst().wrapPlayer(player), WorldGuardFlags.MCMMO_XP_WG_FLAG);
}
public boolean hasHardcoreFlag(Player player)
{
if(player == null)
return false;
BukkitPlayer localPlayer = BukkitAdapter.adapt(player);
com.sk89q.worldedit.util.Location loc = localPlayer.getLocation();
//WorldGuardPlugin worldGuard = getWorldGuard();
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
//ApplicableRegionSet set = query.getApplicableRegions(loc);
return query.testState(loc, WorldGuardPlugin.inst().wrapPlayer(player), WorldGuardFlags.MCMMO_HARDCORE_WG_FLAG);
}
private WorldGuardPlugin getWorldGuard() {
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
@ -88,6 +105,7 @@ public class WorldGuardManager {
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);*/
registry.register(WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);
registry.register(WorldGuardFlags.MCMMO_HARDCORE_WG_FLAG);
System.out.println("mcMMO has registered WG flags successfully!");
} catch (FlagConflictException e) {
e.printStackTrace();