mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 10:14:42 +02:00
Merge branch 'v6' into feature/v6/json
# Conflicts: # Bukkit/build.gradle # Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java # Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java # Core/build.gradle # Core/src/main/java/com/plotsquared/core/PlotPlatform.java # Core/src/main/java/com/plotsquared/core/PlotSquared.java # Core/src/main/java/com/plotsquared/core/command/Add.java # Core/src/main/java/com/plotsquared/core/command/Area.java # Core/src/main/java/com/plotsquared/core/command/Auto.java # Core/src/main/java/com/plotsquared/core/command/Command.java # Core/src/main/java/com/plotsquared/core/command/ListCmd.java # Core/src/main/java/com/plotsquared/core/configuration/Caption.java # Core/src/main/java/com/plotsquared/core/listener/PlotListener.java # Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java # Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java # Core/src/main/java/com/plotsquared/core/plot/message/PlotMessage.java # Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java # Core/src/main/java/com/plotsquared/core/util/MainUtil.java # Core/src/main/java/com/plotsquared/core/util/WorldUtil.java
This commit is contained in:
@ -25,17 +25,21 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit;
|
||||
|
||||
import com.plotsquared.bukkit.generator.BukkitHybridUtils;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
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;
|
||||
@ -47,8 +51,10 @@ 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.BukkitChatManager;
|
||||
import com.plotsquared.bukkit.util.BukkitTaskManager;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitWorld;
|
||||
import com.plotsquared.bukkit.util.SetGenCB;
|
||||
import com.plotsquared.bukkit.util.UpdateUtility;
|
||||
import com.plotsquared.bukkit.uuid.BungeePermsUUIDService;
|
||||
@ -58,57 +64,60 @@ import com.plotsquared.bukkit.uuid.OfflinePlayerUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.PaperUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.SQLiteUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.SquirrelIdUUIDService;
|
||||
import com.plotsquared.core.IPlotMain;
|
||||
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;
|
||||
import com.plotsquared.core.configuration.ConfigurationSection;
|
||||
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;
|
||||
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
||||
import com.plotsquared.core.plot.PlotAreaType;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.comment.CommentManager;
|
||||
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.ChunkManager;
|
||||
import com.plotsquared.core.util.ChatManager;
|
||||
import com.plotsquared.core.util.ConsoleColors;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.InventoryUtil;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
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;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
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;
|
||||
@ -120,7 +129,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;
|
||||
@ -131,9 +139,11 @@ import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.AbstractMap;
|
||||
@ -157,10 +167,10 @@ 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 BukkitMain extends JavaPlugin implements Listener, IPlotMain<Player> {
|
||||
@SuppressWarnings("unused") public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform<Player> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitPlatform.class.getSimpleName());
|
||||
private static final int BSTATS_ID = 1404;
|
||||
@Getter private static WorldEdit worldEdit;
|
||||
|
||||
static {
|
||||
try {
|
||||
@ -175,12 +185,22 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
private Method methodUnloadChunk0;
|
||||
private boolean methodUnloadSetup = false;
|
||||
private boolean metricsStarted;
|
||||
@Getter private BackupManager backupManager;
|
||||
@Getter private PlatformWorldManager<World> worldManager;
|
||||
private final BukkitPlayerManager playerManager = new BukkitPlayerManager();
|
||||
private EconHandler econ;
|
||||
private PermHandler perm;
|
||||
|
||||
@Getter private Injector injector;
|
||||
|
||||
@Inject private PlotAreaManager plotAreaManager;
|
||||
@Inject private EventDispatcher eventDispatcher;
|
||||
@Inject private PlotListener plotListener;
|
||||
@Inject @WorldConfig private YamlConfiguration worldConfiguration;
|
||||
@Inject @WorldFile private File worldfile;
|
||||
@Inject private BukkitPlayerManager playerManager;
|
||||
@Inject private BackupManager backupManager;
|
||||
@Inject @ImpromptuPipeline private UUIDPipeline impromptuPipeline;
|
||||
@Inject @BackgroundPipeline private UUIDPipeline backgroundPipeline;
|
||||
@Inject private PlatformWorldManager<World> worldManager;
|
||||
|
||||
@Override public int[] getServerVersion() {
|
||||
if (this.version == null) {
|
||||
try {
|
||||
@ -193,9 +213,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
PlotSquared.debug(StringMan.getString(Bukkit.getBukkitVersion()));
|
||||
PlotSquared.debug(
|
||||
StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\.")));
|
||||
return new int[] {1, 13, 0};
|
||||
}
|
||||
}
|
||||
@ -208,11 +225,14 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
|
||||
@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));
|
||||
|
||||
new PlotSquared(this, "Bukkit");
|
||||
final PlotSquared plotSquared = new PlotSquared(this, "Bukkit");
|
||||
|
||||
if (PlotSquared.get().IMP.getServerVersion()[1] < 13) {
|
||||
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.");
|
||||
System.out
|
||||
@ -222,182 +242,283 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
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 WorldManagerModule(), new PlotSquaredModule(),
|
||||
new BukkitModule(this), new BackupModule());
|
||||
this.injector.injectMembers(this);
|
||||
|
||||
if (PremiumVerification.isPremium() && Settings.Enabled_Components.UPDATE_NOTIFICATIONS) {
|
||||
new UpdateUtility(this).updateChecker();
|
||||
injector.getInstance(UpdateUtility.class).updateChecker();
|
||||
}
|
||||
|
||||
if (PremiumVerification.isPremium()) {
|
||||
PlotSquared.log(
|
||||
Captions.PREFIX + "&6PlotSquared version licensed to Spigot user " + getUserID());
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/" + getResourceID());
|
||||
PlotSquared.log(Captions.PREFIX + "&6Download ID: " + getDownloadID());
|
||||
PlotSquared.log(Captions.PREFIX + "&6Thanks for supporting us :)");
|
||||
logger.info("[P2] PlotSquared version licensed to Spigot user {}", getUserID());
|
||||
logger.info("[P2] https://www.spigotmc.org/resources/{}", getResourceID());
|
||||
logger.info("[P2] Download ID: {}", getDownloadID());
|
||||
logger.info("[P2] Thanks for supporting us :)");
|
||||
} else {
|
||||
PlotSquared.log(Captions.PREFIX + "&6Couldn't verify purchase :(");
|
||||
logger.info("[P2] Couldn't verify purchase :(");
|
||||
}
|
||||
|
||||
final UUIDPipeline impromptuPipeline = PlotSquared.get().getImpromptuUUIDPipeline();
|
||||
final UUIDPipeline backgroundPipeline = PlotSquared.get().getBackgroundUUIDPipeline();
|
||||
// Database
|
||||
if (Settings.Enabled_Components.DATABASE) {
|
||||
plotSquared.setupDatabase();
|
||||
}
|
||||
|
||||
// Check if we need to convert old flag values, etc
|
||||
if (!plotSquared.getConfigurationVersion().equalsIgnoreCase("v5")) {
|
||||
// Perform upgrade
|
||||
if (DBFunc.dbManager.convertFlags()) {
|
||||
log(Captions.PREFIX.getTranslated() + "Flags were converted successfully!");
|
||||
// Update the config version
|
||||
try {
|
||||
plotSquared.setConfigurationVersion("v5");
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comments
|
||||
CommentManager.registerDefaultInboxes();
|
||||
|
||||
plotSquared.startExpiryTasks();
|
||||
|
||||
// This is getting removed so I won't even bother migrating it
|
||||
ChatManager.manager = this.initChatManager();
|
||||
|
||||
// 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 {
|
||||
logger.info("[P2] {} hooked into WorldEdit", this.getPluginName());
|
||||
WorldEdit.getInstance().getEventBus().register(this.getInjector().getInstance(WESubscriber.class));
|
||||
if (Settings.Enabled_Components.COMMANDS) {
|
||||
new WE_Anywhere();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error("[P2] 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(() -> {
|
||||
final PermHandler permHandler = getInjector().getInstance(PermHandler.class);
|
||||
if (permHandler != null) {
|
||||
permHandler.init();
|
||||
}
|
||||
final EconHandler econHandler = getInjector().getInstance(EconHandler.class);
|
||||
if (econHandler != null) {
|
||||
econHandler.init();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (Settings.Enabled_Components.COMPONENT_PRESETS) {
|
||||
try {
|
||||
getInjector().getInstance(ComponentPresetManager.class);
|
||||
} catch (final Exception e) {
|
||||
logger.error("[P2] Failed to initialize the preset system", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 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("*")) {
|
||||
logger.warn("[P2] `{}` was not properly loaded - {} will now try to load it properly",
|
||||
world, this.getPluginName());
|
||||
logger.warn("[P2] - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml");
|
||||
logger.warn("[P2] - Your world management plugin may be faulty (or non existent)");
|
||||
logger.warn("[P2] 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);
|
||||
PlotSquared.log(Captions.PREFIX + "(UUID) Using the offline mode UUID service");
|
||||
this.impromptuPipeline.registerService(offlineModeUUIDService);
|
||||
this.backgroundPipeline.registerService(offlineModeUUIDService);
|
||||
logger.info("[P2] (UUID) Using the offline mode UUID service");
|
||||
}
|
||||
|
||||
final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService();
|
||||
impromptuPipeline.registerService(offlinePlayerUUIDService);
|
||||
backgroundPipeline.registerService(offlinePlayerUUIDService);
|
||||
if (Settings.UUID.SERVICE_BUKKIT) {
|
||||
final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService();
|
||||
this.impromptuPipeline.registerService(offlinePlayerUUIDService);
|
||||
this.backgroundPipeline.registerService(offlinePlayerUUIDService);
|
||||
}
|
||||
|
||||
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db");
|
||||
|
||||
final SQLiteUUIDService legacyUUIDService;
|
||||
if (Settings.UUID.LEGACY_DATABASE_SUPPORT && MainUtil
|
||||
.getFile(PlotSquared.get().IMP.getDirectory(), "usercache.db").exists()) {
|
||||
.getFile(PlotSquared.platform().getDirectory(), "usercache.db").exists()) {
|
||||
legacyUUIDService = new SQLiteUUIDService("usercache.db");
|
||||
} else {
|
||||
legacyUUIDService = null;
|
||||
}
|
||||
|
||||
final LuckPermsUUIDService luckPermsUUIDService;
|
||||
if (Bukkit.getPluginManager().getPlugin("LuckPerms") != null) {
|
||||
if (Settings.UUID.SERVICE_LUCKPERMS &&
|
||||
Bukkit.getPluginManager().getPlugin("LuckPerms") != null) {
|
||||
luckPermsUUIDService = new LuckPermsUUIDService();
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX + "(UUID) Using LuckPerms as a complementary UUID service");
|
||||
logger.info("[P2] (UUID) Using LuckPerms as a complementary UUID service");
|
||||
} else {
|
||||
luckPermsUUIDService = null;
|
||||
}
|
||||
|
||||
final BungeePermsUUIDService bungeePermsUUIDService;
|
||||
if (Bukkit.getPluginManager().getPlugin("BungeePerms") != null) {
|
||||
if (Settings.UUID.SERVICE_BUNGEE_PERMS &&
|
||||
Bukkit.getPluginManager().getPlugin("BungeePerms") != null) {
|
||||
bungeePermsUUIDService = new BungeePermsUUIDService();
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX + "(UUID) Using BungeePerms as a complementary UUID service");
|
||||
logger.info("[P2] (UUID) Using BungeePerms as a complementary UUID service");
|
||||
} else {
|
||||
bungeePermsUUIDService = null;
|
||||
}
|
||||
|
||||
final EssentialsUUIDService essentialsUUIDService;
|
||||
if (Bukkit.getPluginManager().getPlugin("Essentials") != null) {
|
||||
if (Settings.UUID.SERVICE_ESSENTIALSX && Bukkit.getPluginManager().getPlugin("Essentials") != null) {
|
||||
essentialsUUIDService = new EssentialsUUIDService();
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX + "(UUID) Using Essentials as a complementary UUID service");
|
||||
logger.info("[P2] (UUID) Using EssentialsX as a complementary UUID service");
|
||||
} else {
|
||||
essentialsUUIDService = null;
|
||||
}
|
||||
|
||||
if (!Settings.UUID.OFFLINE) {
|
||||
// If running Paper we'll also try to use their profiles
|
||||
if (PaperLib.isPaper()) {
|
||||
if (Bukkit.getOnlineMode() && PaperLib.isPaper() && Settings.UUID.SERVICE_PAPER) {
|
||||
final PaperUUIDService paperUUIDService = new PaperUUIDService();
|
||||
impromptuPipeline.registerService(paperUUIDService);
|
||||
backgroundPipeline.registerService(paperUUIDService);
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX + "(UUID) Using Paper as a complementary UUID service");
|
||||
this.impromptuPipeline.registerService(paperUUIDService);
|
||||
this.backgroundPipeline.registerService(paperUUIDService);
|
||||
logger.info("[P2] (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");
|
||||
logger.info("[P2] PlotSquared hooked into PlaceholderAPI");
|
||||
} else {
|
||||
PlotSquared
|
||||
.debug(Captions.PREFIX + "&6PlaceholderAPI is not in use. Hook deactivated.");
|
||||
logger.info("[P2] PlaceholderAPI is not in use. Hook deactivated");
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
// Clean up potential memory leak
|
||||
Bukkit.getScheduler().runTaskTimer(this, () -> {
|
||||
try {
|
||||
@ -424,10 +545,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
event.printStackTrace();
|
||||
}
|
||||
}
|
||||
final PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
|
||||
if (manager instanceof SinglePlotAreaManager) {
|
||||
|
||||
if (this.plotAreaManager instanceof SinglePlotAreaManager) {
|
||||
long start = System.currentTimeMillis();
|
||||
final SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
|
||||
final SinglePlotArea area = ((SinglePlotAreaManager) this.plotAreaManager).getArea();
|
||||
|
||||
outer:
|
||||
for (final World world : Bukkit.getWorlds()) {
|
||||
@ -457,7 +578,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
final Chunk[] chunks = world.getLoadedChunks();
|
||||
if (chunks.length == 0) {
|
||||
if (!Bukkit.unloadWorld(world, true)) {
|
||||
PlotSquared.debug("Failed to unload " + world.getName());
|
||||
logger.warn("[P2] Failed to unload {}", world.getName());
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
@ -491,8 +612,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
}
|
||||
}
|
||||
|
||||
private void startUuidCaching(@NotNull final SQLiteUUIDService sqLiteUUIDService,
|
||||
@NotNull final CacheUUIDService cacheUUIDService) {
|
||||
private void startUuidCaching(@Nonnull final SQLiteUUIDService sqLiteUUIDService,
|
||||
@Nonnull final CacheUUIDService cacheUUIDService) {
|
||||
// Load all uuids into a big chunky boi queue
|
||||
final Queue<UUID> uuidQueue = new LinkedBlockingQueue<>();
|
||||
PlotSquared.get().forEachPlotRaw(plot -> {
|
||||
@ -507,8 +628,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
}
|
||||
}
|
||||
});
|
||||
PlotSquared.log(Captions.PREFIX.getTranslated() + "(UUID) " + uuidQueue.size()
|
||||
+ " UUIDs will be cached.");
|
||||
|
||||
logger.info("[P2] (UUID) {} UUIDs will be cached", uuidQueue.size());
|
||||
|
||||
Executors.newSingleThreadScheduledExecutor().schedule(() -> {
|
||||
// Begin by reading all the SQLite cache at once
|
||||
@ -516,9 +637,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
// Now fetch names for all known UUIDs
|
||||
final int totalSize = uuidQueue.size();
|
||||
int read = 0;
|
||||
PlotSquared.log(Captions.PREFIX.getTranslated()
|
||||
+ "(UUID) PlotSquared will fetch UUIDs in groups of "
|
||||
+ Settings.UUID.BACKGROUND_LIMIT);
|
||||
logger.info("[P2] (UUID) PlotSquared will fetch UUIDs in groups of {}", Settings.UUID.BACKGROUND_LIMIT);
|
||||
final List<UUID> uuidList = new ArrayList<>(Settings.UUID.BACKGROUND_LIMIT);
|
||||
|
||||
// Used to indicate that the second retrieval has been attempted
|
||||
@ -526,7 +645,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
|
||||
while (!uuidQueue.isEmpty() || !uuidList.isEmpty()) {
|
||||
if (!uuidList.isEmpty() && secondRun) {
|
||||
PlotSquared.log("Giving up on last batch. Fetching new batch instead.");
|
||||
logger.warn("[P2] (UUID) Giving up on last batch. Fetching new batch instead");
|
||||
uuidList.clear();
|
||||
}
|
||||
if (uuidList.isEmpty()) {
|
||||
@ -550,15 +669,14 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
uuidList.clear();
|
||||
// Print progress
|
||||
final double percentage = ((double) read / (double) totalSize) * 100.0D;
|
||||
PlotSquared.log(Captions.PREFIX.getTranslated() + String
|
||||
.format("(UUID) PlotSquared has cached %.1f%% of UUIDs", percentage));
|
||||
if (Settings.DEBUG) {
|
||||
logger.info("[P2] (UUID) PlotSquared has cached {} of UUIDs", String.format("%.1f%%", percentage));
|
||||
}
|
||||
} catch (final InterruptedException | ExecutionException e) {
|
||||
PlotSquared.log("Failed to retrieve that batch. Will try again.");
|
||||
e.printStackTrace();
|
||||
logger.error("[P2] (UUID) Failed to retrieve last batch. Will try again", e);
|
||||
}
|
||||
}
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX.getTranslated() + "(UUID) PlotSquared has cached all UUIDs");
|
||||
logger.info("[P2] (UUID) PlotSquared has cached all UUIDs");
|
||||
}, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@ -567,7 +685,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
}
|
||||
|
||||
@Override public void log(@NonNull String message) {
|
||||
@Override public void log(@Nonnull String message) {
|
||||
try {
|
||||
message = Captions.color(message);
|
||||
if (!Settings.Chat.CONSOLE_COLOR) {
|
||||
@ -583,21 +701,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
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) {
|
||||
@ -615,13 +719,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
return Bukkit.getWorldContainer();
|
||||
}
|
||||
|
||||
@Override public TaskManager getTaskManager() {
|
||||
return new BukkitTaskManager(this);
|
||||
}
|
||||
|
||||
@Override @SuppressWarnings("deprecation") public void runEntityTask() {
|
||||
PlotSquared.log(Captions.PREFIX + "KillAllEntities started.");
|
||||
TaskManager.runTaskRepeat(() -> PlotSquared.get().forEachPlotArea(plotArea -> {
|
||||
@SuppressWarnings("deprecation") private void runEntityTask() {
|
||||
logger.info("[P2] KillAllEntities started");
|
||||
TaskManager.runTaskRepeat(() -> this.plotAreaManager.forEachPlotArea(plotArea -> {
|
||||
final World world = Bukkit.getWorld(plotArea.getWorldName());
|
||||
try {
|
||||
if (world == null) {
|
||||
@ -756,7 +856,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
if (currentPlotId != null) {
|
||||
entity.setMetadata("shulkerPlot",
|
||||
new FixedMetadataValue(
|
||||
(Plugin) PlotSquared.get().IMP, currentPlotId));
|
||||
(Plugin) PlotSquared.platform(), currentPlotId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -875,13 +975,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
}
|
||||
|
||||
@Override @Nullable
|
||||
public final ChunkGenerator getDefaultWorldGenerator(@NotNull final String worldName,
|
||||
public final ChunkGenerator getDefaultWorldGenerator(@Nonnull final String worldName,
|
||||
final String id) {
|
||||
final IndependentPlotGenerator result;
|
||||
if (id != null && id.equalsIgnoreCase("single")) {
|
||||
result = new SingleWorldGenerator();
|
||||
result = getInjector().getInstance(SingleWorldGenerator.class);
|
||||
} else {
|
||||
result = PlotSquared.get().IMP.getDefaultGenerator();
|
||||
result = getInjector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class));
|
||||
if (!PlotSquared.get().setupPlotWorld(worldName, id, result)) {
|
||||
return null;
|
||||
}
|
||||
@ -889,85 +989,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
return (ChunkGenerator) result.specify(worldName);
|
||||
}
|
||||
|
||||
@Override public void registerPlayerEvents() {
|
||||
final PlayerEvents main = new PlayerEvents();
|
||||
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);
|
||||
}
|
||||
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,
|
||||
@Override @Nullable public GeneratorWrapper<?> getGenerator(@Nonnull final String world,
|
||||
@Nullable final String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
@ -978,20 +1000,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
if (gen instanceof GeneratorWrapper<?>) {
|
||||
return (GeneratorWrapper<?>) gen;
|
||||
}
|
||||
return new BukkitPlotGenerator(world, gen);
|
||||
return new BukkitPlotGenerator(world, gen, this.plotAreaManager);
|
||||
} else {
|
||||
return new BukkitPlotGenerator(world, PlotSquared.get().IMP.getDefaultGenerator());
|
||||
return new BukkitPlotGenerator(world, getInjector()
|
||||
.getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)), this.plotAreaManager);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public HybridUtils initHybridUtils() {
|
||||
return new BukkitHybridUtils();
|
||||
}
|
||||
|
||||
@Override public SetupUtils initSetupUtils() {
|
||||
return new BukkitSetupUtils();
|
||||
}
|
||||
|
||||
@Override public void startMetrics() {
|
||||
if (this.metricsStarted) {
|
||||
return;
|
||||
@ -1007,7 +1022,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
}
|
||||
map.put(plotAreaType.name().toLowerCase(), terrainTypes);
|
||||
}
|
||||
for (final PlotArea plotArea : PlotSquared.get().getPlotAreas()) {
|
||||
for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) {
|
||||
final Map<String, Integer> terrainTypeMap =
|
||||
map.get(plotArea.getType().name().toLowerCase());
|
||||
terrainTypeMap.put(plotArea.getTerrain().name().toLowerCase(),
|
||||
@ -1023,56 +1038,31 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
"WorldEdit"));
|
||||
}
|
||||
|
||||
@Override public ChunkManager initChunkManager() {
|
||||
return new BukkitChunkManager();
|
||||
}
|
||||
|
||||
@Override public RegionManager initRegionManager() {
|
||||
return new BukkitRegionManager();
|
||||
}
|
||||
|
||||
@Override public void unregister(@NonNull final PlotPlayer player) {
|
||||
@Override public void unregister(@Nonnull final PlotPlayer player) {
|
||||
BukkitUtil.removePlayer(player.getUUID());
|
||||
}
|
||||
|
||||
@Override public void registerChunkProcessor() {
|
||||
getServer().getPluginManager().registerEvents(new ChunkListener(), this);
|
||||
}
|
||||
|
||||
@Override public void registerWorldEvents() {
|
||||
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
|
||||
}
|
||||
|
||||
@NotNull @Override public IndependentPlotGenerator getDefaultGenerator() {
|
||||
return new HybridGen();
|
||||
}
|
||||
|
||||
@Override public InventoryUtil initInventoryUtil() {
|
||||
return new BukkitInventoryUtil();
|
||||
}
|
||||
|
||||
@Override public void setGenerator(@NonNull final String worldName) {
|
||||
@Override public void setGenerator(@Nonnull final String worldName) {
|
||||
World world = BukkitUtil.getWorld(worldName);
|
||||
if (world == null) {
|
||||
// create world
|
||||
ConfigurationSection worldConfig =
|
||||
PlotSquared.get().worlds.getConfigurationSection("worlds." + worldName);
|
||||
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 {
|
||||
if (!PlotSquared.get().hasPlotArea(worldName)) {
|
||||
if (!this.plotAreaManager.hasPlotArea(worldName)) {
|
||||
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
PlotSquared.log("Failed to reload world: " + world + " | " + e.getMessage());
|
||||
} catch (final Exception e) {
|
||||
logger.error("[P2] Failed to reload world: {} | {}", world, e.getMessage());
|
||||
Bukkit.getServer().unloadWorld(world, false);
|
||||
return;
|
||||
}
|
||||
@ -1082,16 +1072,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
if (gen instanceof BukkitPlotGenerator) {
|
||||
PlotSquared.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
|
||||
} else if (gen != null) {
|
||||
PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen));
|
||||
} else if (PlotSquared.get().worlds.contains("worlds." + worldName)) {
|
||||
PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen, this.plotAreaManager));
|
||||
} else if (this.worldConfiguration.contains("worlds." + worldName)) {
|
||||
PlotSquared.get().loadWorld(worldName, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public SchematicHandler initSchematicHandler() {
|
||||
return new BukkitSchematicHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to retrieve a {@link PlotPlayer} from a player identifier.
|
||||
* This method accepts:
|
||||
@ -1115,11 +1101,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
return BukkitUtil.getPlayer((OfflinePlayer) player);
|
||||
}
|
||||
if (player instanceof String) {
|
||||
return (PlotPlayer<Player>) PlotSquared.imp().getPlayerManager()
|
||||
return (PlotPlayer<Player>) PlotSquared.platform().getPlayerManager()
|
||||
.getPlayerIfExists((String) player);
|
||||
}
|
||||
if (player instanceof UUID) {
|
||||
return (PlotPlayer<Player>) PlotSquared.imp().getPlayerManager()
|
||||
return (PlotPlayer<Player>) PlotSquared.platform().getPlayerManager()
|
||||
.getPlayerIfExists((UUID) player);
|
||||
}
|
||||
return null;
|
||||
@ -1131,8 +1117,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
}
|
||||
|
||||
@Override public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world,
|
||||
@NonNull final IndependentPlotGenerator generator) {
|
||||
return new BukkitPlotGenerator(world, generator);
|
||||
@Nonnull final IndependentPlotGenerator generator) {
|
||||
return new BukkitPlotGenerator(world, generator, this.plotAreaManager);
|
||||
}
|
||||
|
||||
@Override public List<Map.Entry<Map.Entry<String, String>, Boolean>> getPluginIds() {
|
||||
@ -1145,16 +1131,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
||||
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 public com.plotsquared.core.location.World<?> getPlatformWorld(@Nonnull final String worldName) {
|
||||
return BukkitWorld.of(worldName);
|
||||
}
|
||||
|
||||
@Override @NotNull public Audience getConsoleAudience() {
|
@ -26,11 +26,12 @@
|
||||
package com.plotsquared.bukkit.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Getter
|
||||
public abstract class EntityWrapper {
|
||||
@ -43,7 +44,7 @@ public abstract class EntityWrapper {
|
||||
public double y;
|
||||
public double z;
|
||||
|
||||
EntityWrapper(@NonNull final Entity entity) {
|
||||
EntityWrapper(@Nonnull final Entity entity) {
|
||||
this.entity = entity;
|
||||
this.type = entity.getType();
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.entity;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
@ -55,11 +55,15 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + ReplicatingEntityWrapper.class.getSimpleName());
|
||||
|
||||
private final short depth;
|
||||
private final int hash;
|
||||
private final EntityBaseStats base = new EntityBaseStats();
|
||||
@ -331,10 +335,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
this.dataByte = (byte) 0;
|
||||
}
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
// END LIVING //
|
||||
default:
|
||||
PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,7 +391,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
try {
|
||||
entity.getInventory().setContents(this.inventory);
|
||||
} catch (IllegalArgumentException e) {
|
||||
PlotSquared.debug("&c[WARN] Failed to restore inventory.\n Reason: " + e.getMessage());
|
||||
logger.error("[P2] Failed to restore inventory", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -736,7 +737,9 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
default:
|
||||
PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
|
||||
if (Settings.DEBUG) {
|
||||
logger.info("[P2] Could not identify entity: {}", entity.getType());
|
||||
}
|
||||
return entity;
|
||||
// END LIVING
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.entity;
|
||||
|
||||
import com.plotsquared.bukkit.BukkitMain;
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -53,7 +53,7 @@ public class TeleportEntityWrapper extends EntityWrapper {
|
||||
getEntity().setInvulnerable(invulnerableOld);
|
||||
getEntity().setFireTicks(fireTicksOld);
|
||||
getEntity().setTicksLived(livingTicksOld);
|
||||
getEntity().removeMetadata("ps-tmp-teleport", BukkitMain.getPlugin(BukkitMain.class));
|
||||
getEntity().removeMetadata("ps-tmp-teleport", BukkitPlatform.getPlugin(BukkitPlatform.class));
|
||||
}
|
||||
return getEntity();
|
||||
}
|
||||
@ -78,7 +78,7 @@ public class TeleportEntityWrapper extends EntityWrapper {
|
||||
this.fireTicksOld = this.getEntity().getFireTicks();
|
||||
this.livingTicksOld = this.getEntity().getTicksLived();
|
||||
this.getEntity().setMetadata("ps-tmp-teleport",
|
||||
new FixedMetadataValue(BukkitMain.getPlugin(BukkitMain.class), oldLocation));
|
||||
new FixedMetadataValue(BukkitPlatform.getPlugin(BukkitPlatform.class), oldLocation));
|
||||
final Chunk newChunk = getNewChunk();
|
||||
this.getEntity().teleport(
|
||||
new Location(newChunk.getWorld(), newChunk.getX() << 4, 5000, newChunk.getZ() << 4));
|
||||
|
@ -29,32 +29,40 @@ import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||
import com.plotsquared.core.location.ChunkWrapper;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.queue.LocalBlockQueue;
|
||||
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
final class BlockStatePopulator extends BlockPopulator {
|
||||
|
||||
private final IndependentPlotGenerator plotGenerator;
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
|
||||
private LocalBlockQueue queue;
|
||||
|
||||
public BlockStatePopulator(IndependentPlotGenerator plotGenerator) {
|
||||
public BlockStatePopulator(@Nonnull final IndependentPlotGenerator plotGenerator,
|
||||
@Nonnull final PlotAreaManager plotAreaManager) {
|
||||
this.plotGenerator = plotGenerator;
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(@NotNull final World world, @NotNull final Random random,
|
||||
@NotNull final Chunk source) {
|
||||
public void populate(@Nonnull final World world, @Nonnull final Random random,
|
||||
@Nonnull final Chunk source) {
|
||||
if (this.queue == null) {
|
||||
this.queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false);
|
||||
this.queue = PlotSquared.platform().getGlobalBlockQueue()
|
||||
.getNewQueue(world.getName(), false);
|
||||
}
|
||||
final PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null);
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
final PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
|
||||
final ChunkWrapper wrap =
|
||||
new ChunkWrapper(area.getWorldName(), source.getX(), source.getZ());
|
||||
final ScopedLocalBlockQueue chunk = this.queue.getForChunk(wrap.x, wrap.z);
|
||||
|
@ -29,7 +29,7 @@ import com.plotsquared.core.generator.AugmentedUtils;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@ -51,7 +51,7 @@ public class BukkitAugmentedGenerator extends BlockPopulator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk source) {
|
||||
public void populate(@Nonnull World world, @Nonnull Random random, @Nonnull Chunk source) {
|
||||
AugmentedUtils.generate(source, world.getName(), source.getX(), source.getZ(), null);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||
import com.plotsquared.core.generator.SingleWorldGenerator;
|
||||
import com.plotsquared.core.location.ChunkWrapper;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
@ -42,7 +43,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -54,6 +55,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
|
||||
@SuppressWarnings("unused") public final boolean PAPER_ASYNC_SAFE = true;
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final IndependentPlotGenerator plotGenerator;
|
||||
private final ChunkGenerator platformGenerator;
|
||||
private final boolean full;
|
||||
@ -62,24 +64,25 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
|
||||
@Getter private final String levelName;
|
||||
|
||||
public BukkitPlotGenerator(String name, IndependentPlotGenerator generator) {
|
||||
if (generator == null) {
|
||||
throw new IllegalArgumentException("Generator may not be null!");
|
||||
}
|
||||
public BukkitPlotGenerator(@Nonnull final String name,
|
||||
@Nonnull final IndependentPlotGenerator generator,
|
||||
@Nonnull final PlotAreaManager plotAreaManager) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.levelName = name;
|
||||
this.plotGenerator = generator;
|
||||
this.platformGenerator = this;
|
||||
this.populators = new ArrayList<>();
|
||||
this.populators.add(new BlockStatePopulator(this.plotGenerator));
|
||||
this.populators.add(new BlockStatePopulator(this.plotGenerator, this.plotAreaManager));
|
||||
this.full = true;
|
||||
MainUtil.initCache();
|
||||
}
|
||||
|
||||
public BukkitPlotGenerator(final String world, final ChunkGenerator cg) {
|
||||
public BukkitPlotGenerator(final String world, final ChunkGenerator cg, @Nonnull final PlotAreaManager plotAreaManager) {
|
||||
if (cg instanceof BukkitPlotGenerator) {
|
||||
throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName()
|
||||
+ " is already a BukkitPlotGenerator!");
|
||||
}
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.levelName = world;
|
||||
this.full = false;
|
||||
this.platformGenerator = cg;
|
||||
@ -103,12 +106,12 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
return this.platformGenerator;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
||||
@Override @Nonnull public List<BlockPopulator> getDefaultPopulators(@Nonnull World world) {
|
||||
try {
|
||||
if (!this.loaded) {
|
||||
String name = world.getName();
|
||||
PlotSquared.get().loadWorld(name, this);
|
||||
Set<PlotArea> areas = PlotSquared.get().getPlotAreas(name);
|
||||
final Set<PlotArea> areas = this.plotAreaManager.getPlotAreasSet(name);
|
||||
if (!areas.isEmpty()) {
|
||||
PlotArea area = areas.iterator().next();
|
||||
if (!area.isMobSpawning()) {
|
||||
@ -147,9 +150,9 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
return toAdd;
|
||||
}
|
||||
|
||||
@Override @NotNull
|
||||
public ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z,
|
||||
@NotNull BiomeGrid biome) {
|
||||
@Override @Nonnull
|
||||
public ChunkData generateChunkData(@Nonnull World world, @Nonnull Random random, int x, int z,
|
||||
@Nonnull BiomeGrid biome) {
|
||||
|
||||
GenChunk result = new GenChunk();
|
||||
if (this.getPlotGenerator() instanceof SingleWorldGenerator) {
|
||||
@ -198,8 +201,8 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
if (ChunkManager.preProcessChunk(loc, result)) {
|
||||
return;
|
||||
}
|
||||
PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
|
||||
if (area == null && (area = PlotSquared.get().getPlotArea(this.levelName, null)) == null) {
|
||||
PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null);
|
||||
if (area == null && (area = this.plotAreaManager.getPlotArea(this.levelName, null)) == null) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot regenerate chunk that does not belong to a plot area." + " Location: " + loc
|
||||
+ ", world: " + world);
|
||||
@ -213,7 +216,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
ChunkManager.postProcessChunk(loc, result);
|
||||
}
|
||||
|
||||
@Override public boolean canSpawn(@NotNull final World world, final int x, final int z) {
|
||||
@Override public boolean canSpawn(@Nonnull final World world, final int x, final int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.Random;
|
||||
@ -61,7 +61,7 @@ final class DelegatePlotGenerator extends IndependentPlotGenerator {
|
||||
}
|
||||
|
||||
@Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
|
||||
return PlotSquared.get().IMP.getDefaultGenerator().getNewPlotArea(world, id, min, max);
|
||||
return PlotSquared.platform().getDefaultGenerator().getNewPlotArea(world, id, min, max);
|
||||
}
|
||||
|
||||
@Override public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings) {
|
||||
@ -74,21 +74,21 @@ final class DelegatePlotGenerator extends IndependentPlotGenerator {
|
||||
ChunkGenerator.BiomeGrid grid = new ChunkGenerator.BiomeGrid() {
|
||||
@Override
|
||||
public void setBiome(@Range(from = 0, to = 15) int x,
|
||||
@Range(from = 0, to = 15) int z, @NotNull Biome biome) {
|
||||
@Range(from = 0, to = 15) int z, @Nonnull Biome biome) {
|
||||
result.setBiome(x, z, BukkitAdapter.adapt(biome));
|
||||
}
|
||||
|
||||
//do not annotate with Override until we discontinue support for 1.4.4
|
||||
public void setBiome(int x, int y, int z, @NotNull Biome biome) {
|
||||
public void setBiome(int x, int y, int z, @Nonnull Biome biome) {
|
||||
result.setBiome(x, z, BukkitAdapter.adapt(biome));
|
||||
|
||||
}
|
||||
|
||||
@Override @NotNull public Biome getBiome(int x, int z) {
|
||||
@Override @Nonnull public Biome getBiome(int x, int z) {
|
||||
return Biome.FOREST;
|
||||
}
|
||||
|
||||
@Override public @NotNull Biome getBiome(int x, int y, int z) {
|
||||
@Override public @Nonnull Biome getBiome(int x, int y, int z) {
|
||||
return Biome.FOREST;
|
||||
}
|
||||
};
|
||||
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.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.inject.factory.PlayerBackupProfileFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class BackupModule extends AbstractModule {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + BackupModule.class.getSimpleName());
|
||||
|
||||
@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) {
|
||||
logger.error("[P2] Failed to initialize backup manager", e);
|
||||
logger.error("[P2] Backup features will be disabled");
|
||||
bind(BackupManager.class).to(NullBackupManager.class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.google.inject.util.Providers;
|
||||
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.IndependentPlotGenerator;
|
||||
import com.plotsquared.core.inject.annotations.ConsoleActor;
|
||||
import com.plotsquared.core.inject.annotations.DefaultGenerator;
|
||||
import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
|
||||
import com.plotsquared.core.plot.world.DefaultPlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
||||
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 javax.annotation.Nonnull;
|
||||
|
||||
@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
|
||||
@Nonnull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
||||
WorldEditPlugin wePlugin = ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
|
||||
bind(Actor.class).annotatedWith(ConsoleActor.class).toInstance(wePlugin.wrapCommandSender(console));
|
||||
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);
|
||||
this.setupVault();
|
||||
if (Settings.Enabled_Components.WORLDS) {
|
||||
bind(PlotAreaManager.class).to(SinglePlotAreaManager.class);
|
||||
} else {
|
||||
bind(PlotAreaManager.class).to(DefaultPlotAreaManager.class);
|
||||
}
|
||||
install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class));
|
||||
}
|
||||
|
||||
private void setupVault() {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
||||
BukkitPermHandler bukkitPermHandler = null;
|
||||
try {
|
||||
bukkitPermHandler = new BukkitPermHandler();
|
||||
bind(PermHandler.class).toInstance(bukkitPermHandler);
|
||||
} catch (final Exception ignored) {
|
||||
bind(PermHandler.class).toProvider(Providers.of(null));
|
||||
}
|
||||
try {
|
||||
final BukkitEconHandler bukkitEconHandler = new BukkitEconHandler(bukkitPermHandler);
|
||||
bind(EconHandler.class).toInstance(bukkitEconHandler);
|
||||
} catch (final Exception ignored) {
|
||||
bind(EconHandler.class).toProvider(Providers.of(null));
|
||||
}
|
||||
} else {
|
||||
bind(PermHandler.class).toProvider(Providers.of(null));
|
||||
bind(EconHandler.class).toProvider(Providers.of(null));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -23,11 +23,30 @@
|
||||
* 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.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
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;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class BukkitHybridUtils extends HybridUtils {
|
||||
public class WorldManagerModule extends AbstractModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
PlatformWorldManager<World> provideWorldManager() {
|
||||
if (Bukkit.getPluginManager().getPlugin("Hyperverse") != null) {
|
||||
return new HyperverseWorldManager();
|
||||
} else if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) {
|
||||
return new MultiverseWorldManager();
|
||||
} else {
|
||||
return new BukkitWorldManager();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -25,10 +25,12 @@
|
||||
*/
|
||||
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;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.ReflectionUtils.RefClass;
|
||||
import com.plotsquared.core.util.ReflectionUtils.RefField;
|
||||
import com.plotsquared.core.util.ReflectionUtils.RefMethod;
|
||||
@ -51,6 +53,9 @@ import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
@ -60,12 +65,17 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
@SuppressWarnings("unused")
|
||||
public class ChunkListener implements Listener {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + ChunkListener.class.getSimpleName());
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
|
||||
private RefMethod methodGetHandleChunk;
|
||||
private RefField mustSave;
|
||||
private Chunk lastChunk;
|
||||
private boolean ignoreUnload = false;
|
||||
|
||||
public ChunkListener() {
|
||||
@Inject public ChunkListener(@Nonnull final PlotAreaManager plotAreaManager) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
if (Settings.Chunk_Processor.AUTO_TRIM) {
|
||||
try {
|
||||
RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
@ -73,9 +83,6 @@ public class ChunkListener implements Listener {
|
||||
this.mustSave = classChunk.getField("mustSave");
|
||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||
} catch (Throwable ignored) {
|
||||
PlotSquared.debug(PlotSquared.get().IMP.getPluginName()
|
||||
+ "/Server not compatible for chunk processor trim/gc");
|
||||
|
||||
Settings.Chunk_Processor.AUTO_TRIM = false;
|
||||
}
|
||||
}
|
||||
@ -90,7 +97,7 @@ public class ChunkListener implements Listener {
|
||||
HashSet<Chunk> toUnload = new HashSet<>();
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
String worldName = world.getName();
|
||||
if (!PlotSquared.get().hasPlotArea(worldName)) {
|
||||
if (!this.plotAreaManager.hasPlotArea(worldName)) {
|
||||
continue;
|
||||
}
|
||||
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
|
||||
@ -150,23 +157,23 @@ public class ChunkListener implements Listener {
|
||||
int z = chunkZ << 4;
|
||||
int x2 = x + 15;
|
||||
int z2 = z + 15;
|
||||
Plot plot = new Location(world, x, 1, z).getOwnedPlotAbs();
|
||||
Plot plot = Location.at(world, x, 1, z).getOwnedPlotAbs();
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return true;
|
||||
}
|
||||
plot = new Location(world, x2, 1, z2).getOwnedPlotAbs();
|
||||
plot = Location.at(world, x2, 1, z2).getOwnedPlotAbs();
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return true;
|
||||
}
|
||||
plot = new Location(world, x2, 1, z).getOwnedPlotAbs();
|
||||
plot = Location.at(world, x2, 1, z).getOwnedPlotAbs();
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return true;
|
||||
}
|
||||
plot = new Location(world, x, 1, z2).getOwnedPlotAbs();
|
||||
plot = Location.at(world, x, 1, z2).getOwnedPlotAbs();
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return true;
|
||||
}
|
||||
plot = new Location(world, x + 7, 1, z + 7).getOwnedPlotAbs();
|
||||
plot = Location.at(world, x + 7, 1, z + 7).getOwnedPlotAbs();
|
||||
return plot != null && plot.hasOwner();
|
||||
}
|
||||
|
||||
@ -177,7 +184,7 @@ public class ChunkListener implements Listener {
|
||||
Chunk chunk = event.getChunk();
|
||||
if (Settings.Chunk_Processor.AUTO_TRIM) {
|
||||
String world = chunk.getWorld().getName();
|
||||
if (PlotSquared.get().hasPlotArea(world)) {
|
||||
if (this.plotAreaManager.hasPlotArea(world)) {
|
||||
if (unloadChunk(world, chunk, true)) {
|
||||
return;
|
||||
}
|
||||
@ -200,7 +207,7 @@ public class ChunkListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
Entity[] entities = chunk.getEntities();
|
||||
@ -230,7 +237,7 @@ public class ChunkListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
Entity[] entities = chunk.getEntities();
|
||||
@ -251,7 +258,6 @@ public class ChunkListener implements Listener {
|
||||
if (!chunk.isLoaded()) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PlotSquared.debug("Successfully processed and unloaded chunk!");
|
||||
chunk.unload(true);
|
||||
return;
|
||||
}
|
||||
@ -259,7 +265,6 @@ public class ChunkListener implements Listener {
|
||||
if (tiles.length == 0) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PlotSquared.debug("Successfully processed and unloaded chunk!");
|
||||
chunk.unload(true);
|
||||
return;
|
||||
}
|
||||
@ -269,7 +274,6 @@ public class ChunkListener implements Listener {
|
||||
if (i >= tiles.length - Settings.Chunk_Processor.MAX_TILES) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PlotSquared.debug("Successfully processed and unloaded chunk!");
|
||||
chunk.unload(true);
|
||||
return;
|
||||
}
|
||||
@ -281,7 +285,7 @@ public class ChunkListener implements Listener {
|
||||
}
|
||||
|
||||
public boolean processChunk(Chunk chunk, boolean unload) {
|
||||
if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) {
|
||||
return false;
|
||||
}
|
||||
Entity[] entities = chunk.getEntities();
|
||||
@ -296,16 +300,9 @@ public class ChunkListener implements Listener {
|
||||
toRemove--;
|
||||
}
|
||||
}
|
||||
|
||||
PlotSquared.debug(
|
||||
"PlotSquared detected unsafe chunk and processed: " + (chunk.getX() << 4) + "," + (
|
||||
chunk.getX() << 4));
|
||||
}
|
||||
if (tiles.length > Settings.Chunk_Processor.MAX_TILES) {
|
||||
if (unload) {
|
||||
PlotSquared.debug(
|
||||
"PlotSquared detected unsafe chunk: " + (chunk.getX() << 4) + "," + (
|
||||
chunk.getX() << 4));
|
||||
cleanChunk(chunk);
|
||||
return true;
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -65,7 +65,7 @@ public class EntitySpawnListener implements Listener {
|
||||
private static String areaName = null;
|
||||
|
||||
public static void testNether(final Entity entity) {
|
||||
@NotNull World world = entity.getWorld();
|
||||
@Nonnull World world = entity.getWorld();
|
||||
if (world.getEnvironment() != World.Environment.NETHER
|
||||
&& world.getEnvironment() != World.Environment.THE_END) {
|
||||
return;
|
||||
@ -74,11 +74,11 @@ public class EntitySpawnListener implements Listener {
|
||||
}
|
||||
|
||||
public static void testCreate(final Entity entity) {
|
||||
@NotNull World world = entity.getWorld();
|
||||
@Nonnull World world = entity.getWorld();
|
||||
if (areaName == world.getName()) {
|
||||
} else {
|
||||
areaName = world.getName();
|
||||
hasPlotArea = PlotSquared.get().hasPlotArea(areaName);
|
||||
hasPlotArea = PlotSquared.get().getPlotAreaManager().hasPlotArea(areaName);
|
||||
}
|
||||
if (!hasPlotArea) {
|
||||
return;
|
||||
@ -87,12 +87,12 @@ public class EntitySpawnListener implements Listener {
|
||||
}
|
||||
|
||||
public static void test(Entity entity) {
|
||||
@NotNull World world = entity.getWorld();
|
||||
@Nonnull World world = entity.getWorld();
|
||||
List<MetadataValue> meta = entity.getMetadata(KEY);
|
||||
if (meta.isEmpty()) {
|
||||
if (PlotSquared.get().hasPlotArea(world.getName())) {
|
||||
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world.getName())) {
|
||||
entity.setMetadata(KEY,
|
||||
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, entity.getLocation()));
|
||||
new FixedMetadataValue((Plugin) PlotSquared.platform(), entity.getLocation()));
|
||||
}
|
||||
} else {
|
||||
org.bukkit.Location origin = (org.bukkit.Location) meta.get(0).value();
|
||||
@ -161,13 +161,13 @@ public class EntitySpawnListener implements Listener {
|
||||
case SHULKER:
|
||||
if (!entity.hasMetadata("shulkerPlot")) {
|
||||
entity.setMetadata("shulkerPlot",
|
||||
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot.getId()));
|
||||
new FixedMetadataValue((Plugin) PlotSquared.platform(), plot.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onChunkLoad(ChunkLoadEvent event) {
|
||||
@NotNull Chunk chunk = event.getChunk();
|
||||
@Nonnull Chunk chunk = event.getChunk();
|
||||
for (final Entity entity : chunk.getEntities()) {
|
||||
testCreate(entity);
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ 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.PlotSquared;
|
||||
import com.plotsquared.core.command.Command;
|
||||
import com.plotsquared.core.command.MainCommand;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
@ -43,6 +43,7 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.TileState;
|
||||
@ -58,6 +59,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -71,8 +73,13 @@ import java.util.regex.Pattern;
|
||||
@SuppressWarnings("unused")
|
||||
public class PaperListener implements Listener {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private Chunk lastChunk;
|
||||
|
||||
@Inject public PaperListener(@Nonnull final PlotAreaManager plotAreaManager) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
}
|
||||
|
||||
@EventHandler public void onEntityPathfind(EntityPathfindEvent event) {
|
||||
if (!Settings.Paper_Components.ENTITY_PATHING) {
|
||||
return;
|
||||
@ -305,7 +312,7 @@ public class PaperListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer<?> pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
|
@ -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;
|
||||
@ -99,14 +100,18 @@ import com.plotsquared.core.plot.flag.implementations.VillagerInteractFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.VineGrowFlag;
|
||||
import com.plotsquared.core.plot.flag.types.BlockTypeWrapper;
|
||||
import com.plotsquared.core.plot.message.PlotMessage;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.EntityUtil;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
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;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import io.papermc.lib.PaperLib;
|
||||
@ -210,6 +215,7 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.projectiles.BlockProjectileSource;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.bukkit.util.Vector;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
@ -224,12 +230,16 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* Player Events involving plots.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PlayerEvents extends PlotListener implements Listener {
|
||||
@SuppressWarnings("unused") public class PlayerEvents extends PlotListener implements Listener {
|
||||
|
||||
public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE =
|
||||
new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake");
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final WorldEdit worldEdit;
|
||||
|
||||
private boolean pistonBlocks = true;
|
||||
private float lastRadius;
|
||||
// To prevent recursion
|
||||
private boolean tmpTeleport = true;
|
||||
@ -237,7 +247,14 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
private PlayerMoveEvent moveTmp;
|
||||
private String internalVersion;
|
||||
|
||||
{
|
||||
@Inject public PlayerEvents(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final WorldEdit worldEdit,
|
||||
@Nonnull final WorldUtil worldUtil) {
|
||||
super(eventDispatcher);
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.worldEdit = worldEdit;
|
||||
try {
|
||||
fieldPlayer = PlayerEvent.class.getDeclaredField("player");
|
||||
fieldPlayer.setAccessible(true);
|
||||
@ -253,9 +270,10 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
int z = bloc.getBlockZ();
|
||||
int distance = Bukkit.getViewDistance() * 16;
|
||||
|
||||
for (final PlotPlayer<?> player : PlotSquared.imp().getPlayerManager().getPlayers()) {
|
||||
for (final PlotPlayer<?> player : PlotSquared.platform().getPlayerManager()
|
||||
.getPlayers()) {
|
||||
Location location = player.getLocation();
|
||||
if (location.getWorld().equals(world)) {
|
||||
if (location.getWorldName().equals(world)) {
|
||||
if (16 * Math.abs(location.getX() - x) / 16 > distance
|
||||
|| 16 * Math.abs(location.getZ() - z) / 16 > distance) {
|
||||
continue;
|
||||
@ -358,20 +376,21 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (plot.isMerged()) {
|
||||
disable = true;
|
||||
for (UUID owner : plot.getOwners()) {
|
||||
if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(owner) != null) {
|
||||
if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(owner)
|
||||
!= null) {
|
||||
disable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
disable =
|
||||
PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs())
|
||||
== null;
|
||||
disable = PlotSquared.platform().getPlayerManager()
|
||||
.getPlayerIfExists(plot.getOwnerAbs()) == null;
|
||||
}
|
||||
}
|
||||
if (disable) {
|
||||
for (UUID trusted : plot.getTrusted()) {
|
||||
if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(trusted) != null) {
|
||||
if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(trusted)
|
||||
!= null) {
|
||||
disable = false;
|
||||
break;
|
||||
}
|
||||
@ -385,7 +404,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
}
|
||||
if (Settings.Redstone.DISABLE_UNOCCUPIED) {
|
||||
for (final PlotPlayer<?> player : PlotSquared.imp().getPlayerManager().getPlayers()) {
|
||||
for (final PlotPlayer<?> player : PlotSquared.platform().getPlayerManager()
|
||||
.getPlayers()) {
|
||||
if (plot.equals(player.getCurrentPlot())) {
|
||||
return;
|
||||
}
|
||||
@ -455,16 +475,16 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
switch (piston.getFacing()) {
|
||||
case EAST:
|
||||
location.setX(location.getX() + 1);
|
||||
location = location.add(1, 0, 0);
|
||||
break;
|
||||
case SOUTH:
|
||||
location.setX(location.getX() - 1);
|
||||
location = location.add(-1, 0, 0);
|
||||
break;
|
||||
case WEST:
|
||||
location.setZ(location.getZ() + 1);
|
||||
location = location.add(0, 0, 1);
|
||||
break;
|
||||
case NORTH:
|
||||
location.setZ(location.getZ() - 1);
|
||||
location = location.add(0, 0, -1);
|
||||
break;
|
||||
}
|
||||
Plot newPlot = area.getOwnedPlotAbs(location);
|
||||
@ -490,7 +510,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer<Player> pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
@ -504,7 +524,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
@EventHandler public boolean onProjectileHit(ProjectileHitEvent event) {
|
||||
Projectile entity = event.getEntity();
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return true;
|
||||
}
|
||||
PlotArea area = location.getPlotArea();
|
||||
@ -680,7 +700,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (!player.hasPlayedBefore() && player.isOnline()) {
|
||||
player.saveData();
|
||||
}
|
||||
PlotSquared.get().getEventDispatcher().doJoinTask(pp);
|
||||
this.eventDispatcher.doJoinTask(pp);
|
||||
}, 20);
|
||||
|
||||
if (pp.hasPermission(Captions.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated())
|
||||
@ -703,7 +723,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
public void playerRespawn(PlayerRespawnEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer<Player> pp = BukkitUtil.getPlayer(player);
|
||||
PlotSquared.get().getEventDispatcher().doRespawnTask(pp);
|
||||
this.eventDispatcher.doRespawnTask(pp);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
@ -803,7 +823,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
} else if (toPlot != null) {
|
||||
vehicle.setMetadata("plot",
|
||||
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, toPlot));
|
||||
new FixedMetadataValue((Plugin) PlotSquared.platform(), toPlot));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -973,7 +993,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
Set<Player> recipients = event.getRecipients();
|
||||
recipients.clear();
|
||||
Set<Player> spies = new HashSet<>();
|
||||
for (final PlotPlayer<?> pp : PlotSquared.imp().getPlayerManager().getPlayers()) {
|
||||
for (final PlotPlayer<?> pp : PlotSquared.platform().getPlayerManager().getPlayers()) {
|
||||
if (pp.getAttribute("chatspy")) {
|
||||
spies.add(((BukkitPlayer) pp).player);
|
||||
} else {
|
||||
@ -1000,7 +1020,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
player.sendMessage(spyMessage);
|
||||
}
|
||||
}
|
||||
PlotSquared.debug(full);
|
||||
// TODO: Re-implement
|
||||
// PlotSquared.debug(full);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST) public void blockDestroy(BlockBreakEvent event) {
|
||||
@ -1065,9 +1086,9 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
||||
return;
|
||||
}
|
||||
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
|
||||
if (this.worldEdit!= null && pp.getAttribute("worldedit")) {
|
||||
if (player.getInventory().getItemInMainHand().getType() == Material
|
||||
.getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) {
|
||||
.getMaterial(this.worldEdit.getConfiguration().wandItem)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1082,7 +1103,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
PlotArea area = location.getPlotArea();
|
||||
boolean plotArea = location.isPlotArea();
|
||||
if (!plotArea) {
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
@ -1105,7 +1126,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
.equals(EntityType.MINECART_TNT)) {
|
||||
if (!near.hasMetadata("plot")) {
|
||||
near.setMetadata("plot",
|
||||
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
|
||||
new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1138,7 +1159,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (plot != null) {
|
||||
plotExit(pp, plot);
|
||||
}
|
||||
if (PlotSquared.get().worldedit != null) {
|
||||
if (this.worldEdit != null) {
|
||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_WORLDEDIT_BYPASS)) {
|
||||
if (pp.getAttribute("worldedit")) {
|
||||
pp.removeAttribute("worldedit");
|
||||
@ -1178,7 +1199,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityBlockForm(EntityBlockFormEvent event) {
|
||||
String world = event.getBlock().getWorld().getName();
|
||||
if (!PlotSquared.get().hasPlotArea(world)) {
|
||||
if (!this.plotAreaManager.hasPlotArea(world)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
|
||||
@ -1509,13 +1530,14 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
for (Block block1 : event.getBlocks()) {
|
||||
Location bloc = BukkitUtil.getLocation(block1.getLocation());
|
||||
if (bloc.isPlotArea() || bloc.add(relative.getBlockX(),
|
||||
relative.getBlockY(), relative.getBlockZ()).isPlotArea()) {
|
||||
if (bloc.isPlotArea() || bloc
|
||||
.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())
|
||||
.isPlotArea()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -1546,8 +1568,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!plot.equals(area.getOwnedPlot(location.add(
|
||||
relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
|
||||
if (!plot.equals(area.getOwnedPlot(
|
||||
location.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
|
||||
// This branch is only necessary to prevent pistons from extending
|
||||
// if they are: on a plot edge, facing outside the plot, and not
|
||||
// pushing any blocks
|
||||
@ -1563,13 +1585,14 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
for (Block block1 : event.getBlocks()) {
|
||||
Location bloc = BukkitUtil.getLocation(block1.getLocation());
|
||||
if (bloc.isPlotArea() || bloc.add(relative.getBlockX(),
|
||||
relative.getBlockY(), relative.getBlockZ()).isPlotArea()) {
|
||||
if (bloc.isPlotArea() || bloc
|
||||
.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())
|
||||
.isPlotArea()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -1647,7 +1670,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onStructureGrow(StructureGrowEvent event) {
|
||||
if (!PlotSquared.get().hasPlotArea(event.getWorld().getName())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(event.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
List<org.bukkit.block.BlockState> blocks = event.getBlocks();
|
||||
@ -1710,7 +1733,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}*/
|
||||
HumanEntity entity = event.getWhoClicked();
|
||||
if (!(entity instanceof Player) || !PlotSquared.get()
|
||||
if (!(entity instanceof Player) || !this.plotAreaManager
|
||||
.hasPlotArea(entity.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
@ -1852,7 +1875,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
public void onPotionSplash(LingeringPotionSplashEvent event) {
|
||||
Projectile entity = event.getEntity();
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
if (!this.onProjectileHit(event)) {
|
||||
@ -1918,8 +1941,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
public void onBigBoom(BlockExplodeEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
String world = location.getWorld();
|
||||
if (!PlotSquared.get().hasPlotArea(world)) {
|
||||
String world = location.getWorldName();
|
||||
if (!this.plotAreaManager.hasPlotArea(world)) {
|
||||
return;
|
||||
}
|
||||
PlotArea area = location.getPlotArea();
|
||||
@ -1955,7 +1978,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
Material item = event.getMaterial();
|
||||
if (item.toString().toLowerCase().endsWith("egg")) {
|
||||
if (item.toString().toLowerCase().endsWith("_egg")) {
|
||||
event.setCancelled(true);
|
||||
event.setUseItemInHand(Event.Result.DENY);
|
||||
}
|
||||
@ -1967,11 +1990,11 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (type == Material.AIR) {
|
||||
type = offType;
|
||||
}
|
||||
if (type.toString().toLowerCase().endsWith("egg")) {
|
||||
if (type.toString().toLowerCase().endsWith("_egg")) {
|
||||
Block block = player.getTargetBlockExact(5, FluidCollisionMode.SOURCE_ONLY);
|
||||
if (block != null && block.getType() != Material.AIR) {
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
if (!PlotSquared.get().getEventDispatcher()
|
||||
if (!this.eventDispatcher
|
||||
.checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, null,
|
||||
true)) {
|
||||
event.setCancelled(true);
|
||||
@ -2102,13 +2125,13 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
|
||||
if (this.worldEdit != null && pp.getAttribute("worldedit")) {
|
||||
if (event.getMaterial() == Material
|
||||
.getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) {
|
||||
.getMaterial(this.worldEdit.getConfiguration().wandItem)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!PlotSquared.get().getEventDispatcher()
|
||||
if (!this.eventDispatcher
|
||||
.checkPlayerBlockEvent(pp, eventType, location, blocktype1, true)) {
|
||||
event.setCancelled(true);
|
||||
event.setUseInteractedBlock(Event.Result.DENY);
|
||||
@ -2193,7 +2216,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
Block block = event.getBlock();
|
||||
World world = block.getWorld();
|
||||
String worldName = world.getName();
|
||||
if (!PlotSquared.get().hasPlotArea(worldName)) {
|
||||
if (!this.plotAreaManager.hasPlotArea(worldName)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
@ -2220,7 +2243,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
} else if (event.getTo() == Material.AIR) {
|
||||
event.getEntity()
|
||||
.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
|
||||
.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2396,7 +2419,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
TaskManager.TELEPORT_QUEUE.remove(event.getPlayer().getName());
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
|
||||
pp.unregister();
|
||||
PlotListener.logout(pp.getUUID());
|
||||
this.logout(pp.getUUID());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
@ -2463,7 +2486,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
entity
|
||||
.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
|
||||
.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2477,7 +2500,6 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
Player p = event.getPlayer();
|
||||
if (p == null) {
|
||||
PlotSquared.debug("PlotSquared does not support HangingPlaceEvent for non-players.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -2718,7 +2740,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
public void onPotionSplash(PotionSplashEvent event) {
|
||||
ThrownPotion damager = event.getPotion();
|
||||
Location location = BukkitUtil.getLocation(damager);
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
@ -2748,7 +2770,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||
Entity damager = event.getDamager();
|
||||
Location location = BukkitUtil.getLocation(damager);
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
Entity victim = event.getEntity();
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
@ -36,17 +37,23 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class WorldEvents implements Listener {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
|
||||
@Inject public WorldEvents(@Nonnull final PlotAreaManager plotAreaManager) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onWorldInit(WorldInitEvent event) {
|
||||
World world = event.getWorld();
|
||||
String name = world.getName();
|
||||
PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
|
||||
if (manager instanceof SinglePlotAreaManager) {
|
||||
SinglePlotAreaManager single = (SinglePlotAreaManager) manager;
|
||||
if (this.plotAreaManager instanceof SinglePlotAreaManager) {
|
||||
final SinglePlotAreaManager single = (SinglePlotAreaManager) this.plotAreaManager;
|
||||
if (single.isWorld(name)) {
|
||||
world.setKeepSpawnInMemory(false);
|
||||
return;
|
||||
@ -56,7 +63,7 @@ public class WorldEvents implements Listener {
|
||||
if (gen instanceof GeneratorWrapper) {
|
||||
PlotSquared.get().loadWorld(name, (GeneratorWrapper<?>) gen);
|
||||
} else {
|
||||
PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen));
|
||||
PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen, this.plotAreaManager));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,14 +25,15 @@
|
||||
*/
|
||||
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;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.WorldType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -44,13 +45,13 @@ 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() {
|
||||
}
|
||||
|
||||
@Override @Nullable
|
||||
public World handleWorldCreation(@NotNull String worldName, @Nullable String generator) {
|
||||
public World handleWorldCreation(@Nonnull String worldName, @Nullable String generator) {
|
||||
this.setGenerator(worldName, generator);
|
||||
final WorldCreator wc = new WorldCreator(worldName);
|
||||
wc.environment(World.Environment.NORMAL);
|
||||
|
@ -25,9 +25,10 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.managers;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import se.hyperver.hyperverse.Hyperverse;
|
||||
import se.hyperver.hyperverse.world.WorldConfiguration;
|
||||
import se.hyperver.hyperverse.world.WorldConfigurationBuilder;
|
||||
@ -38,10 +39,10 @@ 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) {
|
||||
public World handleWorldCreation(@Nonnull String worldName, @Nullable String generator) {
|
||||
// First let Bukkit register the world
|
||||
this.setGenerator(worldName, generator);
|
||||
// Create the world
|
||||
|
@ -25,19 +25,20 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.managers;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.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) {
|
||||
public World handleWorldCreation(@Nonnull final String worldName, @Nullable final String generator) {
|
||||
// First let Bukkit register the world
|
||||
this.setGenerator(worldName, generator);
|
||||
// Then we send the console command
|
||||
|
@ -64,7 +64,7 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
}
|
||||
|
||||
@Override public String onPlaceholderRequest(Player p, String identifier) {
|
||||
final PlotPlayer pl = PlotSquared.imp().getPlayerManager().getPlayerIfExists(p.getUniqueId());
|
||||
final PlotPlayer pl = PlotSquared.platform().getPlayerManager().getPlayerIfExists(p.getUniqueId());
|
||||
|
||||
if (pl == null) {
|
||||
return "";
|
||||
|
@ -27,7 +27,7 @@ package com.plotsquared.bukkit.player;
|
||||
|
||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -45,7 +45,7 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@NotNull @Override public UUID getUUID() {
|
||||
@Nonnull @Override public UUID getUUID() {
|
||||
return this.player.getUniqueId();
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,9 @@ import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
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.plotsquared.core.util.MathMan;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
@ -51,7 +53,8 @@ import org.bukkit.event.EventException;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
@ -66,27 +69,36 @@ 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>
|
||||
*
|
||||
* @param player Bukkit player instance
|
||||
*/
|
||||
public BukkitPlayer(@NotNull final Player player) {
|
||||
this(player, false);
|
||||
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final Player player, @Nullable final EconHandler econHandler) {
|
||||
this(plotAreaManager, eventDispatcher, player, false, econHandler);
|
||||
}
|
||||
|
||||
public BukkitPlayer(@NotNull final Player player, final boolean offline) {
|
||||
this(player, offline, true);
|
||||
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final Player player, final boolean offline, @Nullable final EconHandler econHandler) {
|
||||
this(plotAreaManager, eventDispatcher, player, offline, true, econHandler);
|
||||
}
|
||||
|
||||
public BukkitPlayer(@NotNull final Player player, final boolean offline, final boolean realPlayer) {
|
||||
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final
|
||||
EventDispatcher eventDispatcher, @Nonnull 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();
|
||||
}
|
||||
@ -100,12 +112,12 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
@NotNull @Override public Location getLocation() {
|
||||
@Nonnull @Override public Location getLocation() {
|
||||
final Location location = super.getLocation();
|
||||
return location == null ? BukkitUtil.getLocation(this.player) : location;
|
||||
}
|
||||
|
||||
@NotNull @Override public UUID getUUID() {
|
||||
@Nonnull @Override public UUID getUUID() {
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" +
|
||||
@ -122,7 +134,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
return this.player.getLastPlayed();
|
||||
}
|
||||
|
||||
@Override public boolean canTeleport(@NotNull final Location location) {
|
||||
@Override public boolean canTeleport(@Nonnull final Location location) {
|
||||
final org.bukkit.Location to = BukkitUtil.getLocation(location);
|
||||
final org.bukkit.Location from = player.getLocation();
|
||||
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
|
||||
@ -135,10 +147,10 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void callEvent(@NotNull final Event event) {
|
||||
private void callEvent(@Nonnull final Event event) {
|
||||
final RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners();
|
||||
for (final RegisteredListener listener : listeners) {
|
||||
if (listener.getPlugin().getName().equals(PlotSquared.imp().getPluginName())) {
|
||||
if (listener.getPlugin().getName().equals(PlotSquared.platform().getPluginName())) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
@ -150,8 +162,8 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
}
|
||||
|
||||
@Override public boolean hasPermission(@NotNull 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);
|
||||
}
|
||||
@ -221,12 +233,12 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(@NotNull final Location location, @NotNull final TeleportCause cause) {
|
||||
public void teleport(@Nonnull final Location location, @Nonnull final TeleportCause cause) {
|
||||
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) {
|
||||
return;
|
||||
}
|
||||
final org.bukkit.Location bukkitLocation =
|
||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5,
|
||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX() + 0.5,
|
||||
location.getY(), location.getZ() + 0.5, location.getYaw(), location.getPitch());
|
||||
PaperLib.teleportAsync(player, bukkitLocation, getTeleportCause(cause));
|
||||
}
|
||||
@ -244,7 +256,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
|
||||
@Override public void setCompassTarget(Location location) {
|
||||
this.player.setCompassTarget(
|
||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX(),
|
||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX(),
|
||||
location.getY(), location.getZ()));
|
||||
}
|
||||
|
||||
@ -252,7 +264,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
return BukkitUtil.getLocationFull(this.player);
|
||||
}
|
||||
|
||||
@Override public void setWeather(@NotNull final PlotWeather weather) {
|
||||
@Override public void setWeather(@Nonnull final PlotWeather weather) {
|
||||
switch (weather) {
|
||||
case CLEAR:
|
||||
this.player.setPlayerWeather(WeatherType.CLEAR);
|
||||
@ -267,7 +279,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull @Override public com.sk89q.worldedit.world.gamemode.GameMode getGameMode() {
|
||||
@Override public com.sk89q.worldedit.world.gamemode.GameMode getGameMode() {
|
||||
switch (this.player.getGameMode()) {
|
||||
case ADVENTURE:
|
||||
return ADVENTURE;
|
||||
@ -282,7 +294,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameMode(@NotNull final com.sk89q.worldedit.world.gamemode.GameMode gameMode) {
|
||||
public void setGameMode(final com.sk89q.worldedit.world.gamemode.GameMode gameMode) {
|
||||
if (ADVENTURE.equals(gameMode)) {
|
||||
this.player.setGameMode(GameMode.ADVENTURE);
|
||||
} else if (CREATIVE.equals(gameMode)) {
|
||||
@ -310,7 +322,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
this.player.setAllowFlight(fly);
|
||||
}
|
||||
|
||||
@Override public void playMusic(@NotNull final Location location, @NotNull final ItemType id) {
|
||||
@Override public void playMusic(@Nonnull final Location location, @Nonnull final ItemType id) {
|
||||
if (id == ItemTypes.AIR) {
|
||||
// Let's just stop all the discs because why not?
|
||||
for (final Sound sound : Arrays.stream(Sound.values())
|
||||
@ -344,7 +356,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
}
|
||||
|
||||
|
||||
public PlayerTeleportEvent.TeleportCause getTeleportCause(@NotNull final TeleportCause cause) {
|
||||
public PlayerTeleportEvent.TeleportCause getTeleportCause(@Nonnull final TeleportCause cause) {
|
||||
switch (cause) {
|
||||
case COMMAND:
|
||||
return PlayerTeleportEvent.TeleportCause.COMMAND;
|
||||
|
@ -25,33 +25,51 @@
|
||||
*/
|
||||
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.EconHandler;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Player manager providing {@link BukkitPlayer Bukkit players}
|
||||
*/
|
||||
public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, Player> {
|
||||
@Singleton public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, Player> {
|
||||
|
||||
@NotNull @Override public BukkitPlayer getPlayer(@NotNull final Player object) {
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final EconHandler econHandler;
|
||||
|
||||
@Inject public BukkitPlayerManager(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nullable final EconHandler econHandler) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.econHandler = econHandler;
|
||||
}
|
||||
|
||||
@Nonnull @Override public BukkitPlayer getPlayer(@Nonnull final Player object) {
|
||||
try {
|
||||
return getPlayer(object.getUniqueId());
|
||||
} catch (final NoSuchPlayerException exception) {
|
||||
return new BukkitPlayer(object, object.isOnline(), false);
|
||||
return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, object,
|
||||
object.isOnline(), false, this.econHandler);
|
||||
}
|
||||
}
|
||||
|
||||
@Override @NotNull public BukkitPlayer createPlayer(@NotNull final UUID uuid) {
|
||||
@Override @Nonnull public BukkitPlayer createPlayer(@Nonnull final UUID uuid) {
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null || !player.isOnline()) {
|
||||
throw new NoSuchPlayerException(uuid);
|
||||
}
|
||||
return new BukkitPlayer(player);
|
||||
return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, player, this.econHandler);
|
||||
}
|
||||
|
||||
@Nullable @Override public BukkitOfflinePlayer getOfflinePlayer(@Nullable final UUID uuid) {
|
||||
@ -61,7 +79,7 @@ public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, Player> {
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
|
||||
}
|
||||
|
||||
@NotNull @Override public BukkitOfflinePlayer getOfflinePlayer(@NotNull final String username) {
|
||||
@Nonnull @Override public BukkitOfflinePlayer getOfflinePlayer(@Nonnull final String username) {
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username));
|
||||
}
|
||||
|
||||
|
@ -27,11 +27,9 @@ package com.plotsquared.bukkit.queue;
|
||||
|
||||
import com.plotsquared.bukkit.schematic.StateWrapper;
|
||||
import com.plotsquared.bukkit.util.BukkitBlockUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.queue.BasicLocalBlockQueue;
|
||||
import com.plotsquared.core.util.BlockUtil;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -42,7 +40,6 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
@ -51,6 +48,7 @@ import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Consumer;
|
||||
@ -85,8 +83,6 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
if (worldObj != null) {
|
||||
worldObj.refreshChunk(x, z);
|
||||
} else {
|
||||
PlotSquared.debug("Error Refreshing Chunk");
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,8 +105,6 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
|
||||
world.regenerate(region, editSession);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PlotSquared.debug("Error Regenerating Chunk");
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,12 +195,12 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
private void setMaterial(@NonNull final BlockState plotBlock, @NonNull final Block block) {
|
||||
private void setMaterial(@Nonnull final BlockState plotBlock, @Nonnull final Block block) {
|
||||
Material material = BukkitAdapter.adapt(plotBlock.getBlockType());
|
||||
block.setType(material, false);
|
||||
}
|
||||
|
||||
private boolean equals(@NonNull final BlockState plotBlock, @NonNull final Block block) {
|
||||
private boolean equals(@Nonnull final BlockState plotBlock, @Nonnull final Block block) {
|
||||
return plotBlock.equals(BukkitBlockUtil.get(block));
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,326 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.queue;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.plotsquared.bukkit.BukkitMain;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Utility that allows for the loading and coordination of chunk actions
|
||||
* <p>
|
||||
* The coordinator takes in collection of chunk coordinates, loads them
|
||||
* and allows the caller to specify a sink for the loaded chunks. The
|
||||
* coordinator will prevent the chunks from being unloaded until the sink
|
||||
* has fully consumed the chunk
|
||||
* <p>
|
||||
* Usage:
|
||||
* <pre>{@code
|
||||
* final ChunkCoordinator chunkCoordinator = ChunkCoordinator.builder()
|
||||
* .inWorld(Objects.requireNonNull(Bukkit.getWorld("world"))).withChunk(BlockVector2.at(0, 0))
|
||||
* .withConsumer(chunk -> System.out.printf("Got chunk %d;%d", chunk.getX(), chunk.getZ()))
|
||||
* .withFinalAction(() -> System.out.println("All chunks have been loaded"))
|
||||
* .withThrowableConsumer(throwable -> System.err.println("Something went wrong... =("))
|
||||
* .withMaxIterationTime(25L)
|
||||
* .build();
|
||||
* chunkCoordinator.subscribeToProgress((coordinator, progress) ->
|
||||
* System.out.printf("Progress: %.1f", progress * 100.0f));
|
||||
* chunkCoordinator.start();
|
||||
* }</pre>
|
||||
*
|
||||
* @author Alexander Söderberg
|
||||
* @see #builder() To create a new coordinator instance
|
||||
*/
|
||||
public final class ChunkCoordinator extends BukkitRunnable {
|
||||
|
||||
private final List<ProgressSubscriber> progressSubscribers = new LinkedList<>();
|
||||
|
||||
private final Queue<BlockVector2> requestedChunks;
|
||||
private final Queue<Chunk> availableChunks;
|
||||
private final long maxIterationTime;
|
||||
private final Plugin plugin;
|
||||
private final Consumer<Chunk> chunkConsumer;
|
||||
private final World world;
|
||||
private final Runnable whenDone;
|
||||
private final Consumer<Throwable> throwableConsumer;
|
||||
private final int totalSize;
|
||||
|
||||
private AtomicInteger expectedSize;
|
||||
private int batchSize;
|
||||
|
||||
private ChunkCoordinator(final long maxIterationTime, final int initialBatchSize,
|
||||
@NotNull final Consumer<Chunk> chunkConsumer, @NotNull final World world,
|
||||
@NotNull final Collection<BlockVector2> requestedChunks, @NotNull final Runnable whenDone,
|
||||
@NotNull final Consumer<Throwable> throwableConsumer) {
|
||||
this.requestedChunks = new LinkedBlockingQueue<>(requestedChunks);
|
||||
this.availableChunks = new LinkedBlockingQueue<>();
|
||||
this.totalSize = requestedChunks.size();
|
||||
this.expectedSize = new AtomicInteger(this.totalSize);
|
||||
this.world = world;
|
||||
this.batchSize = initialBatchSize;
|
||||
this.chunkConsumer = chunkConsumer;
|
||||
this.maxIterationTime = maxIterationTime;
|
||||
this.whenDone = whenDone;
|
||||
this.throwableConsumer = throwableConsumer;
|
||||
this.plugin = JavaPlugin.getPlugin(BukkitMain.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ChunkCoordinator} instance
|
||||
*
|
||||
* @return Coordinator builder instance
|
||||
*/
|
||||
@NotNull public static ChunkCoordinatorBuilder builder() {
|
||||
return new ChunkCoordinatorBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the coordinator instance
|
||||
*/
|
||||
public void start() {
|
||||
// Request initial batch
|
||||
this.requestBatch();
|
||||
// Wait until next tick to give the chunks a chance to be loaded
|
||||
this.runTaskTimer(this.plugin, 1L, 1L);
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
Chunk chunk = this.availableChunks.poll();
|
||||
if (chunk == null) {
|
||||
return;
|
||||
}
|
||||
long iterationTime;
|
||||
int processedChunks = 0;
|
||||
do {
|
||||
final long start = System.currentTimeMillis();
|
||||
try {
|
||||
this.chunkConsumer.accept(chunk);
|
||||
} catch (final Throwable throwable) {
|
||||
this.throwableConsumer.accept(throwable);
|
||||
}
|
||||
this.freeChunk(chunk);
|
||||
processedChunks++;
|
||||
final long end = System.currentTimeMillis();
|
||||
// Update iteration time
|
||||
iterationTime = end - start;
|
||||
} while (2 * iterationTime /* last chunk + next chunk */ < this.maxIterationTime
|
||||
&& (chunk = availableChunks.poll()) != null);
|
||||
if (processedChunks < this.batchSize) {
|
||||
// Adjust batch size based on the amount of processed chunks per tick
|
||||
this.batchSize = processedChunks;
|
||||
}
|
||||
|
||||
final int expected = this.expectedSize.addAndGet(-processedChunks);
|
||||
|
||||
final float progress = ((float) totalSize - (float) expected) / (float) totalSize;
|
||||
for (final ProgressSubscriber subscriber : this.progressSubscribers) {
|
||||
subscriber.notifyProgress(this, progress);
|
||||
}
|
||||
|
||||
if (expected <= 0) {
|
||||
try {
|
||||
this.whenDone.run();
|
||||
} catch (final Throwable throwable) {
|
||||
this.throwableConsumer.accept(throwable);
|
||||
}
|
||||
this.cancel();
|
||||
} else {
|
||||
if (this.availableChunks.size() < processedChunks) {
|
||||
this.requestBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void requestBatch() {
|
||||
BlockVector2 chunk;
|
||||
for (int i = 0; i < this.batchSize && (chunk = this.requestedChunks.poll()) != null; i++) {
|
||||
// This required PaperLib to be bumped to version 1.0.4 to mark the request as urgent
|
||||
PaperLib.getChunkAtAsync(this.world, chunk.getX(), chunk.getZ(), true, true)
|
||||
.whenComplete((chunkObject, throwable) -> {
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
// We want one less because this couldn't be processed
|
||||
this.expectedSize.decrementAndGet();
|
||||
} else {
|
||||
this.processChunk(chunkObject);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void processChunk(@NotNull final Chunk chunk) {
|
||||
if (!chunk.isLoaded()) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||
}
|
||||
chunk.addPluginChunkTicket(this.plugin);
|
||||
this.availableChunks.add(chunk);
|
||||
}
|
||||
|
||||
private void freeChunk(@NotNull final Chunk chunk) {
|
||||
if (!chunk.isLoaded()) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||
}
|
||||
chunk.removePluginChunkTicket(this.plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of remaining chunks (at the time of the method call)
|
||||
*
|
||||
* @return Snapshot view of remaining chunk count
|
||||
*/
|
||||
public int getRemainingChunks() {
|
||||
return this.expectedSize.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of requested chunks
|
||||
*
|
||||
* @return Requested chunk count
|
||||
*/
|
||||
public int getTotalChunks() {
|
||||
return this.totalSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to coordinator progress updates
|
||||
*
|
||||
* @param subscriber Subscriber
|
||||
*/
|
||||
public void subscribeToProgress(@NotNull final ChunkCoordinator.ProgressSubscriber subscriber) {
|
||||
this.progressSubscribers.add(subscriber);
|
||||
}
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ProgressSubscriber {
|
||||
|
||||
/**
|
||||
* Notify about a progress update in the coordinator
|
||||
*
|
||||
* @param coordinator Coordinator instance that triggered the notification
|
||||
* @param progress Progress in the range [0, 1]
|
||||
*/
|
||||
void notifyProgress(@NotNull final ChunkCoordinator coordinator, final float progress);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static final class ChunkCoordinatorBuilder {
|
||||
|
||||
private final List<BlockVector2> requestedChunks = new LinkedList<>();
|
||||
private Consumer<Throwable> throwableConsumer = Throwable::printStackTrace;
|
||||
private World world;
|
||||
private Consumer<Chunk> chunkConsumer;
|
||||
private Runnable whenDone = () -> {
|
||||
};
|
||||
private long maxIterationTime = 60; // A little over 1 tick;
|
||||
private int initialBatchSize = 4;
|
||||
|
||||
private ChunkCoordinatorBuilder() {
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder inWorld(@NotNull final World world) {
|
||||
this.world = Preconditions.checkNotNull(world, "World may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ChunkCoordinatorBuilder withChunk(@NotNull final BlockVector2 chunkLocation) {
|
||||
this.requestedChunks
|
||||
.add(Preconditions.checkNotNull(chunkLocation, "Chunk location may not be null"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withChunks(
|
||||
@NotNull final Collection<BlockVector2> chunkLocations) {
|
||||
chunkLocations.forEach(this::withChunk);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ChunkCoordinatorBuilder withConsumer(@NotNull final Consumer<Chunk> chunkConsumer) {
|
||||
this.chunkConsumer =
|
||||
Preconditions.checkNotNull(chunkConsumer, "Chunk consumer may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withFinalAction(@NotNull final Runnable whenDone) {
|
||||
this.whenDone = Preconditions.checkNotNull(whenDone, "Final action may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withMaxIterationTime(final long maxIterationTime) {
|
||||
Preconditions
|
||||
.checkArgument(maxIterationTime > 0, "Max iteration time must be positive");
|
||||
this.maxIterationTime = maxIterationTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withInitialBatchSize(final int initialBatchSize) {
|
||||
Preconditions
|
||||
.checkArgument(initialBatchSize > 0, "Initial batch size must be positive");
|
||||
this.initialBatchSize = initialBatchSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withThrowableConsumer(
|
||||
@NotNull final Consumer<Throwable> throwableConsumer) {
|
||||
this.throwableConsumer =
|
||||
Preconditions.checkNotNull(throwableConsumer, "Throwable consumer may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinator build() {
|
||||
Preconditions.checkNotNull(this.world, "No world was supplied");
|
||||
Preconditions.checkNotNull(this.chunkConsumer, "No chunk consumer was supplied");
|
||||
Preconditions.checkNotNull(this.whenDone, "No final action was supplied");
|
||||
Preconditions
|
||||
.checkNotNull(this.throwableConsumer, "No throwable consumer was supplied");
|
||||
return new ChunkCoordinator(this.maxIterationTime, this.initialBatchSize,
|
||||
this.chunkConsumer, this.world, this.requestedChunks, this.whenDone,
|
||||
this.throwableConsumer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -46,7 +46,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -62,7 +62,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
@Getter @Setter private ChunkData chunkData = null;
|
||||
|
||||
public GenChunk() {
|
||||
super(null, new Location(null, 0, 0, 0), new Location(null, 15, 255, 15));
|
||||
super(null, Location.at("", 0, 0, 0), Location.at("", 15, 255, 15));
|
||||
this.biomes = Biome.values();
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, @NotNull Pattern pattern) {
|
||||
@Override public boolean setBlock(int x, int y, int z, @Nonnull Pattern pattern) {
|
||||
return setBlock(x, y, z, PatternUtil
|
||||
.apply(Preconditions.checkNotNull(pattern, "Pattern may not be null"), x, y, z));
|
||||
}
|
||||
@ -196,11 +196,11 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
}
|
||||
|
||||
@Override public Location getMax() {
|
||||
return new Location(getWorld(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
||||
return Location.at(getWorld(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
||||
}
|
||||
|
||||
@Override public Location getMin() {
|
||||
return new Location(getWorld(), getX() << 4, 0, getZ() << 4);
|
||||
return Location.at(getWorld(), getX() << 4, 0, getZ() << 4);
|
||||
}
|
||||
|
||||
public GenChunk clone() {
|
||||
|
@ -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 javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Schematic Handler.
|
||||
*/
|
||||
public class BukkitSchematicHandler extends SchematicHandler {
|
||||
@Singleton public class BukkitSchematicHandler extends SchematicHandler {
|
||||
|
||||
@Inject public BukkitSchematicHandler(@Nonnull final WorldUtil worldUtil) {
|
||||
super(worldUtil);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restoreTile(LocalBlockQueue queue, CompoundTag ct, int x, int y, int z) {
|
||||
|
@ -25,9 +25,9 @@
|
||||
*/
|
||||
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;
|
||||
import com.plotsquared.core.queue.LocalBlockQueue;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.entity.EntityCategories;
|
||||
@ -54,7 +54,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()
|
||||
@ -79,8 +79,8 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
BukkitWorld bukkitWorld1 = new BukkitWorld(world1);
|
||||
BukkitWorld bukkitWorld2 = new BukkitWorld(world2);
|
||||
|
||||
LocalBlockQueue queue1 = GlobalBlockQueue.IMP.getNewQueue(worldName1, false);
|
||||
LocalBlockQueue queue2 = GlobalBlockQueue.IMP.getNewQueue(worldName2, false);
|
||||
LocalBlockQueue queue1 = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(worldName1, false);
|
||||
LocalBlockQueue queue2 = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(worldName2, false);
|
||||
|
||||
for (int x = Math.max(r1.getMinimumPoint().getX(), sx);
|
||||
x <= Math.min(r1.getMaximumPoint().getX(), sx + 15); x++) {
|
||||
|
@ -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 javax.annotation.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.imp().getPermissionHandler() != null) {
|
||||
return PlotSquared.imp().getPermissionHandler().hasPermission(world, player, perm);
|
||||
if (this.permHandler != null) {
|
||||
return this.permHandler.hasPermission(world, player, perm);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -25,7 +25,9 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.plotsquared.bukkit.BukkitMain;
|
||||
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;
|
||||
import com.plotsquared.core.location.Location;
|
||||
@ -33,7 +35,6 @@ import com.plotsquared.core.location.PlotLoc;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotManager;
|
||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.queue.LocalBlockQueue;
|
||||
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
@ -56,7 +57,10 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -74,7 +78,13 @@ 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 {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName());
|
||||
|
||||
@Inject public BukkitRegionManager(@Nonnull final ChunkManager chunkManager) {
|
||||
super(chunkManager);
|
||||
}
|
||||
|
||||
public static boolean isIn(CuboidRegion region, int x, int z) {
|
||||
return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX()
|
||||
@ -91,10 +101,8 @@ public class BukkitRegionManager extends RegionManager {
|
||||
} else {
|
||||
final Semaphore semaphore = new Semaphore(1);
|
||||
try {
|
||||
PlotSquared.debug("Attempting to make an asynchronous call to getLoadedChunks."
|
||||
+ " Will halt the calling thread until completed.");
|
||||
semaphore.acquire();
|
||||
Bukkit.getScheduler().runTask(BukkitMain.getPlugin(BukkitMain.class), () -> {
|
||||
Bukkit.getScheduler().runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> {
|
||||
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world))
|
||||
.getLoadedChunks()) {
|
||||
BlockVector2 loc = BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5);
|
||||
@ -198,14 +206,14 @@ public class BukkitRegionManager extends RegionManager {
|
||||
|
||||
final CuboidRegion region =
|
||||
RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
final World oldWorld = Bukkit.getWorld(pos1.getWorld());
|
||||
final World oldWorld = Bukkit.getWorld(pos1.getWorldName());
|
||||
final BukkitWorld oldBukkitWorld = new BukkitWorld(oldWorld);
|
||||
final World newWorld = Bukkit.getWorld(newPos.getWorld());
|
||||
final World newWorld = Bukkit.getWorld(newPos.getWorldName());
|
||||
assert newWorld != null;
|
||||
assert oldWorld != null;
|
||||
final String newWorldName = newWorld.getName();
|
||||
final ContentMap map = new ContentMap();
|
||||
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(newWorldName, false);
|
||||
final LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(newWorldName, false);
|
||||
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
||||
@Override public void run(int[] value) {
|
||||
int bx = value[2];
|
||||
@ -236,7 +244,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
}
|
||||
}
|
||||
queue.enqueue();
|
||||
GlobalBlockQueue.IMP.addEmptyTask(() -> {
|
||||
PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(() -> {
|
||||
//map.restoreBlocks(newWorld, 0, 0);
|
||||
map.restoreEntities(newWorld, relX, relZ);
|
||||
TaskManager.runTask(whenDone);
|
||||
@ -248,7 +256,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
@Override
|
||||
public boolean regenerateRegion(final Location pos1, final Location pos2,
|
||||
final boolean ignoreAugment, final Runnable whenDone) {
|
||||
final String world = pos1.getWorld();
|
||||
final String world = pos1.getWorldName();
|
||||
|
||||
final int p1x = pos1.getX();
|
||||
final int p1z = pos1.getZ();
|
||||
@ -284,8 +292,8 @@ public class BukkitRegionManager extends RegionManager {
|
||||
if (chunkObj == null) {
|
||||
return;
|
||||
}
|
||||
final LocalBlockQueue queue =
|
||||
GlobalBlockQueue.IMP.getNewQueue(world, false);
|
||||
final LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue()
|
||||
.getNewQueue(world, false);
|
||||
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
|
||||
AugmentedUtils.bypass(ignoreAugment,
|
||||
() -> queue.regenChunkSafe(chunk.getX(), chunk.getZ()));
|
||||
@ -401,7 +409,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
}
|
||||
|
||||
@Override public void clearAllEntities(Location pos1, Location pos2) {
|
||||
String world = pos1.getWorld();
|
||||
String world = pos1.getWorldName();
|
||||
List<Entity> entities = BukkitUtil.getEntities(world);
|
||||
int bx = pos1.getX();
|
||||
int bz = pos1.getZ();
|
||||
@ -428,8 +436,8 @@ public class BukkitRegionManager extends RegionManager {
|
||||
RegionUtil.createRegion(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ());
|
||||
CuboidRegion region2 =
|
||||
RegionUtil.createRegion(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ());
|
||||
final World world1 = Bukkit.getWorld(bot1.getWorld());
|
||||
final World world2 = Bukkit.getWorld(bot2.getWorld());
|
||||
final World world1 = Bukkit.getWorld(bot1.getWorldName());
|
||||
final World world2 = Bukkit.getWorld(bot2.getWorldName());
|
||||
checkNotNull(world1, "Critical error during swap.");
|
||||
checkNotNull(world2, "Critical error during swap.");
|
||||
int relX = bot2.getX() - bot1.getX();
|
||||
@ -445,7 +453,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
BukkitChunkManager.swapChunk(world1, world2, chunk1, chunk2, region1, region2));
|
||||
}
|
||||
}
|
||||
GlobalBlockQueue.IMP.addEmptyTask(() -> {
|
||||
PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(() -> {
|
||||
for (ContentMap map : maps) {
|
||||
map.restoreEntities(world1, 0, 0);
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
@ -456,16 +464,17 @@ public class BukkitRegionManager extends RegionManager {
|
||||
@Override
|
||||
public void setBiome(final CuboidRegion region, final int extendBiome, final BiomeType biome,
|
||||
final String world, final Runnable whenDone) {
|
||||
Location pos1 = new Location(world, region.getMinimumPoint().getX() - extendBiome,
|
||||
Location pos1 = Location.at(world, region.getMinimumPoint().getX() - extendBiome,
|
||||
region.getMinimumPoint().getY(), region.getMinimumPoint().getZ() - extendBiome);
|
||||
Location pos2 = new Location(world, region.getMaximumPoint().getX() + extendBiome,
|
||||
Location pos2 = Location.at(world, region.getMaximumPoint().getX() + extendBiome,
|
||||
region.getMaximumPoint().getY(), region.getMaximumPoint().getZ() + extendBiome);
|
||||
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
|
||||
final LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue()
|
||||
.getNewQueue(world, false);
|
||||
|
||||
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
||||
@Override public void run(int[] value) {
|
||||
BlockVector2 loc = BlockVector2.at(value[0], value[1]);
|
||||
ChunkManager.manager.loadChunk(world, loc, false).thenRun(() -> {
|
||||
PlotSquared.platform().getChunkManager().loadChunk(world, loc, false).thenRun(() -> {
|
||||
MainUtil.setBiome(world, value[2], value[3], value[4], value[5], biome);
|
||||
queue.refreshChunk(value[0], value[1]);
|
||||
});
|
||||
|
@ -25,14 +25,20 @@
|
||||
*/
|
||||
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.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;
|
||||
import com.plotsquared.core.generator.GeneratorWrapper;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotAreaType;
|
||||
import com.plotsquared.core.plot.SetupObject;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.setup.PlotAreaBuilder;
|
||||
import com.plotsquared.core.util.SetupUtils;
|
||||
import io.papermc.lib.PaperLib;
|
||||
@ -42,13 +48,27 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
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;
|
||||
|
||||
@Inject public BukkitSetupUtils(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
|
||||
@WorldFile @Nonnull final File worldFile) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.worldConfiguration = worldConfiguration;
|
||||
this.worldFile = worldFile;
|
||||
}
|
||||
|
||||
@Override public void updateGenerators() {
|
||||
if (!SetupUtils.generators.isEmpty()) {
|
||||
@ -66,7 +86,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
if (generator instanceof GeneratorWrapper<?>) {
|
||||
wrapped = (GeneratorWrapper<?>) generator;
|
||||
} else {
|
||||
wrapped = new BukkitPlotGenerator(testWorld, generator);
|
||||
wrapped = new BukkitPlotGenerator(testWorld, generator, this.plotAreaManager);
|
||||
}
|
||||
SetupUtils.generators.put(name, wrapped);
|
||||
}
|
||||
@ -99,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;
|
||||
@ -107,11 +127,10 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
switch (type) {
|
||||
case PARTIAL: {
|
||||
if (object.id != null) {
|
||||
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||
PlotSquared.get().worlds.createSection(worldPath);
|
||||
if (!this.worldConfiguration.contains(worldPath)) {
|
||||
this.worldConfiguration.createSection(worldPath);
|
||||
}
|
||||
ConfigurationSection worldSection =
|
||||
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||
ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection(worldPath);
|
||||
String areaName = object.id + "-" + object.min + "-" + object.max;
|
||||
String areaPath = "areas." + areaName;
|
||||
if (!worldSection.contains(areaPath)) {
|
||||
@ -151,26 +170,21 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
}
|
||||
case AUGMENTED: {
|
||||
if (!object.plotManager.endsWith(":single")) {
|
||||
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||
PlotSquared.get().worlds.createSection(worldPath);
|
||||
if (!this.worldConfiguration.contains(worldPath)) {
|
||||
this.worldConfiguration.createSection(worldPath);
|
||||
}
|
||||
if (steps.length != 0) {
|
||||
ConfigurationSection worldSection =
|
||||
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||
ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection(worldPath);
|
||||
for (ConfigurationNode step : steps) {
|
||||
worldSection.set(step.getConstant(), step.getValue());
|
||||
}
|
||||
}
|
||||
PlotSquared.get().worlds
|
||||
.set("worlds." + world + ".generator.type", object.type.toString());
|
||||
PlotSquared.get().worlds
|
||||
.set("worlds." + world + ".generator.terrain", object.terrain.toString());
|
||||
PlotSquared.get().worlds
|
||||
.set("worlds." + world + ".generator.plugin", object.plotManager);
|
||||
this.worldConfiguration.set("worlds." + world + ".generator.type", object.type.toString());
|
||||
this.worldConfiguration.set("worlds." + world + ".generator.terrain", object.terrain.toString());
|
||||
this.worldConfiguration.set("worlds." + world + ".generator.plugin", object.plotManager);
|
||||
if (object.setupGenerator != null && !object.setupGenerator
|
||||
.equals(object.plotManager)) {
|
||||
PlotSquared.get().worlds
|
||||
.set("worlds." + world + ".generator.init", object.setupGenerator);
|
||||
this.worldConfiguration.set("worlds." + world + ".generator.init", object.setupGenerator);
|
||||
}
|
||||
}
|
||||
GeneratorWrapper<?> gen = SetupUtils.generators.get(object.setupGenerator);
|
||||
@ -181,11 +195,10 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
}
|
||||
case NORMAL: {
|
||||
if (steps.length != 0) {
|
||||
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||
PlotSquared.get().worlds.createSection(worldPath);
|
||||
if (!this.worldConfiguration.contains(worldPath)) {
|
||||
this.worldConfiguration.createSection(worldPath);
|
||||
}
|
||||
ConfigurationSection worldSection =
|
||||
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||
ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection(worldPath);
|
||||
for (ConfigurationNode step : steps) {
|
||||
worldSection.set(step.getConstant(), step.getValue());
|
||||
}
|
||||
@ -195,12 +208,12 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
}
|
||||
|
||||
try {
|
||||
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
|
||||
this.worldConfiguration.save(this.worldFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Objects.requireNonNull(PlotSquared.imp()).getWorldManager()
|
||||
Objects.requireNonNull(PlotSquared.platform()).getWorldManager()
|
||||
.handleWorldCreation(object.world, object.setupGenerator);
|
||||
|
||||
if (Bukkit.getWorld(world) != null) {
|
||||
@ -211,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();
|
||||
@ -220,11 +233,11 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
switch (type) {
|
||||
case PARTIAL: {
|
||||
if (builder.areaName() != null) {
|
||||
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||
PlotSquared.get().worlds.createSection(worldPath);
|
||||
if (!this.worldConfiguration.contains(worldPath)) {
|
||||
this.worldConfiguration.createSection(worldPath);
|
||||
}
|
||||
ConfigurationSection worldSection =
|
||||
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||
this.worldConfiguration.getConfigurationSection(worldPath);
|
||||
String areaName = builder.areaName() + "-" + builder.minimumId() + "-" + builder.maximumId();
|
||||
String areaPath = "areas." + areaName;
|
||||
if (!worldSection.contains(areaPath)) {
|
||||
@ -264,25 +277,25 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
}
|
||||
case AUGMENTED: {
|
||||
if (!builder.plotManager().endsWith(":single")) {
|
||||
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||
PlotSquared.get().worlds.createSection(worldPath);
|
||||
if (!this.worldConfiguration.contains(worldPath)) {
|
||||
this.worldConfiguration.createSection(worldPath);
|
||||
}
|
||||
if (steps.length != 0) {
|
||||
ConfigurationSection worldSection =
|
||||
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||
this.worldConfiguration.getConfigurationSection(worldPath);
|
||||
for (ConfigurationNode step : steps) {
|
||||
worldSection.set(step.getConstant(), step.getValue());
|
||||
}
|
||||
}
|
||||
PlotSquared.get().worlds
|
||||
this.worldConfiguration
|
||||
.set("worlds." + world + ".generator.type", builder.plotAreaType().toString());
|
||||
PlotSquared.get().worlds
|
||||
this.worldConfiguration
|
||||
.set("worlds." + world + ".generator.terrain", builder.terrainType().toString());
|
||||
PlotSquared.get().worlds
|
||||
this.worldConfiguration
|
||||
.set("worlds." + world + ".generator.plugin", builder.plotManager());
|
||||
if (builder.generatorName() != null && !builder.generatorName()
|
||||
.equals(builder.plotManager())) {
|
||||
PlotSquared.get().worlds
|
||||
this.worldConfiguration
|
||||
.set("worlds." + world + ".generator.init", builder.generatorName());
|
||||
}
|
||||
}
|
||||
@ -294,11 +307,11 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
}
|
||||
case NORMAL: {
|
||||
if (steps.length != 0) {
|
||||
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||
PlotSquared.get().worlds.createSection(worldPath);
|
||||
if (!this.worldConfiguration.contains(worldPath)) {
|
||||
this.worldConfiguration.createSection(worldPath);
|
||||
}
|
||||
ConfigurationSection worldSection =
|
||||
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||
this.worldConfiguration.getConfigurationSection(worldPath);
|
||||
for (ConfigurationNode step : steps) {
|
||||
worldSection.set(step.getConstant(), step.getValue());
|
||||
}
|
||||
@ -308,12 +321,12 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
}
|
||||
|
||||
try {
|
||||
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
|
||||
this.worldConfiguration.save(this.worldFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Objects.requireNonNull(PlotSquared.imp()).getWorldManager()
|
||||
Objects.requireNonNull(PlotSquared.platform()).getWorldManager()
|
||||
.handleWorldCreation(builder.worldName(), builder.generatorName());
|
||||
|
||||
if (Bukkit.getWorld(world) != null) {
|
||||
|
@ -25,15 +25,17 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.plotsquared.bukkit.BukkitMain;
|
||||
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 BukkitMain bukkitMain;
|
||||
private final BukkitPlatform bukkitMain;
|
||||
|
||||
public BukkitTaskManager(BukkitMain bukkitMain) {
|
||||
@Inject public BukkitTaskManager(BukkitPlatform bukkitMain) {
|
||||
this.bukkitMain = bukkitMain;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,9 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.plotsquared.bukkit.BukkitMain;
|
||||
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;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
@ -38,6 +40,7 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.BlockUtil;
|
||||
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;
|
||||
@ -52,11 +55,11 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import lombok.NonNull;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
@ -98,8 +101,10 @@ import org.bukkit.entity.Snowman;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.entity.WaterMob;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -113,7 +118,9 @@ 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 final Logger logger = LoggerFactory.getLogger("P2/" + BukkitUtil.class.getSimpleName());
|
||||
|
||||
public static final BukkitAudiences BUKKIT_AUDIENCES = BukkitAudiences.create(BukkitMain.getPlugin(BukkitMain.class));
|
||||
public static final LegacyComponentSerializer LEGACY_COMPONENT_SERIALIZER = LegacyComponentSerializer.legacy();
|
||||
@ -125,20 +132,25 @@ public class BukkitUtil extends WorldUtil {
|
||||
private static Player lastPlayer = null;
|
||||
private static BukkitPlayer lastPlotPlayer = null;
|
||||
|
||||
@Inject public BukkitUtil(@Nonnull final RegionManager regionManager) {
|
||||
super(regionManager);
|
||||
}
|
||||
|
||||
public static void removePlayer(UUID uuid) {
|
||||
lastPlayer = null;
|
||||
lastPlotPlayer = null;
|
||||
// Make sure that it's removed internally
|
||||
PlotSquared.imp().getPlayerManager().removePlayer(uuid);
|
||||
PlotSquared.platform().getPlayerManager().removePlayer(uuid);
|
||||
}
|
||||
|
||||
public static PlotPlayer<Player> getPlayer(@NonNull final OfflinePlayer op) {
|
||||
public static PlotPlayer<Player> getPlayer(@Nonnull final OfflinePlayer op) {
|
||||
if (op.isOnline()) {
|
||||
return getPlayer(op.getPlayer());
|
||||
}
|
||||
final Player player = OfflinePlayerUtil.loadPlayer(op);
|
||||
player.loadData();
|
||||
return new BukkitPlayer(player, true);
|
||||
return new BukkitPlayer(PlotSquared.get().getPlotAreaManager(),
|
||||
PlotSquared.get().getEventDispatcher(), player, true, PlotSquared.platform().getEconHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -255,39 +267,39 @@ public class BukkitUtil extends WorldUtil {
|
||||
return BukkitUtil.getPlayer(player).getPlotCount(world);
|
||||
}
|
||||
|
||||
public static BukkitPlayer getPlayer(@NonNull final Player player) {
|
||||
public static BukkitPlayer getPlayer(@Nonnull final Player player) {
|
||||
if (player == lastPlayer) {
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
final PlayerManager<?, ?> playerManager = PlotSquared.imp().getPlayerManager();
|
||||
final PlayerManager<?, ?> playerManager = PlotSquared.platform().getPlayerManager();
|
||||
return ((BukkitPlayerManager) playerManager).getPlayer(player);
|
||||
}
|
||||
|
||||
public static Location getLocation(@NonNull final org.bukkit.Location location) {
|
||||
return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()),
|
||||
MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()));
|
||||
public static Location getLocation(final org.bukkit.Location location) {
|
||||
return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
|
||||
MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()));
|
||||
}
|
||||
|
||||
public static Location getLocationFull(@NonNull final org.bukkit.Location location) {
|
||||
return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()),
|
||||
MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(),
|
||||
public static Location getLocationFull(final org.bukkit.Location location) {
|
||||
return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
|
||||
MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(),
|
||||
location.getPitch());
|
||||
}
|
||||
|
||||
public static org.bukkit.Location getLocation(@NonNull final Location location) {
|
||||
return new org.bukkit.Location(getWorld(location.getWorld()), location.getX(),
|
||||
public static org.bukkit.Location getLocation(@Nonnull final Location location) {
|
||||
return new org.bukkit.Location((World) location.getWorld().getPlatformWorld(), location.getX(),
|
||||
location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public static World getWorld(@NonNull final String string) {
|
||||
public static World getWorld(@Nonnull final String string) {
|
||||
return Bukkit.getWorld(string);
|
||||
}
|
||||
|
||||
public static String getWorld(@NonNull final Entity entity) {
|
||||
public static String getWorld(@Nonnull final Entity entity) {
|
||||
return entity.getWorld().getName();
|
||||
}
|
||||
|
||||
public static List<Entity> getEntities(@NonNull final String worldName) {
|
||||
public static List<Entity> getEntities(@Nonnull final String worldName) {
|
||||
World world = getWorld(worldName);
|
||||
if (world != null) {
|
||||
return world.getEntities();
|
||||
@ -296,21 +308,21 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static Location getLocation(@NonNull final Entity entity) {
|
||||
public static Location getLocation(@Nonnull final Entity entity) {
|
||||
final org.bukkit.Location location = entity.getLocation();
|
||||
String world = location.getWorld().getName();
|
||||
return new Location(world, location.getBlockX(), location.getBlockY(),
|
||||
return Location.at(world, location.getBlockX(), location.getBlockY(),
|
||||
location.getBlockZ());
|
||||
}
|
||||
|
||||
@NotNull public static Location getLocationFull(@NonNull final Entity entity) {
|
||||
@Nonnull public static Location getLocationFull(@Nonnull final Entity entity) {
|
||||
final org.bukkit.Location location = entity.getLocation();
|
||||
return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()),
|
||||
return Location.at(location.getWorld().getName(), MathMan.roundInt(location.getX()),
|
||||
MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(),
|
||||
location.getPitch());
|
||||
}
|
||||
|
||||
public static Material getMaterial(@NonNull final BlockState plotBlock) {
|
||||
public static Material getMaterial(@Nonnull final BlockState plotBlock) {
|
||||
return BukkitAdapter.adapt(plotBlock.getBlockType());
|
||||
}
|
||||
|
||||
@ -322,7 +334,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
return mat1 == mat2;
|
||||
}
|
||||
|
||||
@Override public boolean isWorld(@NonNull final String worldName) {
|
||||
@Override public boolean isWorld(@Nonnull final String worldName) {
|
||||
return getWorld(worldName) != null;
|
||||
}
|
||||
|
||||
@ -336,7 +348,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getHighestBlock(@NonNull final String world, final int x, final int z,
|
||||
public void getHighestBlock(@Nonnull final String world, final int x, final int z,
|
||||
final IntConsumer result) {
|
||||
ensureLoaded(world, x, z, chunk -> {
|
||||
final World bukkitWorld = getWorld(world);
|
||||
@ -386,7 +398,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSign(@NonNull final Location location, final Consumer<String[]> result) {
|
||||
public void getSign(@Nonnull final Location location, final Consumer<String[]> result) {
|
||||
ensureLoaded(location, chunk -> {
|
||||
final Block block = chunk.getWorld().getBlockAt(getLocation(location));
|
||||
if (block.getState() instanceof Sign) {
|
||||
@ -396,10 +408,10 @@ public class BukkitUtil extends WorldUtil {
|
||||
});
|
||||
}
|
||||
|
||||
@Override @Nullable public String[] getSignSynchronous(@NonNull final Location location) {
|
||||
Block block = getWorld(location.getWorld())
|
||||
@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();
|
||||
@ -409,20 +421,20 @@ public class BukkitUtil extends WorldUtil {
|
||||
});
|
||||
}
|
||||
|
||||
@Override public Location getSpawn(@NonNull final String world) {
|
||||
@Override public Location getSpawn(@Nonnull final String world) {
|
||||
final org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
||||
return new Location(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(),
|
||||
return Location.at(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(),
|
||||
temp.getYaw(), temp.getPitch());
|
||||
}
|
||||
|
||||
@Override public void setSpawn(@NonNull final Location location) {
|
||||
final World world = getWorld(location.getWorld());
|
||||
@Override public void setSpawn(@Nonnull final Location location) {
|
||||
final World world = getWorld(location.getWorldName());
|
||||
if (world != null) {
|
||||
world.setSpawnLocation(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void saveWorld(@NonNull final String worldName) {
|
||||
@Override public void saveWorld(@Nonnull final String worldName) {
|
||||
final World world = getWorld(worldName);
|
||||
if (world != null) {
|
||||
world.save();
|
||||
@ -430,11 +442,13 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override @SuppressWarnings("deprecation")
|
||||
public void setSign(@NotNull final Location location, @NotNull final Caption[] lines,
|
||||
@NotNull final Template ... replacements) {
|
||||
public void setSign(@Nonull final Location location, @Nonnull final Caption[] lines,
|
||||
@Nonnull final Template ... replacements) {
|
||||
ensureLoaded(location.getWorld(), location.getX(), location.getZ(), chunk -> {
|
||||
final World world = getWorld(location.getWorld());
|
||||
final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
final World world = getWorld(worldName);
|
||||
final Block block = world.getBlockAt(x, y, z);
|
||||
// block.setType(Material.AIR);
|
||||
final Material type = block.getType();
|
||||
if (type != Material.LEGACY_SIGN && type != Material.LEGACY_WALL_SIGN) {
|
||||
@ -446,13 +460,12 @@ public class BukkitUtil extends WorldUtil {
|
||||
} else if (world.getBlockAt(location.getX(), location.getY(), location.getZ() - 1).getType().isSolid()) {
|
||||
facing = BlockFace.SOUTH;
|
||||
}
|
||||
if (PlotSquared.get().IMP.getServerVersion()[1] == 13) {
|
||||
if (PlotSquared.platform().getServerVersion()[1] == 13) {
|
||||
block.setType(Material.valueOf("WALL_SIGN"), false);
|
||||
} else {
|
||||
block.setType(Material.valueOf("OAK_WALL_SIGN"), false);
|
||||
}
|
||||
if (!(block.getBlockData() instanceof WallSign)) {
|
||||
PlotSquared.debug(block.getBlockData().getAsString());
|
||||
throw new RuntimeException("Something went wrong generating a sign");
|
||||
}
|
||||
final Directional sign = (Directional) block.getBlockData();
|
||||
@ -471,11 +484,11 @@ public class BukkitUtil extends WorldUtil {
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean isBlockSolid(@NonNull final BlockState block) {
|
||||
@Override public boolean isBlockSolid(@Nonnull final BlockState block) {
|
||||
return block.getBlockType().getMaterial().isSolid();
|
||||
}
|
||||
|
||||
@Override public String getClosestMatchingName(@NonNull final BlockState block) {
|
||||
@Override public String getClosestMatchingName(@Nonnull final BlockState block) {
|
||||
try {
|
||||
return getMaterial(block).name();
|
||||
} catch (Exception ignored) {
|
||||
@ -490,11 +503,11 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiomes(@NonNull final String worldName, @NonNull final CuboidRegion region,
|
||||
@NonNull final BiomeType biomeType) {
|
||||
public void setBiomes(@Nonnull final String worldName, @Nonnull final CuboidRegion region,
|
||||
@Nonnull final BiomeType biomeType) {
|
||||
final World world = getWorld(worldName);
|
||||
if (world == null) {
|
||||
PlotSquared.log("An error occurred setting the biome because the world was null.");
|
||||
logger.warn("[P2] An error occured while setting the biome because the world was null", new RuntimeException());
|
||||
return;
|
||||
}
|
||||
final Biome biome = BukkitAdapter.adapt(biomeType);
|
||||
@ -513,16 +526,16 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBlock(@NonNull final Location location, final Consumer<BlockState> result) {
|
||||
public void getBlock(@Nonnull final Location location, final Consumer<BlockState> result) {
|
||||
ensureLoaded(location, chunk -> {
|
||||
final World world = getWorld(location.getWorld());
|
||||
final World world = getWorld(location.getWorldName());
|
||||
final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
result.accept(BukkitAdapter.asBlockType(block.getType()).getDefaultState());
|
||||
});
|
||||
}
|
||||
|
||||
@Override public BlockState getBlockSynchronous(@NonNull final Location location) {
|
||||
final World world = getWorld(location.getWorld());
|
||||
@Override public BlockState getBlockSynchronous(@Nonnull final Location location) {
|
||||
final World world = getWorld(location.getWorldName());
|
||||
final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
return BukkitAdapter.asBlockType(block.getType()).getDefaultState();
|
||||
}
|
||||
@ -608,7 +621,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
PlotSquared.log(Captions.PREFIX + "Unknown entity category requested: " + category);
|
||||
logger.error("[P2] Unknown entity category requested: {}", category);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -677,7 +690,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
consumer.accept(value);
|
||||
} else {
|
||||
Bukkit.getScheduler()
|
||||
.runTask(BukkitMain.getPlugin(BukkitMain.class), () -> consumer.accept(value));
|
||||
.runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> consumer.accept(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.util;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.plotsquared.core.location.World;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.bukkit.Bukkit;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@EqualsAndHashCode @ToString public class BukkitWorld implements World<org.bukkit.World> {
|
||||
|
||||
private static final Map<String, BukkitWorld> worldMap = Maps.newHashMap();
|
||||
|
||||
private final org.bukkit.World world;
|
||||
|
||||
private BukkitWorld(final org.bukkit.World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new {@link BukkitWorld} from a world name
|
||||
*
|
||||
* @param worldName World name
|
||||
* @return World instance
|
||||
*/
|
||||
@Nonnull public static BukkitWorld of(@Nonnull final String worldName) {
|
||||
final org.bukkit.World bukkitWorld = Bukkit.getWorld(worldName);
|
||||
if (bukkitWorld == null) {
|
||||
throw new IllegalArgumentException(String.format("There is no world with the name '%s'", worldName));
|
||||
}
|
||||
return of(bukkitWorld);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new {@link BukkitWorld} from a Bukkit world
|
||||
*
|
||||
* @param world Bukkit world
|
||||
* @return World instance
|
||||
*/
|
||||
@Nonnull public static BukkitWorld of(final org.bukkit.World world) {
|
||||
BukkitWorld bukkitWorld = worldMap.get(world.getName());
|
||||
if (bukkitWorld != null && bukkitWorld.getPlatformWorld().equals(world)) {
|
||||
return bukkitWorld;
|
||||
}
|
||||
bukkitWorld = new BukkitWorld(world);
|
||||
worldMap.put(world.getName(), bukkitWorld);
|
||||
return bukkitWorld;
|
||||
}
|
||||
|
||||
@Override public org.bukkit.World getPlatformWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
@Override @Nonnull public String getName() {
|
||||
return this.world.getName();
|
||||
}
|
||||
|
||||
}
|
@ -27,7 +27,6 @@ package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.plotsquared.bukkit.entity.EntityWrapper;
|
||||
import com.plotsquared.bukkit.entity.ReplicatingEntityWrapper;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.location.PlotLoc;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
@ -38,6 +37,8 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -46,6 +47,8 @@ import java.util.Set;
|
||||
|
||||
public class ContentMap {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + ContentMap.class.getSimpleName());
|
||||
|
||||
final Set<EntityWrapper> entities;
|
||||
final Map<PlotLoc, BaseBlock[]> allBlocks;
|
||||
|
||||
@ -123,8 +126,7 @@ public class ContentMap {
|
||||
try {
|
||||
entity.spawn(world, xOffset, zOffset);
|
||||
} catch (Exception e) {
|
||||
PlotSquared.debug("Failed to restore entity (e): " + e.toString());
|
||||
e.printStackTrace();
|
||||
logger.error("[P2] Failed to restore entity", e);
|
||||
}
|
||||
}
|
||||
this.entities.clear();
|
||||
|
@ -38,7 +38,7 @@ import java.util.ArrayList;
|
||||
public class SetGenCB {
|
||||
|
||||
public static void setGenerator(World world) throws Exception {
|
||||
SetupUtils.manager.updateGenerators();
|
||||
PlotSquared.platform().getSetupUtils().updateGenerators();
|
||||
PlotSquared.get().removePlotAreas(world.getName());
|
||||
ChunkGenerator gen = world.getGenerator();
|
||||
if (gen == null) {
|
||||
@ -72,6 +72,6 @@ public class SetGenCB {
|
||||
.removeIf(blockPopulator -> blockPopulator instanceof BukkitAugmentedGenerator);
|
||||
}
|
||||
PlotSquared.get()
|
||||
.loadWorld(world.getName(), PlotSquared.get().IMP.getGenerator(world.getName(), null));
|
||||
.loadWorld(world.getName(), PlotSquared.platform().getGenerator(world.getName(), null));
|
||||
}
|
||||
}
|
||||
|
@ -28,14 +28,16 @@ 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;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.IOException;
|
||||
@ -44,6 +46,8 @@ import java.net.URL;
|
||||
|
||||
public class UpdateUtility implements Listener {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + UpdateUtility.class.getSimpleName());
|
||||
|
||||
public static PlotVersion internalVersion;
|
||||
public static String spigotVersion;
|
||||
public static boolean hasUpdate;
|
||||
@ -51,7 +55,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();
|
||||
}
|
||||
@ -68,26 +72,22 @@ public class UpdateUtility implements Listener {
|
||||
.getAsJsonObject();
|
||||
spigotVersion = result.get("current_version").getAsString();
|
||||
} catch (IOException e) {
|
||||
PlotSquared.log(Captions.PREFIX + "&cUnable to check for updates because: " + e);
|
||||
logger.error("[P2] Unable to check for updates. Error: {}", e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (internalVersion.isLaterVersion(spigotVersion)) {
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX + "&6There appears to be a PlotSquared update available!");
|
||||
PlotSquared.log(
|
||||
Captions.PREFIX + "&6You are running version " + internalVersion.versionString()
|
||||
+ ", &6latest version is " + spigotVersion);
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/77506/updates");
|
||||
logger.info("[P2] There appears to be a PlotSquared update available!");
|
||||
logger.info("[P2] You are running version {}, the latest version is {}",
|
||||
internalVersion.versionString(), spigotVersion);
|
||||
logger.info("[P2] https://www.spigotmc.org/resources/77506/updates");
|
||||
hasUpdate = true;
|
||||
if (Settings.UpdateChecker.NOTIFY_ONCE) {
|
||||
cancelTask();
|
||||
}
|
||||
} else if (notify) {
|
||||
notify = false;
|
||||
PlotSquared.log(Captions.PREFIX
|
||||
+ "Congratulations! You are running the latest PlotSquared version.");
|
||||
logger.info("[P2] Congratulations! You are running the latest PlotSquared version");
|
||||
}
|
||||
}, 0L, Settings.UpdateChecker.POLL_RATE * 60 * 20);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ import com.plotsquared.core.uuid.UUIDService;
|
||||
import net.luckperms.api.model.user.UserManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -54,7 +54,7 @@ public class BungeePermsUUIDService implements UUIDService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
final UUIDPlayerDB uuiddb = BungeePerms.getInstance().getPermissionsManager().getUUIDPlayerDB();
|
||||
for (final UUID uuid : uuids) {
|
||||
@ -68,7 +68,7 @@ public class BungeePermsUUIDService implements UUIDService {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
final UUIDPlayerDB uuiddb = BungeePerms.getInstance().getPermissionsManager().getUUIDPlayerDB();
|
||||
for (final String username : usernames) {
|
||||
|
@ -29,7 +29,7 @@ import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -47,11 +47,11 @@ public class EssentialsUUIDService implements UUIDService {
|
||||
this.essentials = Essentials.getPlugin(Essentials.class);
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
for (final String username : usernames) {
|
||||
try {
|
||||
|
@ -31,7 +31,7 @@ import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.user.UserManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -53,7 +53,7 @@ public class LuckPermsUUIDService implements UUIDService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
final UserManager userManager = this.luckPerms.getUserManager();
|
||||
for (final UUID uuid : uuids) {
|
||||
@ -67,7 +67,7 @@ public class LuckPermsUUIDService implements UUIDService {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
final UserManager userManager = this.luckPerms.getUserManager();
|
||||
for (final String username : usernames) {
|
||||
|
@ -31,7 +31,7 @@ import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -43,7 +43,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class OfflinePlayerUUIDService implements UUIDService {
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE || Bukkit.getWorlds().isEmpty()) {
|
||||
return Collections.emptyList(); // This is useless now
|
||||
}
|
||||
@ -61,7 +61,7 @@ public class OfflinePlayerUUIDService implements UUIDService {
|
||||
return wrappers;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
||||
final List<UUIDMapping> wrappers = new ArrayList<>(usernames.size());
|
||||
for (final String username : usernames) {
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
|
@ -29,7 +29,7 @@ import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -40,7 +40,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PaperUUIDService implements UUIDService {
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
for (final UUID uuid : uuids) {
|
||||
final PlayerProfile playerProfile = Bukkit.createProfile(uuid);
|
||||
@ -51,7 +51,7 @@ public class PaperUUIDService implements UUIDService {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
for (final String username : usernames) {
|
||||
final PlayerProfile playerProfile = Bukkit.createProfile(username);
|
||||
|
@ -30,7 +30,7 @@ import com.plotsquared.core.database.SQLite;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
@ -51,7 +51,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
||||
|
||||
public SQLiteUUIDService(final String fileName) {
|
||||
this.sqlite =
|
||||
new SQLite(MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), fileName));
|
||||
new SQLite(MainUtil.getFile(PlotSquared.platform().getDirectory(), fileName));
|
||||
try {
|
||||
this.sqlite.openConnection();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
@ -72,7 +72,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
||||
}
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
try (final PreparedStatement statement = getConnection()
|
||||
.prepareStatement("SELECT `username` FROM `usercache` WHERE `uuid` = ?")) {
|
||||
@ -90,7 +90,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull List<String> usernames) {
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
try (final PreparedStatement statement = getConnection()
|
||||
.prepareStatement("SELECT `uuid` FROM `usercache` WHERE `username` = ?")) {
|
||||
@ -127,7 +127,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
||||
*
|
||||
* @return All read mappings
|
||||
*/
|
||||
@NotNull public List<UUIDMapping> getAll() {
|
||||
@Nonnull public List<UUIDMapping> getAll() {
|
||||
final List<UUIDMapping> mappings = new LinkedList<>();
|
||||
try (final PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM `usercache`")) {
|
||||
try (final ResultSet resultSet = statement.executeQuery()) {
|
||||
|
@ -26,14 +26,15 @@
|
||||
package com.plotsquared.bukkit.uuid;
|
||||
|
||||
import com.google.common.util.concurrent.RateLimiter;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import com.sk89q.squirrelid.Profile;
|
||||
import com.sk89q.squirrelid.resolver.HttpRepositoryService;
|
||||
import com.sk89q.squirrelid.resolver.ProfileService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -47,6 +48,8 @@ import java.util.UUID;
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class SquirrelIdUUIDService implements UUIDService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + SquirrelIdUUIDService.class.getSimpleName());
|
||||
|
||||
private final ProfileService profileService;
|
||||
private final RateLimiter rateLimiter;
|
||||
|
||||
@ -64,7 +67,7 @@ public class SquirrelIdUUIDService implements UUIDService {
|
||||
this.rateLimiter = RateLimiter.create(rateLimit / 600.0D);
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> results = new ArrayList<>(uuids.size());
|
||||
this.rateLimiter.acquire(uuids.size());
|
||||
try {
|
||||
@ -78,7 +81,9 @@ public class SquirrelIdUUIDService implements UUIDService {
|
||||
// go through them one by one
|
||||
//
|
||||
if (uuids.size() >= 2) {
|
||||
PlotSquared.debug(Captions.PREFIX + "(UUID) Found invalid UUID in batch. Will try each UUID individually.");
|
||||
if (Settings.DEBUG) {
|
||||
logger.info("[P2] (UUID) Found invalid UUID in batch. Will try each UUID individually.");
|
||||
}
|
||||
for (final UUID uuid : uuids) {
|
||||
final List<UUIDMapping> result = this.getNames(Collections.singletonList(uuid));
|
||||
if (result.isEmpty()) {
|
||||
@ -86,8 +91,8 @@ public class SquirrelIdUUIDService implements UUIDService {
|
||||
}
|
||||
results.add(result.get(0));
|
||||
}
|
||||
} else if (uuids.size() == 1) {
|
||||
PlotSquared.debug(Captions.PREFIX + "(UUID) Found invalid UUID: " + uuids.get(0));
|
||||
} else if (uuids.size() == 1 && Settings.DEBUG) {
|
||||
logger.info("[P2] (UUID) Found invalid UUID: {}", uuids.get(0));
|
||||
}
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
@ -96,7 +101,7 @@ public class SquirrelIdUUIDService implements UUIDService {
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
||||
final List<UUIDMapping> results = new ArrayList<>(usernames.size());
|
||||
this.rateLimiter.acquire(usernames.size());
|
||||
try {
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: ${name}
|
||||
main: com.plotsquared.bukkit.BukkitMain
|
||||
main: com.plotsquared.bukkit.BukkitPlatform
|
||||
api-version: "1.13"
|
||||
version: "${version}"
|
||||
load: STARTUP
|
||||
|
Reference in New Issue
Block a user