2015-07-31 03:24:01 +10:00
|
|
|
package com.plotsquared.sponge.object;
|
2015-07-28 21:38:49 +10:00
|
|
|
|
2016-02-20 05:52:26 +11:00
|
|
|
import java.time.Instant;
|
2015-07-28 21:38:49 +10:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
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;
|
2016-02-20 05:52:26 +11:00
|
|
|
import org.spongepowered.api.text.Text;
|
2015-07-28 21:38:49 +10:00
|
|
|
import org.spongepowered.api.text.chat.ChatTypes;
|
|
|
|
|
|
|
|
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;
|
2015-10-07 17:33:33 +11:00
|
|
|
import com.intellectualcrafters.plot.util.EconHandler;
|
2015-07-31 00:25:16 +10:00
|
|
|
import com.intellectualcrafters.plot.util.PlotGamemode;
|
|
|
|
import com.intellectualcrafters.plot.util.PlotWeather;
|
2015-07-28 21:38:49 +10:00
|
|
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
2015-07-31 00:25:16 +10:00
|
|
|
import com.plotsquared.sponge.util.SpongeUtil;
|
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;
|
|
|
|
private UUID uuid;
|
|
|
|
private String name;
|
|
|
|
private long last = 0;
|
2015-07-31 06:13:54 +10:00
|
|
|
public HashSet<String> hasPerm = new HashSet<>();
|
|
|
|
public HashSet<String> noPerm = new HashSet<>();
|
2015-09-13 14:04:31 +10:00
|
|
|
|
|
|
|
public SpongePlayer(final 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-02-20 05:52:26 +11:00
|
|
|
if (last != 0) {
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
final Value<Instant> data = player.getJoinData().lastPlayed();
|
2015-09-13 14:04:31 +10:00
|
|
|
if (data.exists()) {
|
2016-02-20 05:52:26 +11:00
|
|
|
return 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() {
|
2015-09-11 20:09:22 +10:00
|
|
|
final Location loc = super.getLocation();
|
|
|
|
return loc == null ? SpongeUtil.getLocation(player) : loc;
|
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() {
|
2015-07-28 21:38:49 +10:00
|
|
|
return SpongeUtil.getLocationFull(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 UUID getUUID() {
|
|
|
|
if (uuid == null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
uuid = UUIDHandler.getUUID(this);
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
|
|
|
return uuid;
|
|
|
|
}
|
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 hasPermission(final String perm) {
|
|
|
|
if (Settings.PERMISSION_CACHING) {
|
|
|
|
if (noPerm.contains(perm)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (hasPerm.contains(perm)) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
final boolean result = player.hasPermission(perm);
|
2015-09-13 14:04:31 +10:00
|
|
|
if (!result) {
|
2015-09-11 20:09:22 +10:00
|
|
|
noPerm.add(perm);
|
2015-07-28 21:38:49 +10:00
|
|
|
return false;
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
hasPerm.add(perm);
|
2015-07-28 21:38:49 +10:00
|
|
|
return true;
|
|
|
|
}
|
2016-02-19 12:03:22 -05:00
|
|
|
return player.hasPermission(perm);
|
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 void sendMessage(final String message) {
|
2016-02-20 05:52:26 +11:00
|
|
|
player.sendMessage(ChatTypes.CHAT, Text.of(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
|
2015-09-13 14:04:31 +10:00
|
|
|
public void teleport(final Location loc) {
|
|
|
|
if ((Math.abs(loc.getX()) >= 30000000) || (Math.abs(loc.getZ()) >= 30000000)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
final String world = player.getWorld().getName();
|
2015-09-13 14:04:31 +10:00
|
|
|
if (!world.equals(loc.getWorld())) {
|
2015-07-31 00:25:16 +10:00
|
|
|
player.transferToWorld(loc.getWorld(), new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
|
2015-09-13 14:04:31 +10:00
|
|
|
} else {
|
2015-07-28 21:38:49 +10:00
|
|
|
org.spongepowered.api.world.Location current = player.getLocation();
|
2015-07-31 00:25:16 +10:00
|
|
|
current = current.setPosition(new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
|
|
|
|
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() {
|
2015-07-28 21:38:49 +10:00
|
|
|
return player.isOnline();
|
|
|
|
}
|
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() {
|
|
|
|
if (name == null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
name = player.getName();
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
return 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
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setCompassTarget(final Location loc) {
|
2015-09-11 20:09:22 +10:00
|
|
|
final TargetedLocationData target = player.getOrCreate(TargetedLocationData.class).get();
|
2015-08-14 08:52:31 +10:00
|
|
|
target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(loc));
|
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 void loadData() {
|
2015-07-28 21:38:49 +10:00
|
|
|
// TODO Auto-generated method stub
|
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
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 void saveData() {
|
2015-07-28 21:38:49 +10:00
|
|
|
// TODO Auto-generated method stub
|
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
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 void setAttribute(String key) {
|
2015-07-28 21:38:49 +10:00
|
|
|
key = "plotsquared_user_attributes." + key;
|
2015-10-07 17:33:33 +11:00
|
|
|
if ((EconHandler.manager == null) || player.hasPermission("plotsquared_user_attributes.*")) {
|
|
|
|
setMeta(key, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EconHandler.manager.setPermission(getName(), key, true);
|
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 getAttribute(String key) {
|
2015-07-28 21:38:49 +10:00
|
|
|
key = "plotsquared_user_attributes." + key;
|
2015-10-07 17:33:33 +11:00
|
|
|
if ((EconHandler.manager == null) || player.hasPermission("plotsquared_user_attributes.*")) {
|
|
|
|
final Object v = getMeta(key);
|
|
|
|
return v == null ? false : (Boolean) v;
|
|
|
|
}
|
|
|
|
return player.hasPermission(key);
|
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 void removeAttribute(String key) {
|
2015-07-28 21:38:49 +10:00
|
|
|
key = "plotsquared_user_attributes." + key;
|
2015-10-07 17:33:33 +11:00
|
|
|
EconHandler.manager.setPermission(getName(), key, false);
|
2015-09-07 22:31:48 +10:00
|
|
|
deleteMeta(key);
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-31 00:25:16 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setWeather(final 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
|
2015-09-13 14:04:31 +10:00
|
|
|
public PlotGamemode getGamemode() {
|
2015-09-11 20:09:22 +10:00
|
|
|
final GameMode gamemode = player.getGameModeData().type().get();
|
2015-09-13 14:04:31 +10:00
|
|
|
if (gamemode == GameModes.ADVENTURE) {
|
|
|
|
return PlotGamemode.ADVENTURE;
|
|
|
|
}
|
|
|
|
if (gamemode == GameModes.CREATIVE) {
|
|
|
|
return PlotGamemode.CREATIVE;
|
|
|
|
}
|
|
|
|
if (gamemode == GameModes.SPECTATOR) {
|
|
|
|
return PlotGamemode.SPECTATOR;
|
|
|
|
}
|
|
|
|
if (gamemode == GameModes.SURVIVAL) {
|
|
|
|
return PlotGamemode.SURVIVAL;
|
|
|
|
}
|
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
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setGamemode(final PlotGamemode gamemode) {
|
2015-10-07 17:33:33 +11:00
|
|
|
switch (gamemode) {
|
|
|
|
case ADVENTURE:
|
|
|
|
player.offer(Keys.GAME_MODE, GameModes.ADVENTURE);
|
|
|
|
return;
|
|
|
|
case CREATIVE:
|
|
|
|
player.offer(Keys.GAME_MODE, GameModes.CREATIVE);
|
|
|
|
return;
|
|
|
|
case SPECTATOR:
|
|
|
|
player.offer(Keys.GAME_MODE, GameModes.SPECTATOR);
|
|
|
|
return;
|
|
|
|
case SURVIVAL:
|
|
|
|
player.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
|
|
|
|
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
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setTime(final 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
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setFlight(final boolean fly) {
|
2015-10-07 17:33:33 +11:00
|
|
|
player.offer(Keys.IS_FLYING, fly);
|
|
|
|
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
|
2015-09-13 14:04:31 +10:00
|
|
|
public void playMusic(final Location loc, final int id) {
|
2015-10-07 17:33:33 +11:00
|
|
|
switch (id) {
|
|
|
|
case 0:
|
|
|
|
player.playSound(null, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
break;
|
|
|
|
case 2256:
|
|
|
|
player.playSound(SoundTypes.RECORDS_11, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
break;
|
|
|
|
case 2257:
|
|
|
|
player.playSound(SoundTypes.RECORDS_13, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
break;
|
|
|
|
case 2258:
|
|
|
|
player.playSound(SoundTypes.RECORDS_BLOCKS, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
break;
|
|
|
|
case 2259:
|
|
|
|
player.playSound(SoundTypes.RECORDS_CAT, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
break;
|
|
|
|
case 2260:
|
|
|
|
player.playSound(SoundTypes.RECORDS_CHIRP, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
break;
|
|
|
|
case 2261:
|
|
|
|
player.playSound(SoundTypes.RECORDS_FAR, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
break;
|
|
|
|
case 2262:
|
|
|
|
player.playSound(SoundTypes.RECORDS_MALL, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
break;
|
|
|
|
case 2263:
|
|
|
|
player.playSound(SoundTypes.RECORDS_MELLOHI, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
break;
|
|
|
|
case 2264:
|
|
|
|
player.playSound(SoundTypes.RECORDS_STAL, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
break;
|
|
|
|
case 2265:
|
|
|
|
player.playSound(SoundTypes.RECORDS_STRAD, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
break;
|
|
|
|
case 2266:
|
|
|
|
player.playSound(SoundTypes.RECORDS_WAIT, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
break;
|
|
|
|
case 2267:
|
|
|
|
player.playSound(SoundTypes.RECORDS_WARD, SpongeUtil.getLocation(loc).getPosition(), 1);
|
|
|
|
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
|
2015-09-13 14:04:31 +10:00
|
|
|
public void kick(final String message) {
|
2016-02-19 12:03:22 -05:00
|
|
|
player.kick(Text.of(message));
|
2015-07-31 00:25:16 +10:00
|
|
|
}
|
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-02-19 12:01:24 -05:00
|
|
|
return service.isBanned(player.getProfile());
|
2015-10-07 17:33:33 +11:00
|
|
|
}
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|