PlotSquared/src/main/java/com/plotsquared/sponge/uuid/SpongeLowerOfflineUUIDWrapper.java

113 lines
2.8 KiB
Java
Raw Normal View History

2015-07-30 16:25:16 +02:00
package com.plotsquared.sponge.uuid;
import java.util.UUID;
import org.spongepowered.api.GameProfile;
2015-09-06 03:53:56 +02:00
import org.spongepowered.api.entity.player.Player;
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-09-11 12:09:22 +02:00
public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper
{
2015-09-11 12:09:22 +02:00
public SpongeLowerOfflineUUIDWrapper()
{
// Anything?
}
@Override
2015-09-11 12:09:22 +02:00
public UUID getUUID(final PlotPlayer player)
{
return getUUID(player.getName());
}
@Override
2015-09-11 12:09:22 +02:00
public UUID getUUID(final OfflinePlotPlayer player)
{
return getUUID(player.getName());
}
@Override
2015-09-11 12:09:22 +02:00
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid)
{
String name = UUIDHandler.getName(uuid);
2015-09-11 12:09:22 +02:00
if (name == null)
{
try
{
final GameProfile profile = SpongeMain.THIS.getResolver().get(uuid).get();
if (profile != null)
{
name = profile.getName();
}
2015-09-11 12:09:22 +02:00
}
catch (final Exception e)
{
e.printStackTrace();
}
}
2015-09-11 12:09:22 +02:00
if (name == null)
{
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles())
{
if (getUUID(profile.getName()).equals(uuid))
{
name = profile.getName();
break;
}
}
}
final String username = name;
2015-09-11 12:09:22 +02:00
return new OfflinePlotPlayer()
{
@Override
2015-09-11 12:09:22 +02:00
public boolean isOnline()
{
return UUIDHandler.getPlayer(uuid) != null;
}
2015-09-11 12:09:22 +02:00
@Override
2015-09-11 12:09:22 +02:00
public UUID getUUID()
{
return uuid;
}
2015-09-11 12:09:22 +02:00
@Override
2015-09-11 12:09:22 +02:00
public String getName()
{
return username;
}
2015-09-11 12:09:22 +02:00
@Override
2015-09-11 12:09:22 +02:00
public long getLastPlayed()
{
// TODO FIXME
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
};
}
2015-09-11 12:09:22 +02:00
public Player[] getOnlinePlayers()
{
return SpongeMain.THIS.getServer().getOnlinePlayers().toArray(new Player[0]);
}
@Override
2015-09-11 12:09:22 +02:00
public UUID getUUID(final String name)
{
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
}
2015-09-11 12:09:22 +02:00
@Override
2015-09-11 12:09:22 +02:00
public OfflinePlotPlayer[] getOfflinePlayers()
{
// TODO FIXME
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
}