From 1837a9a247ccb6c9cd4cafc9469bf2aea940e3a8 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 19 Jan 2015 21:36:29 -0800 Subject: [PATCH] worldborder + offline player conversion --- .../plot/commands/Helpers.java | 3 +-- .../plot/commands/plugin.java | 4 ++-- .../plot/database/PlotMeConverter.java | 18 ++++++++++++++++-- .../plot/listeners/PlayerEvents.java | 2 +- .../plot/util/PlotHelper.java | 9 ++++++--- .../plot/util/UUIDHandler.java | 5 +++-- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java index 05378be1a..791c09720 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java @@ -24,7 +24,6 @@ package com.intellectualcrafters.plot.commands; import java.util.UUID; import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import com.intellectualcrafters.plot.PlotMain; @@ -35,7 +34,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.UUIDHandler; -@SuppressWarnings("deprecation") public class Helpers extends SubCommand { +public class Helpers extends SubCommand { public Helpers() { super(Command.HELPERS, "Manage plot helpers", "helpers {add|remove} {player}", CommandCategory.ACTIONS, true); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java index 1228a1805..b569d6368 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java @@ -39,7 +39,7 @@ public class plugin extends SubCommand { public static String downloads, version; public plugin() { - super("plugin", "plots.use", "Show plugin information", "plugin", "pl", CommandCategory.INFO, false); + super("plugin", "plots.use", "Show plugin information", "plugin", "version", CommandCategory.INFO, false); } public static void setup(final JavaPlugin plugin) { @@ -99,7 +99,7 @@ public class plugin extends SubCommand { { add(String.format("&c>> &6PlotSquared (Version: %s)", PlotMain.getMain().getDescription().getVersion())); add(String.format("&c>> &6Made by Citymonstret and Empire92")); - add(String.format("&c>> &6Download at &lhttp://i-s.link/ps")); + add(String.format("&c>> &6Download at &lhttp://www.spigotmc.org/resources/1177")); add(String.format("&c>> &cNewest Version (Spigot): %s", version)); add(String.format("&c>> &cTotal Downloads (Spigot): %s", downloads)); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java index ad28b7131..1f12a45a2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java @@ -23,6 +23,7 @@ package com.intellectualcrafters.plot.database; import java.io.File; import java.io.IOException; +import java.nio.ByteBuffer; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -119,8 +120,15 @@ public class PlotMeConverter { if (name.equals("*")) { owner = DBFunc.everyone; } else { - sendMessage("&cCould not identify owner for plot: " + id); - continue; + try { + UUID uuid = uuidFromBytes(r.getBytes("ownerId")); + owner = UUIDHandler.getUUID(UUIDHandler.getName(uuid)); + } + catch (Exception e) {} + if (owner == null) { + sendMessage("&cCould not identify owner for plot: " + id +" -> " + name); + continue; + } } } final Plot plot = new Plot(id, owner, new ArrayList(), new ArrayList(), world); @@ -311,4 +319,10 @@ public class PlotMeConverter { } }, 20); } + private UUID uuidFromBytes(byte[] byteArray) { + ByteBuffer wrapped = ByteBuffer.wrap(byteArray); + long minor = wrapped.getLong(); + long major = wrapped.getLong(); + return new UUID(major, minor); + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 52819307e..3969f23f1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -138,7 +138,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } String worldname = q.getWorld().getName(); if (PlotHelper.worldBorder.containsKey(worldname)) { - int border = PlotHelper.worldBorder.get(worldname); + int border = PlotHelper.getBorder(worldname); boolean passed = false; if (t.getBlockX() >= border) { q.setX(border); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java index 8fdb4138c..a7a8db302 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java @@ -67,10 +67,10 @@ import com.intellectualcrafters.plot.object.PlotWorld; public static HashMap lastPlot = new HashMap<>(); public static HashMap worldBorder = new HashMap<>(); - public static int getBorder(World world) { - String worldname = world.getName(); + public static int getBorder(String worldname) { if (worldBorder.containsKey(worldname)) { - return worldBorder.get(worldname); + PlotWorld plotworld = PlotMain.getWorldSettings(worldname); + return worldBorder.get(worldname) + 16; } return Integer.MAX_VALUE; } @@ -80,6 +80,9 @@ import com.intellectualcrafters.plot.object.PlotWorld; if (!plotworld.WORLD_BORDER) { return; } + if (!worldBorder.containsKey(world)) { + worldBorder.put(world,0); + } for (Plot plot : PlotMain.getPlots(world).values()) { updateWorldBorder(plot); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java index 64a23aa2d..0f828919a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java @@ -17,6 +17,7 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; +import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper; public class UUIDHandler { @@ -203,8 +204,8 @@ public class UUIDHandler { return uuid; } - // Read from disk - if (Settings.UUID_FROM_DISK) { + // Read from disk OR convert directly to offline UUID + if (Settings.UUID_FROM_DISK || uuidWrapper instanceof OfflineUUIDWrapper) { OfflinePlayer op = Bukkit.getOfflinePlayer(name); uuid = UUIDHandler.uuidWrapper.getUUID(op); add(new StringWrapper(name), uuid);