From 89e3bd97f08eaba2b76a32eb0df3d4ec74477d0f Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 28 Jul 2015 21:38:49 +1000 Subject: [PATCH] Nothing is implemented, but it can compile and "run" on sponge now. --- .../intellectualcrafters/plot/IPlotMain.java | 3 +- .../com/intellectualcrafters/plot/PS.java | 261 +++++++++--------- .../plot/commands/Cluster.java | 2 +- .../plot/commands/Comment.java | 3 +- .../plot/commands/Delete.java | 2 +- .../plot/commands/Inbox.java | 3 +- .../plot/commands/Set.java | 3 +- .../plot/commands/Setup.java | 29 +- .../plot/commands/Template.java | 2 +- .../intellectualcrafters/plot/config/C.java | 6 +- .../plot/generator/PlotGenerator.java | 3 + .../plot/object/SetupObject.java | 2 +- .../plot/util}/CommentManager.java | 6 +- .../plot/util/EventUtil.java | 1 - .../plot/util/MathMan.java | 100 +++++++ .../plot}/util/SetupUtils.java | 6 +- .../com/plotsquared/bukkit/BukkitMain.java | 4 +- .../generator/BukkitGeneratorWrapper.java | 11 +- .../bukkit/listeners/PlotListener.java | 5 +- .../bukkit/object/BukkitPlayer.java | 8 +- .../bukkit/titles/AbstractTitle.java | 6 +- .../bukkit/titles/DefaultTitle.java | 6 +- .../bukkit/titles/DefaultTitle_183.java | 6 +- .../plotsquared/bukkit/titles/HackTitle.java | 4 +- .../bukkit/util/bukkit/BukkitSetupUtils.java | 15 +- .../bukkit/util/bukkit/SetGenCB.java | 7 +- .../listeners => listener}/APlotListener.java | 2 +- .../sponge/SpongeGeneratorWrapper.java | 7 + .../sponge/SpongeLowerOfflineUUIDWrapper.java | 93 +++++++ .../com/plotsquared/sponge/SpongeMain.java | 145 ++++++---- .../sponge/SpongeOnlineUUIDWrapper.java | 72 +++++ .../com/plotsquared/sponge/SpongePlayer.java | 205 ++++++++++++++ .../plotsquared/sponge/SpongeTaskManager.java | 59 ++++ .../plotsquared/sponge/SpongeUUIDHandler.java | 53 ++++ .../com/plotsquared/sponge/SpongeUtil.java | 28 ++ 35 files changed, 915 insertions(+), 253 deletions(-) rename src/main/java/com/{plotsquared/bukkit/object/comment => intellectualcrafters/plot/util}/CommentManager.java (91%) rename src/main/java/com/{plotsquared/bukkit => intellectualcrafters/plot}/util/SetupUtils.java (74%) rename src/main/java/com/plotsquared/{bukkit/listeners => listener}/APlotListener.java (89%) create mode 100644 src/main/java/com/plotsquared/sponge/SpongeLowerOfflineUUIDWrapper.java create mode 100644 src/main/java/com/plotsquared/sponge/SpongeOnlineUUIDWrapper.java create mode 100644 src/main/java/com/plotsquared/sponge/SpongePlayer.java create mode 100644 src/main/java/com/plotsquared/sponge/SpongeTaskManager.java create mode 100644 src/main/java/com/plotsquared/sponge/SpongeUUIDHandler.java create mode 100644 src/main/java/com/plotsquared/sponge/SpongeUtil.java diff --git a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index 790157a31..ad8a2faa8 100644 --- a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -5,8 +5,7 @@ import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.PlotGenerator; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.*; -import com.plotsquared.bukkit.listeners.APlotListener; -import com.plotsquared.bukkit.util.SetupUtils; +import com.plotsquared.listener.APlotListener; import java.io.File; import java.util.UUID; diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index 47843e683..29c5f7c8a 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -12,9 +12,7 @@ import com.intellectualcrafters.plot.flag.FlagValue; import com.intellectualcrafters.plot.generator.*; import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.util.*; -import com.plotsquared.bukkit.listeners.APlotListener; -import com.plotsquared.bukkit.object.comment.CommentManager; -import com.plotsquared.bukkit.util.SetupUtils; +import com.plotsquared.listener.APlotListener; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import java.io.*; @@ -73,136 +71,143 @@ public class PS { * @param imp_class */ public PS(final IPlotMain imp_class) { - instance = this; - SetupUtils.generators = new HashMap<>(); - IMP = imp_class; try { - FILE = new File(PS.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); - } catch (Exception e) { - log("Could not determine file path"); - } - VERSION = IMP.getPluginVersion(); - EconHandler.manager = IMP.getEconomyHandler(); - if (getJavaVersion() < 1.7) { - log(C.PREFIX.s() + "&cYour java version is outdated. Please update to at least 1.7."); - // Didn't know of any other link :D - log(C.PREFIX.s() + "&cURL: &6https://java.com/en/download/index.jsp"); - IMP.disable(); - return; - } - if (getJavaVersion() < 1.8) { - log(C.PREFIX.s() + "&cIt's really recommended to run Java 1.8, as it increases performance"); - } - this.TASK = IMP.getTaskManager(); - if (C.ENABLED.s().length() > 0) { - log(C.ENABLED.s()); - } - setupConfigs(); - this.translationFile = new File(IMP.getDirectory() + File.separator + "translations" + File.separator + "PlotSquared.use_THIS.yml"); - C.load(translationFile); - setupDefaultFlags(); - setupDatabase(); - CommentManager.registerDefaultInboxes(); - // Tasks - if (Settings.KILL_ROAD_MOBS) { - IMP.runEntityTask(); - } - // Events - IMP.registerCommands(); - IMP.registerPlayerEvents(); - IMP.registerInventoryEvents(); - IMP.registerPlotPlusEvents(); - IMP.registerForceFieldEvents(); - IMP.registerWorldEditEvents(); - IMP.registerWorldEvents(); - if (Settings.METRICS) { - IMP.startMetrics(); - } else { - log("&dUsing metrics will allow us to improve the plugin, please consider it :)"); - } - IMP.startMetrics(); - if (Settings.TNT_LISTENER) { - IMP.registerTNTListener(); - } - if (Settings.CHUNK_PROCESSOR) { - IMP.registerChunkProcessor(); - } - // create UUIDWrapper - UUIDHandler.implementation = IMP.initUUIDHandler(); - UUIDHandler.implementation.startCaching(null); // TODO maybe a notification when this is done? - // create event util class - EventUtil.manager = IMP.initEventUtil(); - // create Hybrid utility class - HybridUtils.manager = IMP.initHybridUtils(); - // Inventory utility class - InventoryUtil.manager = IMP.initInventoryUtil(); - // create setup util class - SetupUtils.manager = IMP.initSetupUtils(); - // Set block - BlockManager.manager = IMP.initBlockManager(); - // Set chunk - ChunkManager.manager = IMP.initChunkManager(); - // Plot listener - APlotListener.manager = IMP.initPlotListener(); - // Player manager - PlayerManager.manager = IMP.initPlayerManager(); - - // Check for updates - TaskManager.runTaskAsync(new Runnable() { - @Override - public void run() { - URL url = getUpdate(); - if (url != null) { - update = url; - log("&6You are running an older version of PlotSquared..."); - log("&8 - &3Use: &7/plot update"); - log("&8 - &3Or: &7" + url); - } - else if (LAST_VERSION != null && !VERSION.equals(LAST_VERSION)) { - log("&aThanks for updating from: " + LAST_VERSION + " to " + StringMan.join(VERSION, ".")); - } + instance = this; + SetupUtils.generators = new HashMap<>(); + IMP = imp_class; + try { + FILE = new File(PS.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); + } catch (Exception e) { + FILE = new File(IMP.getDirectory().getParentFile(), "PlotSquared.jar"); + e.printStackTrace(); + log("Could not determine file path"); } - }); - - // PlotMe - if (Settings.CONVERT_PLOTME || Settings.CACHE_PLOTME) { - TaskManager.runTaskLater(new Runnable() { - + VERSION = IMP.getPluginVersion(); + EconHandler.manager = IMP.getEconomyHandler(); + if (getJavaVersion() < 1.7) { + log(C.PREFIX.s() + "&cYour java version is outdated. Please update to at least 1.7."); + // Didn't know of any other link :D + log(C.PREFIX.s() + "&cURL: &6https://java.com/en/download/index.jsp"); + IMP.disable(); + return; + } + if (getJavaVersion() < 1.8) { + log(C.PREFIX.s() + "&cIt's really recommended to run Java 1.8, as it increases performance"); + } + this.TASK = IMP.getTaskManager(); + if (C.ENABLED.s().length() > 0) { + log(C.ENABLED.s()); + } + setupConfigs(); + this.translationFile = new File(IMP.getDirectory() + File.separator + "translations" + File.separator + "PlotSquared.use_THIS.yml"); + C.load(translationFile); + setupDefaultFlags(); + setupDatabase(); + CommentManager.registerDefaultInboxes(); + // Tasks + if (Settings.KILL_ROAD_MOBS) { + IMP.runEntityTask(); + } + // Events + IMP.registerCommands(); + IMP.registerPlayerEvents(); + IMP.registerInventoryEvents(); + IMP.registerPlotPlusEvents(); + IMP.registerForceFieldEvents(); + IMP.registerWorldEditEvents(); + IMP.registerWorldEvents(); + if (Settings.METRICS) { + IMP.startMetrics(); + } else { + log("&dUsing metrics will allow us to improve the plugin, please consider it :)"); + } + IMP.startMetrics(); + if (Settings.TNT_LISTENER) { + IMP.registerTNTListener(); + } + if (Settings.CHUNK_PROCESSOR) { + IMP.registerChunkProcessor(); + } + // create UUIDWrapper + UUIDHandler.implementation = IMP.initUUIDHandler(); + UUIDHandler.startCaching(null); // TODO maybe a notification when this is done? + // create event util class + EventUtil.manager = IMP.initEventUtil(); + // create Hybrid utility class + HybridUtils.manager = IMP.initHybridUtils(); + // Inventory utility class + InventoryUtil.manager = IMP.initInventoryUtil(); + // create setup util class + SetupUtils.manager = IMP.initSetupUtils(); + // Set block + BlockManager.manager = IMP.initBlockManager(); + // Set chunk + ChunkManager.manager = IMP.initChunkManager(); + // Plot listener + APlotListener.manager = IMP.initPlotListener(); + // Player manager + PlayerManager.manager = IMP.initPlayerManager(); + + // Check for updates + TaskManager.runTaskAsync(new Runnable() { + @Override public void run() { - if (IMP.initPlotMeConverter()) { - log("&c=== IMPORTANT ==="); - log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME!"); - log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!"); - log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!"); - log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml'"); + URL url = getUpdate(); + if (url != null) { + update = url; + log("&6You are running an older version of PlotSquared..."); + log("&8 - &3Use: &7/plot update"); + log("&8 - &3Or: &7" + url); + } + else if (LAST_VERSION != null && !StringMan.join(VERSION,".").equals(LAST_VERSION)) { + log("&aThanks for updating from: " + LAST_VERSION + " to " + StringMan.join(VERSION, ".")); } } - }, 200); - } - - // Auto clearing - if (Settings.AUTO_CLEAR) { - ExpireManager.runTask(); - } - - // World generators: - ConfigurationSection section = config.getConfigurationSection("worlds"); - if (section != null) { - for (String world : section.getKeys(false)) { - if (BlockManager.manager.isWorld(world)) { - break; + }); + + // PlotMe + if (Settings.CONVERT_PLOTME || Settings.CACHE_PLOTME) { + TaskManager.runTaskLater(new Runnable() { + + public void run() { + if (IMP.initPlotMeConverter()) { + log("&c=== IMPORTANT ==="); + log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME!"); + log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!"); + log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!"); + log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml'"); + } + } + }, 200); + } + + // Auto clearing + if (Settings.AUTO_CLEAR) { + ExpireManager.runTask(); + } + + // World generators: + ConfigurationSection section = config.getConfigurationSection("worlds"); + if (section != null) { + for (String world : section.getKeys(false)) { + if (BlockManager.manager.isWorld(world)) { + break; + } } } + + // Copy files + copyFile("town.template", "templates"); + copyFile("skyblock.template", "templates"); + copyFile("german.yml", "translations"); + copyFile("s_chinese_unescaped.yml", "translations"); + copyFile("s_chinese.yml", "translations"); + copyFile("italian.yml", "translations"); + showDebug(); + } + catch (Throwable e) { + e.printStackTrace(); } - - // Copy files - copyFile("town.template", "templates"); - copyFile("skyblock.template", "templates"); - copyFile("german.yml", "translations"); - copyFile("s_chinese_unescaped.yml", "translations"); - copyFile("s_chinese.yml", "translations"); - copyFile("italian.yml", "translations"); - showDebug(); } public boolean checkVersion(int[] version, int major, int minor, int minor2) { @@ -1260,7 +1265,7 @@ public class PS { */ public void setupConfig() { LAST_VERSION = config.getString("version"); - config.set("version", VERSION); + config.set("version", StringMan.join(VERSION,".")); final Map options = new HashMap<>(); // Command confirmation @@ -1553,7 +1558,7 @@ public class PS { * Setup the storage file (load + save missing nodes) */ private void setupStorage() { - storage.set("version", VERSION); + storage.set("version", StringMan.join(VERSION,".")); final Map options = new HashMap<>(); options.put("mysql.use", false); options.put("sqlite.use", true); @@ -1611,7 +1616,7 @@ public class PS { * Setup the style.yml file */ private void setupStyle() { - style.set("version", VERSION); + style.set("version", StringMan.join(VERSION,".")); final Map o = new HashMap<>(); o.put("color.1", "6"); o.put("color.2", "7"); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java b/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java index 3a7003f02..1e8bc4e5c 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java @@ -28,8 +28,8 @@ import com.intellectualcrafters.plot.util.*; import com.plotsquared.bukkit.generator.AugmentedPopulator; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.plotsquared.bukkit.generator.HybridGen; -import com.plotsquared.bukkit.util.SetupUtils; import com.plotsquared.general.commands.CommandDeclaration; + import org.bukkit.generator.ChunkGenerator; import java.util.ArrayList; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Comment.java b/src/main/java/com/intellectualcrafters/plot/commands/Comment.java index b75bfb4d5..dd2c6bde8 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Comment.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Comment.java @@ -27,9 +27,10 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.comment.CommentInbox; import com.intellectualcrafters.plot.object.comment.PlotComment; +import com.intellectualcrafters.plot.util.CommentManager; import com.intellectualcrafters.plot.util.MainUtil; -import com.plotsquared.bukkit.object.comment.CommentManager; import com.plotsquared.general.commands.CommandDeclaration; + import org.apache.commons.lang.StringUtils; import java.util.Arrays; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index 4eed927f4..1fd5f16b9 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -51,7 +51,7 @@ public class Delete extends SubCommand { if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return !sendMessage(plr, C.UNLINK_REQUIRED); } - if (((!plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUIDWrapper().getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) { + if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) { return !sendMessage(plr, C.NO_PLOT_PERMS); } final PlotWorld pWorld = PS.get().getPlotWorld(plot.world); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java b/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java index daf42c1f5..c9c027951 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java @@ -26,10 +26,11 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.comment.CommentInbox; import com.intellectualcrafters.plot.object.comment.PlotComment; +import com.intellectualcrafters.plot.util.CommentManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.StringMan; -import com.plotsquared.bukkit.object.comment.CommentManager; import com.plotsquared.general.commands.CommandDeclaration; + import org.apache.commons.lang.StringUtils; import java.util.ArrayList; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/src/main/java/com/intellectualcrafters/plot/commands/Set.java index d7c4edd85..bdbad1ea9 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -28,8 +28,9 @@ import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.util.*; -import com.plotsquared.bukkit.listeners.APlotListener; import com.plotsquared.general.commands.CommandDeclaration; +import com.plotsquared.listener.APlotListener; + import org.apache.commons.lang.StringUtils; import java.util.ArrayList; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Setup.java b/src/main/java/com/intellectualcrafters/plot/commands/Setup.java index 58df0ea0c..f0a44ca41 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Setup.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Setup.java @@ -23,14 +23,16 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.generator.PlotGenerator; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.SetupUtils; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.plotsquared.bukkit.generator.HybridGen; -import com.plotsquared.bukkit.util.SetupUtils; import com.plotsquared.general.commands.CommandDeclaration; + import org.apache.commons.lang.StringUtils; import org.bukkit.generator.ChunkGenerator; @@ -52,14 +54,11 @@ public class Setup extends SubCommand { public void displayGenerators(PlotPlayer plr) { StringBuffer message = new StringBuffer(); message.append("&6What generator do you want?"); - for (Entry entry : SetupUtils.generators.entrySet()) { + for (Entry> entry : SetupUtils.generators.entrySet()) { if (entry.getKey().equals("PlotSquared")) { message.append("\n&8 - &2" + entry.getKey() + " (Default Generator)"); } - else if (entry.getValue() instanceof HybridGen) { - message.append("\n&8 - &7" + entry.getKey() + " (Hybrid Generator)"); - } - else if (entry.getValue() instanceof BukkitPlotGenerator) { + else if (entry.getValue().isFull()) { message.append("\n&8 - &7" + entry.getKey() + " (Plot Generator)"); } else { @@ -119,7 +118,7 @@ public class Setup extends SubCommand { List allTypes = Arrays.asList(new String[] { "default", "augmented", "partial"}); List allDesc = Arrays.asList(new String[] { "Standard plot generation", "Plot generation with vanilla terrain", "Vanilla with clusters of plots"}); ArrayList types = new ArrayList<>(); - if (SetupUtils.generators.get(object.setupGenerator) instanceof BukkitPlotGenerator) { + if (SetupUtils.generators.get(object.setupGenerator).isFull()) { types.add("default"); } types.add("augmented"); @@ -140,13 +139,13 @@ public class Setup extends SubCommand { return false; } object.type = allTypes.indexOf(args[0].toLowerCase()); - ChunkGenerator gen = SetupUtils.generators.get(object.setupGenerator); + PlotGenerator gen = SetupUtils.generators.get(object.setupGenerator); if (object.type == 0) { object.current++; if (object.step == null) { object.plotManager = object.setupGenerator; - object.step = ((BukkitPlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes(); - ((BukkitPlotGenerator) SetupUtils.generators.get(object.plotManager)).processSetup(object); + object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes(); + SetupUtils.generators.get(object.plotManager).processSetup(object); } if (object.step.length == 0) { object.current = 4; @@ -157,17 +156,17 @@ public class Setup extends SubCommand { final ConfigurationNode step = object.step[object.setup_index]; sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); } else { - if (gen instanceof BukkitPlotGenerator) { + if (gen.isFull()) { object.plotManager = object.setupGenerator; object.setupGenerator = null; - object.step = ((BukkitPlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes(); - ((BukkitPlotGenerator) SetupUtils.generators.get(object.plotManager)).processSetup(object); + object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes(); + SetupUtils.generators.get(object.plotManager).processSetup(object); } else { object.plotManager = "PlotSquared"; MainUtil.sendMessage(plr, "&c[WARNING] The specified generator does not identify as BukkitPlotGenerator"); MainUtil.sendMessage(plr, "&7 - You may need to manually configure the other plugin"); - object.step = ((BukkitPlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes(); + object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes(); } MainUtil.sendMessage(plr, "&6What terrain would you like in plots?" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ROAD&8 - &7Terrain seperated by roads" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation"); } @@ -183,7 +182,7 @@ public class Setup extends SubCommand { object.terrain = terrain.indexOf(args[0].toLowerCase()); object.current++; if (object.step == null) { - object.step = ((BukkitPlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes(); + object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes(); } final ConfigurationNode step = object.step[object.setup_index]; sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Template.java b/src/main/java/com/intellectualcrafters/plot/commands/Template.java index a29e719d7..7f074e3ce 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Template.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Template.java @@ -28,8 +28,8 @@ import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; -import com.plotsquared.bukkit.util.SetupUtils; import com.plotsquared.general.commands.CommandDeclaration; import java.io.File; diff --git a/src/main/java/com/intellectualcrafters/plot/config/C.java b/src/main/java/com/intellectualcrafters/plot/config/C.java index 05fe7652f..83cc1d34a 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -209,10 +209,8 @@ public enum C { /* * Title Stuff */ - TITLE_ENTERED_PLOT("Plot: %world%;%x%;%z%", "Titles"), - TITLE_ENTERED_PLOT_COLOR("GOLD", "Titles"), - TITLE_ENTERED_PLOT_SUB("Owned by %s", "Titles"), - TITLE_ENTERED_PLOT_SUB_COLOR("RED", "Titles"), + TITLE_ENTERED_PLOT("$1Plot: %world%;%x%;%z%", "Titles"), + TITLE_ENTERED_PLOT_SUB("$4Owned by %s", "Titles"), PREFIX_GREETING("$1%id%$2> ", "Titles"), PREFIX_FAREWELL("$1%id%$2> ", "Titles"), /* diff --git a/src/main/java/com/intellectualcrafters/plot/generator/PlotGenerator.java b/src/main/java/com/intellectualcrafters/plot/generator/PlotGenerator.java index b642f720b..8e4e81e09 100644 --- a/src/main/java/com/intellectualcrafters/plot/generator/PlotGenerator.java +++ b/src/main/java/com/intellectualcrafters/plot/generator/PlotGenerator.java @@ -3,6 +3,7 @@ package com.intellectualcrafters.plot.generator; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.SetupObject; public abstract class PlotGenerator { public final String world; @@ -46,4 +47,6 @@ public abstract class PlotGenerator { public abstract boolean isFull(); public abstract String getName(); + + public abstract void processSetup(SetupObject object); } diff --git a/src/main/java/com/intellectualcrafters/plot/object/SetupObject.java b/src/main/java/com/intellectualcrafters/plot/object/SetupObject.java index 87a1cc6c0..6e8cdbacd 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/SetupObject.java +++ b/src/main/java/com/intellectualcrafters/plot/object/SetupObject.java @@ -1,7 +1,7 @@ package com.intellectualcrafters.plot.object; import com.intellectualcrafters.plot.config.ConfigurationNode; -import com.plotsquared.bukkit.util.SetupUtils; +import com.intellectualcrafters.plot.util.SetupUtils; public class SetupObject { diff --git a/src/main/java/com/plotsquared/bukkit/object/comment/CommentManager.java b/src/main/java/com/intellectualcrafters/plot/util/CommentManager.java similarity index 91% rename from src/main/java/com/plotsquared/bukkit/object/comment/CommentManager.java rename to src/main/java/com/intellectualcrafters/plot/util/CommentManager.java index 78ad77e51..e35bd99f5 100644 --- a/src/main/java/com/plotsquared/bukkit/object/comment/CommentManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/CommentManager.java @@ -1,4 +1,4 @@ -package com.plotsquared.bukkit.object.comment; +package com.intellectualcrafters.plot.util; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; @@ -6,9 +6,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.comment.*; -import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.bukkit.titles.AbstractTitle; -import org.bukkit.ChatColor; import java.util.ArrayList; import java.util.Collection; @@ -50,7 +48,7 @@ public class CommentManager { total = count.get(); } if (size.decrementAndGet() == 0 && total > 0) { - AbstractTitle.sendTitle(player, "", C.INBOX_NOTIFICATION.s().replaceAll("%s", "" + total), ChatColor.GOLD, ChatColor.valueOf(C.TITLE_ENTERED_PLOT_SUB_COLOR.s())); + AbstractTitle.sendTitle(player, "", C.INBOX_NOTIFICATION.s().replaceAll("%s", "" + total)); } } }); diff --git a/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java index 99535ff27..635ecb6ca 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -15,7 +15,6 @@ import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.plotsquared.bukkit.util.SetupUtils; public abstract class EventUtil { diff --git a/src/main/java/com/intellectualcrafters/plot/util/MathMan.java b/src/main/java/com/intellectualcrafters/plot/util/MathMan.java index ec5f86dca..aa162008a 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MathMan.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MathMan.java @@ -16,6 +16,106 @@ public class MathMan { } return count / array.length; } + + /** + * Returns [x, y, z] + * @param yaw + * @param pitch + * @return + */ + public static float[] getDirection(float yaw, float pitch) { + double pitch_sin = Math.sin(pitch); + return new float[] { + (float) (pitch_sin * Math.cos(yaw)), + (float) (pitch_sin * Math.sin(yaw)), + (float) Math.cos(pitch) + }; + } + + /** + * Returns [ pitch, yaw ] + * @param x + * @param y + * @param z + * @return + */ + public static float[] getPitchAndYaw(float x, float y, float z) { + float distance = sqrtApprox(z * z + x * x); + return new float[] { atan2(y, distance), atan2(x, z) }; + } + + private static final int ATAN2_BITS = 7; + + private static final int ATAN2_BITS2 = ATAN2_BITS << 1; + private static final int ATAN2_MASK = ~(-1 << ATAN2_BITS2); + private static final int ATAN2_COUNT = ATAN2_MASK + 1; + private static final int ATAN2_DIM = (int) Math.sqrt(ATAN2_COUNT); + + private static final float INV_ATAN2_DIM_MINUS_1 = 1.0f / (ATAN2_DIM - 1); + + private static final float[] atan2 = new float[ATAN2_COUNT]; + + static { + for (int i = 0; i < ATAN2_DIM; i++) { + for (int j = 0; j < ATAN2_DIM; j++) { + float x0 = (float) i / ATAN2_DIM; + float y0 = (float) j / ATAN2_DIM; + + atan2[j * ATAN2_DIM + i] = (float) Math.atan2(y0, x0); + } + } + } + + public static final float atan2(float y, float x) { + float add, mul; + + if (x < 0.0f) { + if (y < 0.0f) { + x = -x; + y = -y; + + mul = 1.0f; + } else { + x = -x; + mul = -1.0f; + } + + add = -3.141592653f; + } else { + if (y < 0.0f) { + y = -y; + mul = -1.0f; + } else { + mul = 1.0f; + } + + add = 0.0f; + } + + float invDiv = 1.0f / (((x < y) ? y : x) * INV_ATAN2_DIM_MINUS_1); + + int xi = (int) (x * invDiv); + int yi = (int) (y * invDiv); + + return (atan2[yi * ATAN2_DIM + xi] + add) * mul; + } + + public static float sqrtApprox(float f) { + return f * Float.intBitsToFloat(0x5f375a86 - (Float.floatToIntBits(f) >> 1)); + } + + public static double sqrtApprox(double d) { + return Double.longBitsToDouble( ( ( Double.doubleToLongBits( d )-(1l<<52) )>>1 ) + ( 1l<<61 ) ); + } + + public static float invSqrt(float x) { + float xhalf = 0.5f*x; + int i = Float.floatToIntBits(x); + i = 0x5f3759df - (i>>1); + x = Float.intBitsToFloat(i); + x = x*(1.5f - xhalf*x*x); + return x; + } public static int getPositiveId(int i) { if (i < 0) { diff --git a/src/main/java/com/plotsquared/bukkit/util/SetupUtils.java b/src/main/java/com/intellectualcrafters/plot/util/SetupUtils.java similarity index 74% rename from src/main/java/com/plotsquared/bukkit/util/SetupUtils.java rename to src/main/java/com/intellectualcrafters/plot/util/SetupUtils.java index fd9d2a7fb..e64b213d7 100644 --- a/src/main/java/com/plotsquared/bukkit/util/SetupUtils.java +++ b/src/main/java/com/intellectualcrafters/plot/util/SetupUtils.java @@ -1,7 +1,9 @@ -package com.plotsquared.bukkit.util; +package com.intellectualcrafters.plot.util; +import com.intellectualcrafters.plot.generator.PlotGenerator; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.SetupObject; + import org.bukkit.generator.ChunkGenerator; import java.util.HashMap; @@ -12,7 +14,7 @@ public abstract class SetupUtils { public static SetupUtils manager; public final static Map setupMap = new HashMap<>(); - public static HashMap generators = new HashMap<>(); + public static HashMap> generators = new HashMap<>(); public abstract void updateGenerators(); diff --git a/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 31c8fa170..59a9e8848 100644 --- a/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -33,6 +33,7 @@ import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.InventoryUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.PlayerManager; +import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; import com.intellectualcrafters.plot.uuid.UUIDWrapper; @@ -42,7 +43,6 @@ import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter; import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017; import com.plotsquared.bukkit.generator.BukkitGeneratorWrapper; import com.plotsquared.bukkit.generator.HybridGen; -import com.plotsquared.bukkit.listeners.APlotListener; import com.plotsquared.bukkit.listeners.ChunkListener; import com.plotsquared.bukkit.listeners.ForceFieldListener; import com.plotsquared.bukkit.listeners.PlayerEvents; @@ -57,7 +57,6 @@ import com.plotsquared.bukkit.listeners.worldedit.WESubscriber; import com.plotsquared.bukkit.titles.AbstractTitle; import com.plotsquared.bukkit.titles.DefaultTitle; import com.plotsquared.bukkit.util.BukkitHybridUtils; -import com.plotsquared.bukkit.util.SetupUtils; import com.plotsquared.bukkit.util.bukkit.BukkitChunkManager; import com.plotsquared.bukkit.util.bukkit.BukkitEconHandler; import com.plotsquared.bukkit.util.bukkit.BukkitEventUtil; @@ -78,6 +77,7 @@ import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper; import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper; import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper; +import com.plotsquared.listener.APlotListener; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.WorldEditPlugin; diff --git a/src/main/java/com/plotsquared/bukkit/generator/BukkitGeneratorWrapper.java b/src/main/java/com/plotsquared/bukkit/generator/BukkitGeneratorWrapper.java index 8fc8aa35c..611d87e00 100644 --- a/src/main/java/com/plotsquared/bukkit/generator/BukkitGeneratorWrapper.java +++ b/src/main/java/com/plotsquared/bukkit/generator/BukkitGeneratorWrapper.java @@ -5,6 +5,8 @@ import com.intellectualcrafters.plot.generator.PlotGenerator; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.SetupObject; + import org.bukkit.generator.ChunkGenerator; public class BukkitGeneratorWrapper extends PlotGenerator { @@ -13,7 +15,7 @@ public class BukkitGeneratorWrapper extends PlotGenerator { public BukkitGeneratorWrapper(String world, ChunkGenerator generator) { super(world, generator); - full = generator != null; + full = (generator instanceof BukkitPlotGenerator); } @Override @@ -76,5 +78,12 @@ public class BukkitGeneratorWrapper extends PlotGenerator { } return generator.getClass().getName(); } + + @Override + public void processSetup(SetupObject object) { + if (generator instanceof BukkitPlotGenerator) { + ((BukkitPlotGenerator) generator).processSetup(object); + } + } } diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlotListener.java b/src/main/java/com/plotsquared/bukkit/listeners/PlotListener.java index 10f644c3d..3fa60fccc 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlotListener.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlotListener.java @@ -31,8 +31,9 @@ import com.intellectualcrafters.plot.util.*; import com.plotsquared.bukkit.events.PlayerEnterPlotEvent; import com.plotsquared.bukkit.events.PlayerLeavePlotEvent; import com.plotsquared.bukkit.object.BukkitPlayer; -import com.plotsquared.bukkit.object.comment.CommentManager; import com.plotsquared.bukkit.titles.AbstractTitle; +import com.plotsquared.listener.APlotListener; + import org.bukkit.*; import org.bukkit.entity.Player; @@ -205,7 +206,7 @@ public class PlotListener extends APlotListener { replacements.put("%s", getName(plot.owner)); String main = StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT.s(), replacements); String sub = StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT_SUB.s(), replacements); - AbstractTitle.sendTitle(pp, main, sub, ChatColor.valueOf(C.TITLE_ENTERED_PLOT_COLOR.s()), ChatColor.valueOf(C.TITLE_ENTERED_PLOT_SUB_COLOR.s())); + AbstractTitle.sendTitle(pp, main, sub); } } }, 20); diff --git a/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java b/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java index 0050f80cb..01746ff5b 100644 --- a/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java +++ b/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java @@ -21,12 +21,12 @@ import java.util.UUID; public class BukkitPlayer implements PlotPlayer { public final Player player; - UUID uuid; - String name; + private UUID uuid; + private String name; private int op = 0; private long last = 0; - public HashSet hasPerm = new HashSet<>(); - public HashSet noPerm = new HashSet<>(); + private HashSet hasPerm = new HashSet<>(); + private HashSet noPerm = new HashSet<>(); private HashMap meta; diff --git a/src/main/java/com/plotsquared/bukkit/titles/AbstractTitle.java b/src/main/java/com/plotsquared/bukkit/titles/AbstractTitle.java index 14ad2523b..b8d19de76 100644 --- a/src/main/java/com/plotsquared/bukkit/titles/AbstractTitle.java +++ b/src/main/java/com/plotsquared/bukkit/titles/AbstractTitle.java @@ -6,11 +6,11 @@ import org.bukkit.ChatColor; public abstract class AbstractTitle { public static AbstractTitle TITLE_CLASS; - public static void sendTitle(PlotPlayer player, String head, String sub, ChatColor head_color, ChatColor sub_color) { + public static void sendTitle(PlotPlayer player, String head, String sub) { if (TITLE_CLASS != null && !player.getAttribute("disabletitles")) { - TITLE_CLASS.sendTitle(player, head, sub, head_color, sub_color, 1, 2, 1); + TITLE_CLASS.sendTitle(player, head, sub, 1, 2, 1); } } - public abstract void sendTitle(PlotPlayer player, String head, String sub, ChatColor head_color, ChatColor sub_color, int in, int delay, int out); + public abstract void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out); } diff --git a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle.java b/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle.java index a34464ccf..a4defce63 100644 --- a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle.java +++ b/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle.java @@ -6,15 +6,13 @@ import org.bukkit.ChatColor; public class DefaultTitle extends AbstractTitle { @Override - public void sendTitle(final PlotPlayer player, final String head, final String sub, final ChatColor head_color, final ChatColor sub_color, int in, int delay, int out) { + public void sendTitle(final PlotPlayer player, final String head, final String sub, int in, int delay, int out) { try { final DefaultTitleManager title = new DefaultTitleManager(head, sub, in, delay, out); - title.setTitleColor(head_color); - title.setSubtitleColor(sub_color); title.send(((BukkitPlayer) player).player); } catch (final Throwable e) { AbstractTitle.TITLE_CLASS = new DefaultTitle_183(); - AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, head_color, sub_color, in, delay, out); + AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out); } } } diff --git a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle_183.java b/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle_183.java index ebfb09eee..9e412eff4 100644 --- a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle_183.java +++ b/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle_183.java @@ -6,15 +6,13 @@ import org.bukkit.ChatColor; public class DefaultTitle_183 extends AbstractTitle { @Override - public void sendTitle(final PlotPlayer player, final String head, final String sub, final ChatColor head_color, final ChatColor sub_color, int in, int delay, int out) { + public void sendTitle(final PlotPlayer player, final String head, final String sub, int in, int delay, int out) { try { final DefaultTitleManager_183 title = new DefaultTitleManager_183(head, sub, in, delay, out); - title.setTitleColor(head_color); - title.setSubtitleColor(sub_color); title.send(((BukkitPlayer) player).player); } catch (final Throwable e) { AbstractTitle.TITLE_CLASS = new HackTitle(); - AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, head_color, sub_color, in, delay, out); + AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out); } } } diff --git a/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java b/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java index 00c717914..f4defdaf1 100644 --- a/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java +++ b/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java @@ -8,11 +8,9 @@ import org.bukkit.ChatColor; public class HackTitle extends AbstractTitle { @Override - public void sendTitle(final PlotPlayer player, final String head, final String sub, final ChatColor head_color, final ChatColor sub_color, int in, int delay, int out) { + public void sendTitle(final PlotPlayer player, final String head, final String sub, int in, int delay, int out) { try { final HackTitleManager title = new HackTitleManager(head, sub, in, delay, out); - title.setTitleColor(head_color); - title.setSubtitleColor(sub_color); title.send(((BukkitPlayer) player).player); } catch (final Throwable e) { PS.log("&cYour server version does not support titles!"); diff --git a/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitSetupUtils.java b/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitSetupUtils.java index f80a64371..a050febe2 100644 --- a/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitSetupUtils.java +++ b/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitSetupUtils.java @@ -2,10 +2,13 @@ package com.plotsquared.bukkit.util.bukkit; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.ConfigurationNode; +import com.intellectualcrafters.plot.generator.PlotGenerator; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.SetupObject; +import com.intellectualcrafters.plot.util.SetupUtils; +import com.plotsquared.bukkit.generator.BukkitGeneratorWrapper; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; -import com.plotsquared.bukkit.util.SetupUtils; + import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.World.Environment; @@ -32,7 +35,7 @@ public class BukkitSetupUtils extends SetupUtils { final String name = plugin.getDescription().getName(); // final PlotGenerator pgen = (PlotGenerator) generator; // if (pgen.getPlotManager() instanceof SquarePlotManager) { - SetupUtils.generators.put(name, generator); + SetupUtils.generators.put(name, new BukkitGeneratorWrapper("CheckingPlotSquaredGenerator", generator)); // } // } } @@ -55,8 +58,8 @@ public class BukkitSetupUtils extends SetupUtils { if (object.setupGenerator != null && !object.setupGenerator.equals(object.plotManager)) { PS.get().config.set("worlds." + world + "." + "generator.init", object.setupGenerator); } - ChunkGenerator gen = generators.get(object.setupGenerator); - if (gen instanceof BukkitPlotGenerator) { + PlotGenerator gen = (PlotGenerator) generators.get(object.setupGenerator); + if (gen.generator instanceof BukkitPlotGenerator) { object.setupGenerator = null; } } @@ -105,8 +108,8 @@ public class BukkitSetupUtils extends SetupUtils { if (!(generator instanceof BukkitPlotGenerator)) { return null; } - for (Entry entry : generators.entrySet()) { - if (entry.getValue().getClass().getName().equals(generator.getClass().getName())) { + for (Entry> entry : generators.entrySet()) { + if (entry.getValue().generator.getClass().getName().equals(generator.getClass().getName())) { return entry.getKey(); } } diff --git a/src/main/java/com/plotsquared/bukkit/util/bukkit/SetGenCB.java b/src/main/java/com/plotsquared/bukkit/util/bukkit/SetGenCB.java index 24cca00b9..658438f93 100644 --- a/src/main/java/com/plotsquared/bukkit/util/bukkit/SetGenCB.java +++ b/src/main/java/com/plotsquared/bukkit/util/bukkit/SetGenCB.java @@ -1,8 +1,10 @@ package com.plotsquared.bukkit.util.bukkit; import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.generator.PlotGenerator; +import com.intellectualcrafters.plot.util.SetupUtils; import com.plotsquared.bukkit.generator.AugmentedPopulator; -import com.plotsquared.bukkit.util.SetupUtils; + import org.bukkit.World; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; @@ -22,7 +24,8 @@ public class SetGenCB { } String name = gen.getClass().getCanonicalName(); boolean set = false; - for (ChunkGenerator newGen : SetupUtils.generators.values()) { + for (PlotGenerator wrapper : SetupUtils.generators.values()) { + ChunkGenerator newGen = (ChunkGenerator) wrapper.generator; if (newGen.getClass().getCanonicalName().equals(name)) { // set generator Field generator = world.getClass().getDeclaredField("generator"); diff --git a/src/main/java/com/plotsquared/bukkit/listeners/APlotListener.java b/src/main/java/com/plotsquared/listener/APlotListener.java similarity index 89% rename from src/main/java/com/plotsquared/bukkit/listeners/APlotListener.java rename to src/main/java/com/plotsquared/listener/APlotListener.java index f43a30e51..11d616914 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/APlotListener.java +++ b/src/main/java/com/plotsquared/listener/APlotListener.java @@ -1,4 +1,4 @@ -package com.plotsquared.bukkit.listeners; +package com.plotsquared.listener; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; diff --git a/src/main/java/com/plotsquared/sponge/SpongeGeneratorWrapper.java b/src/main/java/com/plotsquared/sponge/SpongeGeneratorWrapper.java index 706f9e354..799530771 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeGeneratorWrapper.java +++ b/src/main/java/com/plotsquared/sponge/SpongeGeneratorWrapper.java @@ -4,6 +4,8 @@ import com.intellectualcrafters.plot.generator.PlotGenerator; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.SetupObject; + import org.spongepowered.api.world.gen.WorldGenerator; public class SpongeGeneratorWrapper extends PlotGenerator{ @@ -54,5 +56,10 @@ public class SpongeGeneratorWrapper extends PlotGenerator{ // TODO Auto-generated method stub return null; } + + @Override + public void processSetup(SetupObject object) { + // TODO Auto-generated method stub + } } diff --git a/src/main/java/com/plotsquared/sponge/SpongeLowerOfflineUUIDWrapper.java b/src/main/java/com/plotsquared/sponge/SpongeLowerOfflineUUIDWrapper.java new file mode 100644 index 000000000..9456e32b8 --- /dev/null +++ b/src/main/java/com/plotsquared/sponge/SpongeLowerOfflineUUIDWrapper.java @@ -0,0 +1,93 @@ +package com.plotsquared.sponge; + +import java.util.UUID; +import java.util.concurrent.ExecutionException; + +import org.spongepowered.api.GameProfile; +import org.spongepowered.api.entity.player.Player; +import org.spongepowered.api.service.profile.GameProfileResolver; + +import com.google.common.base.Charsets; +import com.google.inject.Inject; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDWrapper; + +public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper { + + public SpongeLowerOfflineUUIDWrapper() { + // Anything? + } + + @Override + public UUID getUUID(final PlotPlayer player) { + return getUUID(player.getName()); + } + + @Override + public UUID getUUID(final OfflinePlotPlayer player) { + return getUUID(player.getName()); + } + + @Override + public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) { + String name = UUIDHandler.getName(uuid); + if (name == null) { + try { + GameProfile profile = SpongeMain.THIS.getResolver().get(uuid).get(); + if (profile != null) { + name = profile.getName(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + if (name == null) { + for (GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) { + if (getUUID(profile.getName()).equals(uuid)) { + name = profile.getName(); + break; + } + } + } + final String username = name; + return new OfflinePlotPlayer() { + @Override + public boolean isOnline() { + return UUIDHandler.getPlayer(uuid) != null; + } + + @Override + public UUID getUUID() { + return uuid; + } + + @Override + public String getName() { + return username; + } + + @Override + public long getLastPlayed() { + // TODO FIXME + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); + } + }; + } + + public Player[] getOnlinePlayers() { + return SpongeMain.THIS.getServer().getOnlinePlayers().toArray(new Player[0]); + } + + @Override + public UUID getUUID(final String name) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8)); + } + + @Override + public OfflinePlotPlayer[] getOfflinePlayers() { + // TODO FIXME + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); + } +} diff --git a/src/main/java/com/plotsquared/sponge/SpongeMain.java b/src/main/java/com/plotsquared/sponge/SpongeMain.java index a56dcb6af..91006215f 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -9,11 +9,13 @@ import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.*; -import com.plotsquared.bukkit.listeners.APlotListener; -import com.plotsquared.bukkit.util.SetupUtils; +import com.intellectualcrafters.plot.uuid.UUIDWrapper; +import com.plotsquared.listener.APlotListener; import org.slf4j.Logger; import org.spongepowered.api.Game; +import org.spongepowered.api.GameRegistry; +import org.spongepowered.api.MinecraftVersion; import org.spongepowered.api.Server; import org.spongepowered.api.entity.player.Player; import org.spongepowered.api.entity.player.gamemode.GameModes; @@ -23,6 +25,7 @@ import org.spongepowered.api.event.state.PreInitializationEvent; import org.spongepowered.api.event.state.ServerAboutToStartEvent; import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.PluginContainer; +import org.spongepowered.api.service.profile.GameProfileResolver; import org.spongepowered.api.world.DimensionTypes; import org.spongepowered.api.world.GeneratorTypes; import org.spongepowered.api.world.World; @@ -43,7 +46,33 @@ public class SpongeMain implements IPlotMain, PluginContainer { @Inject private Game game; private Server server; + private GameProfileResolver resolver; + private WorldModify modify; + + private Object plugin; + + // stuff // + public Logger getLogger() { + return logger; + } + + public Game getGame() { + return game; + } + + public Server getServer() { + return server; + } + + public GameProfileResolver getResolver() { + return resolver; + } + + public Object getPlugin() { + return this.plugin; + } + ///////// ////////////////////// SPONGE PLUGIN REGISTRATION //////////////////// @Override @@ -84,27 +113,18 @@ public class SpongeMain implements IPlotMain, PluginContainer { public void onServerAboutToStart(ServerAboutToStartEvent event) { log("INIT"); THIS = this; - PS.instance = new PS(this); - // Setup metrics - if (Settings.METRICS) { - try { - final SpongeMetrics metrics = new SpongeMetrics(game, this); - metrics.start(); - log(C.PREFIX.s() + "&6Metrics enabled."); - } catch (final Exception e) { - log(C.PREFIX.s() + "&cFailed to load up metrics."); - } - } else { - log("&dUsing metrics will allow us to improve the plugin, please consider it :)"); - } + // resolver + resolver = game.getServiceManager().provide(GameProfileResolver.class).get(); + plugin = game.getPluginManager().getPlugin("PlotSquared").get().getInstance(); + + PS.instance = new PS(this); // Set the generators for each world... server = game.getServer(); Collection worlds = server.getWorlds(); if (worlds.size() > 0) { log("INJECTING WORLDS!!!!!!!"); - UUIDHandler.startCaching(null); for (World world : server.getWorlds()) { log("INJECTING WORLD: " + world.getName()); world.setWorldGenerator(new SpongePlotGenerator(world.getName())); @@ -112,31 +132,25 @@ public class SpongeMain implements IPlotMain, PluginContainer { } ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds"); - for (String world : worldSection.getKeys(false)) { - this.modify = new WorldModify(this); - Game game = event.getGame(); - game.getRegistry().registerWorldGeneratorModifier(modify); - game.getRegistry().getWorldBuilder() - .name(world) - .enabled(true) - .loadsOnStartup(true) - .keepsSpawnLoaded(true) - .dimensionType(DimensionTypes.OVERWORLD) - .generator(GeneratorTypes.DEBUG) - .gameMode(GameModes.CREATIVE) - .generatorModifiers(modify) - .build(); + if (worldSection != null) { + for (String world : worldSection.getKeys(false)) { + this.modify = new WorldModify(this); + Game game = event.getGame(); + game.getRegistry().registerWorldGeneratorModifier(modify); + game.getRegistry().getWorldBuilder() + .name(world) + .enabled(true) + .loadsOnStartup(true) + .keepsSpawnLoaded(true) + .dimensionType(DimensionTypes.OVERWORLD) + .generator(GeneratorTypes.DEBUG) + .gameMode(GameModes.CREATIVE) + .generatorModifiers(modify) + .build(); + } } } - public Logger getLogger() { - return logger; - } - - public Game getGame() { - return game; - } - @Subscribe public void onPlayerChat(PlayerChatEvent event) { // This is how events sort of work? @@ -163,68 +177,72 @@ public class SpongeMain implements IPlotMain, PluginContainer { @Override public int[] getPluginVersion() { - // TODO Auto-generated method stub - return null; + PluginContainer plugin = game.getPluginManager().getPlugin("PlotSquared").get(); + String version = plugin.getVersion(); + log("Checking plugin version: PlotSquared: "); + String[] split = version.split("\\."); + return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 }; } @Override public int[] getServerVersion() { - // TODO Auto-generated method stub - return null; + log("Checking minecraft version: Sponge: "); + String version = game.getPlatform().getMinecraftVersion().getName(); + String[] split = version.split("\\."); + return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 }; } @Override public TaskManager getTaskManager() { - // TODO Auto-generated method stub - return null; + return new SpongeTaskManager(); } @Override public void runEntityTask() { // TODO Auto-generated method stub - + log("runEntityTask is not implemented!"); } @Override public void registerCommands() { // TODO Auto-generated method stub - + log("registerCommands is not implemented!"); } @Override public void registerPlayerEvents() { // TODO Auto-generated method stub - + log("registerPlayerEvents is not implemented!"); } @Override public void registerInventoryEvents() { // TODO Auto-generated method stub - + log("registerInventoryEvents is not implemented!"); } @Override public void registerPlotPlusEvents() { // TODO Auto-generated method stub - + log("registerPlotPlusEvents is not implemented!"); } @Override public void registerForceFieldEvents() { // TODO Auto-generated method stub - + log("registerForceFieldEvents is not implemented!"); } @Override public void registerWorldEditEvents() { // TODO Auto-generated method stub - + log("registerWorldEditEvents is not implemented!"); } @Override public void registerTNTListener() { // TODO Auto-generated method stub - + log("registerTNTListener is not implemented!"); } @Override @@ -265,8 +283,14 @@ public class SpongeMain implements IPlotMain, PluginContainer { @Override public UUIDHandlerImplementation initUUIDHandler() { - // TODO Auto-generated method stub - return null; + UUIDWrapper wrapper; + if (Settings.OFFLINE_MODE || !PS.get().checkVersion(this.getServerVersion(), 1, 7, 6)) { + wrapper = new SpongeLowerOfflineUUIDWrapper(); + } + else { + wrapper = new SpongeOnlineUUIDWrapper(); + } + return new SpongeUUIDHandler(wrapper); } @Override @@ -319,14 +343,19 @@ public class SpongeMain implements IPlotMain, PluginContainer { @Override public String getServerName() { - // TODO Auto-generated method stub - return null; + // TODO FIXME + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } @Override public void startMetrics() { - // TODO Auto-generated method stub - + try { + final SpongeMetrics metrics = new SpongeMetrics(game, this); + metrics.start(); + log(C.PREFIX.s() + "&6Metrics enabled."); + } catch (final Exception e) { + log(C.PREFIX.s() + "&cFailed to load up metrics."); + } } @Override diff --git a/src/main/java/com/plotsquared/sponge/SpongeOnlineUUIDWrapper.java b/src/main/java/com/plotsquared/sponge/SpongeOnlineUUIDWrapper.java new file mode 100644 index 000000000..94915fb58 --- /dev/null +++ b/src/main/java/com/plotsquared/sponge/SpongeOnlineUUIDWrapper.java @@ -0,0 +1,72 @@ +package com.plotsquared.sponge; + +import java.util.UUID; +import java.util.concurrent.ExecutionException; + +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDWrapper; + +public class SpongeOnlineUUIDWrapper extends UUIDWrapper { + + @Override + public UUID getUUID(PlotPlayer player) { + return ((SpongePlayer) player).player.getUniqueId(); + } + + @Override + public UUID getUUID(OfflinePlotPlayer player) { + return player.getUUID(); + } + + @Override + public UUID getUUID(String name) { + try { + return SpongeMain.THIS.getResolver().get(name, true).get().getUniqueId(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + @Override + public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) { + String name; + try { + name = SpongeMain.THIS.getResolver().get(uuid, true).get().getName(); + } + catch (Exception e) { + name = null; + } + final String username = name; + return new OfflinePlotPlayer() { + @Override + public boolean isOnline() { + return UUIDHandler.getPlayer(uuid) != null; + } + + @Override + public UUID getUUID() { + return uuid; + } + + @Override + public String getName() { + return username; + } + + @Override + public long getLastPlayed() { + // TODO FIXME + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); + } + }; + } + + @Override + public OfflinePlotPlayer[] getOfflinePlayers() { + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); + } + +} diff --git a/src/main/java/com/plotsquared/sponge/SpongePlayer.java b/src/main/java/com/plotsquared/sponge/SpongePlayer.java new file mode 100644 index 000000000..5c9f2289d --- /dev/null +++ b/src/main/java/com/plotsquared/sponge/SpongePlayer.java @@ -0,0 +1,205 @@ +package com.plotsquared.sponge; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionDefault; +import org.spongepowered.api.entity.player.Player; +import org.spongepowered.api.text.chat.ChatTypes; + +import com.flowpowered.math.vector.Vector3d; +import com.intellectualcrafters.plot.commands.RequiredType; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.EconHandler; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.UUIDHandler; + +public class SpongePlayer implements PlotPlayer { + + public final Player player; + private UUID uuid; + private String name; + private int op = 0; + private long last = 0; + private HashSet hasPerm = new HashSet<>(); + private HashSet noPerm = new HashSet<>(); + + private HashMap meta; + + public SpongePlayer(Player player) { + this.player = player; + } + + @Override + public void sendMessage(C c, String... args) { + MainUtil.sendMessage(this, c, args); + } + + @Override + public RequiredType getSuperCaller() { + return RequiredType.PLAYER; + } + + @Override + public long getPreviousLogin() { + return (long) (player.getJoinData().getLastPlayed().getSeconds()) * 1000; + } + + @Override + public Location getLocation() { + return SpongeUtil.getLocation(player); + } + + @Override + public Location getLocationFull() { + return SpongeUtil.getLocationFull(player); + } + + @Override + public UUID getUUID() { + if (this.uuid == null) { + this.uuid = UUIDHandler.getUUID(this); + } + return uuid; + } + + @Override + public boolean hasPermission(String perm) { + if (Settings.PERMISSION_CACHING) { + if (this.noPerm.contains(perm)) { + return false; + } + if (this.hasPerm.contains(perm)) { + return true; + } + final boolean result = this.player.hasPermission(perm); + if (!result) { + this.noPerm.add(perm); + return false; + } + this.hasPerm.add(perm); + return true; + } + return this.player.hasPermission(perm); + } + + @Override + public void sendMessage(String message) { + player.sendMessage(ChatTypes.CHAT, message); + } + + @Override + public void teleport(Location loc) { + String world = player.getWorld().getName(); + if (world != loc.getWorld()) { + player.transferToWorld(world, new Vector3d(loc.getX(), loc.getY(), loc.getZ())); + } + else { + org.spongepowered.api.world.Location current = player.getLocation(); + player.setLocationSafely(current.setPosition(new Vector3d(loc.getX(), loc.getY(), loc.getZ()))); + } + } + + @Override + public boolean isOp() { + if (this.op != 0) { + return this.op != 1; + } + final boolean result = this.player.hasPermission("*"); + if (!result) { + this.op = 1; + return false; + } + this.op = 2; + return true; + } + + @Override + public boolean isOnline() { + return player.isOnline(); + } + + @Override + public String getName() { + if (this.name == null) { + this.name = this.player.getName(); + } + return this.name; + } + + @Override + public void setCompassTarget(Location loc) { + // TODO set compass target + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); + } + + @Override + public void loadData() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); + } + + @Override + public void saveData() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); + } + + @Override + public void setMeta(String key, Object value) { + if (this.meta == null) { + this.meta = new HashMap(); + } + this.meta.put(key, value); + } + + @Override + public Object getMeta(String key) { + if (this.meta != null) { + return this.meta.get(key); + } + return null; + } + + @Override + public void deleteMeta(String key) { + if (this.meta != null) { + this.meta.remove(key); + } + } + + @Override + public String toString() { + return getName(); + } + + @Override + public void setAttribute(String key) { + key = "plotsquared_user_attributes." + key; + EconHandler.manager.setPermission(this, key, true); + } + + @Override + public boolean getAttribute(String key) { + key = "plotsquared_user_attributes." + key; + Permission perm = Bukkit.getServer().getPluginManager().getPermission(key); + if (perm == null) { + perm = new Permission(key, PermissionDefault.FALSE); + Bukkit.getServer().getPluginManager().addPermission(perm); + Bukkit.getServer().getPluginManager().recalculatePermissionDefaults(perm); + } + return player.hasPermission(key); + } + + @Override + public void removeAttribute(String key) { + key = "plotsquared_user_attributes." + key; + EconHandler.manager.setPermission(this, key, false); + } +} diff --git a/src/main/java/com/plotsquared/sponge/SpongeTaskManager.java b/src/main/java/com/plotsquared/sponge/SpongeTaskManager.java new file mode 100644 index 000000000..c12e4c30d --- /dev/null +++ b/src/main/java/com/plotsquared/sponge/SpongeTaskManager.java @@ -0,0 +1,59 @@ +package com.plotsquared.sponge; + +import java.util.HashMap; +import java.util.concurrent.atomic.AtomicInteger; + +import org.spongepowered.api.service.scheduler.Task; +import org.spongepowered.api.service.scheduler.TaskBuilder; + +import com.intellectualcrafters.plot.util.TaskManager; + +public class SpongeTaskManager extends TaskManager { + + private AtomicInteger i = new AtomicInteger(); + + private HashMap tasks = new HashMap<>(); + + @Override + public int taskRepeat(Runnable r, int interval) { + int val = i.incrementAndGet(); + TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); + TaskBuilder built = builder.delay(interval).interval(interval).execute(r); + Task task = built.submit(SpongeMain.THIS.getPlugin()); + tasks.put(val, task); + return val; + } + + @Override + public void taskAsync(Runnable r) { + TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); + builder.async().execute(r); + } + + @Override + public void task(Runnable r) { + TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); + builder.execute(r); + } + + @Override + public void taskLater(Runnable r, int delay) { + TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); + builder.delay(delay).execute(r); + } + + @Override + public void taskLaterAsync(Runnable r, int delay) { + TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); + builder.async().delay(delay).execute(r); + } + + @Override + public void cancelTask(int i) { + Task task = tasks.remove(i); + if (task != null) { + task.cancel(); + } + } + +} diff --git a/src/main/java/com/plotsquared/sponge/SpongeUUIDHandler.java b/src/main/java/com/plotsquared/sponge/SpongeUUIDHandler.java new file mode 100644 index 000000000..9a5b9c7d3 --- /dev/null +++ b/src/main/java/com/plotsquared/sponge/SpongeUUIDHandler.java @@ -0,0 +1,53 @@ +package com.plotsquared.sponge; + +import java.util.Collection; +import java.util.UUID; + +import org.spongepowered.api.GameProfile; +import org.spongepowered.api.service.profile.GameProfileResolver; + +import com.google.inject.Inject; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; +import com.intellectualcrafters.plot.uuid.UUIDWrapper; + +public class SpongeUUIDHandler extends UUIDHandlerImplementation { + + public SpongeUUIDHandler(UUIDWrapper wrapper) { + super(wrapper); + // TODO Auto-generated constructor stub + } + + @Override + public boolean startCaching(Runnable whenDone) { + if (!super.startCaching(whenDone)) { + return false; + } + return cache(whenDone); + } + + public boolean cache(Runnable whenDone) { + // TODO cache UUIDS +// SpongeMain.THIS.getRegistry().get + add(new StringWrapper("*"), DBFunc.everyone); + for (GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) { + add(new StringWrapper(profile.getName()), profile.getUniqueId()); + } + return true; + } + + @Override + public void fetchUUID(final String name, final RunnableVal ifFetch) { + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + ifFetch.value = uuidWrapper.getUUID(name); + TaskManager.runTask(ifFetch); + } + }); + } + +} diff --git a/src/main/java/com/plotsquared/sponge/SpongeUtil.java b/src/main/java/com/plotsquared/sponge/SpongeUtil.java new file mode 100644 index 000000000..615a1a9fc --- /dev/null +++ b/src/main/java/com/plotsquared/sponge/SpongeUtil.java @@ -0,0 +1,28 @@ +package com.plotsquared.sponge; + +import org.spongepowered.api.entity.Entity; + +import com.flowpowered.math.vector.Vector3d; +import com.flowpowered.math.vector.Vector3i; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.util.MathMan; + +public class SpongeUtil { + + public static Location getLocation(Entity player) { + String world = player.getWorld().getName(); + org.spongepowered.api.world.Location loc = player.getLocation(); + Vector3i pos = loc.getBlockPosition(); + return new Location(world, pos.getX(), pos.getY(), pos.getZ()); + } + + public static Location getLocationFull(Entity player) { + String world = player.getWorld().getName(); + Vector3d rot = player.getRotation(); + float[] pitchYaw = MathMan.getPitchAndYaw((float) rot.getX(), (float) rot.getY(), (float) rot.getZ()); + org.spongepowered.api.world.Location loc = player.getLocation(); + Vector3i pos = loc.getBlockPosition(); + return new Location(world, pos.getX(), pos.getY(), pos.getZ(), pitchYaw[1], pitchYaw[0]); + } + +}