PlotSquared/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java

1119 lines
51 KiB
Java
Raw Normal View History

/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* 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/>.
*/
2020-04-11 02:19:18 +02:00
package com.plotsquared.bukkit;
2015-07-05 17:44:10 +02:00
2020-07-10 22:12:37 +02:00
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Stage;
2020-04-11 02:19:18 +02:00
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
2020-07-10 22:12:37 +02:00
import com.plotsquared.bukkit.inject.BackupModule;
import com.plotsquared.bukkit.inject.BukkitModule;
import com.plotsquared.bukkit.inject.WorldManagerModule;
2020-04-15 21:26:54 +02:00
import com.plotsquared.bukkit.listener.ChunkListener;
import com.plotsquared.bukkit.listener.EntitySpawnListener;
2020-04-30 18:23:18 +02:00
import com.plotsquared.bukkit.listener.PaperListener;
2020-04-15 21:26:54 +02:00
import com.plotsquared.bukkit.listener.PlayerEvents;
import com.plotsquared.bukkit.listener.SingleWorldListener;
import com.plotsquared.bukkit.listener.WorldEvents;
import com.plotsquared.bukkit.placeholder.PlaceholderFormatter;
import com.plotsquared.bukkit.placeholder.Placeholders;
2020-05-19 00:28:52 +02:00
import com.plotsquared.bukkit.player.BukkitPlayerManager;
2020-04-11 02:19:18 +02:00
import com.plotsquared.bukkit.util.BukkitChatManager;
import com.plotsquared.bukkit.util.BukkitTaskManager;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.BukkitWorld;
2020-04-11 02:19:18 +02:00
import com.plotsquared.bukkit.util.SetGenCB;
import com.plotsquared.bukkit.util.UpdateUtility;
import com.plotsquared.bukkit.uuid.BungeePermsUUIDService;
import com.plotsquared.bukkit.uuid.EssentialsUUIDService;
import com.plotsquared.bukkit.uuid.LuckPermsUUIDService;
2020-05-18 00:22:34 +02:00
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.PlotPlatform;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.PlotSquared;
2020-05-10 14:02:25 +02:00
import com.plotsquared.core.backup.BackupManager;
2020-07-10 22:12:37 +02:00
import com.plotsquared.core.command.WE_Anywhere;
import com.plotsquared.core.components.ComponentPresetManager;
2020-04-30 12:01:52 +02:00
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;
2020-07-10 19:25:05 +02:00
import com.plotsquared.core.configuration.file.YamlConfiguration;
2020-05-19 00:28:52 +02:00
import com.plotsquared.core.database.DBFunc;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.generator.GeneratorWrapper;
import com.plotsquared.core.generator.IndependentPlotGenerator;
2020-04-30 12:01:52 +02:00
import com.plotsquared.core.generator.SingleWorldGenerator;
2020-07-10 22:12:37 +02:00
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;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.listener.PlotListener;
2020-07-10 22:12:37 +02:00
import com.plotsquared.core.listener.WESubscriber;
2020-04-30 12:01:52 +02:00
import com.plotsquared.core.player.PlotPlayer;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.plot.PlotId;
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;
2020-07-10 22:12:37 +02:00
import com.plotsquared.core.queue.GlobalBlockQueue;
2020-06-05 02:19:37 +02:00
import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.setup.SettingsNodesWrapper;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.util.ChatManager;
import com.plotsquared.core.util.ConsoleColors;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.EventDispatcher;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.PermHandler;
import com.plotsquared.core.util.PlatformWorldManager;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.util.PremiumVerification;
import com.plotsquared.core.util.ReflectionUtils;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.StringMan;
2020-04-30 12:01:52 +02:00
import com.plotsquared.core.util.WorldUtil;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.util.task.TaskManager;
2020-05-18 00:22:34 +02:00
import com.plotsquared.core.uuid.CacheUUIDService;
import com.plotsquared.core.uuid.UUIDPipeline;
import com.plotsquared.core.uuid.offline.OfflineModeUUIDService;
2016-06-01 22:50:35 +02:00
import com.sk89q.worldedit.WorldEdit;
2020-04-30 18:23:18 +02:00
import io.papermc.lib.PaperLib;
2018-08-10 20:46:38 +02:00
import lombok.Getter;
import lombok.NonNull;
2020-04-11 19:52:45 +02:00
import org.bstats.bukkit.Metrics;
2019-11-04 18:44:23 +01:00
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
2019-05-17 22:21:03 +02:00
import org.jetbrains.annotations.NotNull;
2019-09-08 20:02:45 +02:00
import org.jetbrains.annotations.Nullable;
2016-03-23 02:41:37 +01:00
import java.io.File;
import java.lang.reflect.Method;
2019-11-25 23:38:03 +01:00
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
2020-05-20 15:12:09 +02:00
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
2019-11-25 23:38:03 +01:00
import java.util.Map;
2020-05-20 15:12:09 +02:00
import java.util.Queue;
import java.util.Set;
import java.util.UUID;
2020-05-20 15:12:09 +02:00
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
2020-04-30 12:01:52 +02:00
import static com.plotsquared.core.util.PremiumVerification.getDownloadID;
import static com.plotsquared.core.util.PremiumVerification.getResourceID;
import static com.plotsquared.core.util.PremiumVerification.getUserID;
2020-04-15 21:26:54 +02:00
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
2020-07-10 22:12:37 +02:00
@SuppressWarnings("unused") public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform<Player> {
2016-03-20 23:19:37 +01:00
2020-05-10 14:02:25 +02:00
private static final int BSTATS_ID = 1404;
static {
try {
Settings.load(new File("plugins/PlotSquared/config/settings.yml"));
2019-04-24 00:48:22 +02:00
} catch (Throwable ignored) {
}
}
private int[] version;
2019-02-04 16:18:50 +01:00
@Getter private String pluginName;
2018-08-10 20:46:38 +02:00
@Getter private SingleWorldListener singleWorldListener;
2018-08-10 17:01:10 +02:00
private Method methodUnloadChunk0;
private boolean methodUnloadSetup = false;
private boolean metricsStarted;
private EconHandler econ;
private PermHandler perm;
2020-07-10 22:12:37 +02:00
@Getter private Injector injector;
2020-07-10 17:32:07 +02:00
private PlotAreaManager plotAreaManager;
private EventDispatcher eventDispatcher;
private PlotListener plotListener;
2020-07-10 22:12:37 +02:00
@WorldConfig private YamlConfiguration worldConfiguration;
@WorldFile private File worldfile;
private BukkitPlayerManager playerManager;
private BackupManager backupManager;
@ImpromptuPipeline private UUIDPipeline impromptuPipeline;
@BackgroundPipeline private UUIDPipeline backgroundPipeline;
private PlatformWorldManager<World> worldManager;
2020-07-10 19:25:05 +02:00
2018-08-10 17:01:10 +02:00
@Override public int[] getServerVersion() {
if (this.version == null) {
try {
this.version = new int[3];
String[] split = Bukkit.getBukkitVersion().split("-")[0].split("\\.");
this.version[0] = Integer.parseInt(split[0]);
this.version[1] = Integer.parseInt(split[1]);
if (split.length == 3) {
this.version[2] = Integer.parseInt(split[2]);
}
} catch (NumberFormatException e) {
e.printStackTrace();
PlotSquared.debug(StringMan.getString(Bukkit.getBukkitVersion()));
Merge branch 'master' into breaking # Conflicts: # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotRateEvent.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java # Core/src/main/java/com/intellectualcrafters/plot/commands/PluginCmd.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java # Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java # Core/src/main/java/com/intellectualcrafters/plot/config/C.java # Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java # Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java # Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java # Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java # README.md # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/events/PlotRateEvent.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java # Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java
2018-11-14 15:44:07 +01:00
PlotSquared.debug(
StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\.")));
2018-08-10 17:01:10 +02:00
return new int[] {1, 13, 0};
}
}
return this.version;
}
@Override public String getServerImplementation() {
return Bukkit.getVersion();
}
2018-08-10 17:01:10 +02:00
@Override public void onEnable() {
2018-08-10 20:46:38 +02:00
this.pluginName = getDescription().getName();
2020-07-10 22:12:37 +02:00
// Stuff that needs to be created before the PlotSquared instance
2018-12-19 17:19:54 +01:00
PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer);
2020-07-10 22:12:37 +02:00
TaskManager.setImplementation(new BukkitTaskManager(this));
2020-07-10 17:32:07 +02:00
final PlotSquared plotSquared = new PlotSquared(this, "Bukkit");
if (PlotSquared.platform().getServerVersion()[1] < 13) {
2019-05-13 21:56:28 +02:00
System.out.println(
"You can't use this version of PlotSquared on a server less than Minecraft 1.13.2.");
System.out
.println("Please check the download page for the link to the legacy versions.");
System.out.println("The server will now be shutdown to prevent any corruption.");
2019-05-13 21:56:28 +02:00
Bukkit.shutdown();
return;
}
2020-07-10 22:12:37 +02:00
// We create the injector after PlotSquared has been initialized, so that we have access
// to generated instances and settings
this.injector = Guice.createInjector(Stage.PRODUCTION, new PlotSquaredModule(),
new BukkitModule(this), new BackupModule(), new WorldManagerModule());
this.injector.injectMembers(this);
if (PremiumVerification.isPremium() && Settings.Enabled_Components.UPDATE_NOTIFICATIONS) {
2020-07-10 22:12:37 +02:00
injector.getInstance(UpdateUtility.class).updateChecker();
}
2019-03-18 19:49:22 +01:00
2020-02-19 23:55:43 +01:00
if (PremiumVerification.isPremium()) {
2020-04-30 12:01:52 +02:00
PlotSquared.log(
Captions.PREFIX + "&6PlotSquared version licensed to Spigot user " + getUserID());
PlotSquared
.log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/" + getResourceID());
2020-04-21 23:42:31 +02:00
PlotSquared.log(Captions.PREFIX + "&6Download ID: " + getDownloadID());
2020-02-19 23:55:43 +01:00
PlotSquared.log(Captions.PREFIX + "&6Thanks for supporting us :)");
} else {
PlotSquared.log(Captions.PREFIX + "&6Couldn't verify purchase :(");
}
2020-07-10 22:12:37 +02:00
// Do stuff that was previously done in PlotSquared
// Kill entities
if (Settings.Enabled_Components.KILL_ROAD_MOBS
|| Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
this.runEntityTask();
}
// WorldEdit
if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
try {
PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + this.getPluginName()
+ " hooked into WorldEdit.");
WorldEdit.getInstance().getEventBus().register(this.getInjector().getInstance(WESubscriber.class));
if (Settings.Enabled_Components.COMMANDS) {
new WE_Anywhere();
}
} catch (Throwable e) {
PlotSquared.debug(
"Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master");
}
}
if (Settings.Enabled_Components.EVENTS) {
getServer().getPluginManager().registerEvents(getInjector().getInstance(PlayerEvents.class), this);
getServer().getPluginManager().registerEvents(getInjector().getInstance(EntitySpawnListener.class), this);
if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) {
getServer().getPluginManager().registerEvents(getInjector().getInstance(PaperListener.class), this);
}
this.plotListener.startRunnable();
}
// Required
getServer().getPluginManager().registerEvents(getInjector().getInstance(WorldEvents.class), this);
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
getServer().getPluginManager().registerEvents(getInjector().getInstance(ChunkListener.class), this);
}
// Start the global block queue
final GlobalBlockQueue globalBlockQueue = this.injector.getInstance(GlobalBlockQueue.class);
globalBlockQueue.runTask();
// Commands
if (Settings.Enabled_Components.COMMANDS) {
this.registerCommands();
}
// Economy
if (Settings.Enabled_Components.ECONOMY) {
TaskManager.runTask(() -> {
getInjector().getInstance(PermHandler.class).init();
getInjector().getInstance(EconHandler.class).init();
});
}
if (Settings.Enabled_Components.COMPONENT_PRESETS) {
try {
new ComponentPresetManager();
} catch (final Exception e) {
PlotSquared.log(Captions.PREFIX + "Failed to initialize the preset system");
e.printStackTrace();
}
}
// World generators:
final ConfigurationSection section = this.worldConfiguration.getConfigurationSection("worlds");
final WorldUtil worldUtil = getInjector().getInstance(WorldUtil.class);
if (section != null) {
for (String world : section.getKeys(false)) {
if (world.equals("CheckingPlotSquaredGenerator")) {
continue;
}
if (worldUtil.isWorld(world)) {
this.setGenerator(world);
}
}
TaskManager.runTaskLater(() -> {
for (String world : section.getKeys(false)) {
if (world.equals("CheckingPlotSquaredGenerator")) {
continue;
}
if (!worldUtil.isWorld(world) && !world.equals("*")) {
PlotSquared.debug("`" + world + "` was not properly loaded - " + this.getPluginName()
+ " will now try to load it properly: ");
PlotSquared.debug(
" - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml");
PlotSquared.debug(
" - Your world management plugin may be faulty (or non existent)");
PlotSquared.debug(
" This message may also be a false positive and could be ignored.");
this.setGenerator(world);
}
}
}, 1);
}
2020-05-18 00:22:34 +02:00
// Services are accessed in order
2020-07-10 22:12:37 +02:00
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);
2020-05-18 00:22:34 +02:00
// 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();
2020-07-10 22:12:37 +02:00
this.impromptuPipeline.registerService(offlineModeUUIDService);
this.backgroundPipeline.registerService(offlineModeUUIDService);
PlotSquared.log(Captions.PREFIX + "(UUID) Using the offline mode UUID service");
2020-05-18 00:22:34 +02:00
}
2020-05-18 00:22:34 +02:00
final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService();
2020-07-10 22:12:37 +02:00
this.impromptuPipeline.registerService(offlinePlayerUUIDService);
this.backgroundPipeline.registerService(offlinePlayerUUIDService);
2020-05-20 15:12:09 +02:00
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db");
final SQLiteUUIDService legacyUUIDService;
if (Settings.UUID.LEGACY_DATABASE_SUPPORT && MainUtil
.getFile(PlotSquared.platform().getDirectory(), "usercache.db").exists()) {
legacyUUIDService = new SQLiteUUIDService("usercache.db");
} else {
legacyUUIDService = null;
}
final LuckPermsUUIDService luckPermsUUIDService;
if (Bukkit.getPluginManager().getPlugin("LuckPerms") != null) {
luckPermsUUIDService = new LuckPermsUUIDService();
PlotSquared
.log(Captions.PREFIX + "(UUID) Using LuckPerms as a complementary UUID service");
} else {
luckPermsUUIDService = null;
}
final BungeePermsUUIDService bungeePermsUUIDService;
if (Bukkit.getPluginManager().getPlugin("BungeePerms") != null) {
bungeePermsUUIDService = new BungeePermsUUIDService();
PlotSquared
.log(Captions.PREFIX + "(UUID) Using BungeePerms as a complementary UUID service");
} else {
bungeePermsUUIDService = null;
}
final EssentialsUUIDService essentialsUUIDService;
if (Bukkit.getPluginManager().getPlugin("Essentials") != null) {
essentialsUUIDService = new EssentialsUUIDService();
PlotSquared
.log(Captions.PREFIX + "(UUID) Using Essentials as a complementary UUID service");
} else {
essentialsUUIDService = null;
}
2020-05-24 04:27:20 +02:00
if (!Settings.UUID.OFFLINE) {
2020-05-24 04:28:29 +02:00
// If running Paper we'll also try to use their profiles
if (PaperLib.isPaper()) {
final PaperUUIDService paperUUIDService = new PaperUUIDService();
2020-07-10 22:12:37 +02:00
this.impromptuPipeline.registerService(paperUUIDService);
this.backgroundPipeline.registerService(paperUUIDService);
PlotSquared
.log(Captions.PREFIX + "(UUID) Using Paper as a complementary UUID service");
2020-05-24 04:28:29 +02:00
}
2020-07-10 22:12:37 +02:00
this.impromptuPipeline.registerService(sqLiteUUIDService);
this.backgroundPipeline.registerService(sqLiteUUIDService);
this.impromptuPipeline.registerConsumer(sqLiteUUIDService);
this.backgroundPipeline.registerConsumer(sqLiteUUIDService);
if (legacyUUIDService != null) {
2020-07-10 22:12:37 +02:00
this.impromptuPipeline.registerService(legacyUUIDService);
this.backgroundPipeline.registerService(legacyUUIDService);
}
// Plugin providers
if (luckPermsUUIDService != null) {
2020-07-10 22:12:37 +02:00
this.impromptuPipeline.registerService(luckPermsUUIDService);
this.backgroundPipeline.registerService(luckPermsUUIDService);
}
if (bungeePermsUUIDService != null) {
2020-07-10 22:12:37 +02:00
this.impromptuPipeline.registerService(bungeePermsUUIDService);
this.backgroundPipeline.registerService(bungeePermsUUIDService);
}
if (essentialsUUIDService != null) {
2020-07-10 22:12:37 +02:00
this.impromptuPipeline.registerService(essentialsUUIDService);
this.backgroundPipeline.registerService(essentialsUUIDService);
}
final SquirrelIdUUIDService impromptuMojangService =
new SquirrelIdUUIDService(Settings.UUID.IMPROMPTU_LIMIT);
2020-07-10 22:12:37 +02:00
this.impromptuPipeline.registerService(impromptuMojangService);
final SquirrelIdUUIDService backgroundMojangService =
new SquirrelIdUUIDService(Settings.UUID.BACKGROUND_LIMIT);
2020-07-10 22:12:37 +02:00
this.backgroundPipeline.registerService(backgroundMojangService);
2020-05-20 15:12:09 +02:00
} else {
2020-07-10 22:12:37 +02:00
this.impromptuPipeline.registerService(sqLiteUUIDService);
this.backgroundPipeline.registerService(sqLiteUUIDService);
this.impromptuPipeline.registerConsumer(sqLiteUUIDService);
this.backgroundPipeline.registerConsumer(sqLiteUUIDService);
if (legacyUUIDService != null) {
2020-07-10 22:12:37 +02:00
this.impromptuPipeline.registerService(legacyUUIDService);
this.backgroundPipeline.registerService(legacyUUIDService);
}
2020-05-18 00:22:34 +02:00
}
2020-07-10 22:12:37 +02:00
this.impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE);
if (Settings.UUID.BACKGROUND_CACHING_ENABLED) {
this.startUuidCaching(sqLiteUUIDService, cacheUUIDService);
}
2020-05-19 00:28:52 +02:00
2020-02-16 20:33:24 +01:00
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
2020-07-10 22:12:37 +02:00
injector.getInstance(Placeholders.class).register();
if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) {
2020-07-10 22:12:37 +02:00
ChatFormatter.formatters.add(getInjector().getInstance(PlaceholderFormatter.class));
}
2020-04-25 23:54:30 +02:00
PlotSquared.log(Captions.PREFIX + "&6PlotSquared hooked into PlaceholderAPI");
2020-02-16 20:33:24 +01:00
} else {
2020-04-30 12:01:52 +02:00
PlotSquared
.debug(Captions.PREFIX + "&6PlaceholderAPI is not in use. Hook deactivated.");
2020-02-16 20:33:24 +01:00
}
this.startMetrics();
if (Settings.Enabled_Components.WORLDS) {
2020-07-10 22:12:37 +02:00
TaskManager.getImplementation().taskRepeat(this::unload, 20);
try {
2020-07-10 22:12:37 +02:00
singleWorldListener = getInjector().getInstance(SingleWorldListener.class);
} catch (Exception e) {
e.printStackTrace();
}
}
2020-05-10 14:02:25 +02:00
PlotSquared.log(
Captions.PREFIX.getTranslated() + "Using platform world manager: " + this.worldManager
.getName());
// Clean up potential memory leak
Bukkit.getScheduler().runTaskTimer(this, () -> {
try {
for (final PlotPlayer<? extends Player> player : this.getPlayerManager().getPlayers()) {
if (player.getPlatformPlayer() == null || !player.getPlatformPlayer().isOnline()) {
this.getPlayerManager().removePlayer(player);
}
}
} catch (final Exception e) {
getLogger().warning("Failed to clean up players: " + e.getMessage());
}
}, 100L, 100L);
}
private void unload() {
2018-08-10 20:46:38 +02:00
if (!this.methodUnloadSetup) {
this.methodUnloadSetup = true;
try {
ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
2018-08-10 20:46:38 +02:00
this.methodUnloadChunk0 = classCraftWorld.getRealClass()
2018-08-10 17:01:10 +02:00
.getDeclaredMethod("unloadChunk0", int.class, int.class, boolean.class);
2018-08-10 20:46:38 +02:00
this.methodUnloadChunk0.setAccessible(true);
} catch (Throwable event) {
event.printStackTrace();
}
}
2020-07-10 17:32:07 +02:00
if (this.plotAreaManager instanceof SinglePlotAreaManager) {
long start = System.currentTimeMillis();
2020-07-10 17:32:07 +02:00
final SinglePlotArea area = ((SinglePlotAreaManager) this.plotAreaManager).getArea();
2018-08-10 20:46:38 +02:00
outer:
2018-08-10 20:46:38 +02:00
for (final World world : Bukkit.getWorlds()) {
final String name = world.getName();
final char char0 = name.charAt(0);
if (!Character.isDigit(char0) && char0 != '-') {
2018-08-10 17:01:10 +02:00
continue;
2018-08-10 20:46:38 +02:00
}
if (!world.getPlayers().isEmpty()) {
continue;
}
PlotId id;
try {
id = PlotId.fromString(name);
} catch (IllegalArgumentException ignored) {
continue;
}
final Plot plot = area.getOwnedPlot(id);
if (plot != null) {
if (!MainUtil.isServerOwned(plot) || PlotPlayer.wrap(plot.getOwner()) == null) {
if (world.getKeepSpawnInMemory()) {
world.setKeepSpawnInMemory(false);
return;
}
final Chunk[] chunks = world.getLoadedChunks();
if (chunks.length == 0) {
if (!Bukkit.unloadWorld(world, true)) {
PlotSquared.debug("Failed to unload " + world.getName());
}
return;
} else {
int index = 0;
do {
final Chunk chunkI = chunks[index++];
boolean result;
if (methodUnloadChunk0 != null) {
try {
result = (boolean) methodUnloadChunk0
.invoke(world, chunkI.getX(), chunkI.getZ(), true);
} catch (Throwable e) {
methodUnloadChunk0 = null;
e.printStackTrace();
continue outer;
}
} else {
2019-04-24 00:48:22 +02:00
result = world.unloadChunk(chunkI.getX(), chunkI.getZ(), true);
}
if (!result) {
continue outer;
}
if (System.currentTimeMillis() - start > 5) {
return;
}
} while (index < chunks.length);
}
}
}
}
}
}
2020-07-03 13:47:50 +02:00
private void startUuidCaching(@NotNull final SQLiteUUIDService sqLiteUUIDService,
@NotNull final CacheUUIDService cacheUUIDService) {
2020-05-20 15:12:09 +02:00
// Load all uuids into a big chunky boi queue
final Queue<UUID> uuidQueue = new LinkedBlockingQueue<>();
PlotSquared.get().forEachPlotRaw(plot -> {
final Set<UUID> uuids = new HashSet<>();
uuids.add(plot.getOwnerAbs());
uuids.addAll(plot.getMembers());
uuids.addAll(plot.getTrusted());
uuids.addAll(plot.getDenied());
for (final UUID uuid : uuids) {
if (!uuidQueue.contains(uuid)) {
uuidQueue.add(uuid);
}
}
});
PlotSquared.log(Captions.PREFIX.getTranslated() + "(UUID) " + uuidQueue.size()
+ " UUIDs will be cached.");
2020-05-20 15:12:09 +02:00
Executors.newSingleThreadScheduledExecutor().schedule(() -> {
// Begin by reading all the SQLite cache at once
cacheUUIDService.accept(sqLiteUUIDService.getAll());
// 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 "
2020-05-20 15:12:09 +02:00
+ Settings.UUID.BACKGROUND_LIMIT);
final List<UUID> uuidList = new ArrayList<>(Settings.UUID.BACKGROUND_LIMIT);
// Used to indicate that the second retrieval has been attempted
boolean secondRun = false;
while (!uuidQueue.isEmpty() || !uuidList.isEmpty()) {
if (!uuidList.isEmpty() && secondRun) {
PlotSquared.log("Giving up on last batch. Fetching new batch instead.");
uuidList.clear();
}
if (uuidList.isEmpty()) {
// Retrieve the secondRun variable to indicate that we're retrieving a
// fresh batch
secondRun = false;
// Populate the request list
for (int i = 0;
i < Settings.UUID.BACKGROUND_LIMIT && !uuidQueue.isEmpty(); i++) {
uuidList.add(uuidQueue.poll());
read++;
}
} else {
// If the list isn't empty then this is a second run for
// an old batch, so we re-use the patch
secondRun = true;
2020-05-20 15:12:09 +02:00
}
try {
PlotSquared.get().getBackgroundUUIDPipeline().getNames(uuidList).get();
// Clear the list if we successfully index all the names
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));
2020-05-20 15:12:09 +02:00
} catch (final InterruptedException | ExecutionException e) {
PlotSquared.log("Failed to retrieve that batch. Will try again.");
2020-05-20 15:12:09 +02:00
e.printStackTrace();
}
}
PlotSquared
.log(Captions.PREFIX.getTranslated() + "(UUID) PlotSquared has cached all UUIDs");
2020-05-20 15:12:09 +02:00
}, 10, TimeUnit.SECONDS);
}
2018-08-10 17:01:10 +02:00
@Override public void onDisable() {
PlotSquared.get().disable();
Bukkit.getScheduler().cancelTasks(this);
}
2018-08-10 20:46:38 +02:00
@Override public void log(@NonNull String message) {
try {
message = Captions.color(message);
if (!Settings.Chat.CONSOLE_COLOR) {
message = ChatColor.stripColor(message);
}
this.getServer().getConsoleSender().sendMessage(message);
2018-08-10 20:46:38 +02:00
} catch (final Throwable ignored) {
System.out.println(ConsoleColors.fromString(message));
}
}
@Override public void shutdown() {
this.getServer().getPluginManager().disablePlugin(this);
}
2020-07-10 22:12:37 +02:00
private void registerCommands() {
2018-08-10 20:46:38 +02:00
final BukkitCommand bukkitCommand = new BukkitCommand();
final PluginCommand plotCommand = getCommand("plots");
2019-09-08 20:02:45 +02:00
if (plotCommand != null) {
plotCommand.setExecutor(bukkitCommand);
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
plotCommand.setTabCompleter(bukkitCommand);
}
}
2018-08-10 17:01:10 +02:00
@Override public File getDirectory() {
return getDataFolder();
}
2018-08-10 17:01:10 +02:00
@Override public File getWorldContainer() {
return Bukkit.getWorldContainer();
}
2020-07-10 22:12:37 +02:00
@SuppressWarnings("deprecation") private void runEntityTask() {
PlotSquared.log(Captions.PREFIX + "KillAllEntities started.");
2020-07-10 17:32:07 +02:00
TaskManager.runTaskRepeat(() -> this.plotAreaManager.forEachPlotArea(plotArea -> {
final World world = Bukkit.getWorld(plotArea.getWorldName());
try {
if (world == null) {
return;
}
List<Entity> entities = world.getEntities();
Iterator<Entity> iterator = entities.iterator();
while (iterator.hasNext()) {
Entity entity = iterator.next();
2020-06-29 00:45:40 +02:00
switch (entity.getType().toString()) {
case "EGG":
case "FISHING_HOOK":
case "ENDER_SIGNAL":
case "AREA_EFFECT_CLOUD":
case "EXPERIENCE_ORB":
case "LEASH_HITCH":
case "FIREWORK":
case "LIGHTNING":
case "WITHER_SKULL":
case "UNKNOWN":
case "PLAYER":
// non moving / unmovable
continue;
2020-06-29 00:45:40 +02:00
case "THROWN_EXP_BOTTLE":
case "SPLASH_POTION":
case "SNOWBALL":
case "SHULKER_BULLET":
case "SPECTRAL_ARROW":
case "ENDER_PEARL":
case "ARROW":
case "LLAMA_SPIT":
case "TRIDENT":
// managed elsewhere | projectile
continue;
2020-06-29 00:45:40 +02:00
case "ITEM_FRAME":
case "PAINTING":
// Not vehicles
continue;
2020-06-29 00:45:40 +02:00
case "ARMOR_STAND":
// Temporarily classify as vehicle
2020-06-29 00:45:40 +02:00
case "MINECART":
case "MINECART_CHEST":
case "MINECART_COMMAND":
case "MINECART_FURNACE":
case "MINECART_HOPPER":
case "MINECART_MOB_SPAWNER":
case "ENDER_CRYSTAL":
case "MINECART_TNT":
case "BOAT":
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
2020-04-30 12:01:52 +02:00
com.plotsquared.core.location.Location location =
BukkitUtil.getLocation(entity.getLocation());
Plot plot = location.getPlot();
if (plot == null) {
if (location.isPlotArea()) {
if (entity.hasMetadata("ps-tmp-teleport")) {
continue;
}
iterator.remove();
entity.remove();
}
continue;
}
List<MetadataValue> meta = entity.getMetadata("plot");
if (meta.isEmpty()) {
continue;
}
Plot origin = (Plot) meta.get(0).value();
if (!plot.equals(origin.getBasePlot(false))) {
if (entity.hasMetadata("ps-tmp-teleport")) {
continue;
}
iterator.remove();
entity.remove();
}
}
continue;
2020-06-29 00:45:40 +02:00
case "SMALL_FIREBALL":
case "FIREBALL":
case "DRAGON_FIREBALL":
case "DROPPED_ITEM":
if (Settings.Enabled_Components.KILL_ROAD_ITEMS && plotArea
.getOwnedPlotAbs(BukkitUtil.getLocation(entity.getLocation()))
== null) {
entity.remove();
}
// dropped item
continue;
2020-06-29 00:45:40 +02:00
case "PRIMED_TNT":
case "FALLING_BLOCK":
// managed elsewhere
continue;
2020-06-29 00:45:40 +02:00
case "SHULKER":
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
LivingEntity livingEntity = (LivingEntity) entity;
List<MetadataValue> meta = entity.getMetadata("shulkerPlot");
2019-04-23 19:45:24 +02:00
if (!meta.isEmpty()) {
if (livingEntity.isLeashed()) {
continue;
}
List<MetadataValue> keep = entity.getMetadata("keep");
2019-04-23 19:45:24 +02:00
if (!keep.isEmpty()) {
continue;
}
PlotId originalPlotId = (PlotId) meta.get(0).value();
if (originalPlotId != null) {
2020-04-30 12:01:52 +02:00
com.plotsquared.core.location.Location pLoc =
BukkitUtil.getLocation(entity.getLocation());
PlotArea area = pLoc.getPlotArea();
if (area != null) {
PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc));
if (!originalPlotId.equals(currentPlotId) && (
currentPlotId == null || !area
.getPlot(originalPlotId)
.equals(area.getPlot(currentPlotId)))) {
if (entity.hasMetadata("ps-tmp-teleport")) {
continue;
}
iterator.remove();
entity.remove();
}
}
}
} else {
//This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java)
2020-04-30 12:01:52 +02:00
com.plotsquared.core.location.Location pLoc =
BukkitUtil.getLocation(entity.getLocation());
PlotArea area = pLoc.getPlotArea();
if (area != null) {
PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc));
if (currentPlotId != null) {
2020-04-30 12:01:52 +02:00
entity.setMetadata("shulkerPlot",
new FixedMetadataValue(
(Plugin) PlotSquared.platform(), currentPlotId));
}
}
}
}
continue;
2020-06-29 00:45:40 +02:00
case "ZOMBIFIED_PIGLIN":
case "LLAMA":
case "DONKEY":
case "MULE":
case "ZOMBIE_HORSE":
case "SKELETON_HORSE":
case "HUSK":
case "ELDER_GUARDIAN":
case "WITHER_SKELETON":
case "STRAY":
case "ZOMBIE_VILLAGER":
case "EVOKER":
case "EVOKER_FANGS":
case "VEX":
case "VINDICATOR":
case "POLAR_BEAR":
case "BAT":
case "BLAZE":
case "CAVE_SPIDER":
case "CHICKEN":
case "COW":
case "CREEPER":
case "ENDERMAN":
case "ENDERMITE":
case "ENDER_DRAGON":
case "GHAST":
case "GIANT":
case "GUARDIAN":
case "HORSE":
case "IRON_GOLEM":
case "MAGMA_CUBE":
case "MUSHROOM_COW":
case "OCELOT":
case "PIG":
case "PIG_ZOMBIE":
case "RABBIT":
case "SHEEP":
case "SILVERFISH":
case "SKELETON":
case "SLIME":
case "SNOWMAN":
case "SPIDER":
case "SQUID":
case "VILLAGER":
case "WITCH":
case "WITHER":
case "WOLF":
case "ZOMBIE":
case "PARROT":
case "SALMON":
case "DOLPHIN":
case "TROPICAL_FISH":
case "DROWNED":
case "COD":
case "TURTLE":
case "PUFFERFISH":
case "PHANTOM":
case "ILLUSIONER":
case "CAT":
case "PANDA":
case "FOX":
case "PILLAGER":
case "TRADER_LLAMA":
case "WANDERING_TRADER":
case "RAVAGER":
case "BEE":
case "HOGLIN":
case "PIGLIN":
case "ZOGLIN":
default: {
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
Location location = entity.getLocation();
if (BukkitUtil.getLocation(location).isPlotRoad()) {
if (entity instanceof LivingEntity) {
2019-02-11 00:03:14 +01:00
LivingEntity livingEntity = (LivingEntity) entity;
if (!livingEntity.isLeashed() || !entity
.hasMetadata("keep")) {
Entity passenger = entity.getPassenger();
if (!(passenger instanceof Player) && entity
.getMetadata("keep").isEmpty()) {
if (entity.hasMetadata("ps-tmp-teleport")) {
continue;
2019-02-11 00:03:14 +01:00
}
iterator.remove();
entity.remove();
continue;
2019-02-11 00:03:14 +01:00
}
}
} else {
Entity passenger = entity.getPassenger();
if (!(passenger instanceof Player) && entity
.getMetadata("keep").isEmpty()) {
if (entity.hasMetadata("ps-tmp-teleport")) {
continue;
}
iterator.remove();
entity.remove();
continue;
}
}
}
}
continue;
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}), 20);
}
Merge branch 'master' into breaking # Conflicts: # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotRateEvent.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java # Core/src/main/java/com/intellectualcrafters/plot/commands/PluginCmd.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java # Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java # Core/src/main/java/com/intellectualcrafters/plot/config/C.java # Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java # Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java # Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java # Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java # README.md # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/events/PlotRateEvent.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java # Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java
2018-11-14 15:44:07 +01:00
@Override @Nullable
2019-05-17 22:21:03 +02:00
public final ChunkGenerator getDefaultWorldGenerator(@NotNull final String worldName,
final String id) {
Merge branch 'master' into breaking # Conflicts: # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotRateEvent.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java # Core/src/main/java/com/intellectualcrafters/plot/commands/PluginCmd.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java # Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java # Core/src/main/java/com/intellectualcrafters/plot/config/C.java # Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java # Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java # Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java # Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java # README.md # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/events/PlotRateEvent.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java # Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java
2018-11-14 15:44:07 +01:00
final IndependentPlotGenerator result;
if (id != null && id.equalsIgnoreCase("single")) {
2020-07-10 22:12:37 +02:00
result = getInjector().getInstance(SingleWorldGenerator.class);
} else {
2020-07-10 22:12:37 +02:00
result = getInjector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class));
if (!PlotSquared.get().setupPlotWorld(worldName, id, result)) {
return null;
}
}
return (ChunkGenerator) result.specify(worldName);
}
@Override @Nullable public GeneratorWrapper<?> getGenerator(@NonNull final String world,
Merge branch 'master' into breaking # Conflicts: # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotRateEvent.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java # Core/src/main/java/com/intellectualcrafters/plot/commands/PluginCmd.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java # Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java # Core/src/main/java/com/intellectualcrafters/plot/config/C.java # Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java # Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java # Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java # Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java # README.md # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/events/PlotRateEvent.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java # Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java
2018-11-14 15:44:07 +01:00
@Nullable final String name) {
if (name == null) {
return null;
}
2018-08-10 20:46:38 +02:00
final Plugin genPlugin = Bukkit.getPluginManager().getPlugin(name);
if (genPlugin != null && genPlugin.isEnabled()) {
ChunkGenerator gen = genPlugin.getDefaultWorldGenerator(world, "");
if (gen instanceof GeneratorWrapper<?>) {
return (GeneratorWrapper<?>) gen;
}
2020-07-10 17:32:07 +02:00
return new BukkitPlotGenerator(world, gen, this.plotAreaManager);
} else {
2020-07-10 22:12:37 +02:00
return new BukkitPlotGenerator(world, getInjector()
.getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)), this.plotAreaManager);
}
}
@Override public void startMetrics() {
if (this.metricsStarted) {
return;
}
this.metricsStarted = true;
Metrics metrics = new Metrics(this, BSTATS_ID);// bstats
metrics.addCustomChart(new Metrics.DrilldownPie("area_types", () -> {
final Map<String, Map<String, Integer>> map = new HashMap<>();
for (final PlotAreaType plotAreaType : PlotAreaType.values()) {
final Map<String, Integer> terrainTypes = new HashMap<>();
for (final PlotAreaTerrainType plotAreaTerrainType : PlotAreaTerrainType.values()) {
terrainTypes.put(plotAreaTerrainType.name().toLowerCase(), 0);
}
map.put(plotAreaType.name().toLowerCase(), terrainTypes);
}
2020-07-10 17:32:07 +02:00
for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) {
2020-04-30 12:01:52 +02:00
final Map<String, Integer> terrainTypeMap =
map.get(plotArea.getType().name().toLowerCase());
terrainTypeMap.put(plotArea.getTerrain().name().toLowerCase(),
terrainTypeMap.get(plotArea.getTerrain().name().toLowerCase()) + 1);
}
return map;
}));
2020-04-21 13:38:07 +02:00
metrics.addCustomChart(new Metrics.SimplePie("premium",
() -> PremiumVerification.isPremium() ? "Premium" : "Non-Premium"));
2020-05-14 16:33:26 +02:00
metrics.addCustomChart(new Metrics.SimplePie("worldedit_implementation",
() -> Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null ?
"FastAsyncWorldEdit" :
"WorldEdit"));
}
@Override public void unregister(@NonNull final PlotPlayer player) {
BukkitUtil.removePlayer(player.getUUID());
}
2018-08-10 20:46:38 +02:00
@Override public void setGenerator(@NonNull final String worldName) {
World world = BukkitUtil.getWorld(worldName);
if (world == null) {
// create world
2020-07-10 19:25:05 +02:00
ConfigurationSection worldConfig = this.worldConfiguration.getConfigurationSection("worlds." + worldName);
String manager = worldConfig.getString("generator.plugin", getPluginName());
2020-07-10 22:12:37 +02:00
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);
2020-07-10 22:12:37 +02:00
getInjector().getInstance(SetupUtils.class).setupWorld(builder);
world = Bukkit.getWorld(worldName);
} else {
try {
2020-07-10 17:32:07 +02:00
if (!this.plotAreaManager.hasPlotArea(worldName)) {
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
}
} catch (Exception e) {
PlotSquared.log("Failed to reload world: " + world + " | " + e.getMessage());
Bukkit.getServer().unloadWorld(world, false);
return;
}
}
2019-04-23 19:45:24 +02:00
assert world != null;
ChunkGenerator gen = world.getGenerator();
if (gen instanceof BukkitPlotGenerator) {
PlotSquared.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
} else if (gen != null) {
2020-07-10 17:32:07 +02:00
PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen, this.plotAreaManager));
2020-07-10 19:25:05 +02:00
} else if (this.worldConfiguration.contains("worlds." + worldName)) {
PlotSquared.get().loadWorld(worldName, null);
}
}
/**
* Attempt to retrieve a {@link PlotPlayer} from a player identifier.
* This method accepts:
* - {@link Player} objects,
* - {@link OfflinePlayer} objects,
* - {@link String} usernames for online players, and
* - {@link UUID} UUIDs for online players
* <p>
* In the case of offline players, a fake {@link Player} instance will be created.
* This is a rather expensive operation, and should be avoided if possible.
*
* @param player The player to convert to a PlotPlayer
* @return The plot player instance that corresponds to the identifier, or null
* if no such player object could be created
*/
@Override @Nullable public PlotPlayer<Player> wrapPlayer(final Object player) {
if (player instanceof Player) {
return BukkitUtil.getPlayer((Player) player);
}
if (player instanceof OfflinePlayer) {
return BukkitUtil.getPlayer((OfflinePlayer) player);
}
if (player instanceof String) {
return (PlotPlayer<Player>) PlotSquared.platform().getPlayerManager()
.getPlayerIfExists((String) player);
}
if (player instanceof UUID) {
return (PlotPlayer<Player>) PlotSquared.platform().getPlayerManager()
.getPlayerIfExists((UUID) player);
}
return null;
}
2018-08-10 17:01:10 +02:00
@Override public String getNMSPackage() {
2018-08-10 20:46:38 +02:00
final String name = Bukkit.getServer().getClass().getPackage().getName();
return name.substring(name.lastIndexOf('.') + 1);
}
2018-08-10 17:01:10 +02:00
@Override public ChatManager<?> initChatManager() {
if (Settings.Chat.INTERACTIVE) {
return new BukkitChatManager();
} else {
return new PlainChatManager();
}
}
@Override public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world,
Merge branch 'master' into breaking # Conflicts: # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotRateEvent.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java # Core/src/main/java/com/intellectualcrafters/plot/commands/PluginCmd.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java # Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java # Core/src/main/java/com/intellectualcrafters/plot/config/C.java # Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java # Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java # Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java # Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java # README.md # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/events/PlotRateEvent.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java # Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java
2018-11-14 15:44:07 +01:00
@NonNull final IndependentPlotGenerator generator) {
2020-07-10 17:32:07 +02:00
return new BukkitPlotGenerator(world, generator, this.plotAreaManager);
}
2019-11-25 23:38:03 +01:00
@Override public List<Map.Entry<Map.Entry<String, String>, Boolean>> getPluginIds() {
List<Map.Entry<Map.Entry<String, String>, Boolean>> names = new ArrayList<>();
2018-08-10 20:46:38 +02:00
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
2020-04-30 12:01:52 +02:00
Map.Entry<String, String> id = new AbstractMap.SimpleEntry<>(plugin.getName(),
plugin.getDescription().getVersion());
2019-11-25 23:38:03 +01:00
names.add(new AbstractMap.SimpleEntry<>(id, plugin.isEnabled()));
}
return names;
}
2019-11-04 22:55:40 +01:00
@Override @NotNull public com.plotsquared.core.location.World<?> getPlatformWorld(@NotNull final String worldName) {
return BukkitWorld.of(worldName);
}
2018-08-10 17:01:10 +02:00
}