Use name based UUID for the time being

This commit is contained in:
Jesse Boyd 2018-02-12 00:57:59 +11:00
parent e1c3404b16
commit 4c2754d6df
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 45 additions and 15 deletions

View File

@ -16,6 +16,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.SchematicHandler; 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.GlobalBlockQueue;
import com.intellectualcrafters.plot.util.block.QueueProvider; import com.intellectualcrafters.plot.util.block.QueueProvider;
import com.plotsquared.listener.WEManager; 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() { private void setupBlockQueue() {
try { try {
// If it's going to fail, throw an error now rather than later // If it's going to fail, throw an error now rather than later

View File

@ -24,12 +24,8 @@ import cn.nukkit.Player;
import cn.nukkit.inventory.PlayerInventory; import cn.nukkit.inventory.PlayerInventory;
import cn.nukkit.item.Item; import cn.nukkit.item.Item;
import cn.nukkit.level.Location; import cn.nukkit.level.Location;
import com.sk89q.worldedit.EditSession; import com.google.common.base.Charsets;
import com.sk89q.worldedit.LocalPlayer; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBag;
@ -50,7 +46,7 @@ public class NukkitPlayer extends LocalPlayer {
@Override @Override
public UUID getUniqueId() { public UUID getUniqueId() {
return player.getUniqueId(); return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
} }
@Override @Override

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.nukkit.optimization;
import cn.nukkit.Nukkit; import cn.nukkit.Nukkit;
import cn.nukkit.Player; import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.event.EventHandler; import cn.nukkit.event.EventHandler;
import cn.nukkit.event.Listener; import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerFormRespondedEvent; 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.FaweQueue;
import com.boydti.fawe.object.brush.visualization.VisualChunk; import com.boydti.fawe.object.brush.visualization.VisualChunk;
import com.boydti.fawe.regions.FaweMaskManager; 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.TaskManager;
import com.boydti.fawe.util.gui.FormBuilder; import com.boydti.fawe.util.gui.FormBuilder;
import com.google.common.base.Charsets;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
public class FaweNukkit implements IFawe, Listener { public class FaweNukkit implements IFawe, Listener {
@ -220,12 +218,42 @@ public class FaweNukkit implements IFawe, Listener {
try { try {
return UUID.fromString(name); return UUID.fromString(name);
} catch (Exception e) { } catch (Exception e) {
return null; return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
} }
} }
private Map<UUID, String> names = new HashMap<>();
@Override @Override
public String getName(UUID uuid) { 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(); return uuid.toString();
} }

View File

@ -9,6 +9,7 @@ import com.boydti.fawe.nukkit.core.NukkitPlatform;
import com.boydti.fawe.nukkit.core.NukkitPlayer; import com.boydti.fawe.nukkit.core.NukkitPlayer;
import com.boydti.fawe.object.FaweLocation; import com.boydti.fawe.object.FaweLocation;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.google.common.base.Charsets;
import java.util.UUID; import java.util.UUID;
public class FaweNukkitPlayer extends FawePlayer<Player> { public class FaweNukkitPlayer extends FawePlayer<Player> {
@ -26,7 +27,7 @@ public class FaweNukkitPlayer extends FawePlayer<Player> {
@Override @Override
public UUID getUUID() { public UUID getUUID() {
return this.parent.getUniqueId(); return UUID.nameUUIDFromBytes(("OfflinePlayer:" + parent.getName().toLowerCase()).getBytes(Charsets.UTF_8));
} }
@Override @Override