Moved soft dependencies to own classes and fixed AsyncWorldEdit incompatibility

This commit is contained in:
isokissa3 2018-04-14 00:30:58 +03:00
parent f2e1dc8f61
commit 5903d2769b
9 changed files with 117 additions and 45 deletions

View file

@ -5,21 +5,20 @@ import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.earth2me.essentials.Essentials;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import lombok.Getter;
import net.elseland.xikage.MythicMobs.MythicMobs;
import net.goldtreeservers.worldguardextraflags.essentials.EssentialsUtils;
import net.goldtreeservers.worldguardextraflags.fawe.FAWEUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.listeners.BlockListener;
import net.goldtreeservers.worldguardextraflags.listeners.EntityListener;
import net.goldtreeservers.worldguardextraflags.listeners.EntityListenerOnePointNine;
import net.goldtreeservers.worldguardextraflags.listeners.EssentialsListener;
import net.goldtreeservers.worldguardextraflags.listeners.PlayerListener;
import net.goldtreeservers.worldguardextraflags.listeners.WorldEditListener;
import net.goldtreeservers.worldguardextraflags.listeners.WorldListener;
import net.goldtreeservers.worldguardextraflags.mb.MythicMobsUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldUtils;
import net.goldtreeservers.worldguardextraflags.wg.handlers.BlockedEffectsFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.CommandOnEntryFlagHandler;
@ -41,9 +40,9 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
@Getter private static WorldGuardPlugin worldGuardPlugin;
@Getter private static WorldEditPlugin worldEditPlugin;
@Getter private static Essentials essentialsPlugin;
@Getter private static MythicMobs mythicMobsPlugin;
@Getter private static boolean essentialsPluginEnabled;
@Getter private static boolean mythicMobsPluginEnabled;
@Getter private static boolean fastAsyncWorldEditPluginEnabled;
public WorldGuardExtraFlagsPlugin()
@ -88,19 +87,50 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.JOIN_LOCATION);
//Soft dependencies, due to some compatibility issues or add flags related to a plugin
Plugin essentialsPlugin = this.getServer().getPluginManager().getPlugin("Essentials");
if (essentialsPlugin != null)
try
{
WorldGuardExtraFlagsPlugin.essentialsPlugin = (Essentials)essentialsPlugin;
Plugin essentialsPlugin = WorldGuardExtraFlagsPlugin.getPlugin().getServer().getPluginManager().getPlugin("Essentials");
if (essentialsPlugin != null)
{
EssentialsUtils.onLoad(essentialsPlugin);
WorldGuardExtraFlagsPlugin.essentialsPluginEnabled = true;
}
}
catch(Throwable ex)
{
}
Plugin mythicMobsPlugin = this.getServer().getPluginManager().getPlugin("MythicMobs");
if (mythicMobsPlugin != null)
try
{
WorldGuardExtraFlagsPlugin.mythicMobsPlugin = (MythicMobs)mythicMobsPlugin;
Plugin mythicMobsPlugin = this.getServer().getPluginManager().getPlugin("MythicMobs");
if (mythicMobsPlugin != null)
{
MythicMobsUtils.onLoad(mythicMobsPlugin);
WorldGuardExtraFlagsPlugin.mythicMobsPluginEnabled = true;
}
}
catch(Throwable ex)
{
}
try
{
Plugin fastAsyncWorldEditPlugin = this.getServer().getPluginManager().getPlugin("FastAsyncWorldEdit");
if (fastAsyncWorldEditPlugin != null)
{
FAWEUtils.onLoad(fastAsyncWorldEditPlugin);
WorldGuardExtraFlagsPlugin.fastAsyncWorldEditPluginEnabled = true;
}
}
catch(Throwable ex)
{
}
WorldGuardExtraFlagsPlugin.fastAsyncWorldEditPluginEnabled = this.getServer().getPluginManager().isPluginEnabled("FastAsyncWorldEdit");
}
@Override
@ -137,18 +167,18 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
}
if (WorldGuardExtraFlagsPlugin.fastAsyncWorldEditPluginEnabled)
if (WorldGuardExtraFlagsPlugin.isFastAsyncWorldEditPluginEnabled())
{
FAWEUtils.registerFAWE();
FAWEUtils.onEnable();
}
else
{
WorldGuardExtraFlagsPlugin.worldEditPlugin.getWorldEdit().getEventBus().register(new WorldEditListener());
WorldGuardExtraFlagsPlugin.getWorldEditPlugin().getWorldEdit().getEventBus().register(new WorldEditListener());
}
if (WorldGuardExtraFlagsPlugin.isEssentialsEnable())
if (WorldGuardExtraFlagsPlugin.isEssentialsPluginEnabled())
{
this.getServer().getPluginManager().registerEvents(new EssentialsListener(), this);
EssentialsUtils.onEnable();
}
for(World world : this.getServer().getWorlds())
@ -156,14 +186,4 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
WorldUtils.doUnloadChunkFlagCheck(world);
}
}
public static boolean isEssentialsEnable()
{
return WorldGuardExtraFlagsPlugin.essentialsPlugin != null;
}
public static boolean isMythicMobsPluginEnabled()
{
return WorldGuardExtraFlagsPlugin.essentialsPlugin != null;
}
}

View file

@ -0,0 +1,24 @@
package net.goldtreeservers.worldguardextraflags.essentials;
import org.bukkit.plugin.Plugin;
import com.earth2me.essentials.Essentials;
import lombok.Getter;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.listeners.EssentialsListener;
public class EssentialsUtils
{
@Getter private static Essentials plugin;
public static void onLoad(Plugin essentialsPlugin)
{
EssentialsUtils.plugin = (Essentials)essentialsPlugin;
}
public static void onEnable()
{
WorldGuardExtraFlagsPlugin.getPlugin().getServer().getPluginManager().registerEvents(new EssentialsListener(), WorldGuardExtraFlagsPlugin.getPlugin());
}
}

View file

@ -1,10 +1,21 @@
package net.goldtreeservers.worldguardextraflags.fawe;
import org.bukkit.plugin.Plugin;
import com.boydti.fawe.FaweAPI;
import lombok.Getter;
public class FAWEUtils
{
public static void registerFAWE()
@Getter private static Plugin plugin;
public static void onLoad(Plugin plugin)
{
FAWEUtils.plugin = plugin;
}
public static void onEnable()
{
FaweAPI.addMaskManager(new FaweWorldEditFlagMaskManager());
}

View file

@ -26,6 +26,7 @@ import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.essentials.EssentialsUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.wg.handlers.FlyFlagHandler;
@ -188,9 +189,9 @@ public class PlayerListener implements Listener
{
Player player = event.getPlayer();
if (WorldGuardExtraFlagsPlugin.isEssentialsEnable()) //Essentials how dare u do this to me!?!
if (WorldGuardExtraFlagsPlugin.isEssentialsPluginEnabled()) //Essentials how dare u do this to me!?!
{
if (player.getGameMode() != GameMode.CREATIVE && !WorldGuardExtraFlagsPlugin.getEssentialsPlugin().getUser(player).isAuthorized("essentials.fly"))
if (player.getGameMode() != GameMode.CREATIVE && !EssentialsUtils.getPlugin().getUser(player).isAuthorized("essentials.fly"))
{
//Essentials now turns off flight, fuck him
Boolean value = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlagHandler.class).getCurrentValue();

View file

@ -1,6 +1,5 @@
package net.goldtreeservers.worldguardextraflags.listeners;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Actor;
@ -17,7 +16,7 @@ public class WorldEditListener
Actor actor = event.getActor();
if (actor != null && actor.isPlayer())
{
event.setExtent(new WorldEditFlagHandler((BukkitWorld)event.getWorld(), event.getExtent(), (Player)actor));
event.setExtent(new WorldEditFlagHandler(event.getWorld(), event.getExtent(), (Player)actor));
}
}
}

View file

@ -0,0 +1,16 @@
package net.goldtreeservers.worldguardextraflags.mb;
import org.bukkit.plugin.Plugin;
import lombok.Getter;
import net.elseland.xikage.MythicMobs.MythicMobs;
public class MythicMobsUtils
{
@Getter private static MythicMobs mythicMobsPlugin;
public static void onLoad(Plugin mythicMobsPlugin)
{
MythicMobsUtils.mythicMobsPlugin = (MythicMobs)mythicMobsPlugin;
}
}

View file

@ -4,10 +4,10 @@ import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
@ -17,24 +17,24 @@ import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class WorldEditFlagHandler extends AbstractDelegateExtent
{
private final BukkitWorld world;
private final Player player;
private final org.bukkit.World world;
private final org.bukkit.entity.Player player;
public WorldEditFlagHandler(BukkitWorld world, Extent extent, Player player)
public WorldEditFlagHandler(World world, Extent extent, Player player)
{
super(extent);
this.world = world;
this.player = player;
this.world = WorldGuardExtraFlagsPlugin.getPlugin().getServer().getWorld(world.getName());
this.player = WorldGuardExtraFlagsPlugin.getPlugin().getServer().getPlayer(player.getUniqueId());
}
//TODO: Prebuild list
@Override
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException
{
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(BukkitUtil.toLocation(this.world.getWorld(), location));
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(BukkitUtil.toLocation(this.world, location));
State state = WorldGuardUtils.queryState(WorldGuardExtraFlagsPlugin.getPlugin().getServer().getPlayer(this.player.getUniqueId()), this.world.getWorld(), regions.getRegions(), Flags.WORLDEDIT);
State state = WorldGuardUtils.queryState(this.player, this.world, regions.getRegions(), Flags.WORLDEDIT);
if (state != State.DENY)
{
return super.setBlock(location, block);

View file

@ -17,6 +17,7 @@ import com.sk89q.worldguard.session.handler.Handler;
import lombok.Getter;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.essentials.EssentialsUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
@ -67,9 +68,9 @@ public class GodmodeFlagHandler extends Handler
this.isGodmodeEnabled = null;
}
if (WorldGuardExtraFlagsPlugin.isEssentialsEnable())
if (WorldGuardExtraFlagsPlugin.isEssentialsPluginEnabled())
{
User user = WorldGuardExtraFlagsPlugin.getEssentialsPlugin().getUser(player);
User user = EssentialsUtils.getPlugin().getUser(player);
if (this.isGodmodeEnabled != null)
{

View file

@ -1,5 +1,5 @@
name: WorldGuardExtraFlags
version: 3.0.0
version: 3.0.1
description: Adds more flags to WorldGuard to help manage your server easily!
author: isokissa3
website: https://goldtreevers.net