mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-18 07:07:43 +01:00
Decrease call to PluginManager in WGBukkit
If WorldGuard is already found we bypass the call to the PluginManager and use a cached version.
This commit is contained in:
parent
d6939b7916
commit
c1b98b9e40
@ -27,6 +27,7 @@
|
||||
* Helper class to get a reference to WorldGuard and its components.
|
||||
*/
|
||||
public class WGBukkit {
|
||||
private static WorldGuardPlugin cachedPlugin = null;
|
||||
|
||||
private WGBukkit() {
|
||||
}
|
||||
@ -42,7 +43,17 @@ private WGBukkit() {
|
||||
* @return the WorldGuard plugin or null
|
||||
*/
|
||||
public static WorldGuardPlugin getPlugin() {
|
||||
return (WorldGuardPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if (cachedPlugin == null) {
|
||||
cachedPlugin = (WorldGuardPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
}
|
||||
return cachedPlugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cache to null for reload WorldGuardPlugin
|
||||
*/
|
||||
public static void cleanCache() {
|
||||
cachedPlugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,12 +64,10 @@ public static WorldGuardPlugin getPlugin() {
|
||||
* @return a region manager or null
|
||||
*/
|
||||
public static RegionManager getRegionManager(World world) {
|
||||
WorldGuardPlugin plugin = getPlugin();
|
||||
if (plugin == null) {
|
||||
if (getPlugin() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return plugin.getRegionManager(world);
|
||||
return cachedPlugin.getRegionManager(world);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,6 +34,7 @@
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldguard.bukkit.LoggerToChatHandler;
|
||||
import com.sk89q.worldguard.bukkit.ReportWriter;
|
||||
import com.sk89q.worldguard.bukkit.WGBukkit;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.util.PastebinPoster;
|
||||
import com.sk89q.worldguard.util.PastebinPoster.PasteCallback;
|
||||
@ -72,6 +73,7 @@ public void reload(CommandContext args, CommandSender sender) throws CommandExce
|
||||
plugin.getGlobalRegionManager().unload();
|
||||
plugin.getGlobalStateManager().load();
|
||||
plugin.getGlobalRegionManager().preload();
|
||||
WGBukkit.cleanCache();
|
||||
sender.sendMessage("WorldGuard configuration reloaded.");
|
||||
} catch (Throwable t) {
|
||||
sender.sendMessage("Error while reloading: "
|
||||
|
Loading…
Reference in New Issue
Block a user