use of com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry in project EverNifeCore by EverNife.
the class ProtectionWorldGuard method registerFlag.
public static void registerFlag(Flag<?> flag, JavaPlugin javaPlugin) {
if (!MCVersion.isLegacy()) {
try {
SimpleFlagRegistry simpleFlagRegistry = (SimpleFlagRegistry) ProtectionWorldGuard.getAPI().getFlagRegistry();
Field flagsMapField = simpleFlagRegistry.getClass().getDeclaredField("flags");
flagsMapField.setAccessible(true);
ConcurrentMap<String, Flag<?>> flags = (ConcurrentMap<String, Flag<?>>) flagsMapField.get(simpleFlagRegistry);
flags.remove(flag.getName().toLowerCase());
flags.put(flag.getName().toLowerCase(), flag);
schedulWorldGuardReload();
javaPlugin.getLogger().info("[CustomFlagsRegister] Custom WorldGuard flag registered: " + flag.getName());
} catch (Exception e) {
e.printStackTrace();
}
return;
}
try {
if (flagsListField == null) {
flagsListField = DefaultFlag.class.getDeclaredField("flagsList");
flagsListField.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(flagsListField, flagsListField.getModifiers() & ~Modifier.FINAL);
}
Flag<?>[] oldFlagsArray = (Flag<?>[]) flagsListField.get(null);
Flag<?>[] theNewFlagsArray = new Flag[oldFlagsArray.length + 1];
for (int i = 0; i < oldFlagsArray.length; i++) {
theNewFlagsArray[i] = oldFlagsArray[i];
}
theNewFlagsArray[theNewFlagsArray.length - 1] = flag;
flagsListField.set(null, theNewFlagsArray);
javaPlugin.getLogger().info("[CustomFlagsRegister] Custom WorldGuard flag registered: " + flag.getName());
schedulWorldGuardReload();
} catch (Exception e) {
EverNifeCore.info("Failed to register flag: " + flag.getName());
e.printStackTrace();
}
}
use of com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry in project WorldGuard by EngineHub.
the class WorldGuardPlugin method onEnable.
/**
* Called on plugin enable.
*/
@Override
public void onEnable() {
// Catch bad things being done by naughty plugins that include WorldGuard's classes
ClassSourceValidator verifier = new ClassSourceValidator(this);
verifier.reportMismatches(ImmutableList.of(WorldGuard.class, ProtectedRegion.class, Flag.class));
configureLogger();
// Need to create the plugins/WorldGuard folder
getDataFolder().mkdirs();
PermissionsResolverManager.initialize(this);
// Initialise WorldGuard
WorldGuard.getInstance().setPlatform(platform = new BukkitWorldGuardPlatform());
WorldGuard.getInstance().setup();
BukkitSessionManager sessionManager = (BukkitSessionManager) platform.getSessionManager();
// Set the proper command injector
commands.setInjector(new SimpleInjector(WorldGuard.getInstance()));
// Register command classes
final CommandsManagerRegistration reg = new CommandsManagerRegistration(this, commands);
reg.register(ToggleCommands.class);
reg.register(ProtectionCommands.class);
getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
if (!platform.getGlobalStateManager().hasCommandBookGodMode()) {
reg.register(GeneralCommands.class);
}
}, 0L);
getServer().getScheduler().scheduleSyncRepeatingTask(this, sessionManager, BukkitSessionManager.RUN_DELAY, BukkitSessionManager.RUN_DELAY);
// Register events
getServer().getPluginManager().registerEvents(sessionManager, this);
(new WorldGuardPlayerListener(this)).registerEvents();
(new WorldGuardBlockListener(this)).registerEvents();
(new WorldGuardEntityListener(this)).registerEvents();
(new WorldGuardWeatherListener(this)).registerEvents();
(new WorldGuardVehicleListener(this)).registerEvents();
(new WorldGuardServerListener(this)).registerEvents();
(new WorldGuardHangingListener(this)).registerEvents();
// Modules
(playerMoveListener = new PlayerMoveListener(this)).registerEvents();
(new BlacklistListener(this)).registerEvents();
(new ChestProtectionListener(this)).registerEvents();
(new RegionProtectionListener(this)).registerEvents();
(new RegionFlagsListener(this)).registerEvents();
(new WorldRulesListener(this)).registerEvents();
(new BlockedPotionsListener(this)).registerEvents();
(new EventAbstractionListener(this)).registerEvents();
(new PlayerModesListener(this)).registerEvents();
(new BuildPermissionListener(this)).registerEvents();
(new InvincibilityListener(this)).registerEvents();
if ("true".equalsIgnoreCase(System.getProperty("worldguard.debug.listener"))) {
(new DebuggingListener(this, WorldGuard.logger)).registerEvents();
}
platform.getGlobalStateManager().updateCommandBookGodMode();
if (getServer().getPluginManager().isPluginEnabled("CommandBook")) {
getServer().getPluginManager().registerEvents(new WorldGuardCommandBookListener(this), this);
}
// handle worlds separately to initialize already loaded worlds
WorldGuardWorldListener worldListener = (new WorldGuardWorldListener(this));
for (World world : getServer().getWorlds()) {
worldListener.initWorld(world);
}
worldListener.registerEvents();
Bukkit.getScheduler().runTask(this, () -> {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
ProcessPlayerEvent event = new ProcessPlayerEvent(player);
Events.fire(event);
}
});
((SimpleFlagRegistry) WorldGuard.getInstance().getFlagRegistry()).setInitialized(true);
// Enable metrics
// bStats plugin id
final Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
if (platform.getGlobalStateManager().extraStats) {
setupCustomCharts(metrics);
}
}
Aggregations