mcMMO now supports WorldGuard, added "mcmmo" and "mcmmo-xp" flags!

This commit is contained in:
nossr50 2019-01-22 16:40:54 -08:00
parent c0dde01f3e
commit 0ad1530505
10 changed files with 377 additions and 24 deletions

View File

@ -18,6 +18,7 @@ Version 2.1.0
+ Certain elements of mcMMO's UI have been restyled + Certain elements of mcMMO's UI have been restyled
+ Added the tagline "Overhaul Era" to various locations until 3.0.0 comes out + Added the tagline "Overhaul Era" to various locations until 3.0.0 comes out
+ You can now disable mcMMO completely for specific worlds via world_blacklist.txt in /plugins/mcMMO/ + You can now disable mcMMO completely for specific worlds via world_blacklist.txt in /plugins/mcMMO/
+ (WorldGuard) mcMMO now supports worldguard, you can use the flags "mcmmo" and "mcmmo-xp" on regions (they default to on unless otherwise specified)
! (Scoreboards) Scoreboards are now disabled by default, I don't like them. You can turn them back on in config.yml ! (Scoreboards) Scoreboards are now disabled by default, I don't like them. You can turn them back on in config.yml
+ (Sounds) Rolling now plays a sound (Graceful Roll has a different sound :) ) + (Sounds) Rolling now plays a sound (Graceful Roll has a different sound :) )
+ (Sounds) Activating Super abilities plays a sound (other plays can hear this) + (Sounds) Activating Super abilities plays a sound (other plays can hear this)

View File

@ -0,0 +1,9 @@
package com.gmail.nossr50;
import com.sk89q.worldguard.protection.flags.StateFlag;
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);
}

View File

@ -1,39 +1,87 @@
package com.gmail.nossr50; package com.gmail.nossr50;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import static org.bukkit.Bukkit.getServer;
public class WorldGuardManager { public class WorldGuardManager {
// StateFlag with the name "my-custom-flag", which defaults to "allow"
public static final Flag MCMMO_DISABLE_WG_FLAG = new StateFlag("mcmmo-off", false);
public static final Flag MCMMO_XPOFF_WG_FLAG = new StateFlag("mcmmo-noxp", false);
private static WorldGuardPlugin worldGuardPlugin; private static WorldGuardManager instance;
private Plugin worldGuardPluginRef;
private boolean flagsRegistered = false;
/*public static boolean isWgFlagActive(Location location) public WorldGuardManager()
{ {
instance = this;
init();
}
public void init()
{
if(getWorldGuard() != null)
{
worldGuardPluginRef = getWorldGuard();
registerFlags();
}
}
public boolean hasMainFlag(Player player)
{
BukkitPlayer localPlayer = BukkitAdapter.adapt(player);
com.sk89q.worldedit.util.Location loc = localPlayer.getLocation();
if(flagsRegistered) if(flagsRegistered)
{ {
if(getWorldGuard() != null) if(getWorldGuard() != null)
{ {
WorldGuardPlugin worldGuard = getWorldGuard(); //WorldGuardPlugin worldGuard = getWorldGuard();
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery(); RegionQuery query = container.createQuery();
ApplicableRegionSet set = query.getApplicableRegions(); //ApplicableRegionSet set = query.getApplicableRegions(loc);
*//* if (!query.testState(location, (LocalPlayer)null, MCMMO_DISABLE_WG_FLAG)) { return query.testState(loc, WorldGuardPlugin.inst().wrapPlayer(player), WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
// Can't build
}*//*
} }
} }
//Return False if these fail
mcMMO.p.getLogger().severe("Failed to detect WG flags, is WG running properly?");
return false;
} }
private static WorldGuardPlugin getWorldGuard() { public boolean hasXPFlag(Player player)
if(worldGuardPlugin != null) {
return worldGuardPlugin; BukkitPlayer localPlayer = BukkitAdapter.adapt(player);
com.sk89q.worldedit.util.Location loc = localPlayer.getLocation();
if(flagsRegistered)
{
if(getWorldGuard() != null)
{
//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_XP_WG_FLAG);
}
}
//Return False if these fail
mcMMO.p.getLogger().severe("Failed to detect WG flags, is WG running properly?");
return false;
}
private WorldGuardPlugin getWorldGuard() {
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard"); Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
// WorldGuard may not be loaded // WorldGuard may not be loaded
@ -41,11 +89,10 @@ public class WorldGuardManager {
return null; // Maybe you want throw an exception instead return null; // Maybe you want throw an exception instead
} }
worldGuardPlugin = (WorldGuardPlugin) plugin; return (WorldGuardPlugin) plugin;
return worldGuardPlugin;
} }
private static void registerFlags() private void registerFlags()
{ {
if(getWorldGuard() == null) if(getWorldGuard() == null)
return; return;
@ -53,7 +100,8 @@ public class WorldGuardManager {
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
try { try {
// register our flag with the registry // register our flag with the registry
registry.register(MCMMO_DISABLE_WG_FLAG); registry.register(WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);
flagsRegistered = true; flagsRegistered = true;
} catch (FlagConflictException e) { } catch (FlagConflictException e) {
e.printStackTrace(); e.printStackTrace();
@ -62,5 +110,9 @@ public class WorldGuardManager {
// could cause issues with saved flags in region files. it's better // could cause issues with saved flags in region files. it's better
// to print a message to let the server admin know of the conflict // to print a message to let the server admin know of the conflict
} }
}*/ }
public static WorldGuardManager getInstance() {
return instance;
}
} }

View File

@ -0,0 +1,25 @@
package com.gmail.nossr50;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.plugin.Plugin;
import static org.bukkit.Bukkit.getServer;
public class WorldGuardUtils {
public static boolean isWorldGuardLoaded()
{
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
try {
// WorldGuard may not be loaded
if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
return false; // Maybe you want throw an exception instead
}
} catch (Exception e) {
//Silently Fail
mcMMO.p.getLogger().severe("Failed to detect worldguard.");
}
return true;
}
}

View File

@ -1,6 +1,9 @@
package com.gmail.nossr50.commands.party.teleport; package com.gmail.nossr50.commands.party.teleport;
import com.gmail.nossr50.WorldGuardManager;
import com.gmail.nossr50.WorldGuardUtils;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.WorldBlacklist;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.party.PartyFeature; import com.gmail.nossr50.datatypes.party.PartyFeature;
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord; import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
@ -41,6 +44,17 @@ public class PtpCommand implements TabExecutor {
Player player = (Player) sender; Player player = (Player) sender;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return true;
}
/* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(player.getWorld()))
return true;
if (!UserManager.hasPlayerDataKey(player)) { if (!UserManager.hasPlayerDataKey(player)) {
return true; return true;
} }

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import com.gmail.nossr50.WorldGuardManager;
import com.gmail.nossr50.WorldGuardUtils;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig; import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.config.WorldBlacklist; import com.gmail.nossr50.config.WorldBlacklist;
@ -241,6 +243,13 @@ public class BlockListener implements Listener {
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld()))
return; return;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(event.getPlayer()))
return;
}
if (event instanceof FakeBlockBreakEvent) { if (event instanceof FakeBlockBreakEvent) {
return; return;
} }
@ -326,6 +335,13 @@ public class BlockListener implements Listener {
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld()))
return; return;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(event.getPlayer()))
return;
}
if (event instanceof FakeBlockBreakEvent) { if (event instanceof FakeBlockBreakEvent) {
return; return;
} }
@ -382,6 +398,13 @@ public class BlockListener implements Listener {
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld()))
return; return;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(event.getPlayer()))
return;
}
if (event instanceof FakeBlockDamageEvent) { if (event instanceof FakeBlockDamageEvent) {
return; return;
} }
@ -452,6 +475,13 @@ public class BlockListener implements Listener {
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld()))
return; return;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(event.getPlayer()))
return;
}
if (event instanceof FakeBlockDamageEvent) { if (event instanceof FakeBlockDamageEvent) {
return; return;
} }

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import com.gmail.nossr50.WorldGuardManager;
import com.gmail.nossr50.WorldGuardUtils;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.WorldBlacklist; import com.gmail.nossr50.config.WorldBlacklist;
@ -58,6 +60,18 @@ public class EntityListener implements Listener {
if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld()))
return; return;
if(event.getEntity() instanceof Player)
{
Player player = (Player) event.getEntity();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
}
Entity projectile = event.getProjectile(); Entity projectile = event.getProjectile();
if (!(projectile instanceof Arrow)) { if (!(projectile instanceof Arrow)) {
@ -80,6 +94,18 @@ public class EntityListener implements Listener {
if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld()))
return; return;
if(event.getEntity() instanceof Player)
{
Player player = (Player) event.getEntity();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
}
Projectile projectile = event.getEntity(); Projectile projectile = event.getEntity();
if (!(projectile instanceof Arrow) || projectile.hasMetadata(mcMMO.bowForceKey)) { if (!(projectile instanceof Arrow) || projectile.hasMetadata(mcMMO.bowForceKey)) {
@ -163,6 +189,18 @@ public class EntityListener implements Listener {
Entity defender = event.getEntity(); Entity defender = event.getEntity();
Entity attacker = event.getDamager(); Entity attacker = event.getDamager();
if(attacker instanceof Player)
{
Player player = (Player) attacker;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
}
if (damage <= 0) { if (damage <= 0) {
if (defender instanceof Player && attacker instanceof Player) { if (defender instanceof Player && attacker instanceof Player) {
Player defendingPlayer = (Player) defender; Player defendingPlayer = (Player) defender;
@ -284,6 +322,17 @@ public class EntityListener implements Listener {
if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld()))
return; return;
if(event.getEntity() instanceof Player)
{
Player player = (Player) event.getEntity();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
}
/* /*
* Process Registered Interactions * Process Registered Interactions
*/ */
@ -351,6 +400,17 @@ public class EntityListener implements Listener {
Tameable pet = (Tameable) livingEntity; Tameable pet = (Tameable) livingEntity;
AnimalTamer owner = pet.getOwner(); AnimalTamer owner = pet.getOwner();
if(owner instanceof Player)
{
Player player = (Player) owner;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
}
if (Taming.canPreventDamage(pet, owner)) { if (Taming.canPreventDamage(pet, owner)) {
Player player = (Player) owner; Player player = (Player) owner;
Wolf wolf = (Wolf) pet; Wolf wolf = (Wolf) pet;
@ -533,6 +593,13 @@ public class EntityListener implements Listener {
return; return;
} }
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager(); MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
if (miningManager.canUseBiggerBombs()) { if (miningManager.canUseBiggerBombs()) {
@ -566,6 +633,13 @@ public class EntityListener implements Listener {
return; return;
} }
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager(); MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
if (miningManager.canUseBlastMining()) { if (miningManager.canUseBlastMining()) {
@ -615,6 +689,13 @@ public class EntityListener implements Listener {
Player player = (Player) entity; Player player = (Player) entity;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
if (!UserManager.hasPlayerDataKey(player)) { if (!UserManager.hasPlayerDataKey(player)) {
return; return;
} }
@ -709,6 +790,14 @@ public class EntityListener implements Listener {
} }
Player player = (Player) event.getOwner(); Player player = (Player) event.getOwner();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
LivingEntity entity = event.getEntity(); LivingEntity entity = event.getEntity();
if (!UserManager.hasPlayerDataKey(player) || Misc.isNPCEntity(entity) || entity.hasMetadata(mcMMO.entityMetadataKey)) { if (!UserManager.hasPlayerDataKey(player) || Misc.isNPCEntity(entity) || entity.hasMetadata(mcMMO.entityMetadataKey)) {
@ -739,6 +828,14 @@ public class EntityListener implements Listener {
} }
Player player = (Player) target; Player player = (Player) target;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
Tameable tameable = (Tameable) entity; Tameable tameable = (Tameable) entity;
if (!UserManager.hasPlayerDataKey(player) || !CombatUtils.isFriendlyPet(player, tameable)) { if (!UserManager.hasPlayerDataKey(player) || !CombatUtils.isFriendlyPet(player, tameable)) {

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import com.gmail.nossr50.WorldGuardManager;
import com.gmail.nossr50.WorldGuardUtils;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.WorldBlacklist; import com.gmail.nossr50.config.WorldBlacklist;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
@ -95,6 +97,13 @@ public class InventoryListener implements Listener {
Player player = getPlayerFromFurnace(furnaceBlock); Player player = getPlayerFromFurnace(furnaceBlock);
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
if (!UserManager.hasPlayerDataKey(player) || !Permissions.isSubSkillEnabled(player, SubSkillType.SMELTING_FUEL_EFFICIENCY)) { if (!UserManager.hasPlayerDataKey(player) || !Permissions.isSubSkillEnabled(player, SubSkillType.SMELTING_FUEL_EFFICIENCY)) {
return; return;
} }
@ -117,6 +126,13 @@ public class InventoryListener implements Listener {
Player player = getPlayerFromFurnace(furnaceBlock); Player player = getPlayerFromFurnace(furnaceBlock);
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
if (!UserManager.hasPlayerDataKey(player) || !PrimarySkillType.SMELTING.getPermissions(player)) { if (!UserManager.hasPlayerDataKey(player) || !PrimarySkillType.SMELTING.getPermissions(player)) {
return; return;
} }
@ -138,6 +154,13 @@ public class InventoryListener implements Listener {
Player player = getPlayerFromFurnace(furnaceBlock); Player player = getPlayerFromFurnace(furnaceBlock);
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
if (!UserManager.hasPlayerDataKey(player) || !Permissions.vanillaXpBoost(player, PrimarySkillType.SMELTING)) { if (!UserManager.hasPlayerDataKey(player) || !Permissions.vanillaXpBoost(player, PrimarySkillType.SMELTING)) {
return; return;
} }
@ -171,6 +194,14 @@ public class InventoryListener implements Listener {
} }
Player player = (Player) whoClicked; Player player = (Player) whoClicked;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
BrewingStand stand = (BrewingStand) holder; BrewingStand stand = (BrewingStand) holder;
ItemStack clicked = event.getCurrentItem(); ItemStack clicked = event.getCurrentItem();
ItemStack cursor = event.getCursor(); ItemStack cursor = event.getCursor();
@ -283,6 +314,13 @@ public class InventoryListener implements Listener {
if (AlchemyPotionBrewer.isEmpty(ingredient) || ingredient.isSimilar(cursor)) { if (AlchemyPotionBrewer.isEmpty(ingredient) || ingredient.isSimilar(cursor)) {
Player player = (Player) whoClicked; Player player = (Player) whoClicked;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
if (AlchemyPotionBrewer.isValidIngredient(player, cursor)) { if (AlchemyPotionBrewer.isValidIngredient(player, cursor)) {
// Not handled: dragging custom ingredients over ingredient slot (does not trigger any event) // Not handled: dragging custom ingredients over ingredient slot (does not trigger any event)
AlchemyPotionBrewer.scheduleCheck(player, (BrewingStand) holder); AlchemyPotionBrewer.scheduleCheck(player, (BrewingStand) holder);
@ -377,6 +415,15 @@ public class InventoryListener implements Listener {
return; return;
} }
Player player = (Player) whoClicked;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
new PlayerUpdateInventoryTask((Player) whoClicked).runTaskLater(plugin, 0); new PlayerUpdateInventoryTask((Player) whoClicked).runTaskLater(plugin, 0);
} }

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import com.gmail.nossr50.WorldGuardManager;
import com.gmail.nossr50.WorldGuardUtils;
import com.gmail.nossr50.chat.ChatManager; import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.chat.ChatManagerFactory; import com.gmail.nossr50.chat.ChatManagerFactory;
import com.gmail.nossr50.chat.PartyChatManager; import com.gmail.nossr50.chat.PartyChatManager;
@ -66,6 +68,13 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
if (!UserManager.hasPlayerDataKey(player) || Config.getInstance().getXPAfterTeleportCooldown() <= 0 || event.getFrom().equals(event.getTo())) { if (!UserManager.hasPlayerDataKey(player) || Config.getInstance().getXPAfterTeleportCooldown() <= 0 || event.getFrom().equals(event.getTo())) {
return; return;
} }
@ -90,6 +99,13 @@ public class PlayerListener implements Listener {
String deathMessage = event.getDeathMessage(); String deathMessage = event.getDeathMessage();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(event.getEntity()))
return;
}
if (deathMessage == null) { if (deathMessage == null) {
return; return;
} }
@ -129,6 +145,13 @@ public class PlayerListener implements Listener {
Player killer = killedPlayer.getKiller(); Player killer = killedPlayer.getKiller();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(killedPlayer))
return;
}
if (statLossEnabled || (killer != null && vampirismEnabled)) { if (statLossEnabled || (killer != null && vampirismEnabled)) {
if (EventUtils.callPreDeathPenaltyEvent(killedPlayer).isCancelled()) { if (EventUtils.callPreDeathPenaltyEvent(killedPlayer).isCancelled()) {
return; return;
@ -182,6 +205,13 @@ public class PlayerListener implements Listener {
if(WorldBlacklist.isWorldBlacklisted(event.getPlayer().getWorld())) if(WorldBlacklist.isWorldBlacklisted(event.getPlayer().getWorld()))
return; return;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(event.getPlayer()))
return;
}
Item drop = event.getItemDrop(); Item drop = event.getItemDrop();
ItemStack dropStack = drop.getItemStack(); ItemStack dropStack = drop.getItemStack();
@ -208,6 +238,13 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
if (!UserManager.hasPlayerDataKey(player) || !PrimarySkillType.FISHING.getPermissions(player)) { if (!UserManager.hasPlayerDataKey(player) || !PrimarySkillType.FISHING.getPermissions(player)) {
return; return;
} }
@ -267,6 +304,13 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
if (!UserManager.hasPlayerDataKey(player) || !PrimarySkillType.FISHING.getPermissions(player)) { if (!UserManager.hasPlayerDataKey(player) || !PrimarySkillType.FISHING.getPermissions(player)) {
return; return;
} }
@ -312,6 +356,13 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
if (!UserManager.hasPlayerDataKey(player)) { if (!UserManager.hasPlayerDataKey(player)) {
return; return;
} }
@ -433,6 +484,13 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
if (event.getHand() != EquipmentSlot.HAND || !UserManager.hasPlayerDataKey(player) || player.getGameMode() == GameMode.CREATIVE) { if (event.getHand() != EquipmentSlot.HAND || !UserManager.hasPlayerDataKey(player) || player.getGameMode() == GameMode.CREATIVE) {
return; return;
} }
@ -529,6 +587,13 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
if (event.getHand() != EquipmentSlot.HAND || !UserManager.hasPlayerDataKey(player) || player.getGameMode() == GameMode.CREATIVE) { if (event.getHand() != EquipmentSlot.HAND || !UserManager.hasPlayerDataKey(player) || player.getGameMode() == GameMode.CREATIVE) {
return; return;
} }
@ -657,10 +722,6 @@ public class PlayerListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerChat(AsyncPlayerChatEvent event) { public void onPlayerChat(AsyncPlayerChatEvent event) {
/* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(event.getPlayer().getWorld()))
return;
Player player = event.getPlayer(); Player player = event.getPlayer();
if (Misc.isNPCEntity(player) || !UserManager.hasPlayerDataKey(player)) { if (Misc.isNPCEntity(player) || !UserManager.hasPlayerDataKey(player)) {

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import com.gmail.nossr50.WorldGuardManager;
import com.gmail.nossr50.WorldGuardUtils;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
@ -68,6 +70,21 @@ public class SelfListener implements Listener {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
PrimarySkillType primarySkillType = event.getSkill(); PrimarySkillType primarySkillType = event.getSkill();
//WorldGuard XP Check
if(event.getXpGainReason() == XPGainReason.PVE ||
event.getXpGainReason() == XPGainReason.PVP ||
event.getXpGainReason() == XPGainReason.SHARED_PVE ||
event.getXpGainReason() == XPGainReason.SHARED_PVP)
{
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasXPFlag(player))
event.setRawXpGained(0);
event.setCancelled(true);
}
}
if (event.getXpGainReason() == XPGainReason.COMMAND) if (event.getXpGainReason() == XPGainReason.COMMAND)
{ {
return; return;