2015-07-31 03:24:01 +10:00
|
|
|
package com.plotsquared.sponge.object;
|
2015-07-28 21:38:49 +10:00
|
|
|
|
2015-08-11 20:45:13 +10:00
|
|
|
import java.util.Date;
|
2015-07-28 21:38:49 +10:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
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-09-06 11:53:56 +10:00
|
|
|
import org.spongepowered.api.entity.player.Player;
|
|
|
|
import org.spongepowered.api.entity.player.gamemode.GameMode;
|
|
|
|
import org.spongepowered.api.entity.player.gamemode.GameModes;
|
2015-08-23 11:36:41 +01:00
|
|
|
import org.spongepowered.api.text.Texts;
|
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.C;
|
|
|
|
import com.intellectualcrafters.plot.config.Settings;
|
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.util.MainUtil;
|
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 03:24:01 +10:00
|
|
|
import com.plotsquared.sponge.SpongeMain;
|
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;
|
|
|
|
}
|
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 C c, final String... args) {
|
2015-07-28 21:38:49 +10:00
|
|
|
MainUtil.sendMessage(this, c, args);
|
|
|
|
}
|
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() {
|
2015-09-11 20:09:22 +10:00
|
|
|
final Value<Date> data = player.getJoinData().lastPlayed();
|
2015-09-13 14:04:31 +10:00
|
|
|
if (data.exists()) {
|
|
|
|
return last = data.get().getSeconds() * 1000;
|
|
|
|
}
|
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;
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
final boolean value = player.hasPermission(perm);
|
2015-08-20 14:56:25 +10:00
|
|
|
return value;
|
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) {
|
2015-08-23 11:36:41 +01:00
|
|
|
player.sendMessage(ChatTypes.CHAT, Texts.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-09-11 20:09:22 +10:00
|
|
|
// EconHandler.manager.setPermission(getName(), key, true);
|
2015-09-07 22:31:48 +10:00
|
|
|
setMeta(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-09-07 22:31:48 +10:00
|
|
|
return getMeta(key) != null;
|
2015-07-31 00:25:16 +10:00
|
|
|
// TODO register attributes
|
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-09-11 20:09:22 +10: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-07-31 00:25:16 +10:00
|
|
|
// TODO Auto-generated method stub
|
2015-09-11 20:09:22 +10: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-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
|
|
|
|
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-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 void playMusic(final Location loc, final int id) {
|
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 void kick(final String message) {
|
2015-07-31 00:25:16 +10:00
|
|
|
player.kick(SpongeMain.THIS.getText(message));
|
|
|
|
}
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|