diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index 0b052417a..3859a2c9a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -42,8 +42,10 @@ import com.intellectualcrafters.plot.uuid.PlotUUIDSaver; import com.intellectualcrafters.plot.uuid.UUIDSaver; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; + import me.confuser.barapi.BarAPI; import net.milkbowl.vault.economy.Economy; + import org.bukkit.*; import org.bukkit.command.PluginCommand; import org.bukkit.configuration.file.YamlConfiguration; @@ -338,7 +340,7 @@ public class PlotMain extends JavaPlugin { * @return Set Containing the players plots */ public static Set getPlots(final Player player) { - final UUID uuid = player.getUniqueId(); + final UUID uuid = UUIDHandler.getUUID(player); final ArrayList myplots = new ArrayList<>(); for (final HashMap world : plots.values()) { for (final Plot plot : world.values()) { @@ -358,7 +360,7 @@ public class PlotMain extends JavaPlugin { * @return players plots */ public static Set getPlots(final World world, final Player player) { - final UUID uuid = player.getUniqueId(); + final UUID uuid = UUIDHandler.getUUID(player); final ArrayList myplots = new ArrayList<>(); for (final Plot plot : getPlots(world).values()) { if (plot.hasOwner()) { @@ -912,7 +914,10 @@ public class PlotMain extends JavaPlugin { final int config_ver = 1; config.set("version", config_ver); final Map options = new HashMap<>(); + options.put("auto_update", false); + + options.put("UUID.offline", Settings.OFFLINE_MODE); options.put("worldguard.enabled", Settings.WORLDGUARD); options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT); options.put("mob_pathfinding", Settings.MOB_PATHFINDING_DEFAULT); @@ -953,6 +958,8 @@ public class PlotMain extends JavaPlugin { Settings.MAX_PLOTS = config.getInt("max_plots"); Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path"); + Settings.OFFLINE_MODE = config.getBoolean("UUID.offline"); + Settings.REQUIRE_SELECTION = config.getBoolean("worldedit.require-selection-in-mask"); } @@ -1597,6 +1604,9 @@ public class PlotMain extends JavaPlugin { } // Handle UUIDS { + if (Settings.OFFLINE_MODE) { + UUIDHandler.uuidWrapper = new OfflineUUIDWrapper(); + } setUUIDSaver(new PlotUUIDSaver()); // Looks really cool xD getUUIDSaver().globalPopulate(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java index a5171abeb..f6942c455 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -35,7 +35,9 @@ import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.PlotSquaredException; import com.intellectualcrafters.plot.util.SchematicHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.sun.istack.internal.NotNull; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -420,7 +422,7 @@ public class PlotAPI { final ArrayList pPlots = new ArrayList<>(); for (final Plot plot : PlotMain.getPlots(world).values()) { if (just_owner) { - if ((plot.owner != null) && (plot.owner == plr.getUniqueId())) { + if ((plot.owner != null) && (plot.owner == UUIDHandler.getUUID(plr))) { pPlots.add(plot); } } else { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index 2a904e1c4..48acfb101 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -27,6 +27,8 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; +import com.intellectualcrafters.plot.util.UUIDHandler; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -71,7 +73,7 @@ public class Clear extends SubCommand { if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { return sendMessage(plr, C.UNLINK_REQUIRED); } - if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !PlotMain.hasPermission(plr, "plots.admin")) { + if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !PlotMain.hasPermission(plr, "plots.admin")) { return sendMessage(plr, C.NO_PLOT_PERMS); } assert plot != null; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java index 9b7cb8dd4..ff2adc280 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java @@ -41,7 +41,7 @@ public class SetOwner extends SubCommand { /* * private UUID getUUID(String string) { OfflinePlayer player = * Bukkit.getOfflinePlayer(string); return ((player != null) && - * player.hasPlayedBefore()) ? player.getUniqueId() : null; } + * player.hasPlayedBefore()) ? UUIDHandler.getUUID(player) : null; } */ private UUID getUUID(final String string) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java index a8be141cb..85905c745 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -114,7 +114,11 @@ public class Settings { * Use the custom API */ public static boolean CUSTOM_API = true; - + + /** + * Use offline mode storage + */ + public static boolean OFFLINE_MODE = false; /** * Database settings * diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 114edfd27..177d188b9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -30,6 +30,8 @@ import com.intellectualcrafters.plot.object.PlotHomePosition; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.Logger; import com.intellectualcrafters.plot.util.Logger.LogLevel; +import com.intellectualcrafters.plot.util.UUIDHandler; + import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -1009,7 +1011,7 @@ public class SQLManager implements AbstractDB { try { final PreparedStatement statement = connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); statement.setInt(1, getId(world, plot.id)); - statement.setString(2, player.getUniqueId().toString()); + statement.setString(2, UUIDHandler.getUUID(player).toString()); statement.executeUpdate(); statement.close(); } catch (final SQLException e) { @@ -1032,7 +1034,7 @@ public class SQLManager implements AbstractDB { try { final PreparedStatement statement = connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); statement.setInt(1, getId(world, plot.id)); - statement.setString(2, player.getUniqueId().toString()); + statement.setString(2, UUIDHandler.getUUID(player).toString()); statement.executeUpdate(); statement.close(); } catch (final SQLException e) { @@ -1055,7 +1057,7 @@ public class SQLManager implements AbstractDB { try { final PreparedStatement statement = connection.prepareStatement("INSERT INTO `" + prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); statement.setInt(1, getId(world, plot.id)); - statement.setString(2, player.getUniqueId().toString()); + statement.setString(2, UUIDHandler.getUUID(player).toString()); statement.executeUpdate(); statement.close(); } catch (final SQLException e) { @@ -1078,7 +1080,7 @@ public class SQLManager implements AbstractDB { try { final PreparedStatement statement = connection.prepareStatement("INSERT INTO `" + prefix + "plot_trusted` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); statement.setInt(1, getId(world, plot.id)); - statement.setString(2, player.getUniqueId().toString()); + statement.setString(2, UUIDHandler.getUUID(player).toString()); statement.executeUpdate(); statement.close(); } catch (final SQLException e) { @@ -1101,7 +1103,7 @@ public class SQLManager implements AbstractDB { try { final PreparedStatement statement = connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); statement.setInt(1, getId(world, plot.id)); - statement.setString(2, player.getUniqueId().toString()); + statement.setString(2, UUIDHandler.getUUID(player).toString()); statement.executeUpdate(); statement.close(); } catch (final SQLException e) { @@ -1124,7 +1126,7 @@ public class SQLManager implements AbstractDB { try { final PreparedStatement statement = connection.prepareStatement("INSERT INTO `" + prefix + "plot_denied` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); statement.setInt(1, getId(world, plot.id)); - statement.setString(2, player.getUniqueId().toString()); + statement.setString(2, UUIDHandler.getUUID(player).toString()); statement.executeUpdate(); statement.close(); } catch (final SQLException e) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java index a6f86ff7e..daee64dfe 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java @@ -26,6 +26,8 @@ import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.UUIDHandler; + import org.bukkit.*; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -179,7 +181,7 @@ public class PlotPlusListener extends PlotListener implements Listener { if (player == null) { return; } - if (player.getUniqueId().equals(event.getPlayer().getUniqueId())) { + if (UUIDHandler.getUUID(player).equals(event.getPlayer().getUniqueId())) { return; } if (player.isOnline()) { @@ -218,7 +220,7 @@ public class PlotPlusListener extends PlotListener implements Listener { if (player == null) { return; } - if (player.getUniqueId().equals(event.getPlayer().getUniqueId())) { + if (UUIDHandler.getUUID(player).equals(event.getPlayer().getUniqueId())) { return; } if (player.isOnline()) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 0cda11786..dbea4c478 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -25,6 +25,8 @@ import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.util.PlotHelper; +import com.intellectualcrafters.plot.util.UUIDHandler; + import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.block.Biome; @@ -212,7 +214,7 @@ public class Plot implements Cloneable { * @return true if the player is added as a helper or is the owner */ public boolean hasRights(final Player player) { - return PlotMain.hasPermission(player, "plots.admin") || ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(player.getUniqueId())) || ((this.owner != null) && this.owner.equals(player.getUniqueId())) || ((this.owner != null) && (this.trusted != null) && (Bukkit.getPlayer(this.owner) != null) && (this.trusted.contains(player.getUniqueId()) || this.trusted.contains(DBFunc.everyone))); + return PlotMain.hasPermission(player, "plots.admin") || ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(UUIDHandler.getUUID(player))) || ((this.owner != null) && this.owner.equals(UUIDHandler.getUUID(player))) || ((this.owner != null) && (this.trusted != null) && (Bukkit.getPlayer(this.owner) != null) && (this.trusted.contains(UUIDHandler.getUUID(player)) || this.trusted.contains(DBFunc.everyone))); } /** @@ -222,7 +224,7 @@ public class Plot implements Cloneable { * @return false if the player is allowed to enter */ public boolean deny_entry(final Player player) { - return (this.denied != null) && ((this.denied.contains(DBFunc.everyone) && !this.hasRights(player)) || (!this.hasRights(player) && this.denied.contains(player.getUniqueId()))); + return (this.denied != null) && ((this.denied.contains(DBFunc.everyone) && !this.hasRights(player)) || (!this.hasRights(player) && this.denied.contains(UUIDHandler.getUUID(player)))); } /** @@ -238,7 +240,7 @@ public class Plot implements Cloneable { * @param player */ public void setOwner(final Player player) { - this.owner = player.getUniqueId(); + this.owner = UUIDHandler.getUUID(player); } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/DefaultUUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/DefaultUUIDWrapper.java new file mode 100644 index 000000000..30c200de6 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/DefaultUUIDWrapper.java @@ -0,0 +1,20 @@ +package com.intellectualcrafters.plot.util; + +import java.util.UUID; + +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +public class DefaultUUIDWrapper extends UUIDWrapper { + + @Override + public UUID getUUID(Player player) { + return player.getUniqueId(); + } + + @Override + public UUID getUUID(OfflinePlayer player) { + return player.getUniqueId(); + } + +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/OfflineUUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/OfflineUUIDWrapper.java new file mode 100644 index 000000000..2a4861247 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/OfflineUUIDWrapper.java @@ -0,0 +1,22 @@ +package com.intellectualcrafters.plot.util; + +import java.util.UUID; + +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.google.common.base.Charsets; + +public class OfflineUUIDWrapper extends UUIDWrapper { + + @Override + public UUID getUUID(Player player) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)); + } + + @Override + public UUID getUUID(OfflinePlayer player) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)); + } + +} 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 0627ff8d3..4ec95bcc3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java @@ -345,7 +345,7 @@ public class PlotHelper { if (plot.owner == null) { return; } - if (!plot.owner.equals(player.getUniqueId())) { + if (!plot.owner.equals(UUIDHandler.getUUID(player))) { return; } @@ -403,7 +403,7 @@ public class PlotHelper { final PlotId id_max = plots.get(plots.size() - 1); for (final PlotId myid : plots) { final Plot myplot = PlotMain.getPlots(world).get(myid); - if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(player.getUniqueId()))) { + if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(UUIDHandler.getUUID(player)))) { return false; } final PlotId top = PlayerFunctions.getTopPlot(world, myplot).id; @@ -420,7 +420,7 @@ public class PlotHelper { public static boolean createPlot(final Player player, final Plot plot) { final World w = plot.getWorld(); - final Plot p = new Plot(plot.id, player.getUniqueId(), plot.settings.getBiome(), new ArrayList(), new ArrayList(), w.getName()); + final Plot p = new Plot(plot.id, UUIDHandler.getUUID(player), plot.settings.getBiome(), new ArrayList(), new ArrayList(), w.getName()); PlotMain.updatePlot(p); DBFunc.createPlot(p); DBFunc.createPlotSettings(DBFunc.getId(w.getName(), plot.id), 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 9e6d83561..72544c39e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java @@ -62,6 +62,8 @@ import java.util.UUID; */ @SuppressWarnings("unused") public class UUIDHandler { + + public static UUIDWrapper uuidWrapper = null; /** * Online mode @@ -133,7 +135,7 @@ public class UUIDHandler { @SuppressWarnings("deprecation") final Player player = Bukkit.getPlayer(name); if (player != null) { - final UUID uuid = player.getUniqueId(); + final UUID uuid = getUUID(player); add(nameWrap, uuid); return uuid; } @@ -282,7 +284,7 @@ public class UUIDHandler { if (player == null) { return null; } - final UUID uuid = player.getUniqueId(); + final UUID uuid = getUUID(player); add(name, uuid); return uuid; } @@ -297,4 +299,30 @@ public class UUIDHandler { final UUIDSaver saver = PlotMain.getUUIDSaver(); saver.globalSave(getUuidMap()); } + + public static UUID getUUID(Player player) { + if (uuidWrapper == null) { + try { + getUUID(player); + uuidWrapper = new DefaultUUIDWrapper(); + } + catch (Throwable e) { + uuidWrapper = new OfflineUUIDWrapper(); + } + } + return uuidWrapper.getUUID(player); + } + + public static UUID getUUID(OfflinePlayer player) { + if (uuidWrapper == null) { + try { + getUUID(player); + uuidWrapper = new DefaultUUIDWrapper(); + } + catch (Throwable e) { + uuidWrapper = new OfflineUUIDWrapper(); + } + } + return uuidWrapper.getUUID(player); + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDWrapper.java new file mode 100644 index 000000000..3c09469e7 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDWrapper.java @@ -0,0 +1,12 @@ +package com.intellectualcrafters.plot.util; + +import java.util.UUID; + +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +public abstract class UUIDWrapper { + public abstract UUID getUUID(Player player); + + public abstract UUID getUUID(OfflinePlayer player); +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java index ca6653eab..235199658 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java @@ -56,7 +56,7 @@ public class PlotUUIDSaver implements UUIDSaver { String name; UUID uuid; for (final OfflinePlayer player : offlinePlayers) { - uuid = player.getUniqueId(); + uuid = UUIDHandler.getUUID(player); if (!UUIDHandler.uuidExists(uuid)) { name = player.getName(); if (name != null) {