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-25 02:28:32 +10:00
|
|
|
import org.spongepowered.api.text.TextBuilder;
|
2015-08-23 11:36:41 +01:00
|
|
|
import org.spongepowered.api.text.Texts;
|
2015-08-25 02:28:32 +10:00
|
|
|
import org.spongepowered.api.text.action.HoverAction;
|
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.EconHandler;
|
|
|
|
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-07-31 03:24:01 +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-07-28 21:38:49 +10:00
|
|
|
|
|
|
|
public SpongePlayer(Player player) {
|
|
|
|
this.player = player;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendMessage(C c, String... args) {
|
|
|
|
MainUtil.sendMessage(this, c, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public RequiredType getSuperCaller() {
|
|
|
|
return RequiredType.PLAYER;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getPreviousLogin() {
|
2015-08-11 20:45:13 +10:00
|
|
|
Value<Date> data = player.getJoinData().lastPlayed();
|
|
|
|
if (data.exists()) {
|
|
|
|
return last = data.get().getSeconds() * 1000;
|
|
|
|
}
|
|
|
|
return 0;
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Location getLocation() {
|
2015-07-31 03:24:01 +10:00
|
|
|
Location loc = super.getLocation();
|
|
|
|
return loc == null ? SpongeUtil.getLocation(this.player) : loc;
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Location getLocationFull() {
|
|
|
|
return SpongeUtil.getLocationFull(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public UUID getUUID() {
|
|
|
|
if (this.uuid == null) {
|
|
|
|
this.uuid = UUIDHandler.getUUID(this);
|
|
|
|
}
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasPermission(String perm) {
|
|
|
|
if (Settings.PERMISSION_CACHING) {
|
|
|
|
if (this.noPerm.contains(perm)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (this.hasPerm.contains(perm)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
final boolean result = this.player.hasPermission(perm);
|
|
|
|
if (!result) {
|
|
|
|
this.noPerm.add(perm);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.hasPerm.add(perm);
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-20 14:56:25 +10:00
|
|
|
boolean value = this.player.hasPermission(perm);
|
|
|
|
return value;
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendMessage(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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void teleport(Location loc) {
|
2015-08-28 16:36:26 +10:00
|
|
|
if (Math.abs(loc.getX()) >= 30000000 || Math.abs(loc.getZ()) >= 30000000) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-28 21:38:49 +10:00
|
|
|
String world = player.getWorld().getName();
|
2015-07-31 00:25:16 +10:00
|
|
|
if (!world.equals(loc.getWorld())) {
|
|
|
|
player.transferToWorld(loc.getWorld(), new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOnline() {
|
|
|
|
return player.isOnline();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
if (this.name == null) {
|
|
|
|
this.name = this.player.getName();
|
|
|
|
}
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setCompassTarget(Location loc) {
|
2015-08-14 08:52:31 +10:00
|
|
|
TargetedLocationData target = player.getOrCreate(TargetedLocationData.class).get();
|
|
|
|
target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(loc));
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadData() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void saveData() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setAttribute(String key) {
|
|
|
|
key = "plotsquared_user_attributes." + key;
|
2015-08-02 06:11:28 +10:00
|
|
|
EconHandler.manager.setPermission(getName(), key, true);
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean getAttribute(String key) {
|
|
|
|
key = "plotsquared_user_attributes." + key;
|
2015-07-31 00:25:16 +10:00
|
|
|
|
|
|
|
// TODO register attributes
|
|
|
|
|
|
|
|
return false;
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeAttribute(String key) {
|
|
|
|
key = "plotsquared_user_attributes." + key;
|
2015-08-02 06:11:28 +10:00
|
|
|
EconHandler.manager.setPermission(getName(), key, false);
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|
2015-07-31 00:25:16 +10:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setWeather(PlotWeather weather) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlotGamemode getGamemode() {
|
2015-08-11 20:45:13 +10:00
|
|
|
GameMode gamemode = player.getGameModeData().type().get();
|
2015-07-31 00:25:16 +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;
|
|
|
|
}
|
|
|
|
throw new UnsupportedOperationException("INVALID GAMEMODE");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setGamemode(PlotGamemode gamemode) {
|
|
|
|
// TODO Auto-generated method stub
|
2015-08-11 20:45:13 +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-07-31 00:25:16 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setTime(long time) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFlight(boolean fly) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void playMusic(Location loc, int id) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void kick(String message) {
|
|
|
|
player.kick(SpongeMain.THIS.getText(message));
|
|
|
|
}
|
2015-07-28 21:38:49 +10:00
|
|
|
}
|