diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 1036e1089..3479adaeb 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -99,12 +99,15 @@ shadowJar { include(dependency("org.bstats:bstats-bukkit:1.7")) include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT")) include(dependency("com.sk89q:squirrelid:1.0.0-SNAPSHOT")) + include(dependency("com.google.inject:guice:4.2.3")) + include(dependency("com.google.inject.extensions:guice-assistedinject:4.2.3")) } relocate('net.kyori.text', 'com.plotsquared.formatting.text') relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib") relocate("org.bstats", "com.plotsquared.metrics") relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid') relocate('org.khelekore.prtree', 'com.plotsquared.prtree') + relocate('com.google', 'com.plotsquared.google') archiveFileName = "${project.name}-${parent.version}.jar" destinationDirectory = file "../target" } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index 90fbec806..e849dacfc 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -25,29 +25,24 @@ */ package com.plotsquared.bukkit; -import com.plotsquared.bukkit.generator.BukkitHybridUtils; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.Stage; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; +import com.plotsquared.bukkit.inject.BackupModule; +import com.plotsquared.bukkit.inject.BukkitModule; +import com.plotsquared.bukkit.inject.WorldManagerModule; import com.plotsquared.bukkit.listener.ChunkListener; import com.plotsquared.bukkit.listener.EntitySpawnListener; import com.plotsquared.bukkit.listener.PaperListener; import com.plotsquared.bukkit.listener.PlayerEvents; import com.plotsquared.bukkit.listener.SingleWorldListener; import com.plotsquared.bukkit.listener.WorldEvents; -import com.plotsquared.bukkit.managers.BukkitWorldManager; -import com.plotsquared.bukkit.managers.HyperverseWorldManager; -import com.plotsquared.bukkit.managers.MultiverseWorldManager; import com.plotsquared.bukkit.placeholder.PlaceholderFormatter; import com.plotsquared.bukkit.placeholder.Placeholders; import com.plotsquared.bukkit.player.BukkitPlayerManager; -import com.plotsquared.bukkit.queue.BukkitLocalQueue; -import com.plotsquared.bukkit.schematic.BukkitSchematicHandler; import com.plotsquared.bukkit.util.BukkitChatManager; -import com.plotsquared.bukkit.util.BukkitChunkManager; -import com.plotsquared.bukkit.util.BukkitEconHandler; -import com.plotsquared.bukkit.util.BukkitInventoryUtil; -import com.plotsquared.bukkit.util.BukkitPermHandler; -import com.plotsquared.bukkit.util.BukkitRegionManager; -import com.plotsquared.bukkit.util.BukkitSetupUtils; import com.plotsquared.bukkit.util.BukkitTaskManager; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitWorld; @@ -63,8 +58,8 @@ import com.plotsquared.bukkit.uuid.SquirrelIdUUIDService; import com.plotsquared.core.PlotPlatform; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.backup.BackupManager; -import com.plotsquared.core.backup.NullBackupManager; -import com.plotsquared.core.backup.SimpleBackupManager; +import com.plotsquared.core.command.WE_Anywhere; +import com.plotsquared.core.components.ComponentPresetManager; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ChatFormatter; import com.plotsquared.core.configuration.ConfigurationNode; @@ -73,11 +68,16 @@ import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.generator.GeneratorWrapper; -import com.plotsquared.core.generator.HybridGen; -import com.plotsquared.core.generator.HybridUtils; import com.plotsquared.core.generator.IndependentPlotGenerator; import com.plotsquared.core.generator.SingleWorldGenerator; +import com.plotsquared.core.inject.annotations.BackgroundPipeline; +import com.plotsquared.core.inject.annotations.DefaultGenerator; +import com.plotsquared.core.inject.annotations.ImpromptuPipeline; +import com.plotsquared.core.inject.annotations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldFile; +import com.plotsquared.core.inject.modules.PlotSquaredModule; import com.plotsquared.core.listener.PlotListener; +import com.plotsquared.core.listener.WESubscriber; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; @@ -88,23 +88,18 @@ import com.plotsquared.core.plot.message.PlainChatManager; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.plot.world.SinglePlotAreaManager; -import com.plotsquared.core.queue.QueueProvider; +import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.setup.PlotAreaBuilder; import com.plotsquared.core.setup.SettingsNodesWrapper; import com.plotsquared.core.util.ChatManager; -import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.ConsoleColors; import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.EventDispatcher; -import com.plotsquared.core.util.InventoryUtil; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.PermHandler; import com.plotsquared.core.util.PlatformWorldManager; -import com.plotsquared.core.util.PlayerManager; import com.plotsquared.core.util.PremiumVerification; import com.plotsquared.core.util.ReflectionUtils; -import com.plotsquared.core.util.RegionManager; -import com.plotsquared.core.util.SchematicHandler; import com.plotsquared.core.util.SetupUtils; import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.WorldUtil; @@ -113,8 +108,6 @@ import com.plotsquared.core.uuid.CacheUUIDService; import com.plotsquared.core.uuid.UUIDPipeline; import com.plotsquared.core.uuid.offline.OfflineModeUUIDService; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.extension.platform.Actor; import io.papermc.lib.PaperLib; import lombok.Getter; import lombok.NonNull; @@ -125,7 +118,6 @@ import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.World; -import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -162,10 +154,9 @@ import static com.plotsquared.core.util.PremiumVerification.getResourceID; import static com.plotsquared.core.util.PremiumVerification.getUserID; import static com.plotsquared.core.util.ReflectionUtils.getRefClass; -public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform { +@SuppressWarnings("unused") public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform { private static final int BSTATS_ID = 1404; - @Getter private static WorldEdit worldEdit; static { try { @@ -180,17 +171,21 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl private Method methodUnloadChunk0; private boolean methodUnloadSetup = false; private boolean metricsStarted; - @Getter private BackupManager backupManager; - @Getter private PlatformWorldManager worldManager; - private BukkitPlayerManager playerManager; private EconHandler econ; private PermHandler perm; + @Getter private Injector injector; + private PlotAreaManager plotAreaManager; private EventDispatcher eventDispatcher; private PlotListener plotListener; - private YamlConfiguration worldConfiguration; - private File worldfile; + @WorldConfig private YamlConfiguration worldConfiguration; + @WorldFile private File worldfile; + private BukkitPlayerManager playerManager; + private BackupManager backupManager; + @ImpromptuPipeline private UUIDPipeline impromptuPipeline; + @BackgroundPipeline private UUIDPipeline backgroundPipeline; + private PlatformWorldManager worldManager; @Override public int[] getServerVersion() { if (this.version == null) { @@ -219,17 +214,13 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl @Override public void onEnable() { this.pluginName = getDescription().getName(); + + // Stuff that needs to be created before the PlotSquared instance PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer); + TaskManager.setImplementation(new BukkitTaskManager(this)); final PlotSquared plotSquared = new PlotSquared(this, "Bukkit"); - this.plotAreaManager = plotSquared.getPlotAreaManager(); - this.eventDispatcher = plotSquared.getEventDispatcher(); - this.plotListener = plotSquared.getPlotListener(); - this.playerManager = new BukkitPlayerManager(this.plotAreaManager, this.eventDispatcher); - this.worldConfiguration = plotSquared.getWorldConfiguration(); - this.worldfile = plotSquared.getWorldsFile(); - if (PlotSquared.platform().getServerVersion()[1] < 13) { System.out.println( "You can't use this version of PlotSquared on a server less than Minecraft 1.13.2."); @@ -240,8 +231,14 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl return; } + // We create the injector after PlotSquared has been initialized, so that we have access + // to generated instances and settings + this.injector = Guice.createInjector(Stage.PRODUCTION, new PlotSquaredModule(), + new BukkitModule(this), new BackupModule(), new WorldManagerModule()); + this.injector.injectMembers(this); + if (PremiumVerification.isPremium() && Settings.Enabled_Components.UPDATE_NOTIFICATIONS) { - new UpdateUtility(this).updateChecker(); + injector.getInstance(UpdateUtility.class).updateChecker(); } if (PremiumVerification.isPremium()) { @@ -255,29 +252,121 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl PlotSquared.log(Captions.PREFIX + "&6Couldn't verify purchase :("); } - final UUIDPipeline impromptuPipeline = PlotSquared.get().getImpromptuUUIDPipeline(); - final UUIDPipeline backgroundPipeline = PlotSquared.get().getBackgroundUUIDPipeline(); + // Do stuff that was previously done in PlotSquared + // Kill entities + if (Settings.Enabled_Components.KILL_ROAD_MOBS + || Settings.Enabled_Components.KILL_ROAD_VEHICLES) { + this.runEntityTask(); + } + + // WorldEdit + if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) { + try { + PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + this.getPluginName() + + " hooked into WorldEdit."); + WorldEdit.getInstance().getEventBus().register(this.getInjector().getInstance(WESubscriber.class)); + if (Settings.Enabled_Components.COMMANDS) { + new WE_Anywhere(); + } + } catch (Throwable e) { + PlotSquared.debug( + "Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master"); + } + } + + if (Settings.Enabled_Components.EVENTS) { + getServer().getPluginManager().registerEvents(getInjector().getInstance(PlayerEvents.class), this); + getServer().getPluginManager().registerEvents(getInjector().getInstance(EntitySpawnListener.class), this); + if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) { + getServer().getPluginManager().registerEvents(getInjector().getInstance(PaperListener.class), this); + } + this.plotListener.startRunnable(); + } + + // Required + getServer().getPluginManager().registerEvents(getInjector().getInstance(WorldEvents.class), this); + if (Settings.Enabled_Components.CHUNK_PROCESSOR) { + getServer().getPluginManager().registerEvents(getInjector().getInstance(ChunkListener.class), this); + } + + // Start the global block queue + final GlobalBlockQueue globalBlockQueue = this.injector.getInstance(GlobalBlockQueue.class); + globalBlockQueue.runTask(); + + // Commands + if (Settings.Enabled_Components.COMMANDS) { + this.registerCommands(); + } + + // Economy + if (Settings.Enabled_Components.ECONOMY) { + TaskManager.runTask(() -> { + getInjector().getInstance(PermHandler.class).init(); + getInjector().getInstance(EconHandler.class).init(); + }); + } + + if (Settings.Enabled_Components.COMPONENT_PRESETS) { + try { + new ComponentPresetManager(); + } catch (final Exception e) { + PlotSquared.log(Captions.PREFIX + "Failed to initialize the preset system"); + e.printStackTrace(); + } + } + + // World generators: + final ConfigurationSection section = this.worldConfiguration.getConfigurationSection("worlds"); + final WorldUtil worldUtil = getInjector().getInstance(WorldUtil.class); + + if (section != null) { + for (String world : section.getKeys(false)) { + if (world.equals("CheckingPlotSquaredGenerator")) { + continue; + } + if (worldUtil.isWorld(world)) { + this.setGenerator(world); + } + } + TaskManager.runTaskLater(() -> { + for (String world : section.getKeys(false)) { + if (world.equals("CheckingPlotSquaredGenerator")) { + continue; + } + if (!worldUtil.isWorld(world) && !world.equals("*")) { + PlotSquared.debug("`" + world + "` was not properly loaded - " + this.getPluginName() + + " will now try to load it properly: "); + PlotSquared.debug( + " - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml"); + PlotSquared.debug( + " - Your world management plugin may be faulty (or non existent)"); + PlotSquared.debug( + " This message may also be a false positive and could be ignored."); + this.setGenerator(world); + } + } + }, 1); + } // Services are accessed in order - final CacheUUIDService cacheUUIDService = - new CacheUUIDService(Settings.UUID.UUID_CACHE_SIZE); - impromptuPipeline.registerService(cacheUUIDService); - backgroundPipeline.registerService(cacheUUIDService); - impromptuPipeline.registerConsumer(cacheUUIDService); - backgroundPipeline.registerConsumer(cacheUUIDService); + final CacheUUIDService cacheUUIDService = new CacheUUIDService(Settings.UUID.UUID_CACHE_SIZE); + this.impromptuPipeline.registerService(cacheUUIDService); + this.backgroundPipeline.registerService(cacheUUIDService); + this.impromptuPipeline.registerConsumer(cacheUUIDService); + this.backgroundPipeline.registerConsumer(cacheUUIDService); // Now, if the server is in offline mode we can only use profiles and direct UUID // access, and so we skip the player profile stuff as well as SquirrelID (Mojang lookups) if (Settings.UUID.OFFLINE) { final OfflineModeUUIDService offlineModeUUIDService = new OfflineModeUUIDService(); - impromptuPipeline.registerService(offlineModeUUIDService); - backgroundPipeline.registerService(offlineModeUUIDService); + this.impromptuPipeline.registerService(offlineModeUUIDService); + this.backgroundPipeline.registerService(offlineModeUUIDService); PlotSquared.log(Captions.PREFIX + "(UUID) Using the offline mode UUID service"); } final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService(); - impromptuPipeline.registerService(offlinePlayerUUIDService); - backgroundPipeline.registerService(offlinePlayerUUIDService); + this.impromptuPipeline.registerService(offlinePlayerUUIDService); + this.backgroundPipeline.registerService(offlinePlayerUUIDService); final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db"); @@ -320,64 +409,64 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl // If running Paper we'll also try to use their profiles if (PaperLib.isPaper()) { final PaperUUIDService paperUUIDService = new PaperUUIDService(); - impromptuPipeline.registerService(paperUUIDService); - backgroundPipeline.registerService(paperUUIDService); + this.impromptuPipeline.registerService(paperUUIDService); + this.backgroundPipeline.registerService(paperUUIDService); PlotSquared .log(Captions.PREFIX + "(UUID) Using Paper as a complementary UUID service"); } - impromptuPipeline.registerService(sqLiteUUIDService); - backgroundPipeline.registerService(sqLiteUUIDService); - impromptuPipeline.registerConsumer(sqLiteUUIDService); - backgroundPipeline.registerConsumer(sqLiteUUIDService); + this.impromptuPipeline.registerService(sqLiteUUIDService); + this.backgroundPipeline.registerService(sqLiteUUIDService); + this.impromptuPipeline.registerConsumer(sqLiteUUIDService); + this.backgroundPipeline.registerConsumer(sqLiteUUIDService); if (legacyUUIDService != null) { - impromptuPipeline.registerService(legacyUUIDService); - backgroundPipeline.registerService(legacyUUIDService); + this.impromptuPipeline.registerService(legacyUUIDService); + this.backgroundPipeline.registerService(legacyUUIDService); } // Plugin providers if (luckPermsUUIDService != null) { - impromptuPipeline.registerService(luckPermsUUIDService); - backgroundPipeline.registerService(luckPermsUUIDService); + this.impromptuPipeline.registerService(luckPermsUUIDService); + this.backgroundPipeline.registerService(luckPermsUUIDService); } if (bungeePermsUUIDService != null) { - impromptuPipeline.registerService(bungeePermsUUIDService); - backgroundPipeline.registerService(bungeePermsUUIDService); + this.impromptuPipeline.registerService(bungeePermsUUIDService); + this.backgroundPipeline.registerService(bungeePermsUUIDService); } if (essentialsUUIDService != null) { - impromptuPipeline.registerService(essentialsUUIDService); - backgroundPipeline.registerService(essentialsUUIDService); + this.impromptuPipeline.registerService(essentialsUUIDService); + this.backgroundPipeline.registerService(essentialsUUIDService); } final SquirrelIdUUIDService impromptuMojangService = new SquirrelIdUUIDService(Settings.UUID.IMPROMPTU_LIMIT); - impromptuPipeline.registerService(impromptuMojangService); + this.impromptuPipeline.registerService(impromptuMojangService); final SquirrelIdUUIDService backgroundMojangService = new SquirrelIdUUIDService(Settings.UUID.BACKGROUND_LIMIT); - backgroundPipeline.registerService(backgroundMojangService); + this.backgroundPipeline.registerService(backgroundMojangService); } else { - impromptuPipeline.registerService(sqLiteUUIDService); - backgroundPipeline.registerService(sqLiteUUIDService); - impromptuPipeline.registerConsumer(sqLiteUUIDService); - backgroundPipeline.registerConsumer(sqLiteUUIDService); + this.impromptuPipeline.registerService(sqLiteUUIDService); + this.backgroundPipeline.registerService(sqLiteUUIDService); + this.impromptuPipeline.registerConsumer(sqLiteUUIDService); + this.backgroundPipeline.registerConsumer(sqLiteUUIDService); if (legacyUUIDService != null) { - impromptuPipeline.registerService(legacyUUIDService); - backgroundPipeline.registerService(legacyUUIDService); + this.impromptuPipeline.registerService(legacyUUIDService); + this.backgroundPipeline.registerService(legacyUUIDService); } } - impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE); + this.impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE); if (Settings.UUID.BACKGROUND_CACHING_ENABLED) { this.startUuidCaching(sqLiteUUIDService, cacheUUIDService); } if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { - new Placeholders().register(); + injector.getInstance(Placeholders.class).register(); if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) { - ChatFormatter.formatters.add(new PlaceholderFormatter()); + ChatFormatter.formatters.add(getInjector().getInstance(PlaceholderFormatter.class)); } PlotSquared.log(Captions.PREFIX + "&6PlotSquared hooked into PlaceholderAPI"); } else { @@ -387,31 +476,14 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl this.startMetrics(); if (Settings.Enabled_Components.WORLDS) { - TaskManager.IMP.taskRepeat(this::unload, 20); + TaskManager.getImplementation().taskRepeat(this::unload, 20); try { - singleWorldListener = new SingleWorldListener(this); + singleWorldListener = getInjector().getInstance(SingleWorldListener.class); } catch (Exception e) { e.printStackTrace(); } } - try { - this.backupManager = new SimpleBackupManager(); - } catch (final Exception e) { - PlotSquared.log(Captions.PREFIX + "&6Failed to initialize backup manager"); - e.printStackTrace(); - PlotSquared.log(Captions.PREFIX + "&6Backup features will be disabled"); - this.backupManager = new NullBackupManager(); - } - - if (Bukkit.getPluginManager().getPlugin("Hyperverse") != null) { - this.worldManager = new HyperverseWorldManager(); - } else if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) { - this.worldManager = new MultiverseWorldManager(); - } else { - this.worldManager = new BukkitWorldManager(); - } - PlotSquared.log( Captions.PREFIX.getTranslated() + "Using platform world manager: " + this.worldManager .getName()); @@ -601,21 +673,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl this.getServer().getPluginManager().disablePlugin(this); } - @Override public int[] getPluginVersion() { - String ver = getDescription().getVersion(); - if (ver.contains("-")) { - ver = ver.split("-")[0]; - } - String[] split = ver.split("\\."); - return new int[] {Integer.parseInt(split[0]), Integer.parseInt(split[1]), - Integer.parseInt(split[2])}; - } - - @Override public String getPluginVersionString() { - return getDescription().getVersion(); - } - - @Override public void registerCommands() { + private void registerCommands() { final BukkitCommand bukkitCommand = new BukkitCommand(); final PluginCommand plotCommand = getCommand("plots"); if (plotCommand != null) { @@ -633,11 +691,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl return Bukkit.getWorldContainer(); } - @Override public TaskManager getTaskManager() { - return new BukkitTaskManager(this); - } - - @Override @SuppressWarnings("deprecation") public void runEntityTask() { + @SuppressWarnings("deprecation") private void runEntityTask() { PlotSquared.log(Captions.PREFIX + "KillAllEntities started."); TaskManager.runTaskRepeat(() -> this.plotAreaManager.forEachPlotArea(plotArea -> { final World world = Bukkit.getWorld(plotArea.getWorldName()); @@ -897,9 +951,9 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl final String id) { final IndependentPlotGenerator result; if (id != null && id.equalsIgnoreCase("single")) { - result = new SingleWorldGenerator(this.plotAreaManager); + result = getInjector().getInstance(SingleWorldGenerator.class); } else { - result = PlotSquared.platform().getDefaultGenerator(); + result = getInjector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)); if (!PlotSquared.get().setupPlotWorld(worldName, id, result)) { return null; } @@ -907,84 +961,6 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl return (ChunkGenerator) result.specify(worldName); } - @Override public void registerPlayerEvents() { - final PlayerEvents main = new PlayerEvents(this.plotAreaManager, this.eventDispatcher, worldEdit); - getServer().getPluginManager().registerEvents(main, this); - getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this); - if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) { - getServer().getPluginManager().registerEvents(new PaperListener(this.plotAreaManager), this); - } - this.plotListener.startRunnable(); - } - - @Override public void registerForceFieldEvents() { - } - - @Override public boolean initWorldEdit() { - if (getServer().getPluginManager().getPlugin("WorldEdit") != null) { - worldEdit = WorldEdit.getInstance(); - return true; - } - return false; - } - - @Override public EconHandler getEconomyHandler() { - if (econ != null) { - if (econ.init() /* is inited */) { - return econ; - } else { - return null; - } - } - - try { - econ = new BukkitEconHandler(); - if (econ.init()) { - return econ; - } - } catch (Throwable ignored) { - PlotSquared.debug("No economy detected!"); - } - return null; - } - - @Override public PermHandler getPermissionHandler() { - if (perm != null) { - if (perm.init() /* is inited */) { - return perm; - } else { - return null; - } - } - - try { - perm = new BukkitPermHandler(); - if (perm.init()) { - return perm; - } - } catch (Throwable ignored) { - PlotSquared.debug("No permissions detected!"); - } - return null; - } - - @Override public QueueProvider initBlockQueue() { - //TODO Figure out why this code is still here yet isn't being called anywhere. - // try { - // new SendChunk(); - // MainUtil.canSendChunk = true; - // } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - // PlotSquared.debug( - // SendChunk.class + " does not support " + StringMan.getString(getServerVersion())); - // MainUtil.canSendChunk = false; - // } - return QueueProvider.of(BukkitLocalQueue.class, BukkitLocalQueue.class); - } - - @Override public WorldUtil initWorldUtil() { - return new BukkitUtil(); - } - @Override @Nullable public GeneratorWrapper getGenerator(@NonNull final String world, @Nullable final String name) { if (name == null) { @@ -998,18 +974,11 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } return new BukkitPlotGenerator(world, gen, this.plotAreaManager); } else { - return new BukkitPlotGenerator(world, PlotSquared.platform().getDefaultGenerator(), this.plotAreaManager); + return new BukkitPlotGenerator(world, getInjector() + .getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)), this.plotAreaManager); } } - @Override public HybridUtils initHybridUtils() { - return new BukkitHybridUtils(this.plotAreaManager); - } - - @Override public SetupUtils initSetupUtils() { - return new BukkitSetupUtils(this.plotAreaManager, this.worldConfiguration, this.worldfile); - } - @Override public void startMetrics() { if (this.metricsStarted) { return; @@ -1041,47 +1010,23 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl "WorldEdit")); } - @Override public ChunkManager initChunkManager() { - return new BukkitChunkManager(); - } - - @Override public RegionManager initRegionManager() { - return new BukkitRegionManager(); - } - @Override public void unregister(@NonNull final PlotPlayer player) { BukkitUtil.removePlayer(player.getUUID()); } - @Override public void registerChunkProcessor() { - getServer().getPluginManager().registerEvents(new ChunkListener(this.plotAreaManager), this); - } - - @Override public void registerWorldEvents() { - getServer().getPluginManager().registerEvents(new WorldEvents(this.plotAreaManager), this); - } - - @NotNull @Override public IndependentPlotGenerator getDefaultGenerator() { - return new HybridGen(this.eventDispatcher, this.plotListener, this.worldConfiguration); - } - - @Override public InventoryUtil initInventoryUtil() { - return new BukkitInventoryUtil(); - } - @Override public void setGenerator(@NonNull final String worldName) { World world = BukkitUtil.getWorld(worldName); if (world == null) { // create world ConfigurationSection worldConfig = this.worldConfiguration.getConfigurationSection("worlds." + worldName); String manager = worldConfig.getString("generator.plugin", getPluginName()); - PlotAreaBuilder builder = new PlotAreaBuilder().plotManager(manager) + PlotAreaBuilder builder = PlotAreaBuilder.newBuilder().plotManager(manager) .generatorName(worldConfig.getString("generator.init", manager)) .plotAreaType(MainUtil.getType(worldConfig)) .terrainType(MainUtil.getTerrain(worldConfig)) .settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null)) .worldName(worldName); - SetupUtils.manager.setupWorld(builder); + getInjector().getInstance(SetupUtils.class).setupWorld(builder); world = Bukkit.getWorld(worldName); } else { try { @@ -1105,10 +1050,6 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } } - @Override public SchematicHandler initSchematicHandler() { - return new BukkitSchematicHandler(); - } - /** * Attempt to retrieve a {@link PlotPlayer} from a player identifier. * This method accepts: @@ -1170,18 +1111,6 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl return names; } - @Override public Actor getConsole() { - @NotNull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); - WorldEditPlugin wePlugin = - ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")); - return wePlugin.wrapCommandSender(console); - } - - @Override @NotNull - public PlayerManager, ? extends Player> getPlayerManager() { - return this.playerManager; - } - @Override @NotNull public com.plotsquared.core.location.World getPlatformWorld(@NotNull final String worldName) { return BukkitWorld.of(worldName); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java index 09aaa0ea6..c8169ce9e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -65,7 +65,8 @@ public class BukkitPlotGenerator extends ChunkGenerator @Getter private final String levelName; public BukkitPlotGenerator(@NotNull final String name, - @NotNull final IndependentPlotGenerator generator, @NotNull final PlotAreaManager plotAreaManager) { + @NotNull final IndependentPlotGenerator generator, + @NotNull final PlotAreaManager plotAreaManager) { this.plotAreaManager = plotAreaManager; this.levelName = name; this.plotGenerator = generator; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BackupModule.java b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BackupModule.java new file mode 100644 index 000000000..604ec1de1 --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BackupModule.java @@ -0,0 +1,54 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.bukkit.inject; + +import com.google.inject.AbstractModule; +import com.google.inject.assistedinject.FactoryModuleBuilder; +import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.backup.BackupManager; +import com.plotsquared.core.backup.BackupProfile; +import com.plotsquared.core.backup.NullBackupManager; +import com.plotsquared.core.backup.PlayerBackupProfile; +import com.plotsquared.core.backup.SimpleBackupManager; +import com.plotsquared.core.configuration.Captions; +import com.plotsquared.core.inject.factory.PlayerBackupProfileFactory; + +public class BackupModule extends AbstractModule { + + @Override protected void configure() { + try { + install(new FactoryModuleBuilder() + .implement(BackupProfile.class, PlayerBackupProfile.class).build(PlayerBackupProfileFactory.class)); + bind(BackupManager.class).to(SimpleBackupManager.class); + } catch (final Exception e) { + PlotSquared.log(Captions.PREFIX + "&6Failed to initialize backup manager"); + e.printStackTrace(); + PlotSquared.log(Captions.PREFIX + "&6Backup features will be disabled"); + bind(BackupManager.class).to(NullBackupManager.class); + } + } + +} diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java new file mode 100644 index 000000000..efb28505b --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java @@ -0,0 +1,92 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.bukkit.inject; + +import com.google.inject.AbstractModule; +import com.plotsquared.bukkit.BukkitPlatform; +import com.plotsquared.bukkit.player.BukkitPlayerManager; +import com.plotsquared.bukkit.queue.BukkitLocalQueue; +import com.plotsquared.bukkit.schematic.BukkitSchematicHandler; +import com.plotsquared.bukkit.util.BukkitChunkManager; +import com.plotsquared.bukkit.util.BukkitEconHandler; +import com.plotsquared.bukkit.util.BukkitInventoryUtil; +import com.plotsquared.bukkit.util.BukkitPermHandler; +import com.plotsquared.bukkit.util.BukkitRegionManager; +import com.plotsquared.bukkit.util.BukkitSetupUtils; +import com.plotsquared.bukkit.util.BukkitUtil; +import com.plotsquared.core.PlotPlatform; +import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.generator.HybridGen; +import com.plotsquared.core.generator.HybridUtils; +import com.plotsquared.core.generator.IndependentPlotGenerator; +import com.plotsquared.core.inject.annotations.ConsoleActor; +import com.plotsquared.core.inject.annotations.DefaultGenerator; +import com.plotsquared.core.queue.GlobalBlockQueue; +import com.plotsquared.core.queue.QueueProvider; +import com.plotsquared.core.util.ChunkManager; +import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.InventoryUtil; +import com.plotsquared.core.util.PermHandler; +import com.plotsquared.core.util.PlayerManager; +import com.plotsquared.core.util.RegionManager; +import com.plotsquared.core.util.SchematicHandler; +import com.plotsquared.core.util.SetupUtils; +import com.plotsquared.core.util.WorldUtil; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.extension.platform.Actor; +import lombok.RequiredArgsConstructor; +import org.bukkit.Bukkit; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +@RequiredArgsConstructor public class BukkitModule extends AbstractModule { + + private final BukkitPlatform bukkitPlatform; + + @Override protected void configure() { + bind(PlayerManager.class).to(BukkitPlayerManager.class); + bind(JavaPlugin.class).toInstance(bukkitPlatform); + bind(PlotPlatform.class).toInstance(bukkitPlatform); + bind(IndependentPlotGenerator.class).annotatedWith(DefaultGenerator.class).to(HybridGen.class); + // Console actor + @NotNull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); + WorldEditPlugin wePlugin = ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")); + bind(Actor.class).annotatedWith(ConsoleActor.class).toInstance(wePlugin.wrapCommandSender(console)); + bind(HybridUtils.class).to(BukkitHybridUtils.class); + bind(InventoryUtil.class).to(BukkitInventoryUtil.class); + bind(SetupUtils.class).to(BukkitSetupUtils.class); + bind(WorldUtil.class).to(BukkitUtil.class); + bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue( + QueueProvider.of(BukkitLocalQueue.class, BukkitLocalQueue.class), 1, Settings.QUEUE.TARGET_TIME)); + bind(ChunkManager.class).to(BukkitChunkManager.class); + bind(RegionManager.class).to(BukkitRegionManager.class); + bind(SchematicHandler.class).to(BukkitSchematicHandler.class); + bind(PermHandler.class).to(BukkitPermHandler.class); + bind(EconHandler.class).to(BukkitEconHandler.class); + } + +} diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/WorldManagerModule.java b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/WorldManagerModule.java new file mode 100644 index 000000000..361049d90 --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/WorldManagerModule.java @@ -0,0 +1,47 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.bukkit.inject; + +import com.google.inject.AbstractModule; +import com.plotsquared.bukkit.managers.BukkitWorldManager; +import com.plotsquared.bukkit.managers.HyperverseWorldManager; +import com.plotsquared.bukkit.managers.MultiverseWorldManager; +import com.plotsquared.core.util.PlatformWorldManager; +import org.bukkit.Bukkit; + +public class WorldManagerModule extends AbstractModule { + + @Override protected void configure() { + if (Bukkit.getPluginManager().getPlugin("Hyperverse") != null) { + bind(PlatformWorldManager.class).to(HyperverseWorldManager.class); + } else if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) { + bind(PlatformWorldManager.class).to(MultiverseWorldManager.class); + } else { + bind(PlatformWorldManager.class).to(BukkitWorldManager.class); + } + } + +} diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java index 29f06a263..8c41c30d7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java @@ -25,6 +25,7 @@ */ package com.plotsquared.bukkit.listener; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.location.Location; @@ -69,7 +70,7 @@ public class ChunkListener implements Listener { private Chunk lastChunk; private boolean ignoreUnload = false; - public ChunkListener(@NotNull final PlotAreaManager plotAreaManager) { + @Inject public ChunkListener(@NotNull final PlotAreaManager plotAreaManager) { this.plotAreaManager = plotAreaManager; if (Settings.Chunk_Processor.AUTO_TRIM) { try { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java index 023e72624..059dc2486 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java @@ -32,6 +32,7 @@ import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent; import com.destroystokyo.paper.event.entity.SlimePathfindEvent; import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent; import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent; +import com.google.inject.Inject; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.core.command.Command; import com.plotsquared.core.command.MainCommand; @@ -75,7 +76,7 @@ public class PaperListener implements Listener { private final PlotAreaManager plotAreaManager; private Chunk lastChunk; - public PaperListener(@NotNull final PlotAreaManager plotAreaManager) { + @Inject public PaperListener(@NotNull final PlotAreaManager plotAreaManager) { this.plotAreaManager = plotAreaManager; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 37b73bdf4..78a7bc67d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -27,6 +27,7 @@ package com.plotsquared.bukkit.listener; import com.destroystokyo.paper.MaterialTags; import com.google.common.base.Charsets; +import com.google.inject.Inject; import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.UpdateUtility; @@ -107,6 +108,7 @@ import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.PremiumVerification; import com.plotsquared.core.util.RegExUtil; +import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.entity.EntityCategories; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.WorldEdit; @@ -245,10 +247,11 @@ import java.util.regex.Pattern; private PlayerMoveEvent moveTmp; private String internalVersion; - public PlayerEvents(@NotNull final PlotAreaManager plotAreaManager, - @NotNull final EventDispatcher eventDispatcher, - @NotNull final WorldEdit worldEdit) { - super(eventDispatcher); + @Inject public PlayerEvents(@NotNull final PlotAreaManager plotAreaManager, + @NotNull final EventDispatcher eventDispatcher, + @NotNull final WorldEdit worldEdit, + @NotNull final WorldUtil worldUtil) { + super(eventDispatcher, worldUtil); this.plotAreaManager = plotAreaManager; this.eventDispatcher = eventDispatcher; this.worldEdit = worldEdit; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java index a5a5ff2f8..a5885d733 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java @@ -37,7 +37,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.world.ChunkEvent; import org.bukkit.event.world.ChunkLoadEvent; -import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -50,7 +50,7 @@ public class SingleWorldListener implements Listener { private Method methodGetHandleChunk; private Field mustSave; - public SingleWorldListener(Plugin plugin) throws Exception { + public SingleWorldListener(JavaPlugin plugin) throws Exception { ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk"); ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle").getRealMethod(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/WorldEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/WorldEvents.java index 157ea9e3a..870c6113e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/WorldEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/WorldEvents.java @@ -25,6 +25,7 @@ */ package com.plotsquared.bukkit.listener; +import com.google.inject.Inject; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.generator.GeneratorWrapper; @@ -43,7 +44,7 @@ public class WorldEvents implements Listener { private final PlotAreaManager plotAreaManager; - public WorldEvents(@NotNull final PlotAreaManager plotAreaManager) { + @Inject public WorldEvents(@NotNull final PlotAreaManager plotAreaManager) { this.plotAreaManager = plotAreaManager; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/BukkitWorldManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/BukkitWorldManager.java index 4646868a1..5c0a8934d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/BukkitWorldManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/BukkitWorldManager.java @@ -25,6 +25,7 @@ */ package com.plotsquared.bukkit.managers; +import com.google.inject.Singleton; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.util.PlatformWorldManager; import org.bukkit.Bukkit; @@ -44,7 +45,7 @@ import java.util.List; * Default Bukkit world manager. It will handle world creation by * registering the generator in bukkit.yml */ -public class BukkitWorldManager implements PlatformWorldManager { +@Singleton public class BukkitWorldManager implements PlatformWorldManager { @Override public void initialize() { } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/HyperverseWorldManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/HyperverseWorldManager.java index 705a30286..2fdfbd44a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/HyperverseWorldManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/HyperverseWorldManager.java @@ -25,6 +25,7 @@ */ package com.plotsquared.bukkit.managers; +import com.google.inject.Singleton; import org.bukkit.World; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -38,7 +39,7 @@ import se.hyperver.hyperverse.world.WorldType; * Hyperverse specific manager that creates worlds * using Hyperverse's API */ -public class HyperverseWorldManager extends BukkitWorldManager { +@Singleton public class HyperverseWorldManager extends BukkitWorldManager { @Override @Nullable public World handleWorldCreation(@NotNull String worldName, @Nullable String generator) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/MultiverseWorldManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/MultiverseWorldManager.java index e8cb4cf1e..40f1cb33e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/MultiverseWorldManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/MultiverseWorldManager.java @@ -25,6 +25,7 @@ */ package com.plotsquared.bukkit.managers; +import com.google.inject.Singleton; import org.bukkit.Bukkit; import org.bukkit.World; import org.jetbrains.annotations.NotNull; @@ -34,7 +35,7 @@ import org.jetbrains.annotations.Nullable; * Multiverse specific manager that informs Multiverse of * world creation by executing a console command */ -public class MultiverseWorldManager extends BukkitWorldManager { +@Singleton public class MultiverseWorldManager extends BukkitWorldManager { @Override @Nullable public World handleWorldCreation(@NotNull final String worldName, @Nullable final String generator) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index b7ca57e81..09e332e29 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -54,6 +54,7 @@ import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.RegisteredListener; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.Set; @@ -68,10 +69,13 @@ import static com.sk89q.worldedit.world.gamemode.GameModes.SURVIVAL; public class BukkitPlayer extends PlotPlayer { private static boolean CHECK_EFFECTIVE = true; + + private final EconHandler econHandler; public final Player player; private boolean offline; private String name; + /** *

Please do not use this method. Instead use * BukkitUtil.getPlayer(Player), as it caches player objects.

@@ -79,20 +83,22 @@ public class BukkitPlayer extends PlotPlayer { * @param player Bukkit player instance */ public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher, - @NotNull final Player player) { - this(plotAreaManager, eventDispatcher, player, false); + @NotNull final Player player, @Nullable final EconHandler econHandler) { + this(plotAreaManager, eventDispatcher, player, false, econHandler); } public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher, - @NotNull final Player player, final boolean offline) { - this(plotAreaManager, eventDispatcher, player, offline, true); + @NotNull final Player player, final boolean offline, @Nullable final EconHandler econHandler) { + this(plotAreaManager, eventDispatcher, player, offline, true, econHandler); } public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final - EventDispatcher eventDispatcher, @NotNull final Player player, final boolean offline, final boolean realPlayer) { - super(plotAreaManager, eventDispatcher); + EventDispatcher eventDispatcher, @NotNull final Player player, final boolean offline, + final boolean realPlayer, @Nullable final EconHandler econHandler) { + super(plotAreaManager, eventDispatcher, econHandler); this.player = player; this.offline = offline; + this.econHandler = econHandler; if (realPlayer) { super.populatePersistentMetaMap(); } @@ -161,8 +167,8 @@ public class BukkitPlayer extends PlotPlayer { } @Override public boolean hasPermission(final String permission) { - if (this.offline && EconHandler.getEconHandler() != null) { - return EconHandler.getEconHandler().hasPermission(getName(), permission); + if (this.offline && this.econHandler != null) { + return this.econHandler.hasPermission(getName(), permission); } return this.player.hasPermission(permission); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java index c6c835a37..edb651fbb 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java @@ -25,10 +25,11 @@ */ package com.plotsquared.bukkit.player; +import com.google.inject.Inject; +import com.google.inject.Singleton; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.PlayerManager; -import lombok.RequiredArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -39,11 +40,17 @@ import java.util.UUID; /** * Player manager providing {@link BukkitPlayer Bukkit players} */ -@RequiredArgsConstructor public class BukkitPlayerManager extends PlayerManager { +@Singleton public class BukkitPlayerManager extends PlayerManager { private final PlotAreaManager plotAreaManager; private final EventDispatcher eventDispatcher; + @Inject public BukkitPlayerManager(@NotNull final PlotAreaManager plotAreaManager, + @NotNull final EventDispatcher eventDispatcher) { + this.plotAreaManager = plotAreaManager; + this.eventDispatcher = eventDispatcher; + } + @NotNull @Override public BukkitPlayer getPlayer(@NotNull final Player object) { try { return getPlayer(object.getUniqueId()); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/BukkitSchematicHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/BukkitSchematicHandler.java index 27ce9139f..8860dddab 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/BukkitSchematicHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/BukkitSchematicHandler.java @@ -25,14 +25,22 @@ */ package com.plotsquared.bukkit.schematic; +import com.google.inject.Inject; +import com.google.inject.Singleton; import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.util.SchematicHandler; +import com.plotsquared.core.util.WorldUtil; import com.sk89q.jnbt.CompoundTag; +import org.jetbrains.annotations.NotNull; /** * Schematic Handler. */ -public class BukkitSchematicHandler extends SchematicHandler { +@Singleton public class BukkitSchematicHandler extends SchematicHandler { + + @Inject public BukkitSchematicHandler(@NotNull final WorldUtil worldUtil) { + super(worldUtil); + } @Override public boolean restoreTile(LocalBlockQueue queue, CompoundTag ct, int x, int y, int z) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index 093682cba..dac4377b4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -25,6 +25,7 @@ */ package com.plotsquared.bukkit.util; +import com.google.inject.Singleton; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.listener.WEExtent; import com.plotsquared.core.queue.GlobalBlockQueue; @@ -54,7 +55,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_MOB; import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER; import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; -public class BukkitChunkManager extends ChunkManager { +@Singleton public class BukkitChunkManager extends ChunkManager { public static boolean isIn(CuboidRegion region, int x, int z) { return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX() diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java index 60f574357..3de48ae99 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java @@ -25,9 +25,10 @@ */ package com.plotsquared.bukkit.util; +import com.google.inject.Inject; +import com.google.inject.Singleton; import com.plotsquared.bukkit.player.BukkitOfflinePlayer; import com.plotsquared.bukkit.player.BukkitPlayer; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.player.OfflinePlotPlayer; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.util.EconHandler; @@ -35,11 +36,18 @@ import com.plotsquared.core.util.PermHandler; import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit; import org.bukkit.plugin.RegisteredServiceProvider; +import org.jetbrains.annotations.Nullable; -public class BukkitEconHandler extends EconHandler { +@Singleton public class BukkitEconHandler extends EconHandler { private Economy econ; + private final PermHandler permHandler; + + @Inject public BukkitEconHandler(@Nullable final PermHandler permHandler) { + this.permHandler = permHandler; + } + @Override public boolean init() { if (this.econ == null) { @@ -83,8 +91,8 @@ public class BukkitEconHandler extends EconHandler { * @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead */ @Deprecated @Override public boolean hasPermission(String world, String player, String perm) { - if (PlotSquared.platform().getPermissionHandler() != null) { - return PlotSquared.platform().getPermissionHandler().hasPermission(world, player, perm); + if (this.permHandler != null) { + return this.permHandler.hasPermission(world, player, perm); } else { return false; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java index 00adeb892..ea16fa873 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java @@ -25,6 +25,7 @@ */ package com.plotsquared.bukkit.util; +import com.google.inject.Singleton; import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.PlotInventory; @@ -45,7 +46,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.IntStream; -public class BukkitInventoryUtil extends InventoryUtil { +@Singleton public class BukkitInventoryUtil extends InventoryUtil { @Override public void open(PlotInventory inv) { BukkitPlayer bp = (BukkitPlayer) inv.player; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java index fee00a66d..8987e3527 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java @@ -25,12 +25,13 @@ */ package com.plotsquared.bukkit.util; +import com.google.inject.Singleton; import com.plotsquared.core.util.PermHandler; import net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; import org.bukkit.plugin.RegisteredServiceProvider; -public class BukkitPermHandler extends PermHandler { +@Singleton public class BukkitPermHandler extends PermHandler { private Permission perms; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java index 7a989a4cd..0b405b904 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java @@ -25,6 +25,8 @@ */ package com.plotsquared.bukkit.util; +import com.google.inject.Inject; +import com.google.inject.Singleton; import com.plotsquared.bukkit.BukkitPlatform; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.generator.AugmentedUtils; @@ -56,6 +58,7 @@ import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.ArrayDeque; import java.util.ArrayList; @@ -74,7 +77,11 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_MOB; import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER; import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; -public class BukkitRegionManager extends RegionManager { +@Singleton public class BukkitRegionManager extends RegionManager { + + @Inject public BukkitRegionManager(@NotNull ChunkManager chunkManager) { + super(chunkManager); + } public static boolean isIn(CuboidRegion region, int x, int z) { return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX() diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java index 838b620c5..80df11232 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java @@ -25,10 +25,12 @@ */ package com.plotsquared.bukkit.util; +import com.google.inject.Inject; +import com.google.inject.Singleton; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.annoations.WorldConfig; -import com.plotsquared.core.annoations.WorldFile; +import com.plotsquared.core.inject.annotations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldFile; import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.file.YamlConfiguration; @@ -54,13 +56,13 @@ import java.util.HashMap; import java.util.Map.Entry; import java.util.Objects; -public class BukkitSetupUtils extends SetupUtils { +@Singleton public class BukkitSetupUtils extends SetupUtils { private final PlotAreaManager plotAreaManager; private final YamlConfiguration worldConfiguration; private final File worldFile; - public BukkitSetupUtils(@NotNull final PlotAreaManager plotAreaManager, + @Inject public BukkitSetupUtils(@NotNull final PlotAreaManager plotAreaManager, @WorldConfig @NotNull final YamlConfiguration worldConfiguration, @WorldFile @NotNull final File worldFile) { this.plotAreaManager = plotAreaManager; @@ -117,7 +119,7 @@ public class BukkitSetupUtils extends SetupUtils { } @Deprecated @Override public String setupWorld(SetupObject object) { - SetupUtils.manager.updateGenerators(); + this.updateGenerators(); ConfigurationNode[] steps = object.step == null ? new ConfigurationNode[0] : object.step; String world = object.world; PlotAreaType type = object.type; @@ -222,7 +224,7 @@ public class BukkitSetupUtils extends SetupUtils { } @Override public String setupWorld(PlotAreaBuilder builder) { - SetupUtils.manager.updateGenerators(); + this.updateGenerators(); ConfigurationNode[] steps = builder.settingsNodesWrapper() == null ? new ConfigurationNode[0] : builder.settingsNodesWrapper().getSettingsNodes(); String world = builder.worldName(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java index cf85fa92c..c5928c261 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java @@ -25,15 +25,17 @@ */ package com.plotsquared.bukkit.util; +import com.google.inject.Inject; +import com.google.inject.Singleton; import com.plotsquared.bukkit.BukkitPlatform; import com.plotsquared.core.util.task.TaskManager; import org.bukkit.Bukkit; -public class BukkitTaskManager extends TaskManager { +@Singleton public class BukkitTaskManager extends TaskManager { private final BukkitPlatform bukkitMain; - public BukkitTaskManager(BukkitPlatform bukkitMain) { + @Inject public BukkitTaskManager(BukkitPlatform bukkitMain) { this.bukkitMain = bukkitMain; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 8f532e2e9..a4b147ff9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -25,6 +25,8 @@ */ package com.plotsquared.bukkit.util; +import com.google.inject.Inject; +import com.google.inject.Singleton; import com.plotsquared.bukkit.BukkitPlatform; import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.player.BukkitPlayerManager; @@ -37,6 +39,7 @@ import com.plotsquared.core.util.BlockUtil; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.PlayerManager; +import com.plotsquared.core.util.RegionManager; import com.plotsquared.core.util.StringComparison; import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.task.RunnableVal; @@ -108,7 +111,7 @@ import java.util.function.IntConsumer; import java.util.stream.Stream; @SuppressWarnings({"unused", "WeakerAccess"}) -public class BukkitUtil extends WorldUtil { +@Singleton public class BukkitUtil extends WorldUtil { private static String lastString = null; private static World lastWorld = null; @@ -116,6 +119,10 @@ public class BukkitUtil extends WorldUtil { private static Player lastPlayer = null; private static BukkitPlayer lastPlotPlayer = null; + @Inject public BukkitUtil(@NotNull final RegionManager regionManager) { + super(regionManager); + } + public static void removePlayer(UUID uuid) { lastPlayer = null; lastPlotPlayer = null; @@ -412,7 +419,7 @@ public class BukkitUtil extends WorldUtil { @Override @Nullable public String[] getSignSynchronous(@NonNull final Location location) { Block block = getWorld(location.getWorldName()) .getBlockAt(location.getX(), location.getY(), location.getZ()); - return TaskManager.IMP.sync(new RunnableVal() { + return TaskManager.getImplementation().sync(new RunnableVal() { @Override public void run(String[] value) { if (block.getState() instanceof Sign) { Sign sign = (Sign) block.getState(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java index 458e3ca58..76c2daacb 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java @@ -28,6 +28,7 @@ package com.plotsquared.bukkit.util; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.stream.JsonReader; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotVersion; import com.plotsquared.core.configuration.Captions; @@ -51,7 +52,7 @@ public class UpdateUtility implements Listener { public final JavaPlugin javaPlugin; private boolean notify = true; - public UpdateUtility(final JavaPlugin javaPlugin) { + @Inject public UpdateUtility(final JavaPlugin javaPlugin) { this.javaPlugin = javaPlugin; internalVersion = PlotSquared.get().getVersion(); } diff --git a/Core/build.gradle b/Core/build.gradle index 51f56e187..ed7c50b06 100644 --- a/Core/build.gradle +++ b/Core/build.gradle @@ -18,6 +18,8 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72") implementation("org.jetbrains:annotations:19.0.0") implementation("org.khelekore:prtree:1.7.0-SNAPSHOT") + compile("com.google.inject:guice:4.2.3") + compile("com.google.inject.extensions:guice-assistedinject:4.2.3") } sourceCompatibility = 1.8 diff --git a/Core/pom.xml b/Core/pom.xml index d69f10a99..fab088df7 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -98,6 +98,18 @@ 1.7.0-SNAPSHOT runtime + + com.google.inject + guice + 4.2.3 + runtime + + + com.google.inject.extensions + guice-assistedinject + 4.2.3 + runtime + junit junit diff --git a/Core/src/main/java/com/plotsquared/core/PlotAPI.java b/Core/src/main/java/com/plotsquared/core/PlotAPI.java index ff4101a5c..1e85a2f6e 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotAPI.java +++ b/Core/src/main/java/com/plotsquared/core/PlotAPI.java @@ -102,7 +102,7 @@ import java.util.UUID; * @see ChunkManager */ public ChunkManager getChunkManager() { - return ChunkManager.manager; + return PlotSquared.platform().getInjector().getInstance(ChunkManager.class); } /** @@ -111,7 +111,7 @@ import java.util.UUID; * @return GlobalBlockQueue.IMP */ public GlobalBlockQueue getBlockQueue() { - return GlobalBlockQueue.IMP; + return PlotSquared.platform().getGlobalBlockQueue(); } /** @@ -122,7 +122,7 @@ import java.util.UUID; * @see SchematicHandler */ public SchematicHandler getSchematicHandler() { - return SchematicHandler.manager; + return PlotSquared.platform().getInjector().getInstance(SchematicHandler.class); } /** diff --git a/Core/src/main/java/com/plotsquared/core/PlotPlatform.java b/Core/src/main/java/com/plotsquared/core/PlotPlatform.java index 81ffa5210..38de6a0db 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotPlatform.java +++ b/Core/src/main/java/com/plotsquared/core/PlotPlatform.java @@ -25,27 +25,21 @@ */ package com.plotsquared.core; +import com.google.inject.Injector; +import com.google.inject.Key; import com.plotsquared.core.backup.BackupManager; import com.plotsquared.core.generator.GeneratorWrapper; import com.plotsquared.core.generator.HybridUtils; import com.plotsquared.core.generator.IndependentPlotGenerator; +import com.plotsquared.core.inject.annotations.DefaultGenerator; import com.plotsquared.core.location.World; import com.plotsquared.core.player.PlotPlayer; -import com.plotsquared.core.queue.QueueProvider; +import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.util.ChatManager; -import com.plotsquared.core.util.ChunkManager; -import com.plotsquared.core.util.EconHandler; -import com.plotsquared.core.util.InventoryUtil; -import com.plotsquared.core.util.PermHandler; import com.plotsquared.core.util.PlatformWorldManager; import com.plotsquared.core.util.PlayerManager; -import com.plotsquared.core.util.RegionManager; -import com.plotsquared.core.util.SchematicHandler; -import com.plotsquared.core.util.SetupUtils; import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.logger.ILogger; -import com.plotsquared.core.util.task.TaskManager; -import com.sk89q.worldedit.extension.platform.Actor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -94,20 +88,6 @@ public interface PlotPlatform

extends ILogger { */ void shutdown(); - /** - * Gets the version of the PlotSquared being used. - * - * @return the plugin version - */ - int[] getPluginVersion(); - - /** - * Gets the version of the PlotSquared being used as a string. - * - * @return the plugin version as a string - */ - String getPluginVersionString(); - default String getPluginName() { return "PlotSquared"; } @@ -129,13 +109,6 @@ public interface PlotPlatform

extends ILogger { */ String getNMSPackage(); - /** - * Gets the schematic handler. - * - * @return The {@link SchematicHandler} - */ - SchematicHandler initSchematicHandler(); - /** * Starts the {@link ChatManager}. * @@ -143,86 +116,6 @@ public interface PlotPlatform

extends ILogger { */ ChatManager initChatManager(); - /** - * The task manager will run and manage Minecraft tasks. - * - * @return the PlotSquared task manager - */ - TaskManager getTaskManager(); - - /** - * Run the task that will kill road mobs. - */ - void runEntityTask(); - - /** - * Registerss the implementation specific commands. - */ - void registerCommands(); - - /** - * Register the protection system. - */ - void registerPlayerEvents(); - - /** - * Register force field events. - */ - void registerForceFieldEvents(); - - /** - * Registers the WorldEdit hook. - */ - boolean initWorldEdit(); - - /** - * Gets the economy provider, if there is one - * - * @return the PlotSquared economy manager - */ - @Nullable EconHandler getEconomyHandler(); - - /** - * Gets the permission provider, if there is one - * - * @return the PlotSquared permission manager - */ - @Nullable PermHandler getPermissionHandler(); - - /** - * Gets the {@link QueueProvider} class. - */ - QueueProvider initBlockQueue(); - - /** - * Gets the {@link WorldUtil} class. - */ - WorldUtil initWorldUtil(); - - /** - * Gets the chunk manager. - * - * @return the PlotSquared chunk manager - */ - ChunkManager initChunkManager(); - - /** - * Gets the region manager. - * - * @return the PlotSquared region manager - */ - RegionManager initRegionManager(); - - /** - * Gets the {@link SetupUtils} class. - */ - SetupUtils initSetupUtils(); - - /** - * Gets {@link HybridUtils} class. - */ - HybridUtils initHybridUtils(); - /** * Start Metrics. */ @@ -235,12 +128,6 @@ public interface PlotPlatform

extends ILogger { */ void setGenerator(String world); - /** - * Gets the {@link InventoryUtil} class (used for implementation specific - * inventory guis). - */ - InventoryUtil initInventoryUtil(); - /** * Unregisters a {@link PlotPlayer} from cache e.g. if they have logged off. * @@ -259,49 +146,43 @@ public interface PlotPlatform

extends ILogger { GeneratorWrapper wrapPlotGenerator(String world, IndependentPlotGenerator generator); - /** - * Register the chunk processor which will clean out chunks that have too - * many block states or entities. - */ - void registerChunkProcessor(); - - /** - * Register the world initialization events (used to keep track of worlds - * being generated). - */ - void registerWorldEvents(); - /** * Usually HybridGen * * @return Default implementation generator */ - @NotNull IndependentPlotGenerator getDefaultGenerator(); + @NotNull default IndependentPlotGenerator getDefaultGenerator() { + return getInjector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)); + } List, Boolean>> getPluginIds(); - Actor getConsole(); - /** * Get the backup manager instance * * @return Backup manager */ - @NotNull BackupManager getBackupManager(); + @NotNull default BackupManager getBackupManager() { + return getInjector().getInstance(BackupManager.class); + } /** * Get the platform specific world manager * * @return World manager */ - @NotNull PlatformWorldManager getWorldManager(); + @NotNull default PlatformWorldManager getWorldManager() { + return getInjector().getInstance(PlatformWorldManager.class); + } /** * Get the player manager implementation for the platform * * @return Player manager */ - @NotNull PlayerManager, ? extends P> getPlayerManager(); + @NotNull default PlayerManager, ? extends P> getPlayerManager() { + return getInjector().getInstance(PlayerManager.class); + } /** * Get a platform world wrapper from a world name @@ -311,4 +192,38 @@ public interface PlotPlatform

extends ILogger { */ @NotNull World getPlatformWorld(@NotNull final String worldName); + /** + * Get the {@link com.google.inject.Injector} instance used by PlotSquared + * + * @return Injector instance + */ + @NotNull Injector getInjector(); + + /** + * Get the world utility implementation + * + * @return World utility + */ + @NotNull default WorldUtil getWorldUtil() { + return getInjector().getInstance(WorldUtil.class); + } + + /** + * Get the global block queue implementation + * + * @return Global block queue implementation + */ + @NotNull default GlobalBlockQueue getGlobalBlockQueue() { + return getInjector().getInstance(GlobalBlockQueue.class); + } + + /** + * Get the hybrid utility class + * + * @return Hybrid utility class + */ + @NotNull default HybridUtils getHybridUtils() { + return getInjector().getInstance(HybridUtils.class); + } + } diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 0796d40b4..dfc020d47 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -25,8 +25,6 @@ */ package com.plotsquared.core; -import com.plotsquared.core.command.WE_Anywhere; -import com.plotsquared.core.components.ComponentPresetManager; import com.plotsquared.core.configuration.Caption; import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.Captions; @@ -47,7 +45,6 @@ import com.plotsquared.core.generator.HybridPlotWorld; import com.plotsquared.core.generator.HybridUtils; import com.plotsquared.core.generator.IndependentPlotGenerator; import com.plotsquared.core.listener.PlotListener; -import com.plotsquared.core.listener.WESubscriber; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.plot.BlockBucket; @@ -65,21 +62,13 @@ import com.plotsquared.core.plot.world.DefaultPlotAreaManager; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.plot.world.SinglePlotAreaManager; -import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.util.ChatManager; -import com.plotsquared.core.util.ChunkManager; -import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.EventDispatcher; -import com.plotsquared.core.util.InventoryUtil; import com.plotsquared.core.util.LegacyConverter; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.ReflectionUtils; -import com.plotsquared.core.util.RegionManager; -import com.plotsquared.core.util.SchematicHandler; -import com.plotsquared.core.util.SetupUtils; import com.plotsquared.core.util.StringMan; -import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.logger.ILogger; import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.TaskManager; @@ -202,10 +191,6 @@ public class PlotSquared { "PlotSquared-" + platform + ".jar"); } } - TaskManager.IMP = this.platform.getTaskManager(); - - // World Util. Has to be done before config files are loaded - WorldUtil.IMP = this.platform.initWorldUtil(); if (!setupConfigs()) { return; @@ -215,24 +200,7 @@ public class PlotSquared { + ".use_THIS.yml"); Captions.load(this.translationFile); - // WorldEdit - if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) { - try { - if (this.platform.initWorldEdit()) { - PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + this.platform.getPluginName() - + " hooked into WorldEdit."); - this.worldedit = WorldEdit.getInstance(); - WorldEdit.getInstance().getEventBus().register(new WESubscriber(this.plotAreaManager)); - if (Settings.Enabled_Components.COMMANDS) { - new WE_Anywhere(); - } - - } - } catch (Throwable e) { - PlotSquared.debug( - "Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master"); - } - } + this.worldedit = WorldEdit.getInstance(); // Create Event utility class this.eventDispatcher = new EventDispatcher(this.worldedit); @@ -263,85 +231,11 @@ public class PlotSquared { // Comments CommentManager.registerDefaultInboxes(); - // Kill entities - if (Settings.Enabled_Components.KILL_ROAD_MOBS - || Settings.Enabled_Components.KILL_ROAD_VEHICLES) { - this.platform.runEntityTask(); - } - if (Settings.Enabled_Components.EVENTS) { - this.platform.registerPlayerEvents(); - } - // Required - this.platform.registerWorldEvents(); - if (Settings.Enabled_Components.CHUNK_PROCESSOR) { - this.platform.registerChunkProcessor(); - } + startExpiryTasks(); - // create Hybrid utility class - HybridUtils.manager = this.platform.initHybridUtils(); - // Inventory utility class - InventoryUtil.manager = this.platform.initInventoryUtil(); - // create setup util class - SetupUtils.manager = this.platform.initSetupUtils(); - // Set block - GlobalBlockQueue.IMP = - new GlobalBlockQueue(this.platform.initBlockQueue(), 1, Settings.QUEUE.TARGET_TIME); - GlobalBlockQueue.IMP.runTask(); - // Set chunk - ChunkManager.manager = this.platform.initChunkManager(); - RegionManager.manager = this.platform.initRegionManager(); - // Schematic handler - SchematicHandler.manager = this.platform.initSchematicHandler(); - // Chat + + // This is getting removed so I won't even bother migrating it ChatManager.manager = this.platform.initChatManager(); - // Commands - if (Settings.Enabled_Components.COMMANDS) { - this.platform.registerCommands(); - } - // Economy - if (Settings.Enabled_Components.ECONOMY) { - TaskManager.runTask(() -> EconHandler.initializeEconHandler()); - } - - if (Settings.Enabled_Components.COMPONENT_PRESETS) { - try { - new ComponentPresetManager(); - } catch (final Exception e) { - PlotSquared.log(Captions.PREFIX + "Failed to initialize the preset system"); - e.printStackTrace(); - } - } - - // World generators: - final ConfigurationSection section = this.worldConfiguration.getConfigurationSection("worlds"); - if (section != null) { - for (String world : section.getKeys(false)) { - if (world.equals("CheckingPlotSquaredGenerator")) { - continue; - } - if (WorldUtil.IMP.isWorld(world)) { - this.platform.setGenerator(world); - } - } - TaskManager.runTaskLater(() -> { - for (String world : section.getKeys(false)) { - if (world.equals("CheckingPlotSquaredGenerator")) { - continue; - } - if (!WorldUtil.IMP.isWorld(world) && !world.equals("*")) { - debug("`" + world + "` was not properly loaded - " + this.platform.getPluginName() - + " will now try to load it properly: "); - debug( - " - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml"); - debug( - " - Your world management plugin may be faulty (or non existent)"); - debug( - " This message may also be a false positive and could be ignored."); - PlotSquared.this.platform.setGenerator(world); - } - } - }, 1); - } // Copy files copyFile("addplots.js", Settings.Paths.SCRIPTS); @@ -552,7 +446,7 @@ public class PlotSquared { PlotSquared.debug(" Regions: " + regions.size()); PlotSquared.debug(" Chunks: " + chunks.size()); HybridUtils.UPDATE = true; - HybridUtils.manager.scheduleRoadUpdate(plotArea, regions, height, chunks); + PlotSquared.platform().getHybridUtils().scheduleRoadUpdate(plotArea, regions, height, chunks); } catch (IOException | ClassNotFoundException e) { PlotSquared.log(Captions.PREFIX + "Error restarting road regeneration."); e.printStackTrace(); diff --git a/Core/src/main/java/com/plotsquared/core/backup/NullBackupManager.java b/Core/src/main/java/com/plotsquared/core/backup/NullBackupManager.java index 9ffc223c9..fb0e33fda 100644 --- a/Core/src/main/java/com/plotsquared/core/backup/NullBackupManager.java +++ b/Core/src/main/java/com/plotsquared/core/backup/NullBackupManager.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.backup; +import com.google.inject.Singleton; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -37,7 +38,7 @@ import java.util.Objects; /** * {@inheritDoc} */ -public class NullBackupManager implements BackupManager { +@Singleton public class NullBackupManager implements BackupManager { @Override @NotNull public BackupProfile getProfile(@NotNull Plot plot) { return new NullBackupProfile(); diff --git a/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java b/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java index c71057ab5..27e8b0071 100644 --- a/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java +++ b/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java @@ -25,13 +25,14 @@ */ package com.plotsquared.core.backup; +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.schematic.Schematic; import com.plotsquared.core.util.SchematicHandler; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; -import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -51,12 +52,20 @@ import java.util.concurrent.CompletableFuture; * plot, which is used to store and retrieve plot backups * {@inheritDoc} */ -@RequiredArgsConstructor public class PlayerBackupProfile implements BackupProfile { private final UUID owner; private final Plot plot; private final BackupManager backupManager; + private final SchematicHandler schematicHandler; + + @Inject public PlayerBackupProfile(@Assisted @NotNull final UUID owner, @Assisted @NotNull final Plot plot, + @NotNull final BackupManager backupManager, @NotNull final SchematicHandler schematicHandler) { + this.owner = owner; + this.plot = plot; + this.backupManager = backupManager; + this.schematicHandler = schematicHandler; + } private volatile List backupCache; private final Object backupLock = new Object(); @@ -141,7 +150,7 @@ public class PlayerBackupProfile implements BackupProfile { backups.get(backups.size() - 1).delete(); } final List plots = Collections.singletonList(plot); - final boolean result = SchematicHandler.manager.exportAll(plots, getBackupDirectory().toFile(), + final boolean result = this.schematicHandler.exportAll(plots, getBackupDirectory().toFile(), "%world%-%id%-" + System.currentTimeMillis(), () -> future.complete(new Backup(this, System.currentTimeMillis(), null))); if (!result) { @@ -161,14 +170,14 @@ public class PlayerBackupProfile implements BackupProfile { TaskManager.runTaskAsync(() -> { Schematic schematic = null; try { - schematic = SchematicHandler.manager.getSchematic(backup.getFile().toFile()); + schematic = this.schematicHandler.getSchematic(backup.getFile().toFile()); } catch (SchematicHandler.UnsupportedFormatException e) { e.printStackTrace(); } if (schematic == null) { future.completeExceptionally(new IllegalArgumentException("The backup is non-existent or not in the correct format")); } else { - SchematicHandler.manager.paste(schematic, plot, 0, 1, 0, false, new RunnableVal() { + this.schematicHandler.paste(schematic, plot, 0, 1, 0, false, new RunnableVal() { @Override public void run(Boolean value) { if (value) { future.complete(null); diff --git a/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java b/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java index 468ee23ac..68d75e810 100644 --- a/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java +++ b/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java @@ -27,9 +27,12 @@ package com.plotsquared.core.backup; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import com.google.inject.Inject; +import com.google.inject.Singleton; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.inject.factory.PlayerBackupProfileFactory; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.util.task.TaskManager; @@ -48,15 +51,17 @@ import java.util.concurrent.TimeUnit; /** * {@inheritDoc} */ -@RequiredArgsConstructor public class SimpleBackupManager implements BackupManager { +@RequiredArgsConstructor @Singleton public class SimpleBackupManager implements BackupManager { @Getter private final Path backupPath; private final boolean automaticBackup; @Getter private final int backupLimit; private final Cache backupProfileCache = CacheBuilder.newBuilder() .expireAfterAccess(3, TimeUnit.MINUTES).build(); + private final PlayerBackupProfileFactory playerBackupProfileFactory; - public SimpleBackupManager() throws Exception { + @Inject public SimpleBackupManager(@NotNull final PlayerBackupProfileFactory playerBackupProfileFactory) throws Exception { + this.playerBackupProfileFactory = playerBackupProfileFactory; this.backupPath = Objects.requireNonNull(PlotSquared.platform()).getDirectory().toPath().resolve("backups"); if (!Files.exists(backupPath)) { Files.createDirectory(backupPath); @@ -68,9 +73,9 @@ import java.util.concurrent.TimeUnit; @Override @NotNull public BackupProfile getProfile(@NotNull final Plot plot) { if (plot.hasOwner() && !plot.isMerged()) { try { - return backupProfileCache.get(new PlotCacheKey(plot), () -> new PlayerBackupProfile(plot.getOwnerAbs(), plot, this)); + return backupProfileCache.get(new PlotCacheKey(plot), () -> this.playerBackupProfileFactory.create(plot.getOwnerAbs(), plot)); } catch (ExecutionException e) { - final BackupProfile profile = new PlayerBackupProfile(plot.getOwnerAbs(), plot, this); + final BackupProfile profile = this.playerBackupProfileFactory.create(plot.getOwnerAbs(), plot); this.backupProfileCache.put(new PlotCacheKey(plot), profile); return profile; } diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java index 0465a96ac..9fa17910f 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Area.java +++ b/Core/src/main/java/com/plotsquared/core/command/Area.java @@ -26,8 +26,8 @@ package com.plotsquared.core.command; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.annoations.WorldConfig; -import com.plotsquared.core.annoations.WorldFile; +import com.plotsquared.core.inject.annotations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldFile; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; diff --git a/Core/src/main/java/com/plotsquared/core/command/Backup.java b/Core/src/main/java/com/plotsquared/core/command/Backup.java index 66af54666..6ddeb7e91 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Backup.java +++ b/Core/src/main/java/com/plotsquared/core/command/Backup.java @@ -25,7 +25,8 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; +import com.google.inject.Inject; +import com.plotsquared.core.backup.BackupManager; import com.plotsquared.core.backup.BackupProfile; import com.plotsquared.core.backup.NullBackupProfile; import com.plotsquared.core.backup.PlayerBackupProfile; @@ -35,6 +36,7 @@ import com.plotsquared.core.plot.Plot; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; +import org.jetbrains.annotations.NotNull; import java.nio.file.Files; import java.time.Instant; @@ -60,8 +62,11 @@ import java.util.stream.Stream; permission = "plots.backup") public final class Backup extends Command { - public Backup() { + private final BackupManager backupManager; + + @Inject public Backup(@NotNull final BackupManager backupManager) { super(MainCommand.getInstance(), true); + this.backupManager = backupManager; } private static boolean sendMessage(PlotPlayer player, Captions message, Object... args) { @@ -90,8 +95,7 @@ public final class Backup extends Command { final Plot plot = player.getCurrentPlot(); if (plot != null) { - final BackupProfile backupProfile = - Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(plot); + final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot)); if (backupProfile instanceof PlayerBackupProfile) { final CompletableFuture> backupList = backupProfile.listBackups(); @@ -135,8 +139,7 @@ public final class Backup extends Command { .hasPermission(player, Captions.PERMISSION_ADMIN_BACKUP_OTHER)) { sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_ADMIN_BACKUP_OTHER); } else { - final BackupProfile backupProfile = - Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(plot); + final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot)); if (backupProfile instanceof NullBackupProfile) { sendMessage(player, Captions.BACKUP_IMPOSSIBLE, Captions.GENERIC_OTHER.getTranslated()); @@ -175,8 +178,7 @@ public final class Backup extends Command { .hasPermission(player, Captions.PERMISSION_ADMIN_BACKUP_OTHER)) { sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_ADMIN_BACKUP_OTHER); } else { - final BackupProfile backupProfile = - Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(plot); + final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot)); if (backupProfile instanceof NullBackupProfile) { sendMessage(player, Captions.BACKUP_IMPOSSIBLE, Captions.GENERIC_OTHER.getTranslated()); @@ -237,8 +239,7 @@ public final class Backup extends Command { sendMessage(player, Captions.NOT_A_NUMBER, args[0]); return; } - final BackupProfile backupProfile = - Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(plot); + final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot)); if (backupProfile instanceof NullBackupProfile) { sendMessage(player, Captions.BACKUP_IMPOSSIBLE, Captions.GENERIC_OTHER.getTranslated()); diff --git a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java index 4c7c78b20..bd4216e12 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java @@ -26,7 +26,7 @@ package com.plotsquared.core.command; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.annoations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.database.Database; diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java index aa1c80b21..524d3daa9 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java @@ -28,8 +28,8 @@ package com.plotsquared.core.command; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.annoations.ConfigFile; -import com.plotsquared.core.annoations.WorldFile; +import com.plotsquared.core.inject.annotations.ConfigFile; +import com.plotsquared.core.inject.annotations.WorldFile; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.player.PlotPlayer; diff --git a/Core/src/main/java/com/plotsquared/core/command/Reload.java b/Core/src/main/java/com/plotsquared/core/command/Reload.java index 0bf49442c..2fc3bdb9a 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Reload.java +++ b/Core/src/main/java/com/plotsquared/core/command/Reload.java @@ -26,8 +26,8 @@ package com.plotsquared.core.command; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.annoations.WorldConfig; -import com.plotsquared.core.annoations.WorldFile; +import com.plotsquared.core.inject.annotations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldFile; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.MemorySection; diff --git a/Core/src/main/java/com/plotsquared/core/command/Template.java b/Core/src/main/java/com/plotsquared/core/command/Template.java index 14290282d..e8a1515ef 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Template.java +++ b/Core/src/main/java/com/plotsquared/core/command/Template.java @@ -26,8 +26,8 @@ package com.plotsquared.core.command; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.annoations.WorldConfig; -import com.plotsquared.core.annoations.WorldFile; +import com.plotsquared.core.inject.annotations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldFile; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationSection; diff --git a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java index 915a30bf1..48364b10e 100644 --- a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java +++ b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.components; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.backup.BackupManager; import com.plotsquared.core.command.MainCommand; @@ -36,13 +37,14 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotInventory; import com.plotsquared.core.plot.PlotItemStack; -import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.InventoryUtil; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.PatternUtil; import com.plotsquared.core.util.Permissions; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.item.ItemTypes; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; @@ -59,8 +61,13 @@ public class ComponentPresetManager { private final List presets; private final String guiName; + private final EconHandler econHandler; + private final InventoryUtil inventoryUtil; - public ComponentPresetManager() { + @Inject public ComponentPresetManager(@Nullable final EconHandler econHandler, @NotNull final + InventoryUtil inventoryUtil) { + this.econHandler = econHandler; + this.inventoryUtil = inventoryUtil; final File file = new File(Objects.requireNonNull(PlotSquared.platform()).getDirectory(), "components.yml"); if (!file.exists()) { boolean created = false; @@ -144,7 +151,7 @@ public class ComponentPresetManager { allowedPresets.add(componentPreset); } final int size = (int) Math.ceil((double) allowedPresets.size() / 9.0D); - final PlotInventory plotInventory = new PlotInventory(player, size, this.guiName) { + final PlotInventory plotInventory = new PlotInventory(this.inventoryUtil, player, size, this.guiName) { @Override public boolean onClick(final int index) { if (!player.getCurrentPlot().equals(plot)) { return false; @@ -170,12 +177,12 @@ public class ComponentPresetManager { return false; } - if (componentPreset.getCost() > 0.0D && EconHandler.getEconHandler() != null && plot.getArea().useEconomy()) { - if (EconHandler.getEconHandler().getMoney(player) < componentPreset.getCost()) { + if (componentPreset.getCost() > 0.0D && econHandler != null && plot.getArea().useEconomy()) { + if (econHandler.getMoney(player) < componentPreset.getCost()) { Captions.PRESET_CANNOT_AFFORD.send(player); return false; } else { - EconHandler.getEconHandler().withdrawMoney(player, componentPreset.getCost()); + econHandler.withdrawMoney(player, componentPreset.getCost()); Captions.REMOVED_BALANCE.send(player, componentPreset.getCost() + ""); } } @@ -186,7 +193,7 @@ public class ComponentPresetManager { current.setComponent(componentPreset.getComponent().name(), pattern); } MainUtil.sendMessage(player, Captions.GENERATING_COMPONENT); - GlobalBlockQueue.IMP.addEmptyTask(plot::removeRunning); + PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(plot::removeRunning); }); return false; } @@ -196,7 +203,7 @@ public class ComponentPresetManager { for (int i = 0; i < allowedPresets.size(); i++) { final ComponentPreset preset = allowedPresets.get(i); final List lore = new ArrayList<>(); - if (preset.getCost() > 0 && EconHandler.getEconHandler() != null && plot.getArea().useEconomy()){ + if (preset.getCost() > 0 && this.econHandler != null && plot.getArea().useEconomy()){ lore.add(Captions.PRESET_LORE_COST.getTranslated().replace("%cost%", String.format("%.2f", preset.getCost()))); } diff --git a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java index 4226fc50b..f5a7636d0 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java @@ -27,7 +27,7 @@ package com.plotsquared.core.database; import com.google.common.base.Charsets; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.annoations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.Settings; @@ -1842,7 +1842,7 @@ public class SQLManager implements AbstractDB { } Plot p = new Plot(plot_id, user, new HashSet<>(), new HashSet<>(), new HashSet<>(), "", null, null, null, - new boolean[] {false, false, false, false}, time, id, this.eventDispatcher, this.plotListener); + new boolean[] {false, false, false, false}, time, id); HashMap map = newPlots.get(areaID); if (map != null) { Plot last = map.put(p.getId(), p); diff --git a/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java b/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java index 6c2f2fbd2..73bbb157e 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java @@ -32,7 +32,6 @@ import com.plotsquared.core.plot.PlotAreaTerrainType; import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotManager; import com.plotsquared.core.queue.AreaBoundDelegateLocalBlockQueue; -import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.queue.LocationOffsetDelegateLocalBlockQueue; import com.plotsquared.core.queue.ScopedLocalBlockQueue; @@ -87,7 +86,7 @@ public class AugmentedUtils { IndependentPlotGenerator generator = area.getGenerator(); // Mask if (queue == null) { - queue = GlobalBlockQueue.IMP.getNewQueue(world, false); + queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false); queue.setChunkObject(chunkObject); } LocalBlockQueue primaryMask; diff --git a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java index b1860b0f9..4536aaa74 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java @@ -25,7 +25,7 @@ */ package com.plotsquared.core.generator; -import com.plotsquared.core.annoations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; diff --git a/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java index 3ba66db50..aa4023d27 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java @@ -25,13 +25,16 @@ */ package com.plotsquared.core.generator; -import com.plotsquared.core.annoations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; +import com.plotsquared.core.queue.GlobalBlockQueue; +import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.EventDispatcher; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public abstract class GridPlotWorld extends PlotArea { @@ -39,7 +42,9 @@ public abstract class GridPlotWorld extends PlotArea { public GridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator, PlotId min, PlotId max, @NotNull final EventDispatcher eventDispatcher, @NotNull final - PlotListener plotListener, @WorldConfig @NotNull final YamlConfiguration worldConfiguration) { - super(worldName, id, generator, min, max, eventDispatcher, plotListener, worldConfiguration); + PlotListener plotListener, @WorldConfig @NotNull final YamlConfiguration worldConfiguration, + @NotNull final GlobalBlockQueue blockQueue, + @Nullable final EconHandler econHandler) { + super(worldName, id, generator, min, max, eventDispatcher, plotListener, worldConfiguration, blockQueue, econHandler); } } diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java index c7191f4c3..2d137aa37 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java @@ -26,8 +26,9 @@ package com.plotsquared.core.generator; import com.google.common.base.Preconditions; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.annoations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.listener.PlotListener; @@ -48,7 +49,7 @@ public class HybridGen extends IndependentPlotGenerator { private final PlotListener plotListener; private final YamlConfiguration worldConfiguration; - public HybridGen(@NotNull final EventDispatcher eventDispatcher, + @Inject public HybridGen(@NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener, @WorldConfig @NotNull final YamlConfiguration worldConfiguration) { this.eventDispatcher = eventDispatcher; diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java index 246c89f3c..f883eb8a2 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -26,7 +26,7 @@ package com.plotsquared.core.generator; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.annoations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.Settings; diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java index 4fe97ddc1..cbba50067 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.generator; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.events.PlotFlagAddEvent; @@ -76,9 +77,8 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -public abstract class HybridUtils { +public class HybridUtils { - public static HybridUtils manager; public static Set regions; public static int height; public static Set chunks = new HashSet<>(); @@ -86,14 +86,26 @@ public abstract class HybridUtils { public static boolean UPDATE = false; private final PlotAreaManager plotAreaManager; + private final ChunkManager chunkManager; + private final GlobalBlockQueue blockQueue; + private final WorldUtil worldUtil; + private final RegionManager regionManager; + private final SchematicHandler schematicHandler; - public HybridUtils(@NotNull final PlotAreaManager plotAreaManager) { + @Inject public HybridUtils(@NotNull final PlotAreaManager plotAreaManager, + @NotNull final ChunkManager chunkManager, @NotNull final GlobalBlockQueue blockQueue, + @NotNull final WorldUtil worldUtil, @NotNull final RegionManager regionManager, @NotNull final SchematicHandler schematicHandler) { this.plotAreaManager = plotAreaManager; + this.chunkManager = chunkManager; + this.blockQueue = blockQueue; + this.worldUtil = worldUtil; + this.regionManager = regionManager; + this.schematicHandler = schematicHandler; } - public static boolean regeneratePlotWalls(final PlotArea area) { + public void regeneratePlotWalls(final PlotArea area) { PlotManager plotManager = area.getPlotManager(); - return plotManager.regenerateAllPlotWalls(); + plotManager.regenerateAllPlotWalls(); } public void analyzeRegion(final String world, final CuboidRegion region, @@ -111,7 +123,7 @@ public abstract class HybridUtils { * */ TaskManager.runTaskAsync(() -> { - final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false); + final LocalBlockQueue queue = blockQueue.getNewQueue(world, false); final BlockVector3 bot = region.getMinimumPoint(); final BlockVector3 top = region.getMaximumPoint(); @@ -365,7 +377,7 @@ public abstract class HybridUtils { for (int z = z1; z <= z2; z++) { BlockState block = queue.getBlock(x, y, z); boolean same = - Arrays.stream(blocks).anyMatch(p -> WorldUtil.IMP.isBlockSame(block, p)); + Arrays.stream(blocks).anyMatch(p -> this.worldUtil.isBlockSame(block, p)); if (!same) { count++; } @@ -392,7 +404,7 @@ public abstract class HybridUtils { return false; } HybridUtils.UPDATE = true; - Set regions = RegionManager.manager.getChunkChunks(area.getWorldName()); + Set regions = this.regionManager.getChunkChunks(area.getWorldName()); return scheduleRoadUpdate(area, regions, extend, new HashSet<>()); } @@ -424,7 +436,7 @@ public abstract class HybridUtils { if (!regenedRoad) { PlotSquared.debug("Failed to regenerate roads."); } - ChunkManager.manager.unloadChunk(area.getWorldName(), chunk, true); + chunkManager.unloadChunk(area.getWorldName(), chunk, true); } PlotSquared.debug("Cancelled road task"); return; @@ -460,7 +472,7 @@ public abstract class HybridUtils { } } if (!chunks.isEmpty()) { - TaskManager.IMP.sync(new RunnableVal() { + TaskManager.getImplementation().sync(new RunnableVal() { @Override public void run(Object value) { long start = System.currentTimeMillis(); Iterator iterator = chunks.iterator(); @@ -489,15 +501,14 @@ public abstract class HybridUtils { int sz = loc.getZ() << 5; for (int x = sx; x < sx + 32; x++) { for (int z = sz; z < sz + 32; z++) { - ChunkManager.manager - .unloadChunk(area.getWorldName(), BlockVector2.at(x, z), + chunkManager.unloadChunk(area.getWorldName(), BlockVector2.at(x, z), true); } } PlotSquared.debug(" - Potentially skipping 1024 chunks"); PlotSquared.debug(" - TODO: recommend chunkster if corrupt"); } - GlobalBlockQueue.IMP.addEmptyTask(() -> TaskManager.runTaskLater(task, 20)); + blockQueue.addEmptyTask(() -> TaskManager.runTaskLater(task, 20)); }); } } @@ -507,7 +518,7 @@ public abstract class HybridUtils { public boolean setupRoadSchematic(Plot plot) { final String world = plot.getWorldName(); - final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false); + final LocalBlockQueue queue = blockQueue.getNewQueue(world, false); Location bot = plot.getBottomAbs().subtract(1, 0, 1); Location top = plot.getTopAbs(); final HybridPlotWorld plotworld = (HybridPlotWorld) plot.getArea(); @@ -531,13 +542,12 @@ public abstract class HybridUtils { "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.getArea() .toString() + File.separator; - SchematicHandler.manager.getCompoundTag(world, sideRoad, new RunnableVal() { + this.schematicHandler.getCompoundTag(world, sideRoad, new RunnableVal() { @Override public void run(CompoundTag value) { - SchematicHandler.manager.save(value, dir + "sideroad.schem"); - SchematicHandler.manager - .getCompoundTag(world, intersection, new RunnableVal() { + schematicHandler.save(value, dir + "sideroad.schem"); + schematicHandler.getCompoundTag(world, intersection, new RunnableVal() { @Override public void run(CompoundTag value) { - SchematicHandler.manager.save(value, dir + "intersection.schem"); + schematicHandler.save(value, dir + "intersection.schem"); plotworld.ROAD_SCHEMATIC_ENABLED = true; try { plotworld.setupSchematics(); @@ -595,9 +605,9 @@ public abstract class HybridUtils { z -= plotWorld.ROAD_OFFSET_Z; final int finalX = x; final int finalZ = z; - LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(plotWorld.getWorldName(), false); + LocalBlockQueue queue = this.blockQueue.getNewQueue(plotWorld.getWorldName(), false); if (id1 == null || id2 == null || id1 != id2) { - ChunkManager.manager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> { + this.chunkManager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> { if (id1 != null) { Plot p1 = area.getPlotAbs(id1); if (p1 != null && p1.hasOwner() && p1.isMerged()) { diff --git a/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java b/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java index 94c9da1ea..6be1db74d 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.generator; +import com.google.inject.Inject; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; @@ -47,7 +48,7 @@ public class SingleWorldGenerator extends IndependentPlotGenerator { private final PlotAreaManager plotAreaManager; - public SingleWorldGenerator(@NotNull final PlotAreaManager plotAreaManager) { + @Inject public SingleWorldGenerator(@NotNull final PlotAreaManager plotAreaManager) { this.plotAreaManager = plotAreaManager; } diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java index 7d026f59a..b293558f9 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java @@ -26,7 +26,7 @@ package com.plotsquared.core.generator; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.annoations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.listener.PlotListener; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitHybridUtils.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/BackgroundPipeline.java similarity index 78% rename from Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitHybridUtils.java rename to Core/src/main/java/com/plotsquared/core/inject/annotations/BackgroundPipeline.java index 4c9b40d85..28f9f0ed0 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitHybridUtils.java +++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/BackgroundPipeline.java @@ -23,16 +23,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.plotsquared.bukkit.generator; +package com.plotsquared.core.inject.annotations; -import com.plotsquared.core.generator.HybridUtils; -import com.plotsquared.core.plot.world.PlotAreaManager; -import org.jetbrains.annotations.NotNull; - -public class BukkitHybridUtils extends HybridUtils { - - public BukkitHybridUtils(@NotNull PlotAreaManager plotAreaManager) { - super(plotAreaManager); - } +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +@Target({ElementType.PARAMETER, ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface BackgroundPipeline { } diff --git a/Core/src/main/java/com/plotsquared/core/annoations/ConfigFile.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/ConfigFile.java similarity index 96% rename from Core/src/main/java/com/plotsquared/core/annoations/ConfigFile.java rename to Core/src/main/java/com/plotsquared/core/inject/annotations/ConfigFile.java index a74d13618..69d5bc1fd 100644 --- a/Core/src/main/java/com/plotsquared/core/annoations/ConfigFile.java +++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/ConfigFile.java @@ -23,7 +23,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.plotsquared.core.annoations; +package com.plotsquared.core.inject.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/Core/src/main/java/com/plotsquared/core/inject/annotations/ConsoleActor.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/ConsoleActor.java new file mode 100644 index 000000000..6c0288673 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/ConsoleActor.java @@ -0,0 +1,11 @@ +package com.plotsquared.core.inject.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +public @interface ConsoleActor { +} diff --git a/Core/src/main/java/com/plotsquared/core/inject/annotations/DefaultGenerator.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/DefaultGenerator.java new file mode 100644 index 000000000..6a5842ec5 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/DefaultGenerator.java @@ -0,0 +1,11 @@ +package com.plotsquared.core.inject.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.PARAMETER, ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface DefaultGenerator { +} diff --git a/Core/src/main/java/com/plotsquared/core/inject/annotations/ImpromptuPipeline.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/ImpromptuPipeline.java new file mode 100644 index 000000000..c218b4580 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/ImpromptuPipeline.java @@ -0,0 +1,36 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.core.inject.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.PARAMETER, ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface ImpromptuPipeline { +} diff --git a/Core/src/main/java/com/plotsquared/core/annoations/WorldConfig.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/WorldConfig.java similarity index 93% rename from Core/src/main/java/com/plotsquared/core/annoations/WorldConfig.java rename to Core/src/main/java/com/plotsquared/core/inject/annotations/WorldConfig.java index 2d10323cd..115f71d48 100644 --- a/Core/src/main/java/com/plotsquared/core/annoations/WorldConfig.java +++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/WorldConfig.java @@ -23,14 +23,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.plotsquared.core.annoations; +package com.plotsquared.core.inject.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -@Target(ElementType.PARAMETER) +@Target({ElementType.PARAMETER, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface WorldConfig { } diff --git a/Core/src/main/java/com/plotsquared/core/annoations/WorldFile.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/WorldFile.java similarity index 93% rename from Core/src/main/java/com/plotsquared/core/annoations/WorldFile.java rename to Core/src/main/java/com/plotsquared/core/inject/annotations/WorldFile.java index e01198f3d..47cfc932a 100644 --- a/Core/src/main/java/com/plotsquared/core/annoations/WorldFile.java +++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/WorldFile.java @@ -23,14 +23,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.plotsquared.core.annoations; +package com.plotsquared.core.inject.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -@Target(ElementType.PARAMETER) +@Target({ElementType.PARAMETER, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface WorldFile { } diff --git a/Core/src/main/java/com/plotsquared/core/inject/factory/PlayerBackupProfileFactory.java b/Core/src/main/java/com/plotsquared/core/inject/factory/PlayerBackupProfileFactory.java new file mode 100644 index 000000000..67411d76f --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/inject/factory/PlayerBackupProfileFactory.java @@ -0,0 +1,13 @@ +package com.plotsquared.core.inject.factory; + +import com.plotsquared.core.backup.PlayerBackupProfile; +import com.plotsquared.core.plot.Plot; +import org.jetbrains.annotations.NotNull; + +import java.util.UUID; + +public interface PlayerBackupProfileFactory { + + PlayerBackupProfile create(@NotNull UUID uuid, @NotNull Plot plot); + +} diff --git a/Core/src/main/java/com/plotsquared/core/inject/modules/PlotSquaredModule.java b/Core/src/main/java/com/plotsquared/core/inject/modules/PlotSquaredModule.java new file mode 100644 index 000000000..236ef960c --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/inject/modules/PlotSquaredModule.java @@ -0,0 +1,59 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.core.inject.modules; + +import com.google.inject.AbstractModule; +import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.configuration.file.YamlConfiguration; +import com.plotsquared.core.inject.annotations.BackgroundPipeline; +import com.plotsquared.core.inject.annotations.ConfigFile; +import com.plotsquared.core.inject.annotations.ImpromptuPipeline; +import com.plotsquared.core.inject.annotations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldFile; +import com.plotsquared.core.listener.PlotListener; +import com.plotsquared.core.plot.world.PlotAreaManager; +import com.plotsquared.core.util.EventDispatcher; +import com.plotsquared.core.uuid.UUIDPipeline; +import com.sk89q.worldedit.WorldEdit; + +import java.io.File; + +public class PlotSquaredModule extends AbstractModule { + + @Override protected void configure() { + final PlotSquared plotSquared = PlotSquared.get(); + bind(YamlConfiguration.class).annotatedWith(WorldConfig.class).toInstance(plotSquared.getWorldConfiguration()); + bind(File.class).annotatedWith(WorldFile.class).toInstance(plotSquared.getWorldsFile()); + bind(File.class).annotatedWith(ConfigFile.class).toInstance(plotSquared.getConfigFile()); + bind(PlotAreaManager.class).toInstance(plotSquared.getPlotAreaManager()); + bind(PlotListener.class).toInstance(plotSquared.getPlotListener()); + bind(UUIDPipeline.class).annotatedWith(ImpromptuPipeline.class).toInstance(plotSquared.getImpromptuUUIDPipeline()); + bind(UUIDPipeline.class).annotatedWith(BackgroundPipeline.class).toInstance(plotSquared.getBackgroundUUIDPipeline()); + bind(WorldEdit.class).toInstance(WorldEdit.getInstance()); + bind(EventDispatcher.class).toInstance(plotSquared.getEventDispatcher()); + } + +} diff --git a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java index 5db405f98..46c1747aa 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -59,27 +59,30 @@ import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.StringMan; -import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; -import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.UUID; -@RequiredArgsConstructor public class PlotListener { +public class PlotListener { private final HashMap feedRunnable = new HashMap<>(); private final HashMap healRunnable = new HashMap<>(); private final EventDispatcher eventDispatcher; - + + public PlotListener(@Nullable final EventDispatcher eventDispatcher) { + this.eventDispatcher = eventDispatcher; + } + public void startRunnable() { TaskManager.runTaskRepeat(() -> { if (!healRunnable.isEmpty()) { @@ -90,15 +93,14 @@ import java.util.UUID; ++value.count; if (value.count == value.interval) { value.count = 0; - PlotPlayer player = WorldUtil.IMP.wrapPlayer(entry.getKey()); + PlotPlayer player = PlotPlayer.wrap(entry.getKey()); if (player == null) { iterator.remove(); continue; } - double level = WorldUtil.IMP.getHealth(player); + double level = PlotSquared.platform().getWorldUtil().getHealth(player); if (level != value.max) { - WorldUtil.IMP - .setHealth(player, Math.min(level + value.amount, value.max)); + PlotSquared.platform().getWorldUtil().setHealth(player, Math.min(level + value.amount, value.max)); } } } @@ -111,15 +113,14 @@ import java.util.UUID; ++value.count; if (value.count == value.interval) { value.count = 0; - PlotPlayer player = WorldUtil.IMP.wrapPlayer(entry.getKey()); + PlotPlayer player = PlotSquared.platform().getWorldUtil().wrapPlayer(entry.getKey()); if (player == null) { iterator.remove(); continue; } - int level = WorldUtil.IMP.getFoodLevel(player); + int level = PlotSquared.platform().getWorldUtil().getFoodLevel(player); if (level != value.max) { - WorldUtil.IMP - .setFoodLevel(player, Math.min(level + value.amount, value.max)); + PlotSquared.platform().getWorldUtil().setFoodLevel(player, Math.min(level + value.amount, value.max)); } } } diff --git a/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java b/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java index 0df6c3a3c..fb1324ad7 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java +++ b/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java @@ -44,6 +44,7 @@ import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; +import org.jetbrains.annotations.NotNull; import java.lang.reflect.Field; import java.util.HashMap; @@ -55,17 +56,19 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { private final Set mask; private final String world; private final int max; + private final WorldUtil worldUtil; + int Ecount = 0; boolean Eblocked = false; private int count; private Extent parent; private Map tileEntityCount = new HashMap<>(); - public ProcessedWEExtent(String world, Set mask, int max, Extent child, - Extent parent) { + public ProcessedWEExtent(String world, Set mask, int max, Extent child, Extent parent, @NotNull final WorldUtil worldUtil) { super(child); this.mask = mask; this.world = world; + this.worldUtil = worldUtil; if (max == -1) { max = Integer.MAX_VALUE; } @@ -92,10 +95,10 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { public > boolean setBlock(BlockVector3 location, T block) throws WorldEditException { - final boolean isTile = WorldUtil.IMP.getTileEntityTypes().contains(block.getBlockType()); + final boolean isTile = this.worldUtil.getTileEntityTypes().contains(block.getBlockType()); if (isTile) { final Integer[] tileEntityCount = this.tileEntityCount.computeIfAbsent(getChunkKey(location), - key -> new Integer[] {WorldUtil.IMP.getTileEntityCount(world, + key -> new Integer[] {this.worldUtil.getTileEntityCount(world, BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4))}); if (tileEntityCount[0] >= Settings.Chunk_Processor.MAX_TILES) { return false; diff --git a/Core/src/main/java/com/plotsquared/core/listener/WESubscriber.java b/Core/src/main/java/com/plotsquared/core/listener/WESubscriber.java index a39e28bf2..bac7bd5ec 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/WESubscriber.java +++ b/Core/src/main/java/com/plotsquared/core/listener/WESubscriber.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.listener; +import com.google.inject.Inject; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.player.PlotPlayer; @@ -33,6 +34,7 @@ import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.WEManager; +import com.plotsquared.core.util.WorldUtil; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.extent.EditSessionEvent; @@ -50,9 +52,11 @@ import java.util.Set; public class WESubscriber { private final PlotAreaManager plotAreaManager; - - public WESubscriber(@NotNull final PlotAreaManager plotAreaManager) { + private final WorldUtil worldUtil; + + @Inject public WESubscriber(@NotNull final PlotAreaManager plotAreaManager, @NotNull final WorldUtil worldUtil) { this.plotAreaManager = plotAreaManager; + this.worldUtil = worldUtil; } @Subscribe(priority = Priority.VERY_EARLY) public void onEditSession(EditSessionEvent event) { @@ -99,7 +103,7 @@ public class WESubscriber { if (this.plotAreaManager.hasPlotArea(world)) { event.setExtent( new ProcessedWEExtent(world, mask, event.getMaxBlocks(), event.getExtent(), - event.getExtent())); + event.getExtent(), this.worldUtil)); } } else if (this.plotAreaManager.hasPlotArea(world)) { event.setExtent(new WEExtent(mask, event.getExtent())); diff --git a/Core/src/main/java/com/plotsquared/core/location/Location.java b/Core/src/main/java/com/plotsquared/core/location/Location.java index 7c3e7ae04..b3a72c237 100644 --- a/Core/src/main/java/com/plotsquared/core/location/Location.java +++ b/Core/src/main/java/com/plotsquared/core/location/Location.java @@ -267,7 +267,7 @@ public final class Location implements Comparable { /** * Check whether or not the location belongs to a plot area * - * @return {@code true} if the location belongs to a plot area, else {@link false} + * @return {@code true} if the location belongs to a plot area, else {@code false} */ public boolean isPlotArea() { return this.getPlotArea() != null; @@ -276,7 +276,7 @@ public final class Location implements Comparable { /** * Check whether or not the location belongs to a plot road * - * @return {@code true} if the location belongs to a plot road, else {@link false} + * @return {@code true} if the location belongs to a plot road, else {@code false} */ public boolean isPlotRoad() { final PlotArea area = this.getPlotArea(); @@ -286,7 +286,7 @@ public final class Location implements Comparable { /** * Checks if anyone owns a plot at the current location. * - * @return {@link true} if the location is a road, not a plot area, or if the plot is unclaimed. + * @return {@code true} if the location is a road, not a plot area, or if the plot is unclaimed. */ public boolean isUnownedPlotArea() { final PlotArea area = this.getPlotArea(); diff --git a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java index 2ef277bac..654678253 100644 --- a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java @@ -25,14 +25,17 @@ */ package com.plotsquared.core.player; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.command.RequiredType; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.events.TeleportCause; +import com.plotsquared.core.inject.annotations.ConsoleActor; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotWeather; import com.plotsquared.core.plot.world.PlotAreaManager; +import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.EventDispatcher; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.regions.CuboidRegion; @@ -40,6 +43,7 @@ import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemType; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.UUID; @@ -47,8 +51,14 @@ public class ConsolePlayer extends PlotPlayer { private static ConsolePlayer instance; - private ConsolePlayer(final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) { - super(plotAreaManager, eventDispatcher); + private final Actor actor; + + @Inject private ConsolePlayer(@NotNull final PlotAreaManager plotAreaManager, + @NotNull final EventDispatcher eventDispatcher, + @ConsoleActor @NotNull final Actor actor, + @Nullable final EconHandler econHandler) { + super(plotAreaManager, eventDispatcher, econHandler); + this.actor = actor; final PlotArea[] areas = plotAreaManager.getAllPlotAreas(); final PlotArea area; if (areas.length > 0) { @@ -70,14 +80,14 @@ public class ConsolePlayer extends PlotPlayer { public static ConsolePlayer getConsole() { if (instance == null) { - instance = new ConsolePlayer(PlotSquared.get().getPlotAreaManager(), PlotSquared.get().getEventDispatcher()); + instance = PlotSquared.platform().getInjector().getInstance(ConsolePlayer.class); instance.teleport(instance.getLocation()); } return instance; } @Override public Actor toActor() { - return PlotSquared.platform().getConsole(); + return this.actor; } @Override public Actor getPlatformPlayer() { diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index 7f3a52f4c..3f0fbbd30 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -91,10 +91,12 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer private final PlotAreaManager plotAreaManager; private final EventDispatcher eventDispatcher; + private final EconHandler econHandler; - public PlotPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) { + public PlotPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher, @Nullable final EconHandler econHandler) { this.plotAreaManager = plotAreaManager; this.eventDispatcher = eventDispatcher; + this.econHandler = econHandler; } public static PlotPlayer from(@NonNull final T object) { @@ -764,23 +766,24 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer * The amount of money this Player has. */ public double getMoney() { - return EconHandler.getEconHandler() == null ? 0 : EconHandler.getEconHandler().getMoney(this); + return this.econHandler == null ? 0 : this.econHandler.getMoney(this); } public void withdraw(double amount) { - if (EconHandler.getEconHandler() != null) { - EconHandler.getEconHandler().withdrawMoney(this, amount); + if (this.econHandler != null) { + this.econHandler.withdrawMoney(this, amount); } } public void deposit(double amount) { - if (EconHandler.getEconHandler() != null) { - EconHandler.getEconHandler().depositMoney(this, amount); + if (this.econHandler != null) { + this.econHandler.depositMoney(this, amount); } } @FunctionalInterface public interface PlotPlayerConverter { - PlotPlayer convert(BaseObject object); + PlotPlayer convert(BaseObject object); } + } diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index da18abe3e..6a7006dd5 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -38,6 +38,7 @@ import com.plotsquared.core.events.PlotUnlinkEvent; import com.plotsquared.core.events.Result; import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.generator.SquarePlotWorld; +import com.plotsquared.core.inject.annotations.ImpromptuPipeline; import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.BlockLoc; import com.plotsquared.core.location.Direction; @@ -64,6 +65,7 @@ import com.plotsquared.core.util.SchematicHandler; import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; +import com.plotsquared.core.uuid.UUIDPipeline; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector2; @@ -124,9 +126,16 @@ public class Plot { private static Set regions_cache; @NotNull private final PlotId id; - @NotNull private final EventDispatcher eventDispatcher; - @NotNull private final PlotListener plotListener; - + + // These will be injected + private EventDispatcher eventDispatcher; + private PlotListener plotListener; + private RegionManager regionManager; + private GlobalBlockQueue blockQueue; + private WorldUtil worldUtil; + private SchematicHandler schematicHandler; + @ImpromptuPipeline private UUIDPipeline impromptuPipeline; + /** * Plot flag container */ @@ -197,9 +206,8 @@ public class Plot { * @param owner the plot owner * @see Plot#getPlot(Location) for existing plots */ - public Plot(final PlotArea area, @NotNull final PlotId id, final UUID owner, - @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { - this(area, id, owner, 0, eventDispatcher, plotListener); + public Plot(final PlotArea area, @NotNull final PlotId id, final UUID owner) { + this(area, id, owner, 0); } /** @@ -210,9 +218,8 @@ public class Plot { * @param id the plot id * @see Plot#getPlot(Location) for existing plots */ - public Plot(@NotNull final PlotArea area, @NotNull final PlotId id, - @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { - this(area, id, null, 0, eventDispatcher, plotListener); + public Plot(@NotNull final PlotArea area, @NotNull final PlotId id) { + this(area, id, null, 0); } /** @@ -226,15 +233,13 @@ public class Plot { * @param temp Represents whatever the database manager needs it to * @see Plot#getPlot(Location) for existing plots */ - public Plot(final PlotArea area, @NotNull final PlotId id, final UUID owner, final int temp, - @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { + public Plot(final PlotArea area, @NotNull final PlotId id, final UUID owner, final int temp) { this.area = area; this.id = id; this.owner = owner; this.temp = temp; this.flagContainer.setParentContainer(area.getFlagContainer()); - this.eventDispatcher = eventDispatcher; - this.plotListener = plotListener; + PlotSquared.platform().getInjector().injectMembers(this); } /** @@ -249,8 +254,7 @@ public class Plot { */ public Plot(@NotNull PlotId id, UUID owner, HashSet trusted, HashSet members, HashSet denied, String alias, BlockLoc position, Collection> flags, - PlotArea area, boolean[] merged, long timestamp, int temp, - @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { + PlotArea area, boolean[] merged, long timestamp, int temp) { this.id = id; this.area = area; this.owner = owner; @@ -271,8 +275,7 @@ public class Plot { } } } - this.eventDispatcher = eventDispatcher; - this.plotListener = plotListener; + PlotSquared.platform().getInjector().injectMembers(this); } /** @@ -950,7 +953,7 @@ public class Plot { Runnable run = () -> { for (CuboidRegion region : regions) { Location[] corners = MainUtil.getCorners(getWorldName(), region); - RegionManager.manager.clearAllEntities(corners[0], corners[1]); + regionManager.clearAllEntities(corners[0], corners[1]); } TaskManager.runTask(whenDone); }; @@ -961,14 +964,13 @@ public class Plot { manager.claimPlot(current); } } - GlobalBlockQueue.IMP.addEmptyTask(run); + blockQueue.addEmptyTask(run); return; } Plot current = queue.poll(); if (Plot.this.area.getTerrain() != PlotAreaTerrainType.NONE) { try { - RegionManager.manager - .regenerateRegion(current.getBottomAbs(), current.getTopAbs(), false, + regionManager.regenerateRegion(current.getBottomAbs(), current.getTopAbs(), false, this); } catch (UnsupportedOperationException exception) { MainUtil.sendMessage(null, @@ -1005,7 +1007,7 @@ public class Plot { return; } CuboidRegion region = regions.poll(); - RegionManager.manager.setBiome(region, extendBiome, biome, getWorldName(), this); + regionManager.setBiome(region, extendBiome, biome, getWorldName(), this); } }; run.run(); @@ -1057,7 +1059,7 @@ public class Plot { current.setMerged(merged); } if (createSign) { - GlobalBlockQueue.IMP.addEmptyTask(() -> { + blockQueue.addEmptyTask(() -> { TaskManager.runTaskAsync(() -> { for (Plot current : plots) { current.setSign(MainUtil.getName(current.getOwnerAbs())); @@ -1092,14 +1094,13 @@ public class Plot { "%plr%", name), Captions.OWNER_SIGN_LINE_4.formatted().replaceAll("%id%", id).replaceAll( "%plr%", name)}; - WorldUtil.IMP - .setSign(this.getWorldName(), location.getX(), location.getY(), location.getZ(), + this.worldUtil.setSign(this.getWorldName(), location.getX(), location.getY(), location.getZ(), lines); } } public boolean isLoaded() { - return WorldUtil.IMP.isWorld(getWorldName()); + return this.worldUtil.isWorld(getWorldName()); } /** @@ -1270,7 +1271,7 @@ public class Plot { public int[] countEntities() { int[] count = new int[6]; for (Plot current : this.getConnectedPlots()) { - int[] result = RegionManager.manager.countEntities(current); + int[] result = this.regionManager.countEntities(current); count[CAP_ENTITY] += result[CAP_ENTITY]; count[CAP_ANIMAL] += result[CAP_ANIMAL]; count[CAP_MONSTER] += result[CAP_MONSTER]; @@ -1377,7 +1378,7 @@ public class Plot { result.accept(location); return; } - WorldUtil.IMP.getHighestBlock(getWorldName(), location.getX(), location.getZ(), y -> { + this.worldUtil.getHighestBlock(getWorldName(), location.getX(), location.getZ(), y -> { int height = y; if (area.allowSigns()) { height = Math.max(y, getManager().getSignLoc(this).getY()); @@ -1398,8 +1399,7 @@ public class Plot { if (!isLoaded()) { return location; } - int y = WorldUtil.IMP - .getHighestBlockSynchronous(getWorldName(), location.getX(), location.getZ()); + int y = this.worldUtil.getHighestBlockSynchronous(getWorldName(), location.getX(), location.getZ()); if (area.allowSigns()) { y = Math.max(y, getManager().getSignLoc(this).getY()); } @@ -1415,7 +1415,7 @@ public class Plot { + largest.getMinimumPoint().getX(); int z = largest.getMinimumPoint().getZ() - 1; PlotManager manager = getManager(); - int y = isLoaded() ? WorldUtil.IMP.getHighestBlockSynchronous(getWorldName(), x, z) : 62; + int y = isLoaded() ? this.worldUtil.getHighestBlockSynchronous(getWorldName(), x, z) : 62; if (area.allowSigns() && (y <= 0 || y >= 255)) { y = Math.max(y, manager.getSignLoc(this).getY() - 1); } @@ -1429,7 +1429,7 @@ public class Plot { int z = largest.getMinimumPoint().getZ() - 1; PlotManager manager = getManager(); if (isLoaded()) { - WorldUtil.IMP.getHighestBlock(getWorldName(), x, z, y -> { + this.worldUtil.getHighestBlock(getWorldName(), x, z, y -> { int height = y; if (area.allowSigns() && (y <= 0 || y >= 255)) { height = Math.max(y, manager.getSignLoc(this).getY() - 1); @@ -1460,9 +1460,8 @@ public class Plot { if (!isLoaded()) { return location; } - if (!WorldUtil.IMP.getBlockSynchronous(location).getBlockType().getMaterial().isAir()) { - location = location.withY(Math.max(1 + WorldUtil.IMP - .getHighestBlockSynchronous(this.getWorldName(), location.getX(), + if (!this.worldUtil.getBlockSynchronous(location).getBlockType().getMaterial().isAir()) { + location = location.withY(Math.max(1 + this.worldUtil.getHighestBlockSynchronous(this.getWorldName(), location.getX(), location.getZ()), bottom.getY())); } return location; @@ -1485,10 +1484,9 @@ public class Plot { result.accept(location); return; } - WorldUtil.IMP.getBlock(location, block -> { + this.worldUtil.getBlock(location, block -> { if (!block.getBlockType().getMaterial().isAir()) { - WorldUtil.IMP - .getHighestBlock(this.getWorldName(), location.getX(), location.getZ(), + this.worldUtil.getHighestBlock(this.getWorldName(), location.getX(), location.getZ(), y -> result.accept(location.withY(Math.max(1 + y, bottom.getY())))); } else { result.accept(location); @@ -1547,7 +1545,7 @@ public class Plot { } int y = loc.getY() < 1 ? (isLoaded() ? - WorldUtil.IMP.getHighestBlockSynchronous(plot.getWorldName(), x, z) + 1 : + this.worldUtil.getHighestBlockSynchronous(plot.getWorldName(), x, z) + 1 : 63) : loc.getY(); return Location.at(plot.getWorldName(), x, y, z); @@ -1577,7 +1575,7 @@ public class Plot { } if (loc.getY() < 1) { if (isLoaded()) { - WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z, + this.worldUtil.getHighestBlock(plot.getWorldName(), x, z, y -> result.accept(Location.at(plot.getWorldName(), x, y + 1, z))); } else { result.accept(Location.at(plot.getWorldName(), x, 63, z)); @@ -1680,7 +1678,7 @@ public class Plot { * This should not need to be called */ public void refreshChunks() { - LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(getWorldName(), false); + LocalBlockQueue queue = this.blockQueue.getNewQueue(getWorldName(), false); HashSet chunks = new HashSet<>(); for (CuboidRegion region : Plot.this.getRegions()) { for (int x = region.getMinimumPoint().getX() >> 4; @@ -1704,7 +1702,7 @@ public class Plot { return; } Location location = manager.getSignLoc(this); - LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(getWorldName(), false); + LocalBlockQueue queue = this.blockQueue.getNewQueue(getWorldName(), false); queue.setBlock(location.getX(), location.getY(), location.getZ(), BlockTypes.AIR.getDefaultState()); queue.flush(); @@ -1718,7 +1716,7 @@ public class Plot { this.setSign("unknown"); return; } - PlotSquared.get().getImpromptuUUIDPipeline().getSingle(this.getOwnerAbs(), (username, sign) -> + this.impromptuPipeline.getSingle(this.getOwnerAbs(), (username, sign) -> this.setSign(username)); } @@ -1769,18 +1767,18 @@ public class Plot { Schematic sch; try { if (schematic == null || schematic.isEmpty()) { - sch = SchematicHandler.manager.getSchematic(plotworld.getSchematicFile()); + sch = schematicHandler.getSchematic(plotworld.getSchematicFile()); } else { - sch = SchematicHandler.manager.getSchematic(schematic); + sch = schematicHandler.getSchematic(schematic); if (sch == null) { - sch = SchematicHandler.manager.getSchematic(plotworld.getSchematicFile()); + sch = schematicHandler.getSchematic(plotworld.getSchematicFile()); } } } catch (SchematicHandler.UnsupportedFormatException e) { e.printStackTrace(); return true; } - SchematicHandler.manager.paste(sch, this, 0, 1, 0, Settings.Schematics.PASTE_ON_TOP, + schematicHandler.paste(sch, this, 0, 1, 0, Settings.Schematics.PASTE_ON_TOP, new RunnableVal() { @Override public void run(Boolean value) { if (value) { @@ -1827,7 +1825,7 @@ public class Plot { DBFunc.createPlotAndSettings(this, () -> { PlotArea plotworld = Plot.this.area; if (notify && plotworld.isAutoMerge()) { - PlotPlayer player = WorldUtil.IMP.wrapPlayer(uuid); + PlotPlayer player = this.worldUtil.wrapPlayer(uuid); PlotMergeEvent event = this.eventDispatcher .callMerge(this, Direction.ALL, Integer.MAX_VALUE, player); if (event.getEventResult() == Result.DENY) { @@ -1861,7 +1859,7 @@ public class Plot { * Retrieve the biome of the plot. */ public void getBiome(Consumer result) { - this.getCenter(location -> WorldUtil.IMP + this.getCenter(location -> this.worldUtil .getBiome(location.getWorldName(), location.getX(), location.getZ(), result)); } @@ -1870,7 +1868,7 @@ public class Plot { */ @Deprecated public BiomeType getBiomeSynchronous() { final Location location = this.getCenterSynchronous(); - return WorldUtil.IMP + return this.worldUtil .getBiomeSynchronous(location.getWorldName(), location.getX(), location.getZ()); } @@ -2022,7 +2020,7 @@ public class Plot { Location top = this.getTopAbs(); Location pos1 = Location.at(this.getWorldName(), top.getX(), 0, bot.getZ()); Location pos2 = Location.at(this.getWorldName(), bot.getX(), MAX_HEIGHT, top.getZ()); - RegionManager.manager.regenerateRegion(pos1, pos2, true, null); + this.regionManager.regenerateRegion(pos1, pos2, true, null); } else if (this.area.getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove this.area.getPlotManager().removeRoadEast(this); @@ -2176,7 +2174,7 @@ public class Plot { * Export the plot as a schematic to the configured output directory. */ public void export(final RunnableVal whenDone) { - SchematicHandler.manager.getCompoundTag(this, new RunnableVal() { + this.schematicHandler.getCompoundTag(this, new RunnableVal() { @Override public void run(final CompoundTag value) { if (value == null) { if (whenDone != null) { @@ -2187,7 +2185,7 @@ public class Plot { TaskManager.runTaskAsync(() -> { String name = Plot.this.id + "," + Plot.this.area + ',' + MainUtil .getName(Plot.this.getOwnerAbs()); - boolean result = SchematicHandler.manager.save(value, + boolean result = schematicHandler.save(value, Settings.Paths.SCHEMATICS + File.separator + name + ".schem"); if (whenDone != null) { whenDone.value = result; @@ -2205,9 +2203,9 @@ public class Plot { * @param whenDone value will be null if uploading fails */ public void upload(final RunnableVal whenDone) { - SchematicHandler.manager.getCompoundTag(this, new RunnableVal() { + this.schematicHandler.getCompoundTag(this, new RunnableVal() { @Override public void run(CompoundTag value) { - SchematicHandler.manager.upload(value, null, null, whenDone); + schematicHandler.upload(value, null, null, whenDone); } }); } @@ -2221,7 +2219,7 @@ public class Plot { * @see WorldUtil */ public void uploadWorld(RunnableVal whenDone) { - WorldUtil.IMP.upload(this, null, null, whenDone); + this.worldUtil.upload(this, null, null, whenDone); } @Override public boolean equals(Object obj) { @@ -2394,7 +2392,7 @@ public class Plot { Location top = this.getTopAbs(); Location pos1 = Location.at(this.getWorldName(), bot.getX(), 0, top.getZ()); Location pos2 = Location.at(this.getWorldName(), top.getX(), MAX_HEIGHT, bot.getZ()); - RegionManager.manager.regenerateRegion(pos1, pos2, true, null); + this.regionManager.regenerateRegion(pos1, pos2, true, null); } else if (this.area.getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove this.getManager().removeRoadSouth(this); @@ -2570,7 +2568,7 @@ public class Plot { Plot other = this.getRelative(1, 1); Location pos1 = this.getTopAbs().add(1, 0, 1).withY(0); Location pos2 = other.getBottomAbs().subtract(1, 0, 1).withY(MAX_HEIGHT); - RegionManager.manager.regenerateRegion(pos1, pos2, true, null); + this.regionManager.regenerateRegion(pos1, pos2, true, null); } else if (this.area.getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove this.area.getPlotManager().removeRoadSouthEast(this); @@ -3228,7 +3226,7 @@ public class Plot { Location pos2 = corners[1]; Location pos3 = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); Location pos4 = pos2.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); - RegionManager.manager.swap(pos1, pos2, pos3, pos4, this); + regionManager.swap(pos1, pos2, pos3, pos4, this); } } }.run(); @@ -3259,7 +3257,7 @@ public class Plot { final Location pos1 = corners[0]; final Location pos2 = corners[1]; Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); - RegionManager.manager.copyRegion(pos1, pos2, newPos, task); + regionManager.copyRegion(pos1, pos2, newPos, task); } }.run(); } @@ -3353,7 +3351,7 @@ public class Plot { Location pos1 = corners[0]; Location pos2 = corners[1]; Location newPos = pos1 .add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); - RegionManager.manager.copyRegion(pos1, pos2, newPos, this); + regionManager.copyRegion(pos1, pos2, newPos, this); } }; run.run(); diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index f07aed20e..f722327a9 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -28,7 +28,7 @@ package com.plotsquared.core.plot; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.annoations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.collection.QuadMap; import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.Captions; @@ -140,15 +140,21 @@ public abstract class PlotArea { private final EventDispatcher eventDispatcher; private final PlotListener plotListener; private final YamlConfiguration worldConfiguration; + private final GlobalBlockQueue globalBlockQueue; + private final EconHandler econHandler; public PlotArea(@NotNull final String worldName, @Nullable final String id, @NotNull IndependentPlotGenerator generator, @Nullable final PlotId min, @Nullable final PlotId max, @NotNull final EventDispatcher eventDispatcher, - @NotNull final PlotListener plotListener, @WorldConfig @Nullable final YamlConfiguration worldConfiguration) { + @NotNull final PlotListener plotListener, + @WorldConfig @Nullable final YamlConfiguration worldConfiguration, + @NotNull final GlobalBlockQueue blockQueue, + @Nullable final EconHandler econHandler) { this.worldName = worldName; this.id = id; this.plotManager = createManager(); this.generator = generator; + this.globalBlockQueue = blockQueue; if (min == null || max == null) { if (min != max) { throw new IllegalArgumentException( @@ -164,12 +170,13 @@ public abstract class PlotArea { this.eventDispatcher = eventDispatcher; this.plotListener = plotListener; this.worldConfiguration = worldConfiguration; + this.econHandler = econHandler; } @NotNull protected abstract PlotManager createManager(); public LocalBlockQueue getQueue(final boolean autoQueue) { - return GlobalBlockQueue.IMP.getNewQueue(worldName, autoQueue); + return this.globalBlockQueue.getNewQueue(worldName, autoQueue); } /** @@ -288,7 +295,7 @@ public abstract class PlotArea { this.schematicClaimSpecify = config.getBoolean("schematic.specify_on_claim"); this.schematics = new ArrayList<>(config.getStringList("schematic.schematics")); this.schematics.replaceAll(String::toLowerCase); - this.useEconomy = config.getBoolean("economy.use") && EconHandler.getEconHandler() != null; + this.useEconomy = config.getBoolean("economy.use") && this.econHandler != null; ConfigurationSection priceSection = config.getConfigurationSection("economy.prices"); if (this.useEconomy) { this.prices = new HashMap<>(); @@ -650,7 +657,7 @@ public abstract class PlotArea { //todo check if this method is needed in this class - public int getPlotCount(@Nullable final PlotPlayer player) { + public int getPlotCount(@Nullable final PlotPlayer player) { return player != null ? getPlotCount(player.getUUID()) : 0; } @@ -661,7 +668,7 @@ public abstract class PlotArea { || id.y > this.max.y)) { return null; } - return new Plot(this, id, this.eventDispatcher, this.plotListener); + return new Plot(this, id); } return plot; } @@ -673,7 +680,7 @@ public abstract class PlotArea { || id.y > this.max.y)) { return null; } - return new Plot(this, id, this.eventDispatcher, this.plotListener); + return new Plot(this, id); } return plot.getBasePlot(false); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java b/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java index 88f9c100c..3ef2f1c74 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java @@ -29,6 +29,7 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.util.InventoryUtil; import lombok.NonNull; +import org.jetbrains.annotations.NotNull; public class PlotInventory { @@ -38,19 +39,14 @@ public class PlotInventory { private final PlotItemStack[] items; private String title; private boolean open = false; - - public PlotInventory(PlotPlayer player) { - this.size = 4; - this.title = null; - this.player = player; - this.items = InventoryUtil.manager.getItems(player); - } - - public PlotInventory(PlotPlayer player, int size, String name) { + private final InventoryUtil inventoryUtil; + + public PlotInventory(@NotNull final InventoryUtil inventoryUtil, PlotPlayer player, int size, String name) { this.size = size; this.title = name == null ? "" : name; this.player = player; this.items = new PlotItemStack[size * 9]; + this.inventoryUtil = inventoryUtil; } public static boolean hasPlotInventoryOpen(@NonNull final PlotPlayer plotPlayer) { @@ -84,7 +80,7 @@ public class PlotInventory { } else { this.open = true; setPlotInventoryOpen(player, this); - InventoryUtil.manager.open(this); + this.inventoryUtil.open(this); } } @@ -93,13 +89,13 @@ public class PlotInventory { return; } removePlotInventoryOpen(player); - InventoryUtil.manager.close(this); + this.inventoryUtil.close(this); this.open = false; } public void setItem(int index, PlotItemStack item) { this.items[index] = item; - InventoryUtil.manager.setItem(this, index, item); + this.inventoryUtil.setItem(this, index, item); } public PlotItemStack getItem(int index) { diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java index c0ec0f4c1..9ef1ff446 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java +++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java @@ -80,7 +80,7 @@ public class PlotAnalysis { } public static void analyzePlot(Plot plot, RunnableVal whenDone) { - HybridUtils.manager.analyzePlot(plot, whenDone); + PlotSquared.platform().getInjector().getInstance(HybridUtils.class).analyzePlot(plot, whenDone); } /** diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java index 49bd4c339..684da4562 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java @@ -26,7 +26,7 @@ package com.plotsquared.core.plot.world; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.annoations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java index 195d9b2fa..680b8e9d0 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java @@ -25,7 +25,7 @@ */ package com.plotsquared.core.plot.world; -import com.plotsquared.core.annoations.WorldConfig; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.collection.ArrayUtil; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.generator.SingleWorldGenerator; diff --git a/Core/src/main/java/com/plotsquared/core/queue/BasicLocalBlockQueue.java b/Core/src/main/java/com/plotsquared/core/queue/BasicLocalBlockQueue.java index d63403975..c65baab8e 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/BasicLocalBlockQueue.java +++ b/Core/src/main/java/com/plotsquared/core/queue/BasicLocalBlockQueue.java @@ -51,6 +51,8 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { private int lastZ = Integer.MIN_VALUE; private boolean setbiome = false; + private GlobalBlockQueue globalBlockQueue; + public BasicLocalBlockQueue(String world) { super(world); this.world = world; @@ -182,8 +184,8 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { } @Override public void flush() { - GlobalBlockQueue.IMP.dequeue(this); - TaskManager.IMP.sync(new RunnableVal() { + this.globalBlockQueue.dequeue(this); + TaskManager.getImplementation().sync(new RunnableVal() { @Override public void run(Object value) { while (next()) { } diff --git a/Core/src/main/java/com/plotsquared/core/queue/GlobalBlockQueue.java b/Core/src/main/java/com/plotsquared/core/queue/GlobalBlockQueue.java index 3b63a94c0..9f79102b0 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/GlobalBlockQueue.java +++ b/Core/src/main/java/com/plotsquared/core/queue/GlobalBlockQueue.java @@ -38,7 +38,6 @@ import java.util.concurrent.atomic.AtomicBoolean; public class GlobalBlockQueue { - public static GlobalBlockQueue IMP; private final int PARALLEL_THREADS; private final ConcurrentLinkedDeque activeQueues; private final ConcurrentLinkedDeque inactiveQueues; @@ -92,6 +91,8 @@ public class GlobalBlockQueue { public LocalBlockQueue getNewQueue(String world, boolean autoQueue) { LocalBlockQueue queue = provider.getNewQueue(world); + // Auto-inject into the queue + PlotSquared.platform().getInjector().injectMembers(queue); if (autoQueue) { inactiveQueues.add(queue); } diff --git a/Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java b/Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java index b0eb807bf..83a4bcd7a 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java +++ b/Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java @@ -48,12 +48,17 @@ public abstract class LocalBlockQueue { @Getter @Setter private boolean forceSync = false; @Getter @Setter @Nullable private Object chunkObject; + private SchematicHandler schematicHandler; + private WorldUtil worldUtil; + private GlobalBlockQueue blockQueue; + /** * Needed for compatibility with FAWE. * * @param world unused */ @Deprecated public LocalBlockQueue(String world) { + PlotSquared.platform().getInjector().injectMembers(this); } public ScopedLocalBlockQueue getForChunk(int x, int z) { @@ -94,7 +99,7 @@ public abstract class LocalBlockQueue { } public boolean setTile(int x, int y, int z, CompoundTag tag) { - SchematicHandler.manager.restoreTile(this, tag, x, y, z); + this.schematicHandler.restoreTile(this, tag, x, y, z); return true; } @@ -123,18 +128,18 @@ public abstract class LocalBlockQueue { fixChunkLighting(x, z); BlockVector2 loc = BlockVector2.at(x, z); - for (final PlotPlayer pp : PlotSquared.platform().getPlayerManager().getPlayers()) { + for (final PlotPlayer pp : PlotSquared.platform().getPlayerManager().getPlayers()) { Location pLoc = pp.getLocation(); if (!StringMan.isEqual(getWorld(), pLoc.getWorldName()) || !pLoc.getChunkLocation() .equals(loc)) { continue; } - pp.teleport(pLoc.withY(WorldUtil.IMP.getHighestBlockSynchronous(getWorld(), pLoc.getX(), pLoc.getZ()))); + pp.teleport(pLoc.withY(this.worldUtil.getHighestBlockSynchronous(getWorld(), pLoc.getX(), pLoc.getZ()))); } } public boolean enqueue() { - return GlobalBlockQueue.IMP.enqueue(this); + return blockQueue.enqueue(this); } public void setCuboid(Location pos1, Location pos2, BlockState block) { diff --git a/Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java b/Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java index 6efad1751..bdc6876c3 100644 --- a/Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java +++ b/Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java @@ -38,7 +38,6 @@ import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.SetupUtils; import com.plotsquared.core.util.StringMan; -import com.plotsquared.core.util.WorldUtil; import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -214,7 +213,7 @@ public enum CommonSetupSteps implements SetupStep { MainUtil.sendMessage(plotPlayer, Captions.SETUP_WORLD_NAME_FORMAT + argument); return this; } - if (WorldUtil.IMP.isWorld(argument)) { + if (PlotSquared.platform().getWorldUtil().isWorld(argument)) { if (PlotSquared.get().getPlotAreaManager().hasPlotArea(argument)) { MainUtil.sendMessage(plotPlayer, Captions.SETUP_WORLD_NAME_TAKEN); return this; @@ -225,12 +224,12 @@ public enum CommonSetupSteps implements SetupStep { plotPlayer.deleteMeta("setup"); String world; if (builder.setupManager() == null) { - world = SetupUtils.manager.setupWorld(builder); + world = PlotSquared.platform().getInjector().getInstance(SetupUtils.class).setupWorld(builder); } else { world = builder.setupManager().setupWorld(builder); } try { - plotPlayer.teleport(WorldUtil.IMP.getSpawn(world), TeleportCause.COMMAND); + plotPlayer.teleport(PlotSquared.platform().getWorldUtil().getSpawn(world), TeleportCause.COMMAND); } catch (Exception e) { plotPlayer.sendMessage("&cAn error occurred. See console for more information"); e.printStackTrace(); diff --git a/Core/src/main/java/com/plotsquared/core/setup/PlotAreaBuilder.java b/Core/src/main/java/com/plotsquared/core/setup/PlotAreaBuilder.java index 549c41b55..aa7e46290 100644 --- a/Core/src/main/java/com/plotsquared/core/setup/PlotAreaBuilder.java +++ b/Core/src/main/java/com/plotsquared/core/setup/PlotAreaBuilder.java @@ -49,6 +49,13 @@ public class PlotAreaBuilder { @Getter @Setter private SettingsNodesWrapper settingsNodesWrapper; @Getter @Setter private SetupUtils setupManager; + private PlotAreaBuilder() { + } + + public static PlotAreaBuilder newBuilder() { + return new PlotAreaBuilder(); + } + public static PlotAreaBuilder ofPlotArea(PlotArea area) { return new PlotAreaBuilder() .worldName(area.getWorldName()) diff --git a/Core/src/main/java/com/plotsquared/core/setup/SetupProcess.java b/Core/src/main/java/com/plotsquared/core/setup/SetupProcess.java index 7af19aefb..d8c0a20b6 100644 --- a/Core/src/main/java/com/plotsquared/core/setup/SetupProcess.java +++ b/Core/src/main/java/com/plotsquared/core/setup/SetupProcess.java @@ -39,7 +39,7 @@ public class SetupProcess { private SetupStep current; public SetupProcess() { - this.builder = new PlotAreaBuilder(); + this.builder = PlotAreaBuilder.newBuilder(); this.history = new Stack<>(); this.current = CommonSetupSteps.CHOOSE_GENERATOR; } diff --git a/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java b/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java index 6e6f1750b..f9809840f 100644 --- a/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java @@ -28,7 +28,6 @@ package com.plotsquared.core.util; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; -import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.queue.ScopedLocalBlockQueue; import com.plotsquared.core.util.task.RunnableVal; @@ -47,11 +46,10 @@ public abstract class ChunkManager { new ConcurrentHashMap<>(); private static final Map> addChunks = new ConcurrentHashMap<>(); - public static ChunkManager manager = null; public static void setChunkInPlotArea(RunnableVal force, RunnableVal add, String world, BlockVector2 loc) { - LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false); + LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false); if (PlotSquared.get().getPlotAreaManager().isAugmented(world) && PlotSquared.get().isNonStandardGeneration(world, loc)) { int blockX = loc.getX() << 4; int blockZ = loc.getZ() << 4; diff --git a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java index 6557bc1c5..69363079f 100644 --- a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java @@ -25,41 +25,12 @@ */ package com.plotsquared.core.util; -import com.plotsquared.core.PlotPlatform; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.OfflinePlotPlayer; import com.plotsquared.core.player.PlotPlayer; -import org.jetbrains.annotations.Nullable; public abstract class EconHandler { - /** - * @deprecated This will be removed in the future, - * call {@link PlotPlatform#getEconomyHandler()} instead. - */ - @Deprecated @Nullable public static EconHandler manager; - - /** - * Initialize the economy handler using {@link PlotPlatform#getEconomyHandler()} - * @deprecated Call {@link #init} instead or use {@link PlotPlatform#getEconomyHandler()} - * which does this already. - */ - @Deprecated public static void initializeEconHandler() { - manager = PlotSquared.platform().getEconomyHandler(); - } - - /** - * Return the econ handler instance, if one exists - * - * @return Economy handler instance - * @deprecated Call {@link PlotPlatform#getEconomyHandler()} instead - */ - @Deprecated @Nullable public static EconHandler getEconHandler() { - manager = PlotSquared.platform().getEconomyHandler(); - return manager; - } - public abstract boolean init(); public double getMoney(PlotPlayer player) { @@ -88,4 +59,5 @@ public abstract class EconHandler { @Deprecated public boolean hasPermission(String player, String perm) { return hasPermission(null, player, perm); } + } diff --git a/Core/src/main/java/com/plotsquared/core/util/InventoryUtil.java b/Core/src/main/java/com/plotsquared/core/util/InventoryUtil.java index c2d12ae13..f2f188741 100644 --- a/Core/src/main/java/com/plotsquared/core/util/InventoryUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/InventoryUtil.java @@ -34,11 +34,6 @@ import com.plotsquared.core.plot.PlotItemStack; */ public abstract class InventoryUtil { - /** - * This class is only used by internal functions, for most cases use the PlotInventory class - */ - public static InventoryUtil manager = null; - public abstract void open(final PlotInventory inv); public abstract void close(final PlotInventory inv); diff --git a/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java b/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java index d329a8e23..49b5fc70d 100644 --- a/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java +++ b/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java @@ -64,7 +64,7 @@ public final class LegacyConverter { } private BlockBucket blockToBucket(@NonNull final String block) { - final BlockState plotBlock = WorldUtil.IMP.getClosestBlock(block).best; + final BlockState plotBlock = PlotSquared.platform().getWorldUtil().getClosestBlock(block).best; return BlockBucket.withSingle(plotBlock); } @@ -101,7 +101,7 @@ public final class LegacyConverter { } private BlockState[] splitBlockList(@NonNull final List list) { - return list.stream().map(s -> WorldUtil.IMP.getClosestBlock(s).best) + return list.stream().map(s -> PlotSquared.platform().getWorldUtil().getClosestBlock(s).best) .toArray(BlockState[]::new); } diff --git a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java index 898fdf67a..e86d3e8da 100644 --- a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java @@ -240,8 +240,7 @@ public class MainUtil { */ public static boolean resetBiome(PlotArea area, Location pos1, Location pos2) { BiomeType biome = area.getPlotBiome(); - if (!Objects.equals(WorldUtil.IMP - .getBiomeSynchronous(area.getWorldName(), (pos1.getX() + pos2.getX()) / 2, + if (!Objects.equals(PlotSquared.platform().getWorldUtil().getBiomeSynchronous(area.getWorldName(), (pos1.getX() + pos2.getX()) / 2, (pos1.getZ() + pos2.getZ()) / 2), biome)) { MainUtil .setBiome(area.getWorldName(), pos1.getX(), pos1.getZ(), pos2.getX(), pos2.getZ(), @@ -613,14 +612,14 @@ public class MainUtil { BlockVector3 pos1 = BlockVector2.at(p1x, p1z).toBlockVector3(); BlockVector3 pos2 = BlockVector2.at(p2x, p2z).toBlockVector3(Plot.MAX_HEIGHT - 1); CuboidRegion region = new CuboidRegion(pos1, pos2); - WorldUtil.IMP.setBiomes(world, region, biome); + PlotSquared.platform().getWorldUtil().setBiomes(world, region, biome); } /** * Get the highest block at a location. */ public static void getHighestBlock(String world, int x, int z, IntConsumer result) { - WorldUtil.IMP.getHighestBlock(world, x, z, highest -> { + PlotSquared.platform().getWorldUtil().getHighestBlock(world, x, z, highest -> { if (highest == 0) { result.accept(63); } else { @@ -802,7 +801,7 @@ public class MainUtil { int num = plot.getConnectedPlots().size(); String alias = !plot.getAlias().isEmpty() ? plot.getAlias() : Captions.NONE.getTranslated(); Location bot = plot.getCorners()[0]; - WorldUtil.IMP.getBiome(plot.getWorldName(), bot.getX(), bot.getZ(), biome -> { + PlotSquared.platform().getWorldUtil().getBiome(plot.getWorldName(), bot.getX(), bot.getZ(), biome -> { String info = iInfo; String trusted = getPlayerList(plot.getTrusted()); String members = getPlayerList(plot.getMembers()); diff --git a/Core/src/main/java/com/plotsquared/core/util/PremiumVerification.java b/Core/src/main/java/com/plotsquared/core/util/PremiumVerification.java index 7fd78826d..73db470b5 100644 --- a/Core/src/main/java/com/plotsquared/core/util/PremiumVerification.java +++ b/Core/src/main/java/com/plotsquared/core/util/PremiumVerification.java @@ -26,6 +26,7 @@ package com.plotsquared.core.util; public class PremiumVerification { + private static Boolean usingPremium; /** diff --git a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java index a2bb9b2e8..c6502ed26 100644 --- a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java @@ -37,6 +37,7 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.Collection; @@ -45,19 +46,23 @@ import java.util.Set; public abstract class RegionManager { - public static RegionManager manager = null; - public static BlockVector2 getRegion(Location location) { int x = location.getX() >> 9; int z = location.getZ() >> 9; return BlockVector2.at(x, z); } - public static void largeRegionTask(final String world, final CuboidRegion region, + private final ChunkManager chunkManager; + + public RegionManager(@NotNull final ChunkManager chunkManager) { + this.chunkManager = chunkManager; + } + + public void largeRegionTask(final String world, final CuboidRegion region, final RunnableVal task, final Runnable whenDone) { TaskManager.runTaskAsync(() -> { HashSet chunks = new HashSet<>(); - Set mcrs = manager.getChunkChunks(world); + Set mcrs = this.getChunkChunks(world); for (BlockVector2 mcr : mcrs) { int bx = mcr.getX() << 9; int bz = mcr.getZ() << 9; @@ -85,7 +90,7 @@ public abstract class RegionManager { } TaskManager.objectTask(chunks, new RunnableVal() { @Override public void run(BlockVector2 value) { - ChunkManager.manager.loadChunk(world, value, false) + chunkManager.loadChunk(world, value, false) .thenRun(() -> task.run(value)); } }, whenDone); diff --git a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java index 36a4f0b15..c2c063e17 100644 --- a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java @@ -93,10 +93,15 @@ import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; public abstract class SchematicHandler { - public static SchematicHandler manager; private boolean exportAll = false; + private final WorldUtil worldUtil; + + public SchematicHandler(@NotNull final WorldUtil worldUtil) { + this.worldUtil = worldUtil; + } + public boolean exportAll(Collection collection, final File outputDir, final String namingScheme, final Runnable ifSuccess) { if (this.exportAll) { @@ -144,15 +149,14 @@ public abstract class SchematicHandler { } final Runnable THIS = this; - SchematicHandler.manager.getCompoundTag(plot, new RunnableVal() { + getCompoundTag(plot, new RunnableVal() { @Override public void run(final CompoundTag value) { if (value == null) { MainUtil.sendMessage(null, "&7 - Skipped plot &c" + plot.getId()); } else { TaskManager.runTaskAsync(() -> { MainUtil.sendMessage(null, "&6ID: " + plot.getId()); - boolean result = SchematicHandler.manager - .save(value, directory + File.separator + name + ".schem"); + boolean result = save(value, directory + File.separator + name + ".schem"); if (!result) { MainUtil .sendMessage(null, "&7 - Failed to save &c" + plot.getId()); @@ -223,7 +227,7 @@ public abstract class SchematicHandler { if (pw instanceof ClassicPlotWorld) { y_offset_actual = yOffset + ((ClassicPlotWorld) pw).PLOT_HEIGHT; } else { - y_offset_actual = yOffset + 1 + WorldUtil.IMP + y_offset_actual = yOffset + 1 + this.worldUtil .getHighestBlockSynchronous(plot.getWorldName(), region.getMinimumPoint().getX() + 1, region.getMinimumPoint().getZ() + 1); @@ -493,7 +497,7 @@ public abstract class SchematicHandler { final Location top = corners[1]; CuboidRegion cuboidRegion = - new CuboidRegion(WorldUtil.IMP.getWeWorld(world), bot.getBlockVector3(), + new CuboidRegion(this.worldUtil.getWeWorld(world), bot.getBlockVector3(), top.getBlockVector3()); final int width = cuboidRegion.getWidth(); diff --git a/Core/src/main/java/com/plotsquared/core/util/SetupUtils.java b/Core/src/main/java/com/plotsquared/core/util/SetupUtils.java index cae6f2ae1..d43e68dfc 100644 --- a/Core/src/main/java/com/plotsquared/core/util/SetupUtils.java +++ b/Core/src/main/java/com/plotsquared/core/util/SetupUtils.java @@ -34,8 +34,6 @@ import java.util.HashMap; public abstract class SetupUtils { - public static SetupUtils manager; - public static HashMap> generators = new HashMap<>(); public abstract void updateGenerators(); @@ -48,4 +46,5 @@ public abstract class SetupUtils { public abstract String setupWorld(final PlotAreaBuilder builder); public abstract void unload(String world, boolean save); + } diff --git a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java index fe72385f4..179bf3b91 100644 --- a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java @@ -61,7 +61,12 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public abstract class WorldUtil { - public static WorldUtil IMP; + + private final RegionManager regionManager; + + public WorldUtil(@NotNull final RegionManager regionManager) { + this.regionManager = regionManager; + } public abstract String getMainWorld(); @@ -150,8 +155,7 @@ public abstract class WorldUtil { int brz = bot.getZ() >> 9; int trx = top.getX() >> 9; int trz = top.getZ() >> 9; - Set files = - RegionManager.manager.getChunkChunks(bot.getWorldName()); + Set files = regionManager.getChunkChunks(bot.getWorldName()); for (BlockVector2 mca : files) { if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz && mca.getZ() <= trz) { diff --git a/Core/src/main/java/com/plotsquared/core/util/entity/EntityCategories.java b/Core/src/main/java/com/plotsquared/core/util/entity/EntityCategories.java index ae1a5c0cd..7ea33e3d1 100644 --- a/Core/src/main/java/com/plotsquared/core/util/entity/EntityCategories.java +++ b/Core/src/main/java/com/plotsquared/core/util/entity/EntityCategories.java @@ -25,6 +25,8 @@ */ package com.plotsquared.core.util.entity; +import com.plotsquared.core.PlotSquared; + /** * A collection of {@link EntityCategory entity categories} */ @@ -48,7 +50,7 @@ public class EntityCategories { public static final EntityCategory PLAYER = register("player"); public static EntityCategory register(final String id) { - final EntityCategory entityCategory = new EntityCategory(id); + final EntityCategory entityCategory = new EntityCategory(PlotSquared.platform().getWorldUtil(), id); EntityCategory.REGISTRY.register(entityCategory.getId(), entityCategory); return entityCategory; } diff --git a/Core/src/main/java/com/plotsquared/core/util/entity/EntityCategory.java b/Core/src/main/java/com/plotsquared/core/util/entity/EntityCategory.java index 30236ed34..c8db0427f 100644 --- a/Core/src/main/java/com/plotsquared/core/util/entity/EntityCategory.java +++ b/Core/src/main/java/com/plotsquared/core/util/entity/EntityCategory.java @@ -41,15 +41,17 @@ public class EntityCategory extends Category implements Keyed { public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("entity type"); + private final WorldUtil worldUtil; private final String key; - protected EntityCategory(final String id) { + protected EntityCategory(final WorldUtil worldUtil, final String id) { super("plotsquared:" + id); this.key = id; + this.worldUtil = worldUtil; } @Override protected Set load() { - return WorldUtil.IMP.getTypesInCategory(this.key); + return this.worldUtil.getTypesInCategory(this.key); } } diff --git a/Core/src/main/java/com/plotsquared/core/util/task/TaskManager.java b/Core/src/main/java/com/plotsquared/core/util/task/TaskManager.java index 5878a9247..0e2a923e2 100644 --- a/Core/src/main/java/com/plotsquared/core/util/task/TaskManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/task/TaskManager.java @@ -27,6 +27,8 @@ package com.plotsquared.core.util.task; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.util.RuntimeExceptionRunnableVal; +import lombok.Getter; +import lombok.Setter; import java.util.Collection; import java.util.HashMap; @@ -39,46 +41,47 @@ public abstract class TaskManager { public static final HashSet TELEPORT_QUEUE = new HashSet<>(); public static final HashMap tasks = new HashMap<>(); - public static TaskManager IMP; public static AtomicInteger index = new AtomicInteger(0); + @Getter @Setter private static TaskManager implementation; + public static int runTaskRepeat(Runnable runnable, int interval) { if (runnable != null) { - if (IMP == null) { + if (getImplementation() == null) { throw new IllegalArgumentException("disabled"); } - return IMP.taskRepeat(runnable, interval); + return getImplementation().taskRepeat(runnable, interval); } return -1; } public static int runTaskRepeatAsync(Runnable runnable, int interval) { if (runnable != null) { - if (IMP == null) { + if (getImplementation() == null) { throw new IllegalArgumentException("disabled"); } - return IMP.taskRepeatAsync(runnable, interval); + return getImplementation().taskRepeatAsync(runnable, interval); } return -1; } public static void runTaskAsync(Runnable runnable) { if (runnable != null) { - if (IMP == null) { + if (getImplementation() == null) { runnable.run(); return; } - IMP.taskAsync(runnable); + getImplementation().taskAsync(runnable); } } public static void runTask(Runnable runnable) { if (runnable != null) { - if (IMP == null) { + if (getImplementation() == null) { runnable.run(); return; } - IMP.task(runnable); + getImplementation().task(runnable); } } @@ -90,21 +93,21 @@ public abstract class TaskManager { */ public static void runTaskLater(Runnable runnable, int delay) { if (runnable != null) { - if (IMP == null) { + if (getImplementation() == null) { runnable.run(); return; } - IMP.taskLater(runnable, delay); + getImplementation().taskLater(runnable, delay); } } public static void runTaskLaterAsync(Runnable runnable, int delay) { if (runnable != null) { - if (IMP == null) { + if (getImplementation() == null) { runnable.run(); return; } - IMP.taskLaterAsync(runnable, delay); + getImplementation().taskLaterAsync(runnable, delay); } } @@ -133,7 +136,7 @@ public abstract class TaskManager { final AtomicBoolean running = new AtomicBoolean(true); final RuntimeExceptionRunnableVal run = new RuntimeExceptionRunnableVal<>(function, running); - TaskManager.IMP.task(run); + TaskManager.getImplementation().task(run); try { synchronized (function) { while (running.get()) {