2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* 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.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* 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.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
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;
|
2020-07-12 12:25:44 +02:00
|
|
|
import com.google.inject.Inject;
|
2020-07-10 22:12:37 +02:00
|
|
|
import com.google.inject.Injector;
|
|
|
|
import com.google.inject.Key;
|
2020-08-16 12:43:57 +02:00
|
|
|
import com.google.inject.Singleton;
|
2020-07-10 22:12:37 +02:00
|
|
|
import com.google.inject.Stage;
|
2020-07-23 14:56:06 +02:00
|
|
|
import com.google.inject.TypeLiteral;
|
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;
|
2020-07-21 14:28:54 +02:00
|
|
|
import com.plotsquared.bukkit.inject.PermissionModule;
|
2020-07-10 22:12:37 +02:00
|
|
|
import com.plotsquared.bukkit.inject.WorldManagerModule;
|
2020-07-11 20:03:55 +02:00
|
|
|
import com.plotsquared.bukkit.listener.BlockEventListener;
|
2021-06-26 21:08:25 +02:00
|
|
|
import com.plotsquared.bukkit.listener.BlockEventListener117;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.bukkit.listener.ChunkListener;
|
2020-07-11 20:03:55 +02:00
|
|
|
import com.plotsquared.bukkit.listener.EntityEventListener;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.bukkit.listener.EntitySpawnListener;
|
2020-04-30 18:23:18 +02:00
|
|
|
import com.plotsquared.bukkit.listener.PaperListener;
|
2020-07-11 20:03:55 +02:00
|
|
|
import com.plotsquared.bukkit.listener.PlayerEventListener;
|
|
|
|
import com.plotsquared.bukkit.listener.ProjectileEventListener;
|
2020-07-16 18:04:17 +02:00
|
|
|
import com.plotsquared.bukkit.listener.ServerListener;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.bukkit.listener.SingleWorldListener;
|
2022-09-05 20:06:37 +02:00
|
|
|
import com.plotsquared.bukkit.listener.SpigotListener;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.bukkit.listener.WorldEvents;
|
2020-07-14 20:41:08 +02:00
|
|
|
import com.plotsquared.bukkit.placeholder.PAPIPlaceholders;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.bukkit.placeholder.PlaceholderFormatter;
|
2020-07-23 15:03:27 +02:00
|
|
|
import com.plotsquared.bukkit.player.BukkitPlayer;
|
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.BukkitUtil;
|
2020-07-10 12:21:29 +02:00
|
|
|
import com.plotsquared.bukkit.util.BukkitWorld;
|
2020-04-11 02:19:18 +02:00
|
|
|
import com.plotsquared.bukkit.util.SetGenCB;
|
2023-01-09 23:50:13 +01:00
|
|
|
import com.plotsquared.bukkit.util.TranslationUpdateManager;
|
2023-08-23 12:50:00 +02:00
|
|
|
import com.plotsquared.bukkit.util.UpdateUtility;
|
2020-09-11 16:44:04 +02:00
|
|
|
import com.plotsquared.bukkit.util.task.BukkitTaskManager;
|
2020-07-15 13:18:09 +02:00
|
|
|
import com.plotsquared.bukkit.util.task.PaperTimeConverter;
|
|
|
|
import com.plotsquared.bukkit.util.task.SpigotTimeConverter;
|
2020-05-23 19:43:32 +02:00
|
|
|
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;
|
2020-07-07 12:56:43 +02:00
|
|
|
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-14 19:10:52 +02:00
|
|
|
import com.plotsquared.core.components.ComponentPresetManager;
|
2020-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.core.configuration.ConfigurationNode;
|
|
|
|
import com.plotsquared.core.configuration.ConfigurationSection;
|
2020-07-19 14:23:55 +02:00
|
|
|
import com.plotsquared.core.configuration.ConfigurationUtil;
|
2020-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.core.configuration.Settings;
|
2020-12-07 23:05:25 +01:00
|
|
|
import com.plotsquared.core.configuration.Storage;
|
2020-12-21 20:33:49 +01:00
|
|
|
import com.plotsquared.core.configuration.caption.ChatFormatter;
|
|
|
|
import com.plotsquared.core.configuration.file.YamlConfiguration;
|
2020-05-19 00:28:52 +02:00
|
|
|
import com.plotsquared.core.database.DBFunc;
|
2023-02-09 20:51:59 +01:00
|
|
|
import com.plotsquared.core.events.RemoveRoadEntityEvent;
|
|
|
|
import com.plotsquared.core.events.Result;
|
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;
|
2020-04-16 06:11:03 +02:00
|
|
|
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;
|
2020-07-14 18:49:40 +02:00
|
|
|
import com.plotsquared.core.plot.comment.CommentManager;
|
2020-07-19 14:23:55 +02:00
|
|
|
import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.plot.world.PlotAreaManager;
|
|
|
|
import com.plotsquared.core.plot.world.SinglePlotArea;
|
|
|
|
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
2020-06-05 02:19:37 +02:00
|
|
|
import com.plotsquared.core.setup.PlotAreaBuilder;
|
|
|
|
import com.plotsquared.core.setup.SettingsNodesWrapper;
|
2020-07-10 18:17:44 +02:00
|
|
|
import com.plotsquared.core.util.EventDispatcher;
|
2020-07-19 14:23:55 +02:00
|
|
|
import com.plotsquared.core.util.FileUtils;
|
2020-05-15 18:41:57 +02:00
|
|
|
import com.plotsquared.core.util.PlatformWorldManager;
|
2020-07-23 15:03:27 +02:00
|
|
|
import com.plotsquared.core.util.PlayerManager;
|
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;
|
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-07-15 13:18:09 +02:00
|
|
|
import com.plotsquared.core.util.task.TaskTime;
|
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;
|
2023-02-09 20:51:59 +01:00
|
|
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
2020-04-30 18:23:18 +02:00
|
|
|
import io.papermc.lib.PaperLib;
|
2020-07-05 18:14:29 +02:00
|
|
|
import net.kyori.adventure.audience.Audience;
|
2020-12-28 11:21:35 +01:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
2021-08-18 11:58:18 +02:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2020-04-11 19:52:45 +02:00
|
|
|
import org.bstats.bukkit.Metrics;
|
2021-01-24 10:39:03 +01:00
|
|
|
import org.bstats.charts.DrilldownPie;
|
|
|
|
import org.bstats.charts.SimplePie;
|
2019-11-04 18:44:23 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Chunk;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.World;
|
2016-02-26 07:29:31 +01:00
|
|
|
import org.bukkit.command.PluginCommand;
|
|
|
|
import org.bukkit.entity.Entity;
|
2016-06-03 16:57:25 +02:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
2016-02-26 07:29:31 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.generator.ChunkGenerator;
|
2017-12-03 17:21:15 +01:00
|
|
|
import org.bukkit.metadata.FixedMetadataValue;
|
2016-02-26 07:29:31 +01:00
|
|
|
import org.bukkit.metadata.MetadataValue;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2021-01-09 22:28:41 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
2021-04-27 11:58:49 +02:00
|
|
|
import org.incendo.serverlib.ServerLib;
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2019-02-04 15:02:21 +01:00
|
|
|
import java.io.File;
|
2023-01-09 23:50:13 +01:00
|
|
|
import java.io.IOException;
|
2019-02-04 15:02:21 +01:00
|
|
|
import java.lang.reflect.Method;
|
2019-05-11 03:18:28 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
2022-01-12 22:21:51 +01:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
2020-04-11 20:56:34 +02:00
|
|
|
import java.util.HashMap;
|
2020-05-20 15:12:09 +02:00
|
|
|
import java.util.HashSet;
|
2019-05-11 03:18:28 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2020-07-22 21:06:23 +02:00
|
|
|
import java.util.Locale;
|
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;
|
2019-05-11 03:18:28 +02:00
|
|
|
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;
|
2019-02-04 15:02:21 +01:00
|
|
|
|
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;
|
2019-02-04 15:02:21 +01:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
@Singleton
|
2020-07-17 16:41:06 +02:00
|
|
|
public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform<Player> {
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2021-06-03 12:40:27 +02:00
|
|
|
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + BukkitPlatform.class.getSimpleName());
|
2020-05-10 14:02:25 +02:00
|
|
|
private static final int BSTATS_ID = 1404;
|
2018-07-21 17:32:38 +02:00
|
|
|
|
|
|
|
static {
|
|
|
|
try {
|
2021-05-21 00:35:19 +02:00
|
|
|
Settings.load(new File(PlotSquared.platform().getDirectory(), "settings.yml"));
|
2019-04-24 00:48:22 +02:00
|
|
|
} catch (Throwable ignored) {
|
|
|
|
}
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
2018-12-26 18:21:06 +01:00
|
|
|
|
2018-07-21 17:32:38 +02:00
|
|
|
private int[] version;
|
2020-07-17 17:24:45 +02:00
|
|
|
private String pluginName;
|
|
|
|
private SingleWorldListener singleWorldListener;
|
2018-08-10 17:01:10 +02:00
|
|
|
private Method methodUnloadChunk0;
|
|
|
|
private boolean methodUnloadSetup = false;
|
2018-12-21 21:10:37 +01:00
|
|
|
private boolean metricsStarted;
|
2021-06-08 19:36:45 +02:00
|
|
|
private boolean faweHook = false;
|
2018-07-21 17:32:38 +02:00
|
|
|
|
2020-07-17 17:24:45 +02:00
|
|
|
private Injector injector;
|
2020-07-10 22:12:37 +02:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@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;
|
2020-07-22 21:06:23 +02:00
|
|
|
private Locale serverLocale;
|
2020-07-10 19:25:05 +02:00
|
|
|
|
2022-01-20 12:39:40 +01:00
|
|
|
@SuppressWarnings("StringSplitter")
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
2021-02-24 20:35:38 +01:00
|
|
|
public int @NonNull [] serverVersion() {
|
2018-07-21 17:32:38 +02:00
|
|
|
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();
|
2021-01-09 22:28:41 +01:00
|
|
|
return new int[]{1, 13, 0};
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.version;
|
|
|
|
}
|
|
|
|
|
2022-03-05 19:03:39 +01:00
|
|
|
@Override
|
|
|
|
public int versionMinHeight() {
|
|
|
|
return serverVersion()[1] >= 18 ? -64 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int versionMaxHeight() {
|
|
|
|
return serverVersion()[1] >= 18 ? 319 : 255;
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public @NonNull String serverImplementation() {
|
2019-01-09 23:12:36 +01:00
|
|
|
return Bukkit.getVersion();
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01: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
|
|
|
|
2020-07-15 13:18:09 +02:00
|
|
|
final TaskTime.TimeConverter timeConverter;
|
|
|
|
if (PaperLib.isPaper()) {
|
|
|
|
timeConverter = new PaperTimeConverter();
|
|
|
|
} else {
|
|
|
|
timeConverter = new SpigotTimeConverter();
|
|
|
|
}
|
|
|
|
|
2020-07-10 22:12:37 +02:00
|
|
|
// Stuff that needs to be created before the PlotSquared instance
|
2020-07-17 22:58:10 +02:00
|
|
|
PlotPlayer.registerConverter(Player.class, BukkitUtil::adapt);
|
2020-07-17 16:38:07 +02:00
|
|
|
TaskManager.setPlatformImplementation(new BukkitTaskManager(this, timeConverter));
|
2018-12-26 15:29:39 +01:00
|
|
|
|
2020-07-10 17:32:07 +02:00
|
|
|
final PlotSquared plotSquared = new PlotSquared(this, "Bukkit");
|
2019-03-18 19:49:22 +01:00
|
|
|
|
2022-06-11 16:16:06 +02:00
|
|
|
// FastAsyncWorldEdit
|
2021-06-08 20:31:17 +02:00
|
|
|
if (Settings.FAWE_Components.FAWE_HOOK) {
|
|
|
|
Plugin fawe = getServer().getPluginManager().getPlugin("FastAsyncWorldEdit");
|
|
|
|
if (fawe != null) {
|
|
|
|
try {
|
2021-06-26 17:19:07 +02:00
|
|
|
Class.forName("com.fastasyncworldedit.bukkit.regions.plotsquared.FaweQueueCoordinator");
|
2021-06-08 20:31:17 +02:00
|
|
|
faweHook = true;
|
|
|
|
} catch (Exception ignored) {
|
2022-06-11 16:16:06 +02:00
|
|
|
LOGGER.error("Incompatible version of FastAsyncWorldEdit to enable hook, please upgrade: https://ci.athion" +
|
2022-01-12 22:21:51 +01:00
|
|
|
".net/job/FastAsyncWorldEdit/");
|
2021-06-08 20:31:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2020-07-24 17:24:53 +02:00
|
|
|
this.injector = Guice
|
2021-08-18 11:58:18 +02:00
|
|
|
.createInjector(
|
|
|
|
Stage.PRODUCTION,
|
2021-01-09 22:28:41 +01:00
|
|
|
new PermissionModule(),
|
|
|
|
new WorldManagerModule(),
|
|
|
|
new PlotSquaredModule(),
|
|
|
|
new BukkitModule(this),
|
|
|
|
new BackupModule()
|
|
|
|
);
|
2020-07-10 22:12:37 +02:00
|
|
|
this.injector.injectMembers(this);
|
|
|
|
|
2023-01-09 23:50:13 +01:00
|
|
|
try {
|
|
|
|
this.injector.getInstance(TranslationUpdateManager.class).upgradeTranslationFile();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
|
2020-07-22 21:06:23 +02:00
|
|
|
this.serverLocale = Locale.forLanguageTag(Settings.Enabled_Components.DEFAULT_LOCALE);
|
|
|
|
|
2020-04-21 13:22:42 +02:00
|
|
|
if (PremiumVerification.isPremium() && Settings.Enabled_Components.UPDATE_NOTIFICATIONS) {
|
2020-07-10 22:12:37 +02:00
|
|
|
injector.getInstance(UpdateUtility.class).updateChecker();
|
2020-04-21 09:56:23 +02:00
|
|
|
}
|
2019-03-18 19:49:22 +01:00
|
|
|
|
2020-02-19 23:55:43 +01:00
|
|
|
if (PremiumVerification.isPremium()) {
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("PlotSquared version licensed to Spigot user {}", getUserID());
|
|
|
|
LOGGER.info("https://www.spigotmc.org/resources/{}", getResourceID());
|
|
|
|
LOGGER.info("Download ID: {}", getDownloadID());
|
|
|
|
LOGGER.info("Thanks for supporting us :)");
|
2020-02-19 23:55:43 +01:00
|
|
|
} else {
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("Couldn't verify purchase :(");
|
2020-02-19 23:55:43 +01:00
|
|
|
}
|
|
|
|
|
2020-07-14 18:49:40 +02:00
|
|
|
// 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()) {
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("Flags were converted successfully!");
|
2020-07-14 18:49:40 +02:00
|
|
|
// Update the config version
|
|
|
|
try {
|
|
|
|
plotSquared.setConfigurationVersion("v5");
|
|
|
|
} catch (final Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Comments
|
|
|
|
CommentManager.registerDefaultInboxes();
|
|
|
|
|
2020-07-10 22:12:37 +02:00
|
|
|
// Do stuff that was previously done in PlotSquared
|
|
|
|
// Kill entities
|
2020-07-24 17:24:53 +02:00
|
|
|
if (Settings.Enabled_Components.KILL_ROAD_MOBS || Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
2020-07-10 22:12:37 +02:00
|
|
|
this.runEntityTask();
|
|
|
|
}
|
|
|
|
|
|
|
|
// WorldEdit
|
|
|
|
if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
|
|
|
|
try {
|
2020-12-05 18:41:25 +01:00
|
|
|
WorldEdit.getInstance().getEventBus().register(this.injector().getInstance(WESubscriber.class));
|
2021-06-08 19:36:45 +02:00
|
|
|
LOGGER.info("{} hooked into WorldEdit", this.pluginName());
|
2020-07-10 22:12:37 +02:00
|
|
|
} catch (Throwable e) {
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.error(
|
2021-01-09 22:28:41 +01:00
|
|
|
"Incompatible version of WorldEdit, please upgrade: https://builds.enginehub.org/job/worldedit?branch=master");
|
2020-07-10 22:12:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Settings.Enabled_Components.EVENTS) {
|
2020-12-05 18:41:25 +01:00
|
|
|
getServer().getPluginManager().registerEvents(injector().getInstance(PlayerEventListener.class), this);
|
|
|
|
getServer().getPluginManager().registerEvents(injector().getInstance(BlockEventListener.class), this);
|
2021-06-26 21:08:25 +02:00
|
|
|
if (serverVersion()[1] >= 17) {
|
|
|
|
getServer().getPluginManager().registerEvents(injector().getInstance(BlockEventListener117.class), this);
|
|
|
|
}
|
2020-12-05 18:41:25 +01:00
|
|
|
getServer().getPluginManager().registerEvents(injector().getInstance(EntityEventListener.class), this);
|
|
|
|
getServer().getPluginManager().registerEvents(injector().getInstance(ProjectileEventListener.class), this);
|
|
|
|
getServer().getPluginManager().registerEvents(injector().getInstance(ServerListener.class), this);
|
|
|
|
getServer().getPluginManager().registerEvents(injector().getInstance(EntitySpawnListener.class), this);
|
2020-07-10 22:12:37 +02:00
|
|
|
if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) {
|
2023-03-06 11:38:30 +01:00
|
|
|
getServer().getPluginManager().registerEvents(injector().getInstance(PaperListener.class), this);
|
2022-09-05 20:06:37 +02:00
|
|
|
} else {
|
|
|
|
getServer().getPluginManager().registerEvents(injector().getInstance(SpigotListener.class), this);
|
2020-07-10 22:12:37 +02:00
|
|
|
}
|
|
|
|
this.plotListener.startRunnable();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Required
|
2020-12-05 18:41:25 +01:00
|
|
|
getServer().getPluginManager().registerEvents(injector().getInstance(WorldEvents.class), this);
|
2020-07-10 22:12:37 +02:00
|
|
|
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
|
2020-12-05 18:41:25 +01:00
|
|
|
getServer().getPluginManager().registerEvents(injector().getInstance(ChunkListener.class), this);
|
2020-07-10 22:12:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Commands
|
|
|
|
if (Settings.Enabled_Components.COMMANDS) {
|
|
|
|
this.registerCommands();
|
2020-02-19 23:55:43 +01:00
|
|
|
}
|
|
|
|
|
2021-05-18 21:17:47 +02:00
|
|
|
// Permissions
|
|
|
|
this.permissionHandler().initialize();
|
|
|
|
|
2020-07-10 22:12:37 +02:00
|
|
|
if (Settings.Enabled_Components.COMPONENT_PRESETS) {
|
|
|
|
try {
|
2020-12-05 18:41:25 +01:00
|
|
|
injector().getInstance(ComponentPresetManager.class);
|
2020-07-10 22:12:37 +02:00
|
|
|
} catch (final Exception e) {
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.error("Failed to initialize the preset system", e);
|
2020-07-10 22:12:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// World generators:
|
|
|
|
final ConfigurationSection section = this.worldConfiguration.getConfigurationSection("worlds");
|
2020-12-05 18:41:25 +01:00
|
|
|
final WorldUtil worldUtil = injector().getInstance(WorldUtil.class);
|
2020-07-10 22:12:37 +02:00
|
|
|
|
|
|
|
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("*")) {
|
2021-06-03 12:40:27 +02:00
|
|
|
if (Settings.DEBUG) {
|
|
|
|
LOGGER.warn(
|
|
|
|
"`{}` was not properly loaded - {} will now try to load it properly",
|
|
|
|
world,
|
|
|
|
this.pluginName()
|
|
|
|
);
|
|
|
|
LOGGER.warn(
|
|
|
|
"- Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml");
|
|
|
|
LOGGER.warn("- Your world management plugin may be faulty (or non existent)");
|
|
|
|
LOGGER.warn("- The named world is not a plot world");
|
|
|
|
LOGGER.warn("This message may also be a false positive and could be ignored.");
|
|
|
|
}
|
2020-07-10 22:12:37 +02:00
|
|
|
this.setGenerator(world);
|
|
|
|
}
|
|
|
|
}
|
2020-07-15 13:18:09 +02:00
|
|
|
}, TaskTime.ticks(1L));
|
2020-07-10 22:12:37 +02:00
|
|
|
}
|
2020-05-23 19:43:32 +02:00
|
|
|
|
2022-01-23 10:44:11 +01:00
|
|
|
plotSquared.startExpiryTasks();
|
|
|
|
|
2022-06-11 16:16:06 +02:00
|
|
|
// Once the server has loaded force updating all generators known to PlotSquared
|
2021-09-07 15:47:37 +02:00
|
|
|
TaskManager.runTaskLater(() -> PlotSquared.platform().setupUtils().updateGenerators(true), TaskTime.ticks(1L));
|
|
|
|
|
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-23 19:43:32 +02:00
|
|
|
|
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);
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("(UUID) Using the offline mode UUID service");
|
2020-05-18 00:22:34 +02:00
|
|
|
}
|
2020-05-23 19:43:32 +02:00
|
|
|
|
2020-07-12 17:04:30 +02:00
|
|
|
if (Settings.UUID.SERVICE_BUKKIT) {
|
|
|
|
final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService();
|
2020-07-14 19:18:08 +02:00
|
|
|
this.impromptuPipeline.registerService(offlinePlayerUUIDService);
|
|
|
|
this.backgroundPipeline.registerService(offlinePlayerUUIDService);
|
2020-07-12 17:04:30 +02:00
|
|
|
}
|
2020-05-20 15:12:09 +02:00
|
|
|
|
2020-05-24 04:48:19 +02:00
|
|
|
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db");
|
2020-05-24 05:00:36 +02:00
|
|
|
|
|
|
|
final SQLiteUUIDService legacyUUIDService;
|
2021-01-09 22:28:41 +01:00
|
|
|
if (Settings.UUID.LEGACY_DATABASE_SUPPORT && FileUtils
|
|
|
|
.getFile(PlotSquared.platform().getDirectory(), "usercache.db")
|
|
|
|
.exists()) {
|
2020-05-24 05:00:36 +02:00
|
|
|
legacyUUIDService = new SQLiteUUIDService("usercache.db");
|
|
|
|
} else {
|
|
|
|
legacyUUIDService = null;
|
|
|
|
}
|
2020-05-23 19:43:32 +02:00
|
|
|
|
|
|
|
final LuckPermsUUIDService luckPermsUUIDService;
|
2020-07-24 17:24:53 +02:00
|
|
|
if (Settings.UUID.SERVICE_LUCKPERMS && Bukkit.getPluginManager().getPlugin("LuckPerms") != null) {
|
2020-05-23 19:43:32 +02:00
|
|
|
luckPermsUUIDService = new LuckPermsUUIDService();
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("(UUID) Using LuckPerms as a complementary UUID service");
|
2020-05-23 19:43:32 +02:00
|
|
|
} else {
|
|
|
|
luckPermsUUIDService = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
final EssentialsUUIDService essentialsUUIDService;
|
2020-07-12 17:11:25 +02:00
|
|
|
if (Settings.UUID.SERVICE_ESSENTIALSX && Bukkit.getPluginManager().getPlugin("Essentials") != null) {
|
2020-05-23 19:43:32 +02:00
|
|
|
essentialsUUIDService = new EssentialsUUIDService();
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("(UUID) Using EssentialsX as a complementary UUID service");
|
2020-05-23 19:43:32 +02:00
|
|
|
} 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
|
2020-07-12 17:04:30 +02:00
|
|
|
if (Bukkit.getOnlineMode() && PaperLib.isPaper() && Settings.UUID.SERVICE_PAPER) {
|
2020-05-24 04:28:29 +02:00
|
|
|
final PaperUUIDService paperUUIDService = new PaperUUIDService();
|
2020-07-10 22:12:37 +02:00
|
|
|
this.impromptuPipeline.registerService(paperUUIDService);
|
|
|
|
this.backgroundPipeline.registerService(paperUUIDService);
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("(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);
|
2020-05-23 19:43:32 +02:00
|
|
|
|
2020-05-24 05:00:36 +02:00
|
|
|
if (legacyUUIDService != null) {
|
2020-07-10 22:12:37 +02:00
|
|
|
this.impromptuPipeline.registerService(legacyUUIDService);
|
|
|
|
this.backgroundPipeline.registerService(legacyUUIDService);
|
2020-05-24 05:00:36 +02:00
|
|
|
}
|
2020-05-24 04:48:19 +02:00
|
|
|
|
2020-05-23 19:43:32 +02:00
|
|
|
// Plugin providers
|
|
|
|
if (luckPermsUUIDService != null) {
|
2020-07-10 22:12:37 +02:00
|
|
|
this.impromptuPipeline.registerService(luckPermsUUIDService);
|
|
|
|
this.backgroundPipeline.registerService(luckPermsUUIDService);
|
2020-05-23 19:43:32 +02:00
|
|
|
}
|
|
|
|
if (essentialsUUIDService != null) {
|
2020-07-10 22:12:37 +02:00
|
|
|
this.impromptuPipeline.registerService(essentialsUUIDService);
|
|
|
|
this.backgroundPipeline.registerService(essentialsUUIDService);
|
2020-05-23 19:43:32 +02:00
|
|
|
}
|
|
|
|
|
2022-05-11 14:11:57 +02:00
|
|
|
if (Settings.UUID.IMPROMPTU_SERVICE_MOJANG_API) {
|
|
|
|
final SquirrelIdUUIDService impromptuMojangService = new SquirrelIdUUIDService(Settings.UUID.IMPROMPTU_LIMIT);
|
|
|
|
this.impromptuPipeline.registerService(impromptuMojangService);
|
|
|
|
}
|
2020-07-24 17:24:53 +02:00
|
|
|
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);
|
2020-05-24 04:48:19 +02:00
|
|
|
|
2020-05-24 05:00:36 +02:00
|
|
|
if (legacyUUIDService != null) {
|
2020-07-10 22:12:37 +02:00
|
|
|
this.impromptuPipeline.registerService(legacyUUIDService);
|
|
|
|
this.backgroundPipeline.registerService(legacyUUIDService);
|
2020-05-24 05:00:36 +02:00
|
|
|
}
|
2020-05-18 00:22:34 +02:00
|
|
|
}
|
|
|
|
|
2020-07-10 22:12:37 +02:00
|
|
|
this.impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE);
|
2020-07-03 13:50:12 +02:00
|
|
|
|
|
|
|
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-24 18:15:58 +02:00
|
|
|
injector.getInstance(PAPIPlaceholders.class).register();
|
2020-02-20 16:03:17 +01:00
|
|
|
if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) {
|
2020-12-05 18:41:25 +01:00
|
|
|
ChatFormatter.formatters.add(injector().getInstance(PlaceholderFormatter.class));
|
2020-02-20 16:03:17 +01:00
|
|
|
}
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("PlotSquared hooked into PlaceholderAPI");
|
2020-02-16 20:33:24 +01:00
|
|
|
}
|
|
|
|
|
2020-08-17 19:39:43 +02:00
|
|
|
this.startMetrics();
|
2020-08-14 11:36:17 +02:00
|
|
|
|
2018-07-21 17:32:38 +02:00
|
|
|
if (Settings.Enabled_Components.WORLDS) {
|
2023-09-06 18:46:56 +02:00
|
|
|
TaskManager.getPlatformImplementation().taskRepeat(this::unload, TaskTime.seconds(10L));
|
2018-07-21 17:32:38 +02:00
|
|
|
try {
|
2020-12-05 18:41:25 +01:00
|
|
|
singleWorldListener = injector().getInstance(SingleWorldListener.class);
|
2021-01-07 22:24:38 +01:00
|
|
|
Bukkit.getPluginManager().registerEvents(singleWorldListener, this);
|
2018-07-21 17:32:38 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2020-05-10 14:02:25 +02:00
|
|
|
|
2020-06-23 18:36:53 +02:00
|
|
|
// Clean up potential memory leak
|
|
|
|
Bukkit.getScheduler().runTaskTimer(this, () -> {
|
|
|
|
try {
|
2020-12-05 18:41:25 +01:00
|
|
|
for (final PlotPlayer<? extends Player> player : this.playerManager().getPlayers()) {
|
2020-06-23 18:36:53 +02:00
|
|
|
if (player.getPlatformPlayer() == null || !player.getPlatformPlayer().isOnline()) {
|
2020-12-05 18:41:25 +01:00
|
|
|
this.playerManager().removePlayer(player);
|
2020-06-23 18:36:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (final Exception e) {
|
|
|
|
getLogger().warning("Failed to clean up players: " + e.getMessage());
|
|
|
|
}
|
|
|
|
}, 100L, 100L);
|
2020-12-04 12:25:53 +01:00
|
|
|
|
2021-01-22 23:34:47 +01:00
|
|
|
// Check if we are in a safe environment
|
|
|
|
ServerLib.checkUnsafeForks();
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
|
2018-12-21 21:10:37 +01:00
|
|
|
private void unload() {
|
2018-08-10 20:46:38 +02:00
|
|
|
if (!this.methodUnloadSetup) {
|
|
|
|
this.methodUnloadSetup = true;
|
2018-07-21 17:32:38 +02:00
|
|
|
try {
|
|
|
|
ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
2021-01-09 22:28:41 +01:00
|
|
|
this.methodUnloadChunk0 = classCraftWorld.getRealClass().getDeclaredMethod(
|
|
|
|
"unloadChunk0",
|
|
|
|
int.class,
|
|
|
|
int.class,
|
|
|
|
boolean.class
|
|
|
|
);
|
2018-08-10 20:46:38 +02:00
|
|
|
this.methodUnloadChunk0.setAccessible(true);
|
2019-01-16 04:19:29 +01:00
|
|
|
} catch (Throwable event) {
|
|
|
|
event.printStackTrace();
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-10 17:32:07 +02:00
|
|
|
|
|
|
|
if (this.plotAreaManager instanceof SinglePlotAreaManager) {
|
2018-07-21 17:32:38 +02:00
|
|
|
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
|
|
|
|
2018-07-21 17:32: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
|
|
|
}
|
|
|
|
|
2018-07-21 17:32:38 +02:00
|
|
|
if (!world.getPlayers().isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-02-06 06:03:52 +01:00
|
|
|
PlotId id;
|
|
|
|
try {
|
|
|
|
id = PlotId.fromString(name);
|
|
|
|
} catch (IllegalArgumentException ignored) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
final Plot plot = area.getOwnedPlot(id);
|
|
|
|
if (plot != null) {
|
2021-01-09 22:28:41 +01:00
|
|
|
if (!plot.getFlag(ServerPlotFlag.class) || PlotSquared
|
|
|
|
.platform()
|
|
|
|
.playerManager()
|
|
|
|
.getPlayerIfExists(plot.getOwner()) == null) {
|
2019-02-06 06:03:52 +01:00
|
|
|
if (world.getKeepSpawnInMemory()) {
|
|
|
|
world.setKeepSpawnInMemory(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final Chunk[] chunks = world.getLoadedChunks();
|
|
|
|
if (chunks.length == 0) {
|
|
|
|
if (!Bukkit.unloadWorld(world, true)) {
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.warn("Failed to unload {}", world.getName());
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
2019-02-06 06:03:52 +01:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
int index = 0;
|
|
|
|
do {
|
|
|
|
final Chunk chunkI = chunks[index++];
|
|
|
|
boolean result;
|
|
|
|
if (methodUnloadChunk0 != null) {
|
|
|
|
try {
|
2020-07-24 17:24:53 +02:00
|
|
|
result = (boolean) methodUnloadChunk0.invoke(world, chunkI.getX(), chunkI.getZ(), true);
|
2019-02-06 06:03:52 +01:00
|
|
|
} catch (Throwable e) {
|
|
|
|
methodUnloadChunk0 = null;
|
|
|
|
e.printStackTrace();
|
2018-07-21 17:32:38 +02:00
|
|
|
continue outer;
|
|
|
|
}
|
2019-02-06 06:03:52 +01:00
|
|
|
} else {
|
2019-04-24 00:48:22 +02:00
|
|
|
result = world.unloadChunk(chunkI.getX(), chunkI.getZ(), true);
|
2019-02-06 06:03:52 +01:00
|
|
|
}
|
|
|
|
if (!result) {
|
|
|
|
continue outer;
|
|
|
|
}
|
2019-04-07 17:43:38 +02:00
|
|
|
if (System.currentTimeMillis() - start > 5) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} while (index < chunks.length);
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
private void startUuidCaching(
|
|
|
|
final @NonNull SQLiteUUIDService sqLiteUUIDService,
|
|
|
|
final @NonNull CacheUUIDService cacheUUIDService
|
|
|
|
) {
|
2022-08-08 12:50:22 +02:00
|
|
|
// Record all unique UUID's and put them into a queue
|
|
|
|
final Set<UUID> uuidSet = new HashSet<>();
|
2020-05-20 15:12:09 +02:00
|
|
|
PlotSquared.get().forEachPlotRaw(plot -> {
|
2022-08-08 12:50:22 +02:00
|
|
|
uuidSet.add(plot.getOwnerAbs());
|
|
|
|
uuidSet.addAll(plot.getMembers());
|
|
|
|
uuidSet.addAll(plot.getTrusted());
|
|
|
|
uuidSet.addAll(plot.getDenied());
|
2020-05-20 15:12:09 +02:00
|
|
|
});
|
2022-08-08 12:50:22 +02:00
|
|
|
final Queue<UUID> uuidQueue = new LinkedBlockingQueue<>(uuidSet);
|
2020-07-05 13:56:54 +02:00
|
|
|
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("(UUID) {} UUIDs will be cached", uuidQueue.size());
|
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;
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("(UUID) PlotSquared will fetch UUIDs in groups of {}", Settings.UUID.BACKGROUND_LIMIT);
|
2020-05-20 15:12:09 +02:00
|
|
|
final List<UUID> uuidList = new ArrayList<>(Settings.UUID.BACKGROUND_LIMIT);
|
2020-05-21 21:24:55 +02:00
|
|
|
|
|
|
|
// Used to indicate that the second retrieval has been attempted
|
|
|
|
boolean secondRun = false;
|
|
|
|
|
|
|
|
while (!uuidQueue.isEmpty() || !uuidList.isEmpty()) {
|
|
|
|
if (!uuidList.isEmpty() && secondRun) {
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.warn("(UUID) Giving up on last batch. Fetching new batch instead");
|
2020-05-21 21:24:55 +02:00
|
|
|
uuidList.clear();
|
|
|
|
}
|
|
|
|
if (uuidList.isEmpty()) {
|
|
|
|
// Retrieve the secondRun variable to indicate that we're retrieving a
|
|
|
|
// fresh batch
|
|
|
|
secondRun = false;
|
|
|
|
// Populate the request list
|
2020-07-24 17:24:53 +02:00
|
|
|
for (int i = 0; i < Settings.UUID.BACKGROUND_LIMIT && !uuidQueue.isEmpty(); i++) {
|
2020-05-21 21:24:55 +02:00
|
|
|
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();
|
2020-05-21 21:24:55 +02:00
|
|
|
// Clear the list if we successfully index all the names
|
|
|
|
uuidList.clear();
|
|
|
|
// Print progress
|
|
|
|
final double percentage = ((double) read / (double) totalSize) * 100.0D;
|
2020-07-13 22:51:57 +02:00
|
|
|
if (Settings.DEBUG) {
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("(UUID) PlotSquared has cached {} of UUIDs", String.format("%.1f%%", percentage));
|
2020-07-13 22:51:57 +02:00
|
|
|
}
|
2020-05-20 15:12:09 +02:00
|
|
|
} catch (final InterruptedException | ExecutionException e) {
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.error("(UUID) Failed to retrieve last batch. Will try again", e);
|
2020-05-20 15:12:09 +02:00
|
|
|
}
|
|
|
|
}
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("(UUID) PlotSquared has cached all UUIDs");
|
2020-05-20 15:12:09 +02:00
|
|
|
}, 10, TimeUnit.SECONDS);
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2018-11-14 14:19:56 +01:00
|
|
|
PlotSquared.get().disable();
|
2018-07-21 17:32:38 +02:00
|
|
|
Bukkit.getScheduler().cancelTasks(this);
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public void shutdown() {
|
2018-12-23 19:43:36 +01:00
|
|
|
this.getServer().getPluginManager().disablePlugin(this);
|
|
|
|
}
|
|
|
|
|
2022-07-25 21:02:54 +02:00
|
|
|
@Override
|
|
|
|
public void shutdownServer() {
|
|
|
|
getServer().shutdown();
|
|
|
|
}
|
|
|
|
|
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-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public @NonNull File getDirectory() {
|
2018-07-21 17:32:38 +02:00
|
|
|
return getDataFolder();
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public @NonNull File worldContainer() {
|
2018-07-21 17:32:38 +02:00
|
|
|
return Bukkit.getWorldContainer();
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
private void runEntityTask() {
|
2020-07-10 17:32:07 +02:00
|
|
|
TaskManager.runTaskRepeat(() -> this.plotAreaManager.forEachPlotArea(plotArea -> {
|
2020-04-02 14:34:38 +02:00
|
|
|
final World world = Bukkit.getWorld(plotArea.getWorldName());
|
2019-02-15 18:50:43 +01:00
|
|
|
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":
|
2019-02-15 18:50:43 +01:00
|
|
|
// 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":
|
2019-02-15 18:50:43 +01:00
|
|
|
// managed elsewhere | projectile
|
|
|
|
continue;
|
2020-06-29 00:45:40 +02:00
|
|
|
case "ITEM_FRAME":
|
|
|
|
case "PAINTING":
|
2019-02-15 18:50:43 +01:00
|
|
|
// Not vehicles
|
|
|
|
continue;
|
2020-06-29 00:45:40 +02:00
|
|
|
case "ARMOR_STAND":
|
2019-02-15 18:50:43 +01:00
|
|
|
// 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":
|
2019-02-15 18:50:43 +01:00
|
|
|
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
2020-07-24 17:24:53 +02:00
|
|
|
com.plotsquared.core.location.Location location = BukkitUtil.adapt(entity.getLocation());
|
2019-02-15 18:50:43 +01:00
|
|
|
Plot plot = location.getPlot();
|
|
|
|
if (plot == null) {
|
|
|
|
if (location.isPlotArea()) {
|
|
|
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-02-09 20:51:59 +01:00
|
|
|
this.removeRoadEntity(entity, iterator);
|
2019-02-15 18:50:43 +01:00
|
|
|
}
|
2018-12-26 18:21:06 +01:00
|
|
|
continue;
|
2019-02-15 18:50:43 +01:00
|
|
|
}
|
|
|
|
List<MetadataValue> meta = entity.getMetadata("plot");
|
|
|
|
if (meta.isEmpty()) {
|
2018-12-26 18:21:06 +01:00
|
|
|
continue;
|
2019-02-15 18:50:43 +01:00
|
|
|
}
|
|
|
|
Plot origin = (Plot) meta.get(0).value();
|
|
|
|
if (!plot.equals(origin.getBasePlot(false))) {
|
|
|
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-02-09 20:51:59 +01:00
|
|
|
this.removeRoadEntity(entity, iterator);
|
2019-02-15 18:50:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
2020-06-29 00:45:40 +02:00
|
|
|
case "SMALL_FIREBALL":
|
|
|
|
case "FIREBALL":
|
|
|
|
case "DRAGON_FIREBALL":
|
|
|
|
case "DROPPED_ITEM":
|
2020-07-24 17:24:53 +02:00
|
|
|
if (Settings.Enabled_Components.KILL_ROAD_ITEMS
|
2021-01-09 22:28:41 +01:00
|
|
|
&& plotArea.getOwnedPlotAbs(BukkitUtil.adapt(entity.getLocation())) == null) {
|
2023-02-09 20:51:59 +01:00
|
|
|
this.removeRoadEntity(entity, iterator);
|
2019-02-15 18:50:43 +01:00
|
|
|
}
|
|
|
|
// dropped item
|
|
|
|
continue;
|
2020-06-29 00:45:40 +02:00
|
|
|
case "PRIMED_TNT":
|
|
|
|
case "FALLING_BLOCK":
|
2019-02-15 18:50:43 +01:00
|
|
|
// managed elsewhere
|
|
|
|
continue;
|
2020-06-29 00:45:40 +02:00
|
|
|
case "SHULKER":
|
2022-10-10 18:41:25 +02:00
|
|
|
if (Settings.Enabled_Components.KILL_ROAD_MOBS && (Settings.Enabled_Components.KILL_NAMED_ROAD_MOBS || entity.getCustomName() == null)) {
|
2019-02-15 18:50:43 +01:00
|
|
|
LivingEntity livingEntity = (LivingEntity) entity;
|
2019-04-25 03:23:57 +02:00
|
|
|
List<MetadataValue> meta = entity.getMetadata("shulkerPlot");
|
2019-04-23 19:45:24 +02:00
|
|
|
if (!meta.isEmpty()) {
|
2022-10-10 18:41:25 +02:00
|
|
|
if (livingEntity.isLeashed() && !Settings.Enabled_Components.KILL_OWNED_ROAD_MOBS) {
|
2019-02-15 18:50:43 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
List<MetadataValue> keep = entity.getMetadata("keep");
|
2019-04-23 19:45:24 +02:00
|
|
|
if (!keep.isEmpty()) {
|
2019-02-15 18:50:43 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlotId originalPlotId = (PlotId) meta.get(0).value();
|
|
|
|
if (originalPlotId != null) {
|
2020-07-24 17:24:53 +02:00
|
|
|
com.plotsquared.core.location.Location pLoc = BukkitUtil.adapt(entity.getLocation());
|
2019-02-15 18:50:43 +01:00
|
|
|
PlotArea area = pLoc.getPlotArea();
|
|
|
|
if (area != null) {
|
2022-10-15 15:26:14 +02:00
|
|
|
Plot currentPlot = area.getPlotAbs(pLoc);
|
|
|
|
if (currentPlot == null || !originalPlotId.equals(currentPlot.getId())) {
|
2018-12-26 18:21:06 +01:00
|
|
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-02-09 20:51:59 +01:00
|
|
|
this.removeRoadEntity(entity, iterator);
|
2018-12-26 18:21:06 +01:00
|
|
|
}
|
2018-12-21 21:10:37 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-15 18:50:43 +01:00
|
|
|
} else {
|
|
|
|
//This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java)
|
2020-07-24 17:24:53 +02:00
|
|
|
com.plotsquared.core.location.Location pLoc = BukkitUtil.adapt(entity.getLocation());
|
2019-02-15 18:50:43 +01:00
|
|
|
PlotArea area = pLoc.getPlotArea();
|
|
|
|
if (area != null) {
|
2022-10-15 15:26:14 +02:00
|
|
|
Plot currentPlot = area.getPlotAbs(pLoc);
|
|
|
|
if (currentPlot != null) {
|
2021-01-09 22:28:41 +01:00
|
|
|
entity.setMetadata(
|
|
|
|
"shulkerPlot",
|
2022-10-15 15:26:14 +02:00
|
|
|
new FixedMetadataValue((Plugin) PlotSquared.platform(), currentPlot.getId())
|
2021-01-09 22:28:41 +01:00
|
|
|
);
|
2019-02-15 18:50:43 +01:00
|
|
|
}
|
2018-12-21 21:10:37 +01:00
|
|
|
}
|
2019-02-15 18:50:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
2020-06-29 00:45:40 +02:00
|
|
|
case "ZOMBIFIED_PIGLIN":
|
2020-08-11 16:20:33 +02:00
|
|
|
case "PIGLIN_BRUTE":
|
2020-06-29 00:45:40 +02:00
|
|
|
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":
|
2019-02-15 18:50:43 +01:00
|
|
|
default: {
|
|
|
|
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
|
|
|
|
Location location = entity.getLocation();
|
2020-07-17 22:58:10 +02:00
|
|
|
if (BukkitUtil.adapt(location).isPlotRoad()) {
|
2021-05-15 20:39:16 +02:00
|
|
|
if (entity instanceof LivingEntity livingEntity) {
|
2020-12-10 22:14:32 +01:00
|
|
|
if ((Settings.Enabled_Components.KILL_OWNED_ROAD_MOBS || !livingEntity.isLeashed())
|
2021-01-09 22:28:41 +01:00
|
|
|
|| !entity.hasMetadata("keep")) {
|
2019-02-15 18:50:43 +01:00
|
|
|
Entity passenger = entity.getPassenger();
|
2020-12-10 22:14:32 +01:00
|
|
|
if ((Settings.Enabled_Components.KILL_OWNED_ROAD_MOBS
|
2022-10-10 18:41:25 +02:00
|
|
|
|| !((passenger instanceof Player) || livingEntity.isLeashed()))
|
|
|
|
&& (Settings.Enabled_Components.KILL_NAMED_ROAD_MOBS || entity.getCustomName() == null)
|
|
|
|
&& entity.getMetadata("keep").isEmpty()) {
|
2019-02-15 18:50:43 +01:00
|
|
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
|
|
|
continue;
|
2019-02-11 00:03:14 +01:00
|
|
|
}
|
2023-02-09 20:51:59 +01:00
|
|
|
this.removeRoadEntity(entity, iterator);
|
2019-02-11 00:03:14 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-15 18:50:43 +01:00
|
|
|
} else {
|
|
|
|
Entity passenger = entity.getPassenger();
|
2022-10-10 18:41:25 +02:00
|
|
|
if ((Settings.Enabled_Components.KILL_OWNED_ROAD_MOBS || !(passenger instanceof Player))
|
|
|
|
&& (Settings.Enabled_Components.KILL_NAMED_ROAD_MOBS && entity.getCustomName() != null)
|
|
|
|
&& entity.getMetadata("keep").isEmpty()) {
|
2019-02-15 18:50:43 +01:00
|
|
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
|
|
|
continue;
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
2023-02-09 20:51:59 +01:00
|
|
|
this.removeRoadEntity(entity, iterator);
|
2018-12-21 21:10:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-21 21:10:37 +01:00
|
|
|
}
|
2019-02-15 18:50:43 +01:00
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2020-07-15 13:18:09 +02:00
|
|
|
}), TaskTime.seconds(1L));
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 20:51:59 +01:00
|
|
|
private void removeRoadEntity(Entity entity, Iterator<Entity> entityIterator) {
|
|
|
|
RemoveRoadEntityEvent event = eventDispatcher.callRemoveRoadEntity(BukkitAdapter.adapt(entity));
|
|
|
|
|
|
|
|
if (event.getEventResult() == Result.DENY) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
entityIterator.remove();
|
|
|
|
entity.remove();
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
2021-08-18 11:58:18 +02:00
|
|
|
public @Nullable
|
|
|
|
final ChunkGenerator getDefaultWorldGenerator(
|
2021-01-10 00:01:48 +01:00
|
|
|
final @NonNull String worldName,
|
2021-08-18 11:58:18 +02:00
|
|
|
final @Nullable String id
|
|
|
|
) {
|
2018-11-14 15:44:07 +01:00
|
|
|
final IndependentPlotGenerator result;
|
2018-07-21 17:32:38 +02:00
|
|
|
if (id != null && id.equalsIgnoreCase("single")) {
|
2020-12-05 18:41:25 +01:00
|
|
|
result = injector().getInstance(SingleWorldGenerator.class);
|
2018-07-21 17:32:38 +02:00
|
|
|
} else {
|
2020-12-05 18:41:25 +01:00
|
|
|
result = injector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class));
|
2019-02-06 06:03:52 +01:00
|
|
|
if (!PlotSquared.get().setupPlotWorld(worldName, id, result)) {
|
2018-07-21 17:32:38 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2019-02-06 06:03:52 +01:00
|
|
|
return (ChunkGenerator) result.specify(worldName);
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
2021-01-10 00:01:48 +01:00
|
|
|
public @Nullable GeneratorWrapper<?> getGenerator(
|
|
|
|
final @NonNull String world,
|
|
|
|
final @Nullable String name
|
|
|
|
) {
|
2018-07-21 17:32:38 +02:00
|
|
|
if (name == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-08-10 20:46:38 +02:00
|
|
|
final Plugin genPlugin = Bukkit.getPluginManager().getPlugin(name);
|
2018-07-21 17:32:38 +02:00
|
|
|
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);
|
2018-07-21 17:32:38 +02:00
|
|
|
} else {
|
2021-08-18 11:58:18 +02:00
|
|
|
return new BukkitPlotGenerator(
|
|
|
|
world,
|
2021-01-09 22:28:41 +01:00
|
|
|
injector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)),
|
|
|
|
this.plotAreaManager
|
|
|
|
);
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public void startMetrics() {
|
2019-02-22 17:51:06 +01:00
|
|
|
if (this.metricsStarted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.metricsStarted = true;
|
2020-08-17 19:39:43 +02:00
|
|
|
Metrics metrics = new Metrics(this, BSTATS_ID); // bstats
|
2021-01-24 10:39:03 +01:00
|
|
|
metrics.addCustomChart(new DrilldownPie("area_types", () -> {
|
2020-04-11 20:56:34 +02:00
|
|
|
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-07-24 17:24:53 +02:00
|
|
|
final Map<String, Integer> terrainTypeMap = map.get(plotArea.getType().name().toLowerCase());
|
2021-01-09 22:28:41 +01:00
|
|
|
terrainTypeMap.put(
|
|
|
|
plotArea.getTerrain().name().toLowerCase(),
|
|
|
|
terrainTypeMap.get(plotArea.getTerrain().name().toLowerCase()) + 1
|
|
|
|
);
|
2020-04-11 20:56:34 +02:00
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}));
|
2021-01-24 10:39:03 +01:00
|
|
|
metrics.addCustomChart(new SimplePie(
|
2021-01-09 22:28:41 +01:00
|
|
|
"premium",
|
|
|
|
() -> PremiumVerification.isPremium() ? "Premium" : "Non-Premium"
|
|
|
|
));
|
2021-01-24 10:39:03 +01:00
|
|
|
metrics.addCustomChart(new SimplePie("worlds", () -> Settings.Enabled_Components.WORLDS ? "true" : "false"));
|
|
|
|
metrics.addCustomChart(new SimplePie("economy", () -> Settings.Enabled_Components.ECONOMY ? "true" : "false"));
|
|
|
|
metrics.addCustomChart(new SimplePie(
|
2021-01-09 22:28:41 +01:00
|
|
|
"plot_expiry",
|
|
|
|
() -> Settings.Enabled_Components.PLOT_EXPIRY ? "true" : "false"
|
|
|
|
));
|
2021-01-24 10:39:03 +01:00
|
|
|
metrics.addCustomChart(new SimplePie("database_type", () -> Storage.MySQL.USE ? "MySQL" : "SQLite"));
|
|
|
|
metrics.addCustomChart(new SimplePie(
|
2021-01-09 22:28:41 +01:00
|
|
|
"worldedit_implementation",
|
|
|
|
() -> Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null ? "FastAsyncWorldEdit" : "WorldEdit"
|
|
|
|
));
|
2021-02-22 15:18:20 +01:00
|
|
|
metrics.addCustomChart(new SimplePie("offline_mode", () -> Settings.UUID.OFFLINE ? "true" : "false"));
|
|
|
|
metrics.addCustomChart(new SimplePie("offline_mode_force", () -> Settings.UUID.FORCE_LOWERCASE ? "true" : "false"));
|
2019-02-22 17:51:06 +01:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public void unregister(final @NonNull PlotPlayer<?> player) {
|
2020-12-05 18:41:25 +01:00
|
|
|
PlotSquared.platform().playerManager().removePlayer(player.getUUID());
|
2019-02-22 17:51:06 +01:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public void setGenerator(final @NonNull String worldName) {
|
2018-07-21 17:32:38 +02:00
|
|
|
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);
|
2020-12-05 18:41:25 +01:00
|
|
|
String manager = worldConfig.getString("generator.plugin", pluginName());
|
2020-07-24 17:24:53 +02:00
|
|
|
PlotAreaBuilder builder =
|
2021-01-09 22:28:41 +01:00
|
|
|
PlotAreaBuilder.newBuilder().plotManager(manager).generatorName(worldConfig.getString(
|
2021-08-18 11:58:18 +02:00
|
|
|
"generator.init",
|
|
|
|
manager
|
|
|
|
))
|
2021-01-09 22:28:41 +01:00
|
|
|
.plotAreaType(ConfigurationUtil.getType(worldConfig)).terrainType(ConfigurationUtil.getTerrain(
|
2021-08-18 11:58:18 +02:00
|
|
|
worldConfig))
|
2021-01-09 22:28:41 +01:00
|
|
|
.settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null)).worldName(worldName);
|
2020-12-05 18:41:25 +01:00
|
|
|
injector().getInstance(SetupUtils.class).setupWorld(builder);
|
2018-07-21 17:32:38 +02:00
|
|
|
world = Bukkit.getWorld(worldName);
|
|
|
|
} else {
|
|
|
|
try {
|
2020-07-10 17:32:07 +02:00
|
|
|
if (!this.plotAreaManager.hasPlotArea(worldName)) {
|
2018-07-21 17:32:38 +02:00
|
|
|
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
|
|
|
|
}
|
2020-07-05 13:56:54 +02:00
|
|
|
} catch (final Exception e) {
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.error("Failed to reload world: {} | {}", world, e.getMessage());
|
2018-07-21 17:32:38 +02:00
|
|
|
Bukkit.getServer().unloadWorld(world, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 19:45:24 +02:00
|
|
|
assert world != null;
|
2018-07-21 17:32:38 +02:00
|
|
|
ChunkGenerator gen = world.getGenerator();
|
|
|
|
if (gen instanceof BukkitPlotGenerator) {
|
2019-02-04 15:24:17 +01:00
|
|
|
PlotSquared.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
|
2018-07-21 17:32:38 +02:00
|
|
|
} 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)) {
|
2018-11-14 14:19:56 +01:00
|
|
|
PlotSquared.get().loadWorld(worldName, null);
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public @NonNull String serverNativePackage() {
|
2018-08-10 20:46:38 +02:00
|
|
|
final String name = Bukkit.getServer().getClass().getPackage().getName();
|
2018-07-21 17:32:38 +02:00
|
|
|
return name.substring(name.lastIndexOf('.') + 1);
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public @NonNull GeneratorWrapper<?> wrapPlotGenerator(
|
2021-01-10 00:01:48 +01:00
|
|
|
final @NonNull String world,
|
2021-01-09 22:28:41 +01:00
|
|
|
final @NonNull IndependentPlotGenerator generator
|
|
|
|
) {
|
2020-07-10 17:32:07 +02:00
|
|
|
return new BukkitPlotGenerator(world, generator, this.plotAreaManager);
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public @NonNull String pluginsFormatted() {
|
2020-10-04 18:19:29 +02:00
|
|
|
StringBuilder msg = new StringBuilder();
|
2022-01-12 22:21:51 +01:00
|
|
|
List<Plugin> plugins = new ArrayList<>();
|
|
|
|
Collections.addAll(plugins, Bukkit.getServer().getPluginManager().getPlugins());
|
|
|
|
plugins.sort(Comparator.comparing(Plugin::getName));
|
|
|
|
msg.append("Plugins (").append(plugins.size()).append("): \n");
|
2020-10-04 18:19:29 +02:00
|
|
|
for (Plugin p : plugins) {
|
|
|
|
msg.append(" - ").append(p.getName()).append(":").append("\n")
|
2021-01-09 22:28:41 +01:00
|
|
|
.append(" • Version: ").append(p.getDescription().getVersion()).append("\n")
|
|
|
|
.append(" • Enabled: ").append(p.isEnabled()).append("\n")
|
|
|
|
.append(" • Main: ").append(p.getDescription().getMain()).append("\n")
|
|
|
|
.append(" • Authors: ").append(p.getDescription().getAuthors()).append("\n")
|
|
|
|
.append(" • Load Before: ").append(p.getDescription().getLoadBefore()).append("\n")
|
|
|
|
.append(" • Dependencies: ").append(p.getDescription().getDepend()).append("\n")
|
|
|
|
.append(" • Soft Dependencies: ").append(p.getDescription().getSoftDepend()).append("\n");
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
2020-10-04 18:19:29 +02:00
|
|
|
return msg.toString();
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
2019-11-04 22:55:40 +01:00
|
|
|
|
2022-01-12 22:21:51 +01:00
|
|
|
@Override
|
|
|
|
@SuppressWarnings("ConstantConditions")
|
|
|
|
public @NonNull String worldEditImplementations() {
|
|
|
|
StringBuilder msg = new StringBuilder();
|
|
|
|
if (Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null) {
|
2023-03-06 11:38:30 +01:00
|
|
|
msg.append("FastAsyncWorldEdit: ").append(Bukkit
|
|
|
|
.getPluginManager()
|
|
|
|
.getPlugin("FastAsyncWorldEdit")
|
|
|
|
.getDescription()
|
|
|
|
.getVersion());
|
2022-01-12 22:21:51 +01:00
|
|
|
} else if (Bukkit.getPluginManager().getPlugin("AsyncWorldEdit") != null) {
|
2023-03-06 11:38:30 +01:00
|
|
|
msg.append("AsyncWorldEdit: ").append(Bukkit
|
|
|
|
.getPluginManager()
|
|
|
|
.getPlugin("AsyncWorldEdit")
|
|
|
|
.getDescription()
|
|
|
|
.getVersion()).append("\n");
|
2022-01-12 22:21:51 +01:00
|
|
|
msg.append("WorldEdit: ").append(Bukkit.getPluginManager().getPlugin("WorldEdit").getDescription().getVersion());
|
|
|
|
} else {
|
|
|
|
msg.append("WorldEdit: ").append(Bukkit.getPluginManager().getPlugin("WorldEdit").getDescription().getVersion());
|
|
|
|
}
|
|
|
|
return msg.toString();
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public com.plotsquared.core.location.@NonNull World<?> getPlatformWorld(final @NonNull String worldName) {
|
2020-07-10 12:21:29 +02:00
|
|
|
return BukkitWorld.of(worldName);
|
2020-05-27 14:08:48 +02:00
|
|
|
}
|
2020-06-22 15:45:57 +02:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public @NonNull Audience consoleAudience() {
|
2020-10-07 13:20:32 +02:00
|
|
|
return BukkitUtil.BUKKIT_AUDIENCES.console();
|
2020-07-05 18:14:29 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public @NonNull String pluginName() {
|
2020-07-17 17:24:45 +02:00
|
|
|
return this.pluginName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SingleWorldListener getSingleWorldListener() {
|
|
|
|
return this.singleWorldListener;
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public @NonNull Injector injector() {
|
2020-07-17 17:24:45 +02:00
|
|
|
return this.injector;
|
|
|
|
}
|
2020-07-22 21:06:23 +02:00
|
|
|
|
2021-11-02 14:38:48 +01:00
|
|
|
@Override
|
|
|
|
public @NonNull PlotAreaManager plotAreaManager() {
|
|
|
|
return this.plotAreaManager;
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Locale getLocale() {
|
2020-07-22 21:06:23 +02:00
|
|
|
return this.serverLocale;
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public void setLocale(final @NonNull Locale locale) {
|
2020-07-22 21:06:23 +02:00
|
|
|
throw new UnsupportedOperationException("Cannot replace server locale");
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public @NonNull PlatformWorldManager<?> worldManager() {
|
2020-12-05 18:41:25 +01:00
|
|
|
return injector().getInstance(Key.get(new TypeLiteral<PlatformWorldManager<World>>() {
|
2020-07-24 17:24:53 +02:00
|
|
|
}));
|
2020-07-23 14:56:06 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
@NonNull
|
2022-01-20 12:39:40 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2021-01-09 22:28:41 +01:00
|
|
|
public PlayerManager<? extends PlotPlayer<Player>, ? extends Player> playerManager() {
|
2020-12-05 18:41:25 +01:00
|
|
|
return (PlayerManager<BukkitPlayer, Player>) injector().getInstance(PlayerManager.class);
|
2020-07-23 15:03:27 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public void copyCaptionMaps() {
|
2020-08-16 13:49:16 +02:00
|
|
|
/* Make this prettier at some point */
|
2021-01-09 22:28:41 +01:00
|
|
|
final String[] languages = new String[]{"en"};
|
2020-08-16 13:49:16 +02:00
|
|
|
for (final String language : languages) {
|
|
|
|
if (!new File(new File(this.getDataFolder(), "lang"), String.format("messages_%s.json", language)).exists()) {
|
|
|
|
this.saveResource(String.format("lang/messages_%s.json", language), false);
|
2021-06-03 12:40:27 +02:00
|
|
|
LOGGER.info("Copied language file 'messages_{}.json'", language);
|
2020-08-16 13:49:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@NonNull
|
2020-12-28 11:21:35 +01:00
|
|
|
@Override
|
2021-01-10 00:01:48 +01:00
|
|
|
public String toLegacyPlatformString(final @NonNull Component component) {
|
2020-12-28 11:21:35 +01:00
|
|
|
return LegacyComponentSerializer.legacyAmpersand().serialize(component);
|
|
|
|
}
|
|
|
|
|
2021-06-08 19:36:45 +02:00
|
|
|
@Override
|
|
|
|
public boolean isFaweHooking() {
|
|
|
|
return faweHook;
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
}
|