2015-07-30 16:25:16 +02:00
|
|
|
package com.plotsquared.sponge.uuid;
|
2015-07-28 13:38:49 +02:00
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
2016-11-26 22:49:13 +01:00
|
|
|
import com.plotsquared.sponge.object.SpongeOfflinePlayer;
|
2015-07-30 19:24:01 +02:00
|
|
|
import com.plotsquared.sponge.object.SpongePlayer;
|
2016-11-26 22:49:13 +01:00
|
|
|
import org.spongepowered.api.Sponge;
|
|
|
|
import org.spongepowered.api.entity.living.player.Player;
|
|
|
|
import org.spongepowered.api.entity.living.player.User;
|
|
|
|
import org.spongepowered.api.service.user.UserStorageService;
|
|
|
|
import org.spongepowered.api.util.Identifiable;
|
2015-07-28 13:38:49 +02:00
|
|
|
|
2016-11-26 22:49:13 +01:00
|
|
|
import java.util.Optional;
|
2016-03-12 17:57:24 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
public class SpongeOnlineUUIDWrapper extends UUIDWrapper {
|
2016-11-26 22:49:13 +01:00
|
|
|
|
|
|
|
private UserStorageService userStorageService;
|
|
|
|
public SpongeOnlineUUIDWrapper() {
|
|
|
|
Optional<UserStorageService> userStorage = Sponge.getServiceManager().provide(UserStorageService.class);
|
|
|
|
userStorage.ifPresent(userStorageService -> this.userStorageService = userStorageService);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
@Override
|
2016-11-26 22:49:13 +01:00
|
|
|
public UUID getUUID(PlotPlayer player) {
|
2015-07-28 13:38:49 +02:00
|
|
|
return ((SpongePlayer) player).player.getUniqueId();
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
@Override
|
2016-11-26 22:49:13 +01:00
|
|
|
public UUID getUUID(OfflinePlotPlayer player) {
|
2015-07-28 13:38:49 +02:00
|
|
|
return player.getUUID();
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
@Override
|
2016-11-26 22:49:13 +01:00
|
|
|
public UUID getUUID(String name) {
|
|
|
|
Optional<Player> player = Sponge.getServer().getPlayer(name);
|
|
|
|
if (player.isPresent()) {
|
|
|
|
return player.get().getUniqueId();
|
2015-07-28 13:38:49 +02:00
|
|
|
}
|
2016-11-26 22:49:13 +01:00
|
|
|
Optional<User> user = userStorageService.get(name);
|
|
|
|
return user.map(Identifiable::getUniqueId).orElse(null);
|
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
|
2016-11-26 22:49:13 +01:00
|
|
|
public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
|
|
|
Optional<Player> player = Sponge.getServer().getPlayer(uuid);
|
|
|
|
if (player.isPresent()) {
|
|
|
|
return new SpongeOfflinePlayer(player.get());
|
2015-07-28 13:38:49 +02:00
|
|
|
}
|
2016-11-26 22:49:13 +01:00
|
|
|
Optional<User> user = userStorageService.get(uuid);
|
|
|
|
return user.map(SpongeOfflinePlayer::new).orElse(null);
|
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 OfflinePlotPlayer[] getOfflinePlayers() {
|
2015-07-28 13:38:49 +02:00
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
2016-11-26 22:49:13 +01:00
|
|
|
|
2016-02-19 20:13:41 +01:00
|
|
|
@Override
|
|
|
|
public OfflinePlotPlayer getOfflinePlayer(String name) {
|
2016-11-26 22:49:13 +01:00
|
|
|
Optional<Player> player = Sponge.getServer().getPlayer(name);
|
|
|
|
if (player.isPresent()) {
|
|
|
|
return new SpongeOfflinePlayer(player.get());
|
|
|
|
}
|
|
|
|
Optional<User> user = userStorageService.get(name);
|
|
|
|
return user.map(SpongeOfflinePlayer::new).orElse(null);
|
2016-02-19 20:13:41 +01:00
|
|
|
}
|
|
|
|
|
2015-07-28 13:38:49 +02:00
|
|
|
}
|