Remove Static Abuse - WorldGuardUtils

This commit is contained in:
nossr50 2019-09-20 15:07:37 -07:00
parent 3aa896cfc9
commit 7c0d1f4e0a
9 changed files with 55 additions and 48 deletions

View File

@ -7,7 +7,6 @@ import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.worldguard.WorldGuardUtils;
import com.google.common.collect.ImmutableList;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -44,7 +43,7 @@ public class PtpCommand implements TabExecutor {
Player player = (Player) sender;
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return true;
}

View File

@ -15,7 +15,6 @@ import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType;
import com.gmail.nossr50.worldguard.WorldGuardUtils;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
@ -249,7 +248,7 @@ public class BlockListener implements Listener {
return;
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(event.getPlayer()))
return;
}
@ -343,7 +342,7 @@ public class BlockListener implements Listener {
return;
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(event.getPlayer()))
return;
}
@ -412,7 +411,7 @@ public class BlockListener implements Listener {
return;
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(event.getPlayer()))
return;
}
@ -482,7 +481,7 @@ public class BlockListener implements Listener {
return;
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(event.getPlayer()))
return;
}

View File

@ -14,7 +14,6 @@ import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.SkillActivationType;
import com.gmail.nossr50.worldguard.WorldGuardUtils;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
@ -78,7 +77,7 @@ public class EntityListener implements Listener {
Player player = (Player) event.getEntity();
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -115,7 +114,7 @@ public class EntityListener implements Listener {
Player player = (Player) event.getEntity().getShooter();
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -276,7 +275,7 @@ public class EntityListener implements Listener {
Entity defender = event.getEntity();
Entity attacker = event.getDamager();
if(WorldGuardUtils.isWorldGuardLoaded())
if(pluginRef.getWorldGuardUtils().isWorldGuardLoaded())
{
if(attacker instanceof Player) {
@ -450,7 +449,7 @@ public class EntityListener implements Listener {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -528,7 +527,7 @@ public class EntityListener implements Listener {
if (owner instanceof Player) {
Player player = (Player) owner;
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -745,7 +744,7 @@ public class EntityListener implements Listener {
}
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -783,7 +782,7 @@ public class EntityListener implements Listener {
}
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -846,7 +845,7 @@ public class EntityListener implements Listener {
}
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -947,7 +946,7 @@ public class EntityListener implements Listener {
Player player = (Player) event.getOwner();
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -993,7 +992,7 @@ public class EntityListener implements Listener {
Player player = (Player) target;
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}

View File

@ -5,7 +5,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.player.PlayerUpdateInventoryTask;
import com.gmail.nossr50.worldguard.WorldGuardUtils;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.BrewingStand;
@ -93,7 +92,7 @@ public class InventoryListener implements Listener {
Player player = getPlayerFromFurnace(furnaceBlock);
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -126,7 +125,7 @@ public class InventoryListener implements Listener {
Player player = getPlayerFromFurnace(furnaceBlock);
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -158,7 +157,7 @@ public class InventoryListener implements Listener {
Player player = getPlayerFromFurnace(furnaceBlock);
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -225,7 +224,7 @@ public class InventoryListener implements Listener {
Player player = (Player) whoClicked;
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -343,7 +342,7 @@ public class InventoryListener implements Listener {
// Player player = (Player) whoClicked;
//
// /* WORLD GUARD MAIN FLAG CHECK */
// if (WorldGuardUtils.isWorldGuardLoaded()) {
// if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
// if (!plugin.getWorldGuardManager().hasMainFlag(player))
// return;
// }
@ -466,7 +465,7 @@ public class InventoryListener implements Listener {
Player player = (Player) whoClicked;
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}

View File

@ -7,7 +7,6 @@ import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
@ -23,7 +22,6 @@ import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Motd;
import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType;
import com.gmail.nossr50.worldguard.WorldGuardUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@ -67,7 +65,7 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer();
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -106,7 +104,7 @@ public class PlayerListener implements Listener {
String deathMessage = event.getDeathMessage();
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(event.getEntity()))
return;
}
@ -151,7 +149,7 @@ public class PlayerListener implements Listener {
Player killer = killedPlayer.getKiller();
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(killedPlayer))
return;
}
@ -215,7 +213,7 @@ public class PlayerListener implements Listener {
return;
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(event.getPlayer()))
return;
}
@ -247,7 +245,7 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer();
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -322,7 +320,7 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer();
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -415,7 +413,7 @@ public class PlayerListener implements Listener {
Player player = (Player) event.getEntity();
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -567,7 +565,7 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer();
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}
@ -682,7 +680,7 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer();
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasMainFlag(player))
return;
}

View File

@ -7,7 +7,6 @@ import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.worldguard.WorldGuardUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -72,7 +71,7 @@ public class SelfListener implements Listener {
event.getXpGainReason() == XPGainReason.PVP ||
event.getXpGainReason() == XPGainReason.SHARED_PVE ||
event.getXpGainReason() == XPGainReason.SHARED_PVP) {
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if (!pluginRef.getWorldGuardManager().hasXPFlag(player)) {
event.setRawXpGained(0);
event.setCancelled(true);

View File

@ -44,6 +44,7 @@ import com.gmail.nossr50.util.skills.CombatTools;
import com.gmail.nossr50.util.skills.RankTools;
import com.gmail.nossr50.util.skills.SkillTools;
import com.gmail.nossr50.worldguard.WorldGuardManager;
import com.gmail.nossr50.worldguard.WorldGuardUtils;
import net.shatteredlands.shatt.backup.ZipLibrary;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
@ -97,6 +98,7 @@ public class mcMMO extends JavaPlugin {
private RankTools rankTools;
private ItemTools itemTools;
private PermissionTools permissionTools;
private WorldGuardUtils worldGuardUtils;
/* Never-Ending tasks */
private BleedTimerTask bleedTimerTask;
@ -271,6 +273,9 @@ public class mcMMO extends JavaPlugin {
//Init Item Tools
itemTools = new ItemTools(this);
//Init World Guard Utils (Not sure about the order of this one, might need to be loaded earlier)
worldGuardUtils = new WorldGuardUtils(this);
}
@Override
@ -798,4 +803,8 @@ public class mcMMO extends JavaPlugin {
public PermissionTools getPermissionTools() {
return permissionTools;
}
public WorldGuardUtils getWorldGuardUtils() {
return worldGuardUtils;
}
}

View File

@ -4,7 +4,6 @@ import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.worldguard.WorldGuardManager;
import com.gmail.nossr50.worldguard.WorldGuardUtils;
import org.bukkit.entity.Player;
import java.util.HashMap;
@ -15,7 +14,7 @@ public final class HardcoreManager {
public static void invokeStatPenalty(Player player) {
if(WorldGuardUtils.isWorldGuardLoaded()) {
if(pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if(!WorldGuardManager.getInstance().hasHardcoreFlag(player)) {
return;
}
@ -67,7 +66,7 @@ public final class HardcoreManager {
public static void invokeVampirism(Player killer, Player victim) {
if(WorldGuardUtils.isWorldGuardLoaded()) {
if(pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if(!WorldGuardManager.getInstance().hasHardcoreFlag(killer) || !WorldGuardManager.getInstance().hasHardcoreFlag(victim)) {
return;
}

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.worldguard;
import com.gmail.nossr50.mcMMO;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.plugin.Plugin;
@ -8,10 +9,15 @@ import java.util.ArrayList;
import static org.bukkit.Bukkit.getServer;
public class WorldGuardUtils {
private static WorldGuardPlugin worldGuardPluginRef;
private static boolean isLoaded = false;
private static boolean detectedIncompatibleWG = false;
private WorldGuardPlugin worldGuardPluginRef;
private boolean isLoaded = false;
private boolean detectedIncompatibleWG = false;
private static final ArrayList<String> WGClassList;
private final mcMMO pluginRef;
public WorldGuardUtils(mcMMO pluginRef) {
this.pluginRef = pluginRef;
}
static {
/*
@ -37,7 +43,7 @@ public class WorldGuardUtils {
WGClassList.add("com.sk89q.worldguard.protection.regions.RegionQuery");
}
public static boolean isWorldGuardLoaded()
public boolean isWorldGuardLoaded()
{
if(detectedIncompatibleWG)
return false;
@ -52,7 +58,7 @@ public class WorldGuardUtils {
* Results are cached
* @return the instance of WG plugin, null if its not compatible or isn't present
*/
private static WorldGuardPlugin getWorldGuard()
private WorldGuardPlugin getWorldGuard()
{
//WG plugin reference is already cached so just return it
if(isLoaded)
@ -90,7 +96,7 @@ public class WorldGuardUtils {
* This does not guarantee compatibility, but it should help reduce the chance that mcMMO tries to hook into WG and its not compatible
* @return true if the version of WG appears to be compatible
*/
private static boolean isCompatibleVersion(Plugin plugin) {
private boolean isCompatibleVersion(Plugin plugin) {
//Check that the version of WG is at least version 7.xx
if(!plugin.getDescription().getVersion().startsWith("7")) {
markWGIncompatible();
@ -114,7 +120,7 @@ public class WorldGuardUtils {
/**
* Mark WG as being incompatible to avoid unnecessary operations
*/
private static void markWGIncompatible() {
private void markWGIncompatible() {
pluginRef.getLogger().severe("You are using a version of WG that is not compatible with mcMMO, " +
"WG features for mcMMO will be disabled. mcMMO requires you to be using a new version of WG7 " +
"in order for it to use WG features. Not all versions of WG7 are compatible.");