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

663 lines
26 KiB
Java
Raw Normal View History

2015-07-26 16:51:12 +02:00
package com.plotsquared.bukkit;
2015-07-05 17:44:10 +02:00
2015-08-09 11:58:29 +02:00
import com.intellectualcrafters.configuration.ConfigurationSection;
2015-07-26 16:51:12 +02:00
import com.intellectualcrafters.plot.IPlotMain;
import com.intellectualcrafters.plot.PS;
2015-02-21 05:27:01 +01:00
import com.intellectualcrafters.plot.config.C;
2015-08-09 11:58:29 +02:00
import com.intellectualcrafters.plot.config.ConfigurationNode;
2015-02-21 05:27:01 +01:00
import com.intellectualcrafters.plot.config.Settings;
2015-07-27 19:50:04 +02:00
import com.intellectualcrafters.plot.flag.FlagManager;
2016-02-10 19:59:51 +01:00
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridGen;
2015-07-27 19:50:04 +02:00
import com.intellectualcrafters.plot.generator.HybridUtils;
2016-02-10 19:59:51 +01:00
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ConsoleColors;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlotQueue;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.util.WorldUtil;
2015-07-27 19:50:04 +02:00
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector;
import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter;
import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017;
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
import com.plotsquared.bukkit.listeners.ChunkListener;
import com.plotsquared.bukkit.listeners.ForceFieldListener;
import com.plotsquared.bukkit.listeners.PlayerEvents;
2016-03-23 02:41:37 +01:00
import com.plotsquared.bukkit.listeners.PlayerEvents183;
import com.plotsquared.bukkit.listeners.PlayerEvents_1_8;
import com.plotsquared.bukkit.listeners.PlayerEvents_1_9;
import com.plotsquared.bukkit.listeners.PlotPlusListener;
import com.plotsquared.bukkit.listeners.WorldEvents;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.listeners.worldedit.WEListener;
2016-03-02 23:08:43 +01:00
import com.plotsquared.bukkit.titles.DefaultTitle_19;
import com.plotsquared.bukkit.util.BukkitChatManager;
import com.plotsquared.bukkit.util.BukkitChunkManager;
import com.plotsquared.bukkit.util.BukkitCommand;
import com.plotsquared.bukkit.util.BukkitEconHandler;
import com.plotsquared.bukkit.util.BukkitEventUtil;
import com.plotsquared.bukkit.util.BukkitHybridUtils;
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
import com.plotsquared.bukkit.util.BukkitPlainChatManager;
import com.plotsquared.bukkit.util.BukkitSchematicHandler;
import com.plotsquared.bukkit.util.BukkitSetupUtils;
import com.plotsquared.bukkit.util.BukkitTaskManager;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.Metrics;
import com.plotsquared.bukkit.util.SendChunk;
import com.plotsquared.bukkit.util.SetGenCB;
import com.plotsquared.bukkit.util.block.FastQueue_1_7;
import com.plotsquared.bukkit.util.block.FastQueue_1_8;
import com.plotsquared.bukkit.util.block.FastQueue_1_8_3;
import com.plotsquared.bukkit.util.block.FastQueue_1_9;
import com.plotsquared.bukkit.util.block.SlowQueue;
import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
import com.plotsquared.bukkit.uuid.FileUUIDHandler;
import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
import com.plotsquared.bukkit.uuid.SQLUUIDHandler;
2015-02-21 05:27:01 +01:00
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
2016-03-23 02:41:37 +01:00
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
2015-09-13 06:04:31 +02:00
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
2016-03-20 23:19:37 +01:00
2015-08-02 21:25:41 +02:00
public static WorldEditPlugin worldEdit;
2016-03-20 23:19:37 +01:00
2015-09-11 12:09:22 +02:00
private int[] version;
2016-03-20 23:19:37 +01:00
@Override
2015-09-13 06:04:31 +02:00
public int[] getServerVersion() {
2016-03-23 02:41:37 +01:00
if (this.version == null) {
2015-09-13 06:04:31 +02:00
try {
2016-03-23 02:41:37 +01:00
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]);
2015-09-13 06:04:31 +02:00
if (split.length == 3) {
2016-03-23 02:41:37 +01:00
this.version[2] = Integer.parseInt(split[2]);
}
} catch (NumberFormatException e) {
2015-07-17 05:48:23 +02:00
e.printStackTrace();
2015-08-03 20:20:04 +02:00
PS.debug(StringMan.getString(Bukkit.getBukkitVersion()));
PS.debug(StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\.")));
return new int[]{Integer.MAX_VALUE, 0, 0};
2015-02-20 11:53:18 +01:00
}
}
2016-03-23 02:41:37 +01:00
return this.version;
2015-02-20 11:53:18 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public void onEnable() {
new PS(this, "Bukkit");
2015-02-19 07:08:15 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public void onDisable() {
PS.get().disable();
Bukkit.getScheduler().cancelTasks(this);
2015-02-19 07:08:15 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public void log(String message) {
try {
message = C.color(message);
if (!Settings.CONSOLE_COLOR) {
message = ChatColor.stripColor(message);
2016-03-23 02:41:37 +01:00
}
this.getServer().getConsoleSender().sendMessage(message);
return;
} catch (Throwable ignored) {
//ignored
2015-02-19 09:51:10 +01:00
}
System.out.println(ConsoleColors.fromString(message));
2015-02-19 07:08:15 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public void disable() {
onDisable();
2015-02-19 07:08:15 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
public int[] getPluginVersion() {
String ver = getDescription().getVersion();
if (ver.contains("-SNAPSHOT")) {
ver = ver.split("-SNAPSHOT")[0];
2016-03-29 05:23:56 +02:00
}
String[] split = ver.split("\\.");
2016-03-23 02:41:37 +01:00
return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])};
2015-02-19 07:08:15 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public void registerCommands() {
2016-03-29 21:47:59 +02:00
BukkitCommand bukkitCommand = new BukkitCommand();
2016-03-23 02:41:37 +01:00
PluginCommand plotCommand = getCommand("plots");
2016-03-29 21:47:59 +02:00
plotCommand.setExecutor(bukkitCommand);
2015-02-19 07:08:15 +01:00
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
2016-03-29 21:47:59 +02:00
plotCommand.setTabCompleter(bukkitCommand);
2015-02-19 07:08:15 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public File getDirectory() {
2015-02-19 07:08:15 +01:00
return getDataFolder();
}
2016-03-20 23:19:37 +01:00
@Override
public File getWorldContainer() {
return Bukkit.getWorldContainer();
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public TaskManager getTaskManager() {
return new BukkitTaskManager(this);
2015-02-19 07:08:15 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public void runEntityTask() {
2016-03-20 23:19:37 +01:00
log(C.PREFIX + "KillAllEntities started.");
2015-09-13 06:04:31 +02:00
TaskManager.runTaskRepeat(new Runnable() {
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public void run() {
2016-02-10 19:59:51 +01:00
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
@Override
public void run(PlotArea pw) {
World world = Bukkit.getWorld(pw.worldname);
try {
if (world == null) {
return;
}
List<Entity> entities = world.getEntities();
2016-03-23 02:41:37 +01:00
Iterator<Entity> iterator = entities.iterator();
while (iterator.hasNext()) {
Entity entity = iterator.next();
2016-02-10 19:59:51 +01:00
switch (entity.getType()) {
case EGG:
case ENDER_CRYSTAL:
case COMPLEX_PART:
case FISHING_HOOK:
case ENDER_SIGNAL:
2016-03-23 02:41:37 +01:00
case AREA_EFFECT_CLOUD:
2016-02-10 19:59:51 +01:00
case EXPERIENCE_ORB:
case LEASH_HITCH:
case FIREWORK:
case WEATHER:
case LIGHTNING:
case WITHER_SKULL:
case UNKNOWN:
case PLAYER:
2016-03-29 21:47:59 +02:00
// non moving / unmovable
2015-08-04 14:21:12 +02:00
continue;
2016-02-10 19:59:51 +01:00
case THROWN_EXP_BOTTLE:
case SPLASH_POTION:
case SNOWBALL:
2016-03-23 02:41:37 +01:00
case SHULKER_BULLET:
case SPECTRAL_ARROW:
case TIPPED_ARROW:
2016-02-10 19:59:51 +01:00
case ENDER_PEARL:
case ARROW:
2016-02-10 19:59:51 +01:00
// managed elsewhere | projectile
continue;
case ARMOR_STAND:
case ITEM_FRAME:
case PAINTING:
// TEMPORARILY CLASSIFY AS VEHICLE
2016-02-10 19:59:51 +01:00
case MINECART:
case MINECART_CHEST:
case MINECART_COMMAND:
case MINECART_FURNACE:
case MINECART_HOPPER:
case MINECART_MOB_SPAWNER:
case MINECART_TNT:
case BOAT: {
if (!Settings.KILL_ROAD_VEHICLES) {
continue;
}
2016-03-23 02:41:37 +01:00
com.intellectualcrafters.plot.object.Location location = BukkitUtil.getLocation(entity.getLocation());
Plot plot = location.getPlot();
2016-02-10 19:59:51 +01:00
if (plot == null) {
2016-03-23 02:41:37 +01:00
if (location.isPlotArea()) {
iterator.remove();
2016-02-10 19:59:51 +01:00
entity.remove();
}
continue;
}
List<MetadataValue> meta = entity.getMetadata("plot");
if (meta.isEmpty()) {
2016-02-10 19:59:51 +01:00
continue;
}
Plot origin = (Plot) meta.get(0).value();
if (!plot.equals(origin.getBasePlot(false))) {
2016-03-23 02:41:37 +01:00
iterator.remove();
2015-10-29 13:13:10 +01:00
entity.remove();
}
continue;
2015-10-29 13:13:10 +01:00
}
2016-02-10 19:59:51 +01:00
case SMALL_FIREBALL:
case FIREBALL:
2016-03-23 02:41:37 +01:00
case DRAGON_FIREBALL:
case DROPPED_ITEM:
2016-02-10 19:59:51 +01:00
// dropped item
continue;
2016-02-10 19:59:51 +01:00
case PRIMED_TNT:
case FALLING_BLOCK:
2016-02-10 19:59:51 +01:00
// managed elsewhere
2015-08-04 14:21:12 +02:00
continue;
2016-02-10 19:59:51 +01:00
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:
2016-03-23 02:41:37 +01:00
case SHULKER:
default:
2016-02-10 19:59:51 +01:00
if (!Settings.KILL_ROAD_MOBS) {
continue;
}
2016-03-23 02:41:37 +01:00
Location location = entity.getLocation();
if (BukkitUtil.getLocation(location).isPlotRoad()) {
Entity passenger = entity.getPassenger();
2016-03-19 19:07:55 +01:00
if (!(passenger instanceof Player) && entity.getMetadata("keep").isEmpty()) {
2016-03-23 02:41:37 +01:00
iterator.remove();
2016-03-19 19:07:55 +01:00
entity.remove();
2015-10-07 08:33:33 +02:00
}
2015-08-08 19:27:18 +02:00
}
2015-02-19 07:08:15 +01:00
}
}
2016-03-23 02:41:37 +01:00
} catch (Throwable e) {
2016-02-10 19:59:51 +01:00
e.printStackTrace();
2015-02-19 07:08:15 +01:00
}
}
2016-02-10 19:59:51 +01:00
});
2015-02-19 07:08:15 +01:00
}
}, 20);
}
2016-03-20 23:19:37 +01:00
2015-02-19 09:51:10 +01:00
@Override
2016-03-23 18:09:13 +01:00
public final ChunkGenerator getDefaultWorldGenerator(String world, String id) {
2016-03-23 02:41:37 +01:00
HybridGen result = new HybridGen();
2016-02-10 19:59:51 +01:00
if (!PS.get().setupPlotWorld(world, id, result)) {
2015-09-13 06:04:31 +02:00
return null;
}
return (ChunkGenerator) result.specify();
2015-02-19 09:51:10 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public void registerPlayerEvents() {
PlayerEvents main = new PlayerEvents();
getServer().getPluginManager().registerEvents(main, this);
2015-09-13 06:04:31 +02:00
if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) {
2015-02-19 07:08:15 +01:00
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this);
}
2015-09-13 06:04:31 +02:00
if (PS.get().checkVersion(getServerVersion(), 1, 8, 3)) {
2016-03-23 02:41:37 +01:00
getServer().getPluginManager().registerEvents(new PlayerEvents183(), this);
}
if (PS.get().checkVersion(getServerVersion(), 1, 9, 0)) {
getServer().getPluginManager().registerEvents(new PlayerEvents_1_9(main), this);
}
2015-02-19 07:08:15 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public void registerInventoryEvents() {
2015-07-28 08:06:19 +02:00
// Part of PlayerEvents - can be moved if necessary
2015-02-19 07:08:15 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public void registerPlotPlusEvents() {
2015-02-19 07:08:15 +01:00
PlotPlusListener.startRunnable(this);
getServer().getPluginManager().registerEvents(new PlotPlusListener(), this);
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public void registerForceFieldEvents() {
2015-02-19 07:08:15 +01:00
getServer().getPluginManager().registerEvents(new ForceFieldListener(), this);
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public boolean initWorldEdit() {
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
2016-03-23 02:41:37 +01:00
getServer().getPluginManager().registerEvents(new WEListener(), this);
return true;
2015-02-19 07:08:15 +01:00
}
return false;
2015-02-19 07:08:15 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 07:08:15 +01:00
@Override
2015-09-13 06:04:31 +02:00
public EconHandler getEconomyHandler() {
try {
2016-03-23 02:41:37 +01:00
BukkitEconHandler econ = new BukkitEconHandler();
2015-09-13 06:04:31 +02:00
if (econ.init()) {
return econ;
}
2016-03-23 02:41:37 +01:00
} catch (Throwable ignored) {
2016-03-29 08:39:29 +02:00
PS.debug("No economy detected!");
}
2015-02-19 07:08:15 +01:00
return null;
}
2016-03-20 23:19:37 +01:00
2015-02-19 09:51:10 +01:00
@Override
public PlotQueue<Chunk> initPlotQueue() {
2016-02-10 19:59:51 +01:00
try {
new SendChunk();
MainUtil.canSendChunk = true;
2016-03-23 02:41:37 +01:00
} catch (Throwable e) {
2016-02-10 19:59:51 +01:00
e.printStackTrace();
MainUtil.canSendChunk = false;
}
2016-03-02 22:51:01 +01:00
if (PS.get().checkVersion(getServerVersion(), 1, 9, 0)) {
try {
return new FastQueue_1_9();
2016-03-23 02:41:37 +01:00
} catch (Throwable e) {
2016-03-02 22:51:01 +01:00
e.printStackTrace();
return new SlowQueue();
}
}
2015-09-13 06:04:31 +02:00
if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) {
try {
2016-02-10 19:59:51 +01:00
return new FastQueue_1_8_3();
} catch (Throwable e) {
2015-08-25 02:51:33 +02:00
e.printStackTrace();
2016-02-10 19:59:51 +01:00
try {
return new FastQueue_1_8();
} catch (Throwable e2) {
2016-02-10 19:59:51 +01:00
e2.printStackTrace();
return new SlowQueue();
}
2015-02-19 09:51:10 +01:00
}
}
2016-02-10 19:59:51 +01:00
try {
return new FastQueue_1_7();
} catch (Throwable e) {
e.printStackTrace();
2016-02-10 19:59:51 +01:00
return new SlowQueue();
}
}
2016-03-20 23:19:37 +01:00
2016-02-10 19:59:51 +01:00
@Override
public WorldUtil initWorldUtil() {
return new BukkitUtil();
2015-02-19 09:51:10 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 09:51:10 +01:00
@Override
2015-09-13 06:04:31 +02:00
public boolean initPlotMeConverter() {
TaskManager.runTaskLaterAsync(new Runnable() {
2015-05-01 13:00:17 +02:00
@Override
2015-09-13 06:04:31 +02:00
public void run() {
if (new LikePlotMeConverter().run(new ClassicPlotMeConnector())) {
2015-09-11 12:09:22 +02:00
return;
}
if (new LikePlotMeConverter().run(new PlotMeConnector_017())) {
2015-09-11 12:09:22 +02:00
return;
}
2015-05-01 13:00:17 +02:00
}
}, 20);
return Bukkit.getPluginManager().getPlugin("PlotMe") != null;
2015-02-19 09:51:10 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-19 09:51:10 +01:00
@Override
2016-03-23 02:41:37 +01:00
public GeneratorWrapper<?> getGenerator(String world, String name) {
2015-09-13 06:04:31 +02:00
if (name == null) {
2016-02-10 19:59:51 +01:00
return null;
2015-09-13 06:04:31 +02:00
}
2016-03-23 02:41:37 +01:00
Plugin genPlugin = Bukkit.getPluginManager().getPlugin(name);
if (genPlugin != null && genPlugin.isEnabled()) {
ChunkGenerator gen = genPlugin.getDefaultWorldGenerator(world, "");
2016-02-10 19:59:51 +01:00
if (gen instanceof GeneratorWrapper<?>) {
return (GeneratorWrapper<?>) gen;
}
return new BukkitPlotGenerator(world, gen);
2015-09-13 06:04:31 +02:00
} else {
return new BukkitPlotGenerator(new HybridGen());
2015-02-19 09:51:10 +01:00
}
}
2016-03-20 23:19:37 +01:00
2015-02-22 14:20:41 +01:00
@Override
2015-09-13 06:04:31 +02:00
public HybridUtils initHybridUtils() {
2015-02-22 14:20:41 +01:00
return new BukkitHybridUtils();
}
2016-03-20 23:19:37 +01:00
2015-02-22 14:20:41 +01:00
@Override
2015-09-13 06:04:31 +02:00
public SetupUtils initSetupUtils() {
2015-02-22 14:20:41 +01:00
return new BukkitSetupUtils();
}
2016-03-20 23:19:37 +01:00
2015-02-23 00:12:33 +01:00
@Override
2015-09-13 06:04:31 +02:00
public UUIDHandlerImplementation initUUIDHandler() {
2016-03-23 02:41:37 +01:00
boolean checkVersion = PS.get().checkVersion(getServerVersion(), 1, 7, 6);
2015-07-27 09:26:50 +02:00
UUIDWrapper wrapper;
2015-09-13 06:04:31 +02:00
if (Settings.OFFLINE_MODE) {
if (Settings.UUID_LOWERCASE) {
2016-03-21 03:52:16 +01:00
wrapper = new LowerOfflineUUIDWrapper();
2015-09-13 06:04:31 +02:00
} else {
2016-03-21 03:52:16 +01:00
wrapper = new OfflineUUIDWrapper();
}
2015-02-23 00:12:33 +01:00
Settings.OFFLINE_MODE = true;
2015-09-13 06:04:31 +02:00
} else if (checkVersion) {
2016-03-21 03:52:16 +01:00
wrapper = new DefaultUUIDWrapper();
2015-02-23 00:12:33 +01:00
Settings.OFFLINE_MODE = false;
2015-09-13 06:04:31 +02:00
} else {
if (Settings.UUID_LOWERCASE) {
2016-03-21 03:52:16 +01:00
wrapper = new LowerOfflineUUIDWrapper();
2015-09-13 06:04:31 +02:00
} else {
2016-03-21 03:52:16 +01:00
wrapper = new OfflineUUIDWrapper();
}
2015-02-23 00:12:33 +01:00
Settings.OFFLINE_MODE = true;
}
2015-09-13 06:04:31 +02:00
if (!checkVersion) {
2016-03-20 23:19:37 +01:00
log(C.PREFIX + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
2015-05-02 12:08:30 +02:00
Settings.TITLES = false;
FlagManager.removeFlag(FlagManager.getFlag("titles"));
2015-09-13 06:04:31 +02:00
} else {
2016-03-02 23:08:43 +01:00
AbstractTitle.TITLE_CLASS = new DefaultTitle_19();
if (wrapper instanceof DefaultUUIDWrapper || wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
2015-05-02 12:08:30 +02:00
Settings.TWIN_MODE_UUID = true;
}
}
2015-09-13 06:04:31 +02:00
if (Settings.OFFLINE_MODE) {
2016-03-23 02:41:37 +01:00
log(C.PREFIX
+ " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
+ "Bukkit");
2015-09-13 06:04:31 +02:00
} else {
2016-03-20 23:19:37 +01:00
log(C.PREFIX + " &6PlotSquared is using online UUIDs");
2015-02-23 00:12:33 +01:00
}
2016-03-23 02:41:37 +01:00
if (Settings.USE_SQLUUIDHANDLER) {
return new SQLUUIDHandler(wrapper);
} else {
return new FileUUIDHandler(wrapper);
}
2015-02-23 00:12:33 +01:00
}
2016-03-20 23:19:37 +01:00
2015-02-23 01:05:25 +01:00
@Override
2015-09-13 06:04:31 +02:00
public ChunkManager initChunkManager() {
2015-02-23 06:29:45 +01:00
return new BukkitChunkManager();
}
2016-03-20 23:19:37 +01:00
2015-02-23 06:29:45 +01:00
@Override
2015-09-13 06:04:31 +02:00
public EventUtil initEventUtil() {
2015-02-23 06:29:45 +01:00
return new BukkitEventUtil();
2015-02-23 01:05:25 +01:00
}
2016-03-20 23:19:37 +01:00
2015-04-09 07:41:14 +02:00
@Override
2016-03-23 02:41:37 +01:00
public void unregister(PlotPlayer player) {
2015-04-09 07:41:14 +02:00
BukkitUtil.removePlayer(player.getName());
}
2016-03-20 23:19:37 +01:00
2015-04-26 08:29:58 +02:00
@Override
2015-09-13 06:04:31 +02:00
public void registerChunkProcessor() {
2015-04-26 08:29:58 +02:00
getServer().getPluginManager().registerEvents(new ChunkListener(), this);
}
2016-03-20 23:19:37 +01:00
2015-04-26 08:29:58 +02:00
@Override
2015-09-13 06:04:31 +02:00
public void registerWorldEvents() {
2015-04-26 08:29:58 +02:00
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
}
2016-03-20 23:19:37 +01:00
@Override
2015-09-13 06:04:31 +02:00
public InventoryUtil initInventoryUtil() {
return new BukkitInventoryUtil();
}
2016-03-20 23:19:37 +01:00
2015-07-24 19:37:39 +02:00
@Override
2015-09-13 06:04:31 +02:00
public String getServerName() {
2015-07-24 19:37:39 +02:00
return Bukkit.getServerName();
}
2016-03-20 23:19:37 +01:00
2015-07-28 08:06:19 +02:00
@Override
2015-09-13 06:04:31 +02:00
public void startMetrics() {
2016-03-23 18:16:05 +01:00
Metrics metrics = new Metrics(this);
metrics.start();
log(C.PREFIX + "&6Metrics enabled.");
2015-07-28 08:06:19 +02:00
}
2016-03-20 23:19:37 +01:00
2015-07-28 08:06:19 +02:00
@Override
2016-03-23 02:41:37 +01:00
public void setGenerator(String worldName) {
World world = BukkitUtil.getWorld(worldName);
2015-09-13 06:04:31 +02:00
if (world == null) {
2015-08-09 11:58:29 +02:00
// create world
2016-03-23 02:41:37 +01:00
ConfigurationSection worldConfig = PS.get().config.getConfigurationSection("worlds." + worldName);
2016-03-19 19:07:55 +01:00
String manager = worldConfig.getString("generator.plugin", "PlotSquared");
2016-03-23 02:41:37 +01:00
SetupObject setup = new SetupObject();
2015-08-09 11:58:29 +02:00
setup.plotManager = manager;
2016-03-23 18:09:13 +01:00
setup.setupGenerator = worldConfig.getString("generator.init", manager);
setup.type = worldConfig.getInt("generator.type");
setup.terrain = worldConfig.getInt("generator.terrain");
2015-08-09 11:58:29 +02:00
setup.step = new ConfigurationNode[0];
2016-03-23 02:41:37 +01:00
setup.world = worldName;
2015-08-09 11:58:29 +02:00
SetupUtils.manager.setupWorld(setup);
2015-09-13 06:04:31 +02:00
} else {
try {
2016-03-23 02:41:37 +01:00
if (!PS.get().hasPlotArea(worldName)) {
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
}
2016-03-23 02:41:37 +01:00
} catch (Exception e) {
log("Failed to reload world: " + world);
Bukkit.getServer().unloadWorld(world, false);
}
}
2016-03-23 02:41:37 +01:00
world = Bukkit.getWorld(worldName);
ChunkGenerator gen = world.getGenerator();
2015-09-13 06:04:31 +02:00
if (gen instanceof BukkitPlotGenerator) {
2016-03-23 02:41:37 +01:00
PS.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
2016-02-10 19:59:51 +01:00
} else if (gen != null) {
2016-03-23 02:41:37 +01:00
PS.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen));
} else if (PS.get().config.contains("worlds." + worldName)) {
PS.get().loadWorld(worldName, null);
2015-07-28 08:06:19 +02:00
}
}
2016-03-20 23:19:37 +01:00
2015-07-30 16:25:16 +02:00
@Override
2015-09-13 06:04:31 +02:00
public SchematicHandler initSchematicHandler() {
2015-07-30 16:25:16 +02:00
return new BukkitSchematicHandler();
}
2016-03-20 23:19:37 +01:00
2015-07-30 16:25:16 +02:00
@Override
2015-09-13 06:04:31 +02:00
public AbstractTitle initTitleManager() {
2015-07-30 16:25:16 +02:00
// Already initialized in UUID handler
return AbstractTitle.TITLE_CLASS;
}
2016-03-20 23:19:37 +01:00
2015-07-30 19:24:01 +02:00
@Override
2016-03-23 02:41:37 +01:00
public PlotPlayer wrapPlayer(Object player) {
if (player instanceof Player) {
return BukkitUtil.getPlayer((Player) player);
} else if (player instanceof OfflinePlayer) {
return BukkitUtil.getPlayer((OfflinePlayer) player);
} else if (player instanceof String) {
return UUIDHandler.getPlayer((String) player);
} else if (player instanceof UUID) {
return UUIDHandler.getPlayer((UUID) player);
2015-07-30 19:24:01 +02:00
}
return null;
}
2016-03-20 23:19:37 +01:00
2015-08-03 20:20:04 +02:00
@Override
2015-09-13 06:04:31 +02:00
public String getNMSPackage() {
2016-03-19 05:39:42 +01:00
String name = Bukkit.getServer().getClass().getPackage().getName();
return name.substring(name.lastIndexOf('.') + 1);
2015-08-03 20:20:04 +02:00
}
2016-03-20 23:19:37 +01:00
@Override
2015-09-13 06:04:31 +02:00
public ChatManager<?> initChatManager() {
if (Settings.FANCY_CHAT) {
return new BukkitChatManager();
2015-09-13 06:04:31 +02:00
} else {
return new BukkitPlainChatManager();
}
}
2016-03-20 23:19:37 +01:00
2016-02-10 19:59:51 +01:00
@Override
public GeneratorWrapper<?> wrapPlotGenerator(IndependentPlotGenerator generator) {
return new BukkitPlotGenerator(generator);
2016-02-10 19:59:51 +01:00
}
2016-03-20 23:19:37 +01:00
2016-02-10 19:59:51 +01:00
@Override
public List<String> getPluginIds() {
ArrayList<String> names = new ArrayList<>();
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
names.add(plugin.getName() + ";" + plugin.getDescription().getVersion() + ":" + plugin.isEnabled());
}
return names;
}
2015-02-19 04:24:05 +01:00
}