2020-04-16 04:52:39 +02:00
|
|
|
/*
|
|
|
|
* _____ _ _ _____ _
|
|
|
|
* | __ \| | | | / ____| | |
|
|
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
|
|
* | |
|
|
|
|
* |_|
|
|
|
|
* 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-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.bukkit.generator.BukkitHybridUtils;
|
2020-04-11 02:19:18 +02:00
|
|
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
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-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.bukkit.queue.BukkitLocalQueue;
|
|
|
|
import com.plotsquared.bukkit.schematic.BukkitSchematicHandler;
|
2020-04-11 02:19:18 +02:00
|
|
|
import com.plotsquared.bukkit.util.BukkitChatManager;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitEconHandler;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitSetupUtils;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitTaskManager;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
|
|
import com.plotsquared.bukkit.util.SetGenCB;
|
|
|
|
import com.plotsquared.bukkit.util.UpdateUtility;
|
|
|
|
import com.plotsquared.bukkit.util.uuid.DefaultUUIDWrapper;
|
|
|
|
import com.plotsquared.bukkit.util.uuid.FileUUIDHandler;
|
|
|
|
import com.plotsquared.bukkit.util.uuid.LowerOfflineUUIDWrapper;
|
|
|
|
import com.plotsquared.bukkit.util.uuid.OfflineUUIDWrapper;
|
|
|
|
import com.plotsquared.bukkit.util.uuid.SQLUUIDHandler;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.IPlotMain;
|
|
|
|
import com.plotsquared.core.PlotSquared;
|
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-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.generator.GeneratorWrapper;
|
|
|
|
import com.plotsquared.core.generator.HybridGen;
|
|
|
|
import com.plotsquared.core.generator.HybridUtils;
|
|
|
|
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
2020-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.core.generator.SingleWorldGenerator;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.listener.PlotListener;
|
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;
|
|
|
|
import com.plotsquared.core.plot.SetupObject;
|
|
|
|
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-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.core.queue.QueueProvider;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.util.ChatManager;
|
|
|
|
import com.plotsquared.core.util.ChunkManager;
|
|
|
|
import com.plotsquared.core.util.ConsoleColors;
|
|
|
|
import com.plotsquared.core.util.EconHandler;
|
|
|
|
import com.plotsquared.core.util.InventoryUtil;
|
|
|
|
import com.plotsquared.core.util.MainUtil;
|
|
|
|
import com.plotsquared.core.util.PremiumVerification;
|
|
|
|
import com.plotsquared.core.util.ReflectionUtils;
|
|
|
|
import com.plotsquared.core.util.SchematicHandler;
|
|
|
|
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;
|
|
|
|
import com.plotsquared.core.util.uuid.UUIDHandler;
|
|
|
|
import com.plotsquared.core.util.uuid.UUIDHandlerImplementation;
|
|
|
|
import com.plotsquared.core.util.uuid.UUIDWrapper;
|
2016-06-01 22:50:35 +02:00
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
2019-11-04 22:55:40 +01:00
|
|
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
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;
|
2019-11-04 22:55:40 +01:00
|
|
|
import org.bukkit.command.ConsoleCommandSender;
|
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;
|
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
|
|
|
|
2019-02-04 15:02:21 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.lang.reflect.Method;
|
2019-11-25 23:38:03 +01:00
|
|
|
import java.util.AbstractMap;
|
2019-05-11 03:18:28 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
2020-04-11 20:56:34 +02:00
|
|
|
import java.util.HashMap;
|
2019-05-11 03:18:28 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2019-11-25 23:38:03 +01:00
|
|
|
import java.util.Map;
|
2019-05-11 03:18:28 +02:00
|
|
|
import java.util.UUID;
|
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
|
|
|
|
2018-12-19 17:19:54 +01:00
|
|
|
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2018-11-14 15:44:07 +01:00
|
|
|
@Getter private static WorldEdit worldEdit;
|
2018-07-21 17:32:38 +02:00
|
|
|
|
|
|
|
static {
|
|
|
|
try {
|
|
|
|
Settings.load(new File("plugins/PlotSquared/config/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;
|
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;
|
2018-12-21 21:10:37 +01:00
|
|
|
private boolean metricsStarted;
|
2020-01-24 16:08:48 +01:00
|
|
|
private static final int BSTATS_ID = 1404;
|
2018-07-21 17:32:38 +02:00
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public int[] getServerVersion() {
|
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();
|
2018-11-14 14:19:56 +01:00
|
|
|
PlotSquared.debug(StringMan.getString(Bukkit.getBukkitVersion()));
|
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};
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.version;
|
|
|
|
}
|
|
|
|
|
2019-01-09 23:12:36 +01:00
|
|
|
@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();
|
2018-12-19 17:19:54 +01:00
|
|
|
PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer);
|
2018-12-26 15:29:39 +01:00
|
|
|
|
2018-11-14 14:19:56 +01:00
|
|
|
new PlotSquared(this, "Bukkit");
|
2019-03-18 19:49:22 +01:00
|
|
|
|
2019-05-13 21:56:28 +02:00
|
|
|
if (PlotSquared.get().IMP.getServerVersion()[1] < 13) {
|
|
|
|
System.out.println(
|
|
|
|
"You can't use this version of PlotSquared on a server less than Minecraft 1.13.2.");
|
|
|
|
System.out
|
|
|
|
.println("Please check the download page for the link to the legacy versions.");
|
2019-05-17 20:38:57 +02:00
|
|
|
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-04-21 13:22:42 +02:00
|
|
|
if (PremiumVerification.isPremium() && Settings.Enabled_Components.UPDATE_NOTIFICATIONS) {
|
2020-04-21 09:56:23 +02:00
|
|
|
new UpdateUtility(this).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-02-16 20:33:24 +01:00
|
|
|
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
2020-04-23 10:06:37 +02:00
|
|
|
new Placeholders().register();
|
2020-02-20 16:03:17 +01:00
|
|
|
if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) {
|
|
|
|
ChatFormatter.formatters.add(new PlaceholderFormatter());
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2019-05-11 03:18:28 +02:00
|
|
|
this.startMetrics();
|
2018-07-21 17:32:38 +02:00
|
|
|
if (Settings.Enabled_Components.WORLDS) {
|
2018-12-21 21:10:37 +01:00
|
|
|
TaskManager.IMP.taskRepeat(this::unload, 20);
|
2018-07-21 17:32:38 +02:00
|
|
|
try {
|
|
|
|
singleWorldListener = new SingleWorldListener(this);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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");
|
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);
|
2019-01-16 04:19:29 +01:00
|
|
|
} catch (Throwable event) {
|
|
|
|
event.printStackTrace();
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-14 14:19:56 +01:00
|
|
|
final PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
|
2018-07-21 17:32:38 +02:00
|
|
|
if (manager instanceof SinglePlotAreaManager) {
|
|
|
|
long start = System.currentTimeMillis();
|
2018-08-10 20:46:38 +02:00
|
|
|
final SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
|
|
|
|
|
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) {
|
2019-03-30 13:27:18 +01:00
|
|
|
if (!MainUtil.isServerOwned(plot) || PlotPlayer.wrap(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)) {
|
|
|
|
PlotSquared.debug("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 {
|
|
|
|
result = (boolean) methodUnloadChunk0
|
|
|
|
.invoke(world, chunkI.getX(), chunkI.getZ(), true);
|
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02: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);
|
|
|
|
}
|
|
|
|
|
2018-08-10 20:46:38 +02:00
|
|
|
@Override public void log(@NonNull String message) {
|
2018-07-21 17:32:38 +02:00
|
|
|
try {
|
2019-02-22 17:51:06 +01:00
|
|
|
message = Captions.color(message);
|
2018-07-21 17:32:38 +02:00
|
|
|
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) {
|
2018-07-21 17:32:38 +02:00
|
|
|
System.out.println(ConsoleColors.fromString(message));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-23 19:43:36 +01:00
|
|
|
@Override public void shutdown() {
|
|
|
|
this.getServer().getPluginManager().disablePlugin(this);
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public int[] getPluginVersion() {
|
2018-07-21 17:32:38 +02:00
|
|
|
String ver = getDescription().getVersion();
|
|
|
|
if (ver.contains("-")) {
|
|
|
|
ver = ver.split("-")[0];
|
|
|
|
}
|
|
|
|
String[] split = ver.split("\\.");
|
2018-08-10 17:01:10 +02:00
|
|
|
return new int[] {Integer.parseInt(split[0]), Integer.parseInt(split[1]),
|
|
|
|
Integer.parseInt(split[2])};
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override public String getPluginVersionString() {
|
|
|
|
return getDescription().getVersion();
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public 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
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public File getDirectory() {
|
2018-07-21 17:32:38 +02:00
|
|
|
return getDataFolder();
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public File getWorldContainer() {
|
2018-07-21 17:32:38 +02:00
|
|
|
return Bukkit.getWorldContainer();
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public TaskManager getTaskManager() {
|
2018-07-21 17:32:38 +02:00
|
|
|
return new BukkitTaskManager(this);
|
|
|
|
}
|
|
|
|
|
2018-08-10 20:46:38 +02:00
|
|
|
@Override @SuppressWarnings("deprecation") public void runEntityTask() {
|
2019-02-22 17:51:06 +01:00
|
|
|
PlotSquared.log(Captions.PREFIX + "KillAllEntities started.");
|
2019-02-15 18:50:43 +01:00
|
|
|
TaskManager.runTaskRepeat(() -> PlotSquared.get().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();
|
|
|
|
switch (entity.getType()) {
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
case ITEM_FRAME:
|
|
|
|
case PAINTING:
|
|
|
|
// Not vehicles
|
|
|
|
continue;
|
|
|
|
case ARMOR_STAND:
|
|
|
|
// Temporarily classify as vehicle
|
|
|
|
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());
|
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;
|
|
|
|
}
|
|
|
|
iterator.remove();
|
|
|
|
entity.remove();
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
iterator.remove();
|
|
|
|
entity.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
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;
|
|
|
|
case PRIMED_TNT:
|
|
|
|
case FALLING_BLOCK:
|
|
|
|
// managed elsewhere
|
|
|
|
continue;
|
|
|
|
case SHULKER:
|
|
|
|
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
|
|
|
|
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()) {
|
2019-02-15 18:50:43 +01:00
|
|
|
if (livingEntity.isLeashed()) {
|
|
|
|
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-04-30 12:01:52 +02:00
|
|
|
com.plotsquared.core.location.Location pLoc =
|
|
|
|
BukkitUtil.getLocation(entity.getLocation());
|
2019-02-15 18:50:43 +01:00
|
|
|
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)))) {
|
2018-12-26 18:21:06 +01:00
|
|
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
iterator.remove();
|
|
|
|
entity.remove();
|
|
|
|
}
|
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-04-30 12:01:52 +02:00
|
|
|
com.plotsquared.core.location.Location pLoc =
|
|
|
|
BukkitUtil.getLocation(entity.getLocation());
|
2019-02-15 18:50:43 +01:00
|
|
|
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.get().IMP, currentPlotId));
|
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;
|
|
|
|
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:
|
2019-12-09 20:43:53 +01:00
|
|
|
case CAT:
|
|
|
|
case PANDA:
|
|
|
|
case FOX:
|
|
|
|
case PILLAGER:
|
|
|
|
case TRADER_LLAMA:
|
|
|
|
case WANDERING_TRADER:
|
|
|
|
case RAVAGER:
|
|
|
|
//case BEE:
|
2019-02-15 18:50:43 +01:00
|
|
|
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;
|
2019-02-15 18:50:43 +01:00
|
|
|
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
|
|
|
}
|
2019-02-15 18:50:43 +01:00
|
|
|
iterator.remove();
|
|
|
|
entity.remove();
|
|
|
|
continue;
|
2019-02-11 00:03:14 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-15 18:50:43 +01:00
|
|
|
} else {
|
|
|
|
Entity passenger = entity.getPassenger();
|
|
|
|
if (!(passenger instanceof Player) && entity
|
|
|
|
.getMetadata("keep").isEmpty()) {
|
|
|
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
|
|
|
continue;
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
2019-02-15 18:50:43 +01:00
|
|
|
iterator.remove();
|
|
|
|
entity.remove();
|
|
|
|
continue;
|
2018-12-21 21:10:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
2019-02-15 18:50:43 +01:00
|
|
|
continue;
|
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();
|
|
|
|
}
|
|
|
|
}), 20);
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
|
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) {
|
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")) {
|
|
|
|
result = new SingleWorldGenerator();
|
|
|
|
} else {
|
2018-11-14 14:19:56 +01:00
|
|
|
result = PlotSquared.get().IMP.getDefaultGenerator();
|
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
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public void registerPlayerEvents() {
|
2018-08-10 20:46:38 +02:00
|
|
|
final PlayerEvents main = new PlayerEvents();
|
2018-07-21 17:32:38 +02:00
|
|
|
getServer().getPluginManager().registerEvents(main, this);
|
2019-02-08 20:49:37 +01:00
|
|
|
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
|
2020-04-30 18:23:18 +02:00
|
|
|
if (PaperLib.isPaper() && Settings.Paper_Components.ENTITY_PATHING
|
|
|
|
|| Settings.Paper_Components.PRE_SPAWN_LISTENER) {
|
|
|
|
getServer().getPluginManager().registerEvents(new PaperListener(), this);
|
|
|
|
}
|
2020-04-08 17:22:53 +02:00
|
|
|
PlotListener.startRunnable();
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public void registerForceFieldEvents() {
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public boolean initWorldEdit() {
|
2018-07-21 17:32:38 +02:00
|
|
|
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
|
|
|
|
worldEdit = WorldEdit.getInstance();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public EconHandler getEconomyHandler() {
|
2018-07-21 17:32:38 +02:00
|
|
|
try {
|
|
|
|
BukkitEconHandler econ = new BukkitEconHandler();
|
|
|
|
if (econ.init()) {
|
|
|
|
return econ;
|
|
|
|
}
|
|
|
|
} catch (Throwable ignored) {
|
2018-11-14 14:19:56 +01:00
|
|
|
PlotSquared.debug("No economy detected!");
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public QueueProvider initBlockQueue() {
|
2019-09-08 20:02:45 +02:00
|
|
|
//TODO Figure out why this code is still here yet isn't being called anywhere.
|
|
|
|
// try {
|
|
|
|
// new SendChunk();
|
|
|
|
// MainUtil.canSendChunk = true;
|
|
|
|
// } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) {
|
|
|
|
// PlotSquared.debug(
|
|
|
|
// SendChunk.class + " does not support " + StringMan.getString(getServerVersion()));
|
|
|
|
// MainUtil.canSendChunk = false;
|
|
|
|
// }
|
2018-12-17 20:57:21 +01:00
|
|
|
return QueueProvider.of(BukkitLocalQueue.class, BukkitLocalQueue.class);
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public WorldUtil initWorldUtil() {
|
2018-07-21 17:32:38 +02:00
|
|
|
return new BukkitUtil();
|
|
|
|
}
|
|
|
|
|
2020-04-30 12:01:52 +02:00
|
|
|
@Override @Nullable
|
|
|
|
public GeneratorWrapper<?> getGenerator(@NonNull final String world,
|
2018-11-14 15:44:07 +01:00
|
|
|
@Nullable final 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;
|
|
|
|
}
|
|
|
|
return new BukkitPlotGenerator(world, gen);
|
|
|
|
} else {
|
2020-02-24 14:00:45 +01:00
|
|
|
return new BukkitPlotGenerator(world, PlotSquared.get().IMP.getDefaultGenerator());
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public HybridUtils initHybridUtils() {
|
2018-07-21 17:32:38 +02:00
|
|
|
return new BukkitHybridUtils();
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public SetupUtils initSetupUtils() {
|
2018-07-21 17:32:38 +02:00
|
|
|
return new BukkitSetupUtils();
|
|
|
|
}
|
|
|
|
|
2019-02-22 17:51:06 +01:00
|
|
|
@Override public void startMetrics() {
|
|
|
|
if (this.metricsStarted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.metricsStarted = true;
|
2020-01-24 16:08:48 +01:00
|
|
|
Metrics metrics = new Metrics(this, BSTATS_ID);// bstats
|
2020-04-11 20:56:34 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
for (final PlotArea plotArea : PlotSquared.get().getPlotAreas()) {
|
2020-04-30 12:01:52 +02:00
|
|
|
final Map<String, Integer> terrainTypeMap =
|
|
|
|
map.get(plotArea.getType().name().toLowerCase());
|
2020-04-11 20:56:34 +02:00
|
|
|
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"));
|
2019-02-22 17:51:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override public ChunkManager initChunkManager() {
|
|
|
|
return new BukkitChunkManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override public void unregister(@NonNull final PlotPlayer player) {
|
|
|
|
BukkitUtil.removePlayer(player.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override public void registerChunkProcessor() {
|
|
|
|
getServer().getPluginManager().registerEvents(new ChunkListener(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override public void registerWorldEvents() {
|
|
|
|
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
|
|
|
|
}
|
|
|
|
|
2019-05-17 22:21:03 +02:00
|
|
|
@NotNull @Override public IndependentPlotGenerator getDefaultGenerator() {
|
2019-02-22 17:51:06 +01:00
|
|
|
return new HybridGen();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override public InventoryUtil initInventoryUtil() {
|
|
|
|
return new BukkitInventoryUtil();
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public UUIDHandlerImplementation initUUIDHandler() {
|
2018-08-10 20:46:38 +02:00
|
|
|
final UUIDWrapper wrapper;
|
2018-07-21 17:32:38 +02:00
|
|
|
if (Settings.UUID.OFFLINE) {
|
|
|
|
if (Settings.UUID.FORCE_LOWERCASE) {
|
|
|
|
wrapper = new LowerOfflineUUIDWrapper();
|
|
|
|
} else {
|
|
|
|
wrapper = new OfflineUUIDWrapper();
|
|
|
|
}
|
|
|
|
Settings.UUID.OFFLINE = true;
|
2019-05-11 04:42:07 +02:00
|
|
|
} else {
|
2018-07-21 17:32:38 +02:00
|
|
|
wrapper = new DefaultUUIDWrapper();
|
|
|
|
Settings.UUID.OFFLINE = false;
|
|
|
|
}
|
2019-05-14 00:20:58 +02:00
|
|
|
if (!Bukkit.getVersion().contains("git-Spigot")) {
|
2018-08-10 17:01:10 +02:00
|
|
|
if (wrapper instanceof DefaultUUIDWrapper
|
|
|
|
|| wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
|
2018-07-21 17:32:38 +02:00
|
|
|
Settings.UUID.NATIVE_UUID_PROVIDER = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Settings.UUID.OFFLINE) {
|
2019-11-04 00:46:08 +01:00
|
|
|
PlotSquared.log(Captions.PREFIX + "&6" + getPluginName()
|
2018-08-10 17:01:10 +02:00
|
|
|
+ " is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
|
|
|
|
+ "Bukkit");
|
2018-07-21 17:32:38 +02:00
|
|
|
} else {
|
2019-11-04 00:46:08 +01:00
|
|
|
PlotSquared.log(Captions.PREFIX + "&6" + getPluginName() + " is using online UUIDs");
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
if (Settings.UUID.USE_SQLUUIDHANDLER) {
|
|
|
|
return new SQLUUIDHandler(wrapper);
|
|
|
|
} else {
|
|
|
|
return new FileUUIDHandler(wrapper);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 20:46:38 +02:00
|
|
|
@Override public void setGenerator(@NonNull final String worldName) {
|
2018-07-21 17:32:38 +02:00
|
|
|
World world = BukkitUtil.getWorld(worldName);
|
|
|
|
if (world == null) {
|
|
|
|
// create world
|
2018-08-10 17:01:10 +02:00
|
|
|
ConfigurationSection worldConfig =
|
2018-11-14 14:19:56 +01:00
|
|
|
PlotSquared.get().worlds.getConfigurationSection("worlds." + worldName);
|
2018-07-21 17:32:38 +02:00
|
|
|
String manager = worldConfig.getString("generator.plugin", getPluginName());
|
|
|
|
SetupObject setup = new SetupObject();
|
|
|
|
setup.plotManager = manager;
|
|
|
|
setup.setupGenerator = worldConfig.getString("generator.init", manager);
|
2020-04-02 14:34:38 +02:00
|
|
|
setup.type = MainUtil.getType(worldConfig);
|
|
|
|
setup.terrain = MainUtil.getTerrain(worldConfig);
|
2018-07-21 17:32:38 +02:00
|
|
|
setup.step = new ConfigurationNode[0];
|
|
|
|
setup.world = worldName;
|
|
|
|
SetupUtils.manager.setupWorld(setup);
|
|
|
|
world = Bukkit.getWorld(worldName);
|
|
|
|
} else {
|
|
|
|
try {
|
2018-11-14 14:19:56 +01:00
|
|
|
if (!PlotSquared.get().hasPlotArea(worldName)) {
|
2018-07-21 17:32:38 +02:00
|
|
|
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
|
|
|
|
}
|
2018-12-21 21:10:37 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
PlotSquared.log("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) {
|
2018-11-14 14:19:56 +01:00
|
|
|
PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen));
|
|
|
|
} else if (PlotSquared.get().worlds.contains("worlds." + worldName)) {
|
|
|
|
PlotSquared.get().loadWorld(worldName, null);
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public SchematicHandler initSchematicHandler() {
|
2018-07-21 17:32:38 +02:00
|
|
|
return new BukkitSchematicHandler();
|
|
|
|
}
|
|
|
|
|
2018-08-10 20:46:38 +02:00
|
|
|
@Override @Nullable public PlotPlayer wrapPlayer(final Object player) {
|
2018-07-21 17:32:38 +02:00
|
|
|
if (player instanceof Player) {
|
|
|
|
return BukkitUtil.getPlayer((Player) player);
|
|
|
|
}
|
|
|
|
if (player instanceof OfflinePlayer) {
|
|
|
|
return BukkitUtil.getPlayer((OfflinePlayer) player);
|
|
|
|
}
|
|
|
|
if (player instanceof String) {
|
|
|
|
return UUIDHandler.getPlayer((String) player);
|
|
|
|
}
|
|
|
|
if (player instanceof UUID) {
|
|
|
|
return UUIDHandler.getPlayer((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();
|
2018-07-21 17:32:38 +02:00
|
|
|
return name.substring(name.lastIndexOf('.') + 1);
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public ChatManager<?> initChatManager() {
|
2018-07-21 17:32:38 +02:00
|
|
|
if (Settings.Chat.INTERACTIVE) {
|
|
|
|
return new BukkitChatManager();
|
|
|
|
} else {
|
|
|
|
return new PlainChatManager();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-30 12:01:52 +02:00
|
|
|
@Override
|
|
|
|
public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world,
|
2018-11-14 15:44:07 +01:00
|
|
|
@NonNull final IndependentPlotGenerator generator) {
|
2020-02-24 14:00:45 +01:00
|
|
|
return new BukkitPlotGenerator(world, generator);
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
|
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()));
|
2018-07-21 17:32:38 +02:00
|
|
|
}
|
|
|
|
return names;
|
|
|
|
}
|
2019-11-04 22:55:40 +01:00
|
|
|
|
|
|
|
@Override public Actor getConsole() {
|
|
|
|
@NotNull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
2020-04-30 12:01:52 +02:00
|
|
|
WorldEditPlugin wePlugin =
|
|
|
|
((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
|
2019-11-04 22:55:40 +01:00
|
|
|
return wePlugin.wrapCommandSender(console);
|
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
}
|