2015-07-31 03:24:01 +10:00
|
|
|
package com.plotsquared.sponge.object;
|
2015-07-28 21:38:49 +10:00
|
|
|
|
2016-02-25 20:13:07 +11:00
|
|
|
import com.flowpowered.math.vector.Vector3d;
|
|
|
|
import com.intellectualcrafters.plot.commands.RequiredType;
|
|
|
|
import com.intellectualcrafters.plot.config.Settings;
|
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
2016-03-22 21:41:37 -04:00
|
|
|
import com.intellectualcrafters.plot.util.PlotGameMode;
|
2016-02-25 20:13:07 +11:00
|
|
|
import com.intellectualcrafters.plot.util.PlotWeather;
|
|
|
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
|
|
import com.plotsquared.sponge.util.SpongeUtil;
|
2016-02-19 12:03:22 -05:00
|
|
|
import org.spongepowered.api.Sponge;
|
2015-08-23 11:36:41 +01:00
|
|
|
import org.spongepowered.api.data.key.Keys;
|
|
|
|
import org.spongepowered.api.data.manipulator.mutable.TargetedLocationData;
|
|
|
|
import org.spongepowered.api.data.value.mutable.Value;
|
2015-10-07 17:33:33 +11:00
|
|
|
import org.spongepowered.api.effect.sound.SoundTypes;
|
|
|
|
import org.spongepowered.api.entity.living.player.Player;
|
|
|
|
import org.spongepowered.api.entity.living.player.gamemode.GameMode;
|
|
|
|
import org.spongepowered.api.entity.living.player.gamemode.GameModes;
|
|
|
|
import org.spongepowered.api.service.ban.BanService;
|
2015-07-28 21:38:49 +10:00
|
|
|
import org.spongepowered.api.text.chat.ChatTypes;
|
2016-02-22 17:20:22 +11:00
|
|
|
import org.spongepowered.api.text.serializer.TextSerializers;
|
2015-07-28 21:38:49 +10:00
|
|
|
|
2016-02-25 20:13:07 +11:00
|
|
|
import java.time.Instant;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.UUID;
|
2015-07-28 21:38:49 +10:00
|
|
|
|
2015-09-13 14:04:31 +10:00
|
|
|
public class SpongePlayer extends PlotPlayer {
|
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
public final Player player;
|
2016-03-22 21:41:37 -04:00
|
|
|
public HashSet<String> hasPerm = new HashSet<>();
|
|
|
|
public HashSet<String> noPerm = new HashSet<>();
|
2015-07-28 21:38:49 +10:00
|
|
|
private UUID uuid;
|
|
|
|
private String name;
|
|
|
|
private long last = 0;
|
2016-03-22 21:41:37 -04:00
|
|
|
|
|
|
|
public SpongePlayer(Player player) {
|
2015-07-28 21:38:49 +10:00
|
|
|
this.player = player;
|
2016-01-16 17:07:42 +01:00
|
|
|
super.populatePersistentMetaMap();
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public RequiredType getSuperCaller() {
|
2015-07-28 21:38:49 +10:00
|
|
|
return RequiredType.PLAYER;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public long getPreviousLogin() {
|
2016-03-22 21:41:37 -04:00
|
|
|
if (this.last != 0) {
|
|
|
|
return this.last;
|
2016-02-20 05:52:26 +11:00
|
|
|
}
|
2016-03-22 21:41:37 -04:00
|
|
|
Value<Instant> data = this.player.getJoinData().lastPlayed();
|
2015-09-13 14:04:31 +10:00
|
|
|
if (data.exists()) {
|
2016-03-22 21:41:37 -04:00
|
|
|
return this.last = data.get().getEpochSecond() * 1000;
|
2015-09-13 14:04:31 +10:00
|
|
|
}
|
2015-08-11 20:45:13 +10:00
|
|
|
return 0;
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public Location getLocation() {
|
2016-03-22 21:41:37 -04:00
|
|
|
Location location = super.getLocation();
|
|
|
|
if (location == null) {
|
|
|
|
return SpongeUtil.getLocation(this.player);
|
|
|
|
} else {
|
|
|
|
return location;
|
|
|
|
}
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public Location getLocationFull() {
|
2016-03-22 21:41:37 -04:00
|
|
|
return SpongeUtil.getLocationFull(this.player);
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public UUID getUUID() {
|
2016-03-22 21:41:37 -04:00
|
|
|
if (this.uuid == null) {
|
|
|
|
this.uuid = UUIDHandler.getUUID(this);
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2016-03-22 21:41:37 -04:00
|
|
|
return this.uuid;
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
@Override
|
2016-03-22 21:41:37 -04:00
|
|
|
public boolean hasPermission(String permission) {
|
2015-09-13 14:04:31 +10:00
|
|
|
if (Settings.PERMISSION_CACHING) {
|
2016-03-22 21:41:37 -04:00
|
|
|
if (this.noPerm.contains(permission)) {
|
2015-09-13 14:04:31 +10:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-22 21:41:37 -04:00
|
|
|
if (this.hasPerm.contains(permission)) {
|
2015-09-13 14:04:31 +10:00
|
|
|
return true;
|
|
|
|
}
|
2016-03-22 21:41:37 -04:00
|
|
|
boolean result = this.player.hasPermission(permission);
|
2015-09-13 14:04:31 +10:00
|
|
|
if (!result) {
|
2016-03-22 21:41:37 -04:00
|
|
|
this.noPerm.add(permission);
|
2015-07-28 21:38:49 +10:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-22 21:41:37 -04:00
|
|
|
this.hasPerm.add(permission);
|
2015-07-28 21:38:49 +10:00
|
|
|
return true;
|
|
|
|
}
|
2016-03-22 21:41:37 -04:00
|
|
|
return this.player.hasPermission(permission);
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
@Override
|
2016-03-22 21:41:37 -04:00
|
|
|
public void sendMessage(String message) {
|
|
|
|
this.player.sendMessage(ChatTypes.CHAT, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message));
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
@Override
|
2016-03-22 21:41:37 -04:00
|
|
|
public void teleport(Location location) {
|
|
|
|
if ((Math.abs(location.getX()) >= 30000000) || (Math.abs(location.getZ()) >= 30000000)) {
|
2015-09-13 14:04:31 +10:00
|
|
|
return;
|
|
|
|
}
|
2016-03-22 21:41:37 -04:00
|
|
|
String world = this.player.getWorld().getName();
|
|
|
|
if (!world.equals(location.getWorld())) {
|
|
|
|
this.player.transferToWorld(location.getWorld(), new Vector3d(location.getX(), location.getY(), location.getZ()));
|
2015-09-13 14:04:31 +10:00
|
|
|
} else {
|
2016-03-22 21:41:37 -04:00
|
|
|
org.spongepowered.api.world.Location current = this.player.getLocation();
|
|
|
|
current = current.setPosition(new Vector3d(location.getX(), location.getY(), location.getZ()));
|
|
|
|
this.player.setLocation(current);
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean isOnline() {
|
2016-03-22 21:41:37 -04:00
|
|
|
return this.player.isOnline();
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public String getName() {
|
2016-03-22 21:41:37 -04:00
|
|
|
if (this.name == null) {
|
|
|
|
this.name = this.player.getName();
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2016-03-22 21:41:37 -04:00
|
|
|
return this.name;
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
@Override
|
2016-03-22 21:41:37 -04:00
|
|
|
public void setCompassTarget(Location location) {
|
|
|
|
TargetedLocationData target = this.player.getOrCreate(TargetedLocationData.class).get();
|
|
|
|
target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(location).getPosition());
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2016-03-22 21:41:37 -04:00
|
|
|
|
2015-07-31 00:25:16 +10:00
|
|
|
@Override
|
2016-03-22 21:41:37 -04:00
|
|
|
public void setWeather(PlotWeather weather) {
|
2015-07-31 00:25:16 +10:00
|
|
|
// TODO Auto-generated method stub
|
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-31 00:25:16 +10:00
|
|
|
@Override
|
2016-03-22 21:41:37 -04:00
|
|
|
public PlotGameMode getGameMode() {
|
|
|
|
GameMode gamemode = this.player.getGameModeData().type().get();
|
2015-09-13 14:04:31 +10:00
|
|
|
if (gamemode == GameModes.ADVENTURE) {
|
2016-03-22 21:41:37 -04:00
|
|
|
return PlotGameMode.ADVENTURE;
|
2015-09-13 14:04:31 +10:00
|
|
|
}
|
|
|
|
if (gamemode == GameModes.CREATIVE) {
|
2016-03-22 21:41:37 -04:00
|
|
|
return PlotGameMode.CREATIVE;
|
2015-09-13 14:04:31 +10:00
|
|
|
}
|
|
|
|
if (gamemode == GameModes.SPECTATOR) {
|
2016-03-22 21:41:37 -04:00
|
|
|
return PlotGameMode.SPECTATOR;
|
2015-09-13 14:04:31 +10:00
|
|
|
}
|
|
|
|
if (gamemode == GameModes.SURVIVAL) {
|
2016-03-22 21:41:37 -04:00
|
|
|
return PlotGameMode.SURVIVAL;
|
2015-09-13 14:04:31 +10:00
|
|
|
}
|
2015-07-31 00:25:16 +10:00
|
|
|
throw new UnsupportedOperationException("INVALID GAMEMODE");
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-31 00:25:16 +10:00
|
|
|
@Override
|
2016-03-22 21:41:37 -04:00
|
|
|
public void setGameMode(PlotGameMode gameMode) {
|
|
|
|
switch (gameMode) {
|
2015-10-07 17:33:33 +11:00
|
|
|
case ADVENTURE:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.offer(Keys.GAME_MODE, GameModes.ADVENTURE);
|
2015-10-07 17:33:33 +11:00
|
|
|
return;
|
|
|
|
case CREATIVE:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.offer(Keys.GAME_MODE, GameModes.CREATIVE);
|
2015-10-07 17:33:33 +11:00
|
|
|
return;
|
|
|
|
case SPECTATOR:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.offer(Keys.GAME_MODE, GameModes.SPECTATOR);
|
2015-10-07 17:33:33 +11:00
|
|
|
return;
|
|
|
|
case SURVIVAL:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
|
2015-10-07 17:33:33 +11:00
|
|
|
return;
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
@Override
|
2016-03-22 21:41:37 -04:00
|
|
|
public void setTime(long time) {
|
2015-07-31 00:25:16 +10:00
|
|
|
// TODO Auto-generated method stub
|
2015-11-15 13:30:52 +11:00
|
|
|
if (time != Long.MAX_VALUE) {} else {}
|
2015-07-31 00:25:16 +10:00
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-31 00:25:16 +10:00
|
|
|
@Override
|
2016-03-22 21:41:37 -04:00
|
|
|
public void setFlight(boolean fly) {
|
|
|
|
this.player.offer(Keys.IS_FLYING, fly);
|
|
|
|
this.player.offer(Keys.CAN_FLY, fly);
|
2015-07-31 00:25:16 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-31 00:25:16 +10:00
|
|
|
@Override
|
2016-03-22 21:41:37 -04:00
|
|
|
public void playMusic(Location location, int id) {
|
2015-10-07 17:33:33 +11:00
|
|
|
switch (id) {
|
|
|
|
case 0:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(null, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
case 2256:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(SoundTypes.RECORDS_11, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
case 2257:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(SoundTypes.RECORDS_13, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
case 2258:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(SoundTypes.RECORDS_BLOCKS, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
case 2259:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(SoundTypes.RECORDS_CAT, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
case 2260:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(SoundTypes.RECORDS_CHIRP, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
case 2261:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(SoundTypes.RECORDS_FAR, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
case 2262:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(SoundTypes.RECORDS_MALL, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
case 2263:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(SoundTypes.RECORDS_MELLOHI, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
case 2264:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(SoundTypes.RECORDS_STAL, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
case 2265:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(SoundTypes.RECORDS_STRAD, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
case 2266:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(SoundTypes.RECORDS_WAIT, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
case 2267:
|
2016-03-22 21:41:37 -04:00
|
|
|
this.player.playSound(SoundTypes.RECORDS_WARD, SpongeUtil.getLocation(location).getPosition(), 1);
|
2015-10-07 17:33:33 +11:00
|
|
|
break;
|
|
|
|
}
|
2015-07-31 00:25:16 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-31 00:25:16 +10:00
|
|
|
@Override
|
2016-03-22 21:41:37 -04:00
|
|
|
public void kick(String message) {
|
|
|
|
this.player.kick(SpongeUtil.getText(message));
|
2015-07-31 00:25:16 +10:00
|
|
|
}
|
2016-02-27 20:11:18 -05:00
|
|
|
|
|
|
|
@Override public void stopSpectating() {
|
|
|
|
//Not Implemented
|
|
|
|
}
|
|
|
|
|
2015-10-07 17:33:33 +11:00
|
|
|
@Override
|
|
|
|
public boolean isBanned() {
|
2016-02-19 12:03:22 -05:00
|
|
|
BanService service = Sponge.getServiceManager().provide(BanService.class).get();
|
2016-03-22 21:41:37 -04:00
|
|
|
return service.isBanned(this.player.getProfile());
|
2015-10-07 17:33:33 +11:00
|
|
|
}
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|