2015-07-30 16:25:16 +02:00
|
|
|
package com.plotsquared.sponge.uuid;
|
2015-07-28 13:38:49 +02:00
|
|
|
|
2016-02-10 19:59:51 +01:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import org.spongepowered.api.entity.living.player.Player;
|
|
|
|
import org.spongepowered.api.profile.GameProfile;
|
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
import com.google.common.base.Charsets;
|
|
|
|
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
|
|
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
2015-07-30 16:25:16 +02:00
|
|
|
import com.plotsquared.sponge.SpongeMain;
|
2015-07-28 13:38:49 +02:00
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper {
|
|
|
|
|
|
|
|
public SpongeLowerOfflineUUIDWrapper() {
|
2015-07-28 13:38:49 +02:00
|
|
|
// Anything?
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public UUID getUUID(final PlotPlayer player) {
|
2015-07-28 13:38:49 +02:00
|
|
|
return getUUID(player.getName());
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public UUID getUUID(final OfflinePlotPlayer player) {
|
2015-07-28 13:38:49 +02:00
|
|
|
return getUUID(player.getName());
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
|
2015-07-28 13:38:49 +02:00
|
|
|
String name = UUIDHandler.getName(uuid);
|
2015-09-13 06:04:31 +02:00
|
|
|
if (name == null) {
|
|
|
|
try {
|
2015-09-11 12:09:22 +02:00
|
|
|
final GameProfile profile = SpongeMain.THIS.getResolver().get(uuid).get();
|
2015-09-13 06:04:31 +02:00
|
|
|
if (profile != null) {
|
2015-07-28 13:38:49 +02:00
|
|
|
name = profile.getName();
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
} catch (final Exception e) {
|
2015-07-28 13:38:49 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
if (name == null) {
|
|
|
|
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) {
|
|
|
|
if (getUUID(profile.getName()).equals(uuid)) {
|
2015-07-28 13:38:49 +02:00
|
|
|
name = profile.getName();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final String username = name;
|
2015-09-13 06:04:31 +02:00
|
|
|
return new OfflinePlotPlayer() {
|
2015-07-28 13:38:49 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public boolean isOnline() {
|
2015-07-28 13:38:49 +02:00
|
|
|
return UUIDHandler.getPlayer(uuid) != null;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public UUID getUUID() {
|
2015-07-28 13:38:49 +02:00
|
|
|
return uuid;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public String getName() {
|
2015-07-28 13:38:49 +02:00
|
|
|
return username;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public long getLastPlayed() {
|
2015-09-11 12:09:22 +02:00
|
|
|
// TODO FIXME
|
2015-07-28 13:38:49 +02:00
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
|
|
|
public Player[] getOnlinePlayers() {
|
2016-01-10 21:00:56 +01:00
|
|
|
Collection<Player> onlinePlayers = SpongeMain.THIS.getServer().getOnlinePlayers();
|
|
|
|
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
2015-07-28 13:38:49 +02:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public UUID getUUID(final String name) {
|
2015-07-28 13:38:49 +02:00
|
|
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public OfflinePlotPlayer[] getOfflinePlayers() {
|
2015-09-11 12:09:22 +02:00
|
|
|
// TODO FIXME
|
2015-07-28 13:38:49 +02:00
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
2016-02-19 20:13:41 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public OfflinePlotPlayer getOfflinePlayer(String name) {
|
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
2015-07-28 13:38:49 +02:00
|
|
|
}
|