Guice progress

This commit is contained in:
Alexander Söderberg 2020-07-10 22:12:37 +02:00
parent 55bf41d2da
commit c0f69f321d
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
90 changed files with 1026 additions and 830 deletions

View File

@ -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"
}

View File

@ -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<Player> {
@SuppressWarnings("unused") public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform<Player> {
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<World> 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<World> 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 PlotPlayer<Player>, ? extends Player> getPlayerManager() {
return this.playerManager;
}
@Override @NotNull public com.plotsquared.core.location.World<?> getPlatformWorld(@NotNull final String worldName) {
return BukkitWorld.of(worldName);
}

View File

@ -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;

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}
}

View File

@ -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 {

View File

@ -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;
}

View File

@ -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;

View File

@ -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();

View File

@ -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;
}

View File

@ -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<World> {
@Singleton public class BukkitWorldManager implements PlatformWorldManager<World> {
@Override public void initialize() {
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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<Player> {
private static boolean CHECK_EFFECTIVE = true;
private final EconHandler econHandler;
public final Player player;
private boolean offline;
private String name;
/**
* <p>Please do not use this method. Instead use
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
@ -79,20 +83,22 @@ public class BukkitPlayer extends PlotPlayer<Player> {
* @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<Player> {
}
@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);
}

View File

@ -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<BukkitPlayer, Player> {
@Singleton public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, Player> {
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());

View File

@ -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) {

View File

@ -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()

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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()

View File

@ -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();

View File

@ -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;
}

View File

@ -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<String[]>() {
return TaskManager.getImplementation().sync(new RunnableVal<String[]>() {
@Override public void run(String[] value) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();

View File

@ -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();
}

View File

@ -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

View File

@ -98,6 +98,18 @@
<version>1.7.0-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.3</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-assistedinject</artifactId>
<version>4.2.3</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@ -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);
}
/**

View File

@ -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<P> 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<P> 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<P> 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<P> 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<P> 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<Map.Entry<Map.Entry<String, String>, 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 PlotPlayer<P>, ? extends P> getPlayerManager();
@NotNull default PlayerManager<? extends PlotPlayer<P>, ? extends P> getPlayerManager() {
return getInjector().getInstance(PlayerManager.class);
}
/**
* Get a platform world wrapper from a world name
@ -311,4 +192,38 @@ public interface PlotPlatform<P> 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);
}
}

View File

@ -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();

View File

@ -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();

View File

@ -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<Backup> backupCache;
private final Object backupLock = new Object();
@ -141,7 +150,7 @@ public class PlayerBackupProfile implements BackupProfile {
backups.get(backups.size() - 1).delete();
}
final List<Plot> 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<Boolean>() {
this.schematicHandler.paste(schematic, plot, 0, 1, 0, false, new RunnableVal<Boolean>() {
@Override public void run(Boolean value) {
if (value) {
future.complete(null);

View File

@ -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<PlotCacheKey, BackupProfile> 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;
}

View File

@ -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;

View File

@ -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<List<com.plotsquared.core.backup.Backup>> 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());

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<ComponentPreset> 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<String> 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())));
}

View File

@ -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<PlotId, Plot> map = newPlots.get(areaID);
if (map != null) {
Plot last = map.put(p.getId(), p);

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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<BlockVector2> regions;
public static int height;
public static Set<BlockVector2> 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<BlockVector2> regions = RegionManager.manager.getChunkChunks(area.getWorldName());
Set<BlockVector2> 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<Object>() {
TaskManager.getImplementation().sync(new RunnableVal<Object>() {
@Override public void run(Object value) {
long start = System.currentTimeMillis();
Iterator<BlockVector2> 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<CompoundTag>() {
this.schematicHandler.getCompoundTag(world, sideRoad, new RunnableVal<CompoundTag>() {
@Override public void run(CompoundTag value) {
SchematicHandler.manager.save(value, dir + "sideroad.schem");
SchematicHandler.manager
.getCompoundTag(world, intersection, new RunnableVal<CompoundTag>() {
schematicHandler.save(value, dir + "sideroad.schem");
schematicHandler.getCompoundTag(world, intersection, new RunnableVal<CompoundTag>() {
@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()) {

View File

@ -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;
}

View File

@ -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;

View File

@ -23,16 +23,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 {
}

View File

@ -23,7 +23,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.annoations;
package com.plotsquared.core.inject.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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 {
}

View File

@ -23,14 +23,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 {
}

View File

@ -23,14 +23,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 {
}

View File

@ -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);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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());
}
}

View File

@ -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<UUID, Interval> feedRunnable = new HashMap<>();
private final HashMap<UUID, Interval> 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));
}
}
}

View File

@ -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<CuboidRegion> 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<Long, Integer[]> tileEntityCount = new HashMap<>();
public ProcessedWEExtent(String world, Set<CuboidRegion> mask, int max, Extent child,
Extent parent) {
public ProcessedWEExtent(String world, Set<CuboidRegion> 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 <T extends BlockStateHolder<T>> 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;

View File

@ -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()));

View File

@ -267,7 +267,7 @@ public final class Location implements Comparable<Location> {
/**
* 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<Location> {
/**
* 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<Location> {
/**
* 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();

View File

@ -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<Actor> {
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<Actor> {
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() {

View File

@ -91,10 +91,12 @@ public abstract class PlotPlayer<P> 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 <T> PlotPlayer<T> from(@NonNull final T object) {
@ -764,23 +766,24 @@ public abstract class PlotPlayer<P> 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<BaseObject> {
PlotPlayer convert(BaseObject object);
PlotPlayer<?> convert(BaseObject object);
}
}

View File

@ -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<CuboidRegion> 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<UUID> trusted, HashSet<UUID> members,
HashSet<UUID> denied, String alias, BlockLoc position, Collection<PlotFlag<?, ?>> 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<BlockVector2> 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<Boolean>() {
@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<BiomeType> 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<Boolean> whenDone) {
SchematicHandler.manager.getCompoundTag(this, new RunnableVal<CompoundTag>() {
this.schematicHandler.getCompoundTag(this, new RunnableVal<CompoundTag>() {
@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<URL> whenDone) {
SchematicHandler.manager.getCompoundTag(this, new RunnableVal<CompoundTag>() {
this.schematicHandler.getCompoundTag(this, new RunnableVal<CompoundTag>() {
@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<URL> 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();

View File

@ -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);
}

View File

@ -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) {

View File

@ -80,7 +80,7 @@ public class PlotAnalysis {
}
public static void analyzePlot(Plot plot, RunnableVal<PlotAnalysis> whenDone) {
HybridUtils.manager.analyzePlot(plot, whenDone);
PlotSquared.platform().getInjector().getInstance(HybridUtils.class).analyzePlot(plot, whenDone);
}
/**

View File

@ -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;

View File

@ -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;

View File

@ -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<Object>() {
this.globalBlockQueue.dequeue(this);
TaskManager.getImplementation().sync(new RunnableVal<Object>() {
@Override public void run(Object value) {
while (next()) {
}

View File

@ -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<LocalBlockQueue> activeQueues;
private final ConcurrentLinkedDeque<LocalBlockQueue> 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);
}

View File

@ -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) {

View File

@ -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();

View File

@ -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())

View File

@ -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;
}

View File

@ -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<BlockVector2, RunnableVal<ScopedLocalBlockQueue>> addChunks =
new ConcurrentHashMap<>();
public static ChunkManager manager = null;
public static void setChunkInPlotArea(RunnableVal<ScopedLocalBlockQueue> force,
RunnableVal<ScopedLocalBlockQueue> 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;

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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<String> 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);
}

View File

@ -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());

View File

@ -26,6 +26,7 @@
package com.plotsquared.core.util;
public class PremiumVerification {
private static Boolean usingPremium;
/**

View File

@ -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<BlockVector2> task, final Runnable whenDone) {
TaskManager.runTaskAsync(() -> {
HashSet<BlockVector2> chunks = new HashSet<>();
Set<BlockVector2> mcrs = manager.getChunkChunks(world);
Set<BlockVector2> 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<BlockVector2>() {
@Override public void run(BlockVector2 value) {
ChunkManager.manager.loadChunk(world, value, false)
chunkManager.loadChunk(world, value, false)
.thenRun(() -> task.run(value));
}
}, whenDone);

View File

@ -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<Plot> 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<CompoundTag>() {
getCompoundTag(plot, new RunnableVal<CompoundTag>() {
@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();

View File

@ -34,8 +34,6 @@ import java.util.HashMap;
public abstract class SetupUtils {
public static SetupUtils manager;
public static HashMap<String, GeneratorWrapper<?>> 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);
}

View File

@ -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<BlockVector2> files =
RegionManager.manager.getChunkChunks(bot.getWorldName());
Set<BlockVector2> files = regionManager.getChunkChunks(bot.getWorldName());
for (BlockVector2 mca : files) {
if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz
&& mca.getZ() <= trz) {

View File

@ -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;
}

View File

@ -41,15 +41,17 @@ public class EntityCategory extends Category<EntityType> implements Keyed {
public static final NamespacedRegistry<EntityCategory> 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<EntityType> load() {
return WorldUtil.IMP.getTypesInCategory(this.key);
return this.worldUtil.getTypesInCategory(this.key);
}
}

View File

@ -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<String> TELEPORT_QUEUE = new HashSet<>();
public static final HashMap<Integer, Integer> 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<T> run =
new RuntimeExceptionRunnableVal<>(function, running);
TaskManager.IMP.task(run);
TaskManager.getImplementation().task(run);
try {
synchronized (function) {
while (running.get()) {