2014-12-16 05:58:54 +01:00
|
|
|
package com.intellectualcrafters.plot.uuid;
|
|
|
|
|
|
|
|
import com.google.common.base.Charsets;
|
|
|
|
import com.google.common.collect.BiMap;
|
|
|
|
import com.intellectualcrafters.plot.object.StringWrapper;
|
|
|
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
2014-12-18 03:15:11 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.OfflinePlayer;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
2014-12-16 05:58:54 +01:00
|
|
|
|
|
|
|
public class OfflineUUIDWrapper extends UUIDWrapper {
|
|
|
|
|
|
|
|
@Override
|
2014-12-16 06:03:20 +01:00
|
|
|
public UUID getUUID(final Player player) {
|
2014-12-16 05:58:54 +01:00
|
|
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-16 06:03:20 +01:00
|
|
|
public UUID getUUID(final OfflinePlayer player) {
|
2014-12-16 05:58:54 +01:00
|
|
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-16 06:03:20 +01:00
|
|
|
public OfflinePlayer getOfflinePlayer(final UUID uuid) {
|
|
|
|
final BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
|
|
|
|
final String name = map.get(uuid).value;
|
2014-12-16 05:58:54 +01:00
|
|
|
if (name != null) {
|
|
|
|
return Bukkit.getOfflinePlayer(name);
|
2014-12-18 03:15:11 +01:00
|
|
|
} else {
|
2014-12-16 06:03:20 +01:00
|
|
|
for (final OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
2014-12-16 05:58:54 +01:00
|
|
|
if (getUUID(player).equals(uuid)) {
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Bukkit.getOfflinePlayer(uuid.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-16 06:03:20 +01:00
|
|
|
public Player getPlayer(final UUID uuid) {
|
|
|
|
for (final Player player : Bukkit.getOnlinePlayers()) {
|
2014-12-16 05:58:54 +01:00
|
|
|
if (getUUID(player).equals(uuid)) {
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2014-12-16 06:03:20 +01:00
|
|
|
|
2014-12-16 05:58:54 +01:00
|
|
|
}
|