Fixed UUID caching and name changes

This commit is contained in:
boy0001 2015-02-26 22:13:17 +11:00
parent 2341b2b972
commit 8e8489d4a7
15 changed files with 63 additions and 26 deletions

View File

@ -36,7 +36,6 @@ import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8;
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
import com.intellectualcrafters.plot.listeners.WorldEditListener;
import com.intellectualcrafters.plot.listeners.WorldEvents;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.titles.AbstractTitle;
import com.intellectualcrafters.plot.titles.DefaultTitle;
import com.intellectualcrafters.plot.util.BlockManager;

View File

@ -2,10 +2,10 @@ package com.intellectualcrafters.plot;
import java.io.File;
import org.bukkit.generator.ChunkGenerator;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.generator.ChunkGenerator;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;

View File

@ -35,8 +35,8 @@ import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
@ -111,7 +111,7 @@ public class DebugExec extends SubCommand {
if (uuid == null) {
return MainUtil.sendMessage(null, "player not found: " + args[1]);
}
final BukkitOfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
final OfflinePlotPlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
if ((op == null) || (op.getLastPlayed() == 0)) {
return MainUtil.sendMessage(null, "player hasn't connected before: " + args[1]);
}

View File

@ -32,9 +32,9 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection;
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;

View File

@ -31,8 +31,8 @@ import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper;

View File

@ -27,14 +27,12 @@ import java.util.HashSet;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.commands.Template;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.FileBytes;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;

View File

@ -29,8 +29,8 @@ import org.bukkit.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection;

View File

@ -18,8 +18,6 @@ import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.jnbt.ListTag;
import com.intellectualcrafters.jnbt.ShortTag;
import com.intellectualcrafters.jnbt.Tag;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
public class StateWrapper {

View File

@ -1,7 +1,5 @@
package com.intellectualcrafters.plot.util;
import org.bukkit.inventory.ItemStack;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PseudoRandom;

View File

@ -18,7 +18,7 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -171,7 +171,7 @@ public class ExpireManager {
keep.add(uuid);
continue;
}
final BukkitOfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
final OfflinePlotPlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
if ((op == null) || (op.getLastPlayed() == 0)) {
continue;
}

View File

@ -12,8 +12,6 @@ import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.bukkit.block.BlockState;
import com.intellectualcrafters.jnbt.ByteArrayTag;
import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.jnbt.IntTag;
@ -23,7 +21,6 @@ import com.intellectualcrafters.jnbt.NBTOutputStream;
import com.intellectualcrafters.jnbt.ShortTag;
import com.intellectualcrafters.jnbt.Tag;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.commands.Set;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;

View File

@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
@ -35,6 +36,13 @@ public class UUIDHandler {
if ((uuid == null) || (name == null)) {
return;
}
BiMap<UUID, StringWrapper> inverse = uuidMap.inverse();
if (inverse.containsKey(uuid)) {
if (uuidMap.containsKey(name)) {
return;
}
inverse.remove(uuid);
}
uuidMap.put(name, uuid);
}
@ -81,6 +89,18 @@ public class UUIDHandler {
}
PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching");
UUIDHandler.CACHED = true;
for (OfflinePlotPlayer op : uuidWrapper.getOfflinePlayers()) {
if (op.getLastPlayed() != 0) {
String name = op.getName();
StringWrapper wrap = new StringWrapper(name);
UUID uuid = uuidWrapper.getUUID(op);
add(wrap, uuid);
}
}
// OLD UUID CACHING SYSTEM
/*
final HashSet<String> worlds = new HashSet<>();
worlds.add(world);
worlds.add("world");
@ -136,6 +156,8 @@ public class UUIDHandler {
final StringWrapper nameWrap = new StringWrapper(name);
add(nameWrap, uuid);
}
*/
// add the Everyone '*' UUID
add(new StringWrapper("*"), DBFunc.everyone);
PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs");

View File

@ -3,9 +3,11 @@ package com.intellectualcrafters.plot.uuid;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
import com.intellectualcrafters.plot.object.BukkitPlayer;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
public class DefaultUUIDWrapper extends UUIDWrapper {
@ -15,12 +17,12 @@ public class DefaultUUIDWrapper extends UUIDWrapper {
}
@Override
public UUID getUUID(final BukkitOfflinePlayer player) {
public UUID getUUID(final OfflinePlotPlayer player) {
return player.getUUID();
}
@Override
public BukkitOfflinePlayer getOfflinePlayer(final UUID uuid) {
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
}
@ -28,4 +30,14 @@ public class DefaultUUIDWrapper extends UUIDWrapper {
public UUID getUUID(final String name) {
return Bukkit.getOfflinePlayer(name).getUniqueId();
}
@Override
public OfflinePlotPlayer[] getOfflinePlayers() {
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length] ;
for (int i = 0; i < ops.length; i++) {
toReturn[i] = new BukkitOfflinePlayer(ops[i]);
}
return toReturn;
}
}

View File

@ -13,6 +13,7 @@ import com.google.common.base.Charsets;
import com.google.common.collect.BiMap;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
@ -37,7 +38,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
}
@Override
public UUID getUUID(final BukkitOfflinePlayer player) {
public UUID getUUID(final OfflinePlotPlayer player) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
}
@ -46,7 +47,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
}
@Override
public BukkitOfflinePlayer getOfflinePlayer(final UUID uuid) {
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
final BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
String name;
try {
@ -92,4 +93,14 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
public UUID getUUID(final String name) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
}
@Override
public OfflinePlotPlayer[] getOfflinePlayers() {
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length] ;
for (int i = 0; i < ops.length; i++) {
toReturn[i] = new BukkitOfflinePlayer(ops[i]);
}
return toReturn;
}
}

View File

@ -2,15 +2,17 @@ package com.intellectualcrafters.plot.uuid;
import java.util.UUID;
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
public abstract class UUIDWrapper {
public abstract UUID getUUID(PlotPlayer player);
public abstract UUID getUUID(BukkitOfflinePlayer player);
public abstract UUID getUUID(OfflinePlotPlayer player);
public abstract UUID getUUID(String name);
public abstract BukkitOfflinePlayer getOfflinePlayer(UUID uuid);
public abstract OfflinePlotPlayer getOfflinePlayer(UUID uuid);
public abstract OfflinePlotPlayer[] getOfflinePlayers();
}