Guice progress

This commit is contained in:
Alexander Söderberg
2020-07-10 22:12:37 +02:00
parent 55bf41d2da
commit c0f69f321d
90 changed files with 1026 additions and 830 deletions

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

@ -23,16 +23,25 @@
* 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.bukkit.inject;
import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.plot.world.PlotAreaManager;
import org.jetbrains.annotations.NotNull;
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 BukkitHybridUtils extends HybridUtils {
public class WorldManagerModule extends AbstractModule {
public BukkitHybridUtils(@NotNull PlotAreaManager plotAreaManager) {
super(plotAreaManager);
@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();
}