Prettify BukkitMain

This commit is contained in:
sauilitired 2018-08-10 20:46:38 +02:00
parent 2898e9ae2b
commit 724fb34b1f
4 changed files with 55 additions and 55 deletions

View File

@ -29,6 +29,8 @@ import com.github.intellectualsites.plotsquared.plot.util.*;
import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider; import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider;
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import lombok.Getter;
import lombok.NonNull;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
@ -43,6 +45,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import javax.annotation.Nullable;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -53,8 +56,9 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
public static WorldEdit worldEdit; @Getter
private static ConcurrentHashMap<String, Plugin> pluginMap; private static WorldEdit worldEdit;
private static Map<String, Plugin> pluginMap;
static { static {
// Disable AWE as otherwise both fail to load // Disable AWE as otherwise both fail to load
@ -103,8 +107,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} }
private int[] version; private int[] version;
private String name; @Getter private String pluginName;
private SingleWorldListener singleWorldListener; @Getter private SingleWorldListener singleWorldListener;
private Method methodUnloadChunk0; private Method methodUnloadChunk0;
private boolean methodUnloadSetup = false; private boolean methodUnloadSetup = false;
@ -132,7 +136,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
if (pluginMap != null) { if (pluginMap != null) {
pluginMap.put("PlotMe-DefaultGenerator", this); pluginMap.put("PlotMe-DefaultGenerator", this);
} }
this.name = getDescription().getName(); this.pluginName = getDescription().getName();
getServer().getName(); getServer().getName();
new PS(this, "Bukkit"); new PS(this, "Bukkit");
if (Settings.Enabled_Components.METRICS) { if (Settings.Enabled_Components.METRICS) {
@ -155,46 +159,45 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} }
} }
public SingleWorldListener getSingleWorldListener() {
return singleWorldListener;
}
public void unload() { public void unload() {
if (!methodUnloadSetup) { if (!this.methodUnloadSetup) {
methodUnloadSetup = true; this.methodUnloadSetup = true;
try { try {
ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
methodUnloadChunk0 = classCraftWorld.getRealClass() this.methodUnloadChunk0 = classCraftWorld.getRealClass()
.getDeclaredMethod("unloadChunk0", int.class, int.class, boolean.class); .getDeclaredMethod("unloadChunk0", int.class, int.class, boolean.class);
methodUnloadChunk0.setAccessible(true); this.methodUnloadChunk0.setAccessible(true);
} catch (Throwable ignore) { } catch (Throwable ignore) {
ignore.printStackTrace(); ignore.printStackTrace();
} }
} }
PlotAreaManager manager = PS.get().getPlotAreaManager(); final PlotAreaManager manager = PS.get().getPlotAreaManager();
if (manager instanceof SinglePlotAreaManager) { if (manager instanceof SinglePlotAreaManager) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea(); final SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
outer: outer:
for (World world : Bukkit.getWorlds()) { for (final World world : Bukkit.getWorlds()) {
String name = world.getName(); final String name = world.getName();
char char0 = name.charAt(0); final char char0 = name.charAt(0);
if (!Character.isDigit(char0) && char0 != '-') if (!Character.isDigit(char0) && char0 != '-') {
continue; continue;
}
if (!world.getPlayers().isEmpty()) { if (!world.getPlayers().isEmpty()) {
continue; continue;
} }
PlotId id = PlotId.fromString(name); final PlotId id = PlotId.fromString(name);
if (id != null) { if (id != null) {
Plot plot = area.getOwnedPlot(id); final Plot plot = area.getOwnedPlot(id);
if (plot != null) { if (plot != null) {
if (PlotPlayer.wrap(plot.owner) == null) { if (PlotPlayer.wrap(plot.owner) == null) {
if (world.getKeepSpawnInMemory()) { if (world.getKeepSpawnInMemory()) {
world.setKeepSpawnInMemory(false); world.setKeepSpawnInMemory(false);
return; return;
} }
Chunk[] chunks = world.getLoadedChunks(); final Chunk[] chunks = world.getLoadedChunks();
if (chunks.length == 0) { if (chunks.length == 0) {
if (!Bukkit.unloadWorld(world, true)) { if (!Bukkit.unloadWorld(world, true)) {
PS.debug("Failed to unload " + world.getName()); PS.debug("Failed to unload " + world.getName());
@ -203,7 +206,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} else { } else {
int index = 0; int index = 0;
do { do {
Chunk chunkI = chunks[index++]; final Chunk chunkI = chunks[index++];
boolean result; boolean result;
if (methodUnloadChunk0 != null) { if (methodUnloadChunk0 != null) {
try { try {
@ -237,14 +240,14 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
Bukkit.getScheduler().cancelTasks(this); Bukkit.getScheduler().cancelTasks(this);
} }
@Override public void log(String message) { @Override public void log(@NonNull String message) {
try { try {
message = C.color(message); message = C.color(message);
if (!Settings.Chat.CONSOLE_COLOR) { if (!Settings.Chat.CONSOLE_COLOR) {
message = ChatColor.stripColor(message); message = ChatColor.stripColor(message);
} }
this.getServer().getConsoleSender().sendMessage(message); this.getServer().getConsoleSender().sendMessage(message);
} catch (Throwable ignored) { } catch (final Throwable ignored) {
System.out.println(ConsoleColors.fromString(message)); System.out.println(ConsoleColors.fromString(message));
} }
} }
@ -267,13 +270,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return getDescription().getVersion(); return getDescription().getVersion();
} }
@Override public String getPluginName() {
return name;
}
@Override public void registerCommands() { @Override public void registerCommands() {
BukkitCommand bukkitCommand = new BukkitCommand(); final BukkitCommand bukkitCommand = new BukkitCommand();
PluginCommand plotCommand = getCommand("plots"); final PluginCommand plotCommand = getCommand("plots");
plotCommand.setExecutor(bukkitCommand); plotCommand.setExecutor(bukkitCommand);
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot")); plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
plotCommand.setTabCompleter(bukkitCommand); plotCommand.setTabCompleter(bukkitCommand);
@ -291,13 +290,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return new BukkitTaskManager(this); return new BukkitTaskManager(this);
} }
@Override public void runEntityTask() { @Override @SuppressWarnings("deprecation") public void runEntityTask() {
PS.log(C.PREFIX + "KillAllEntities started."); PS.log(C.PREFIX + "KillAllEntities started.");
TaskManager.runTaskRepeat(new Runnable() { TaskManager.runTaskRepeat(new Runnable() {
@Override public void run() { @Override public void run() {
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() { PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
@Override public void run(PlotArea plotArea) { @Override public void run(PlotArea plotArea) {
World world = Bukkit.getWorld(plotArea.worldname); final World world = Bukkit.getWorld(plotArea.worldname);
try { try {
if (world == null) { if (world == null) {
return; return;
@ -514,7 +513,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} }
} }
} }
continue;
} }
} }
} }
@ -527,12 +525,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
}, 20); }, 20);
} }
@Override public final ChunkGenerator getDefaultWorldGenerator(String world, String id) { @Override @Nullable public final ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
if (Settings.Enabled_Components.PLOTME_CONVERTER) { if (Settings.Enabled_Components.PLOTME_CONVERTER) {
initPlotMeConverter(); initPlotMeConverter();
Settings.Enabled_Components.PLOTME_CONVERTER = false; Settings.Enabled_Components.PLOTME_CONVERTER = false;
} }
IndependentPlotGenerator result; final IndependentPlotGenerator result;
if (id != null && id.equalsIgnoreCase("single")) { if (id != null && id.equalsIgnoreCase("single")) {
result = new SingleWorldGenerator(); result = new SingleWorldGenerator();
} else { } else {
@ -545,13 +543,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} }
@Override public void registerPlayerEvents() { @Override public void registerPlayerEvents() {
PlayerEvents main = new PlayerEvents(); final PlayerEvents main = new PlayerEvents();
getServer().getPluginManager().registerEvents(main, this); getServer().getPluginManager().registerEvents(main, this);
try { try {
getServer().getClass().getMethod("spigot"); getServer().getClass().getMethod("spigot");
Class.forName("org.bukkit.event.entity.EntitySpawnEvent"); Class.forName("org.bukkit.event.entity.EntitySpawnEvent");
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this); getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
} catch (NoSuchMethodException | ClassNotFoundException ignored) { } catch (final NoSuchMethodException | ClassNotFoundException ignored) {
PS.debug("Not running Spigot. Skipping EntitySpawnListener event."); PS.debug("Not running Spigot. Skipping EntitySpawnListener event.");
} }
if (PS.get().checkVersion(getServerVersion(), 1, 7, 9)) { if (PS.get().checkVersion(getServerVersion(), 1, 7, 9)) {
@ -658,11 +656,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return false; return false;
} }
@Override public GeneratorWrapper<?> getGenerator(String world, String name) { @Override @Nullable public GeneratorWrapper<?> getGenerator(@NonNull final String world, @Nullable final String name) {
if (name == null) { if (name == null) {
return null; return null;
} }
Plugin genPlugin = Bukkit.getPluginManager().getPlugin(name); final Plugin genPlugin = Bukkit.getPluginManager().getPlugin(name);
if (genPlugin != null && genPlugin.isEnabled()) { if (genPlugin != null && genPlugin.isEnabled()) {
ChunkGenerator gen = genPlugin.getDefaultWorldGenerator(world, ""); ChunkGenerator gen = genPlugin.getDefaultWorldGenerator(world, "");
if (gen instanceof GeneratorWrapper<?>) { if (gen instanceof GeneratorWrapper<?>) {
@ -689,7 +687,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
checkVersion = true; checkVersion = true;
} catch (Throwable ignore) { } catch (Throwable ignore) {
} }
UUIDWrapper wrapper; final UUIDWrapper wrapper;
if (Settings.UUID.OFFLINE) { if (Settings.UUID.OFFLINE) {
if (Settings.UUID.FORCE_LOWERCASE) { if (Settings.UUID.FORCE_LOWERCASE) {
wrapper = new LowerOfflineUUIDWrapper(); wrapper = new LowerOfflineUUIDWrapper();
@ -741,7 +739,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return new BukkitEventUtil(); return new BukkitEventUtil();
} }
@Override public void unregister(PlotPlayer player) { @Override public void unregister(@NonNull final PlotPlayer player) {
BukkitUtil.removePlayer(player.getName()); BukkitUtil.removePlayer(player.getName());
} }
@ -766,7 +764,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
PS.log(C.PREFIX + "&6Metrics enabled."); PS.log(C.PREFIX + "&6Metrics enabled.");
} }
@Override public void setGenerator(String worldName) { @Override public void setGenerator(@NonNull final String worldName) {
World world = BukkitUtil.getWorld(worldName); World world = BukkitUtil.getWorld(worldName);
if (world == null) { if (world == null) {
// create world // create world
@ -812,7 +810,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return AbstractTitle.TITLE_CLASS; return AbstractTitle.TITLE_CLASS;
} }
@Override public PlotPlayer wrapPlayer(Object player) { @Override @Nullable public PlotPlayer wrapPlayer(final Object player) {
if (player instanceof Player) { if (player instanceof Player) {
return BukkitUtil.getPlayer((Player) player); return BukkitUtil.getPlayer((Player) player);
} }
@ -829,7 +827,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} }
@Override public String getNMSPackage() { @Override public String getNMSPackage() {
String name = Bukkit.getServer().getClass().getPackage().getName(); final String name = Bukkit.getServer().getClass().getPackage().getName();
return name.substring(name.lastIndexOf('.') + 1); return name.substring(name.lastIndexOf('.') + 1);
} }
@ -842,13 +840,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} }
@Override @Override
public GeneratorWrapper<?> wrapPlotGenerator(String world, IndependentPlotGenerator generator) { public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world, @NonNull final IndependentPlotGenerator generator) {
return new BukkitPlotGenerator(generator); return new BukkitPlotGenerator(generator);
} }
@Override public List<String> getPluginIds() { @Override public List<String> getPluginIds() {
ArrayList<String> names = new ArrayList<>(); final List<String> names = new ArrayList<>();
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
names.add(plugin.getName() + ';' + plugin.getDescription().getVersion() + ':' + plugin names.add(plugin.getName() + ';' + plugin.getDescription().getVersion() + ':' + plugin
.isEnabled()); .isEnabled());
} }

View File

@ -557,7 +557,7 @@ public class PlayerEvents extends PlotListener implements Listener {
} }
String[] parts = msg.split(" "); String[] parts = msg.split(" ");
Plot plot = pp.getCurrentPlot(); Plot plot = pp.getCurrentPlot();
if (BukkitMain.worldEdit != null) { // Check WorldEdit if (BukkitMain.getWorldEdit() != null) { // Check WorldEdit
switch (parts[0].toLowerCase()) { switch (parts[0].toLowerCase()) {
case "up": case "up":
case "/up": case "/up":

View File

@ -10,6 +10,7 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.StringComparison; import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import lombok.NonNull;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -76,7 +77,7 @@ public class BukkitUtil extends WorldUtil {
location.getY(), location.getZ()); location.getY(), location.getZ());
} }
public static World getWorld(String string) { public static World getWorld(@NonNull final String string) {
return Bukkit.getWorld(string); return Bukkit.getWorld(string);
} }

View File

@ -19,11 +19,6 @@ plugins {
id 'io.franzbecker.gradle-lombok' version '1.14' id 'io.franzbecker.gradle-lombok' version '1.14'
} }
lombok {
version = '1.18.2'
sha256 = ""
}
group = 'com.intellectualcrafters' group = 'com.intellectualcrafters'
def revision = "" def revision = ""
@ -55,6 +50,11 @@ subprojects {
apply plugin: 'idea' apply plugin: 'idea'
apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'com.github.johnrengelman.shadow'
lombok {
version = '1.18.2'
sha256 = ""
}
dependencies { dependencies {
compile(group: 'com.sk89q.worldedit', name: 'worldedit-core', version: '6.1.3-SNAPSHOT') { compile(group: 'com.sk89q.worldedit', name: 'worldedit-core', version: '6.1.3-SNAPSHOT') {
exclude(module: 'bukkit-classloader-check') exclude(module: 'bukkit-classloader-check')
@ -62,6 +62,7 @@ subprojects {
exclude(module: 'dummypermscompat') exclude(module: 'dummypermscompat')
} }
compile 'com.google.guava:guava:10.0' compile 'com.google.guava:guava:10.0'
compileOnly 'org.projectlombok:lombok:1.16.18'
} }
clean { clean {
delete file("../target") delete file("../target")