From 4c2754d6df560e0cb9772cfabfccecc80d11c8e0 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 12 Feb 2018 00:57:59 +1100 Subject: [PATCH] Use name based UUID for the time being --- .../general/plot/PlotSquaredFeature.java | 5 +++ .../boydti/fawe/nukkit/core/NukkitPlayer.java | 10 ++--- .../fawe/nukkit/optimization/FaweNukkit.java | 42 +++++++++++++++---- .../nukkit/optimization/FaweNukkitPlayer.java | 3 +- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSquaredFeature.java b/core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSquaredFeature.java index f3f04ebf..ef28a453 100644 --- a/core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSquaredFeature.java +++ b/core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSquaredFeature.java @@ -16,6 +16,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.SchematicHandler; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.block.GlobalBlockQueue; import com.intellectualcrafters.plot.util.block.QueueProvider; import com.plotsquared.listener.WEManager; @@ -48,6 +49,10 @@ public class PlotSquaredFeature extends FaweMaskManager { } } + public static String getName(UUID uuid) { + return UUIDHandler.getName(uuid); + } + private void setupBlockQueue() { try { // If it's going to fail, throw an error now rather than later diff --git a/nukkit/src/main/java/com/boydti/fawe/nukkit/core/NukkitPlayer.java b/nukkit/src/main/java/com/boydti/fawe/nukkit/core/NukkitPlayer.java index 08f9f874..0e89c487 100644 --- a/nukkit/src/main/java/com/boydti/fawe/nukkit/core/NukkitPlayer.java +++ b/nukkit/src/main/java/com/boydti/fawe/nukkit/core/NukkitPlayer.java @@ -24,12 +24,8 @@ import cn.nukkit.Player; import cn.nukkit.inventory.PlayerInventory; import cn.nukkit.item.Item; import cn.nukkit.level.Location; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalWorld; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.WorldVector; +import com.google.common.base.Charsets; +import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.extent.inventory.BlockBag; @@ -50,7 +46,7 @@ public class NukkitPlayer extends LocalPlayer { @Override public UUID getUniqueId() { - return player.getUniqueId(); + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8)); } @Override diff --git a/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/FaweNukkit.java b/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/FaweNukkit.java index 453ae23c..91138139 100644 --- a/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/FaweNukkit.java +++ b/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/FaweNukkit.java @@ -2,6 +2,7 @@ package com.boydti.fawe.nukkit.optimization; import cn.nukkit.Nukkit; import cn.nukkit.Player; +import cn.nukkit.Server; import cn.nukkit.event.EventHandler; import cn.nukkit.event.Listener; import cn.nukkit.event.player.PlayerFormRespondedEvent; @@ -27,16 +28,13 @@ import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.brush.visualization.VisualChunk; import com.boydti.fawe.regions.FaweMaskManager; +import com.boydti.fawe.regions.general.plot.PlotSquaredFeature; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.gui.FormBuilder; +import com.google.common.base.Charsets; import com.sk89q.worldedit.world.World; import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.logging.Level; public class FaweNukkit implements IFawe, Listener { @@ -220,12 +218,42 @@ public class FaweNukkit implements IFawe, Listener { try { return UUID.fromString(name); } catch (Exception e) { - return null; + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8)); } } + private Map names = new HashMap<>(); + @Override public String getName(UUID uuid) { + try { + Class.forName("com.boydti.fawe.regions.general.plot.PlotSquaredFeature"); + String name = PlotSquaredFeature.getName(uuid); + if (name != null) return name; + } catch (Throwable ignore){ + String mapped = names.get(uuid); + if (mapped != null) return mapped; + + boolean namesEmpty = names.isEmpty(); + for (Player player : Server.getInstance().getOnlinePlayers().values()) { + String name = player.getName(); + UUID plrUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8)); + names.put(plrUUID, name); + } + + if (namesEmpty) { + for (File file : new File("players").listFiles()) { + String name = file.getName(); + name = name.substring(0, name.length() - 4); + UUID plrUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8)); + names.put(plrUUID, name); + + } + } + + mapped = names.get(uuid); + if (mapped != null) return mapped; + } return uuid.toString(); } diff --git a/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/FaweNukkitPlayer.java b/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/FaweNukkitPlayer.java index 8131b7c3..6a778519 100644 --- a/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/FaweNukkitPlayer.java +++ b/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/FaweNukkitPlayer.java @@ -9,6 +9,7 @@ import com.boydti.fawe.nukkit.core.NukkitPlatform; import com.boydti.fawe.nukkit.core.NukkitPlayer; import com.boydti.fawe.object.FaweLocation; import com.boydti.fawe.object.FawePlayer; +import com.google.common.base.Charsets; import java.util.UUID; public class FaweNukkitPlayer extends FawePlayer { @@ -26,7 +27,7 @@ public class FaweNukkitPlayer extends FawePlayer { @Override public UUID getUUID() { - return this.parent.getUniqueId(); + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + parent.getName().toLowerCase()).getBytes(Charsets.UTF_8)); } @Override