256 lines
7.3 KiB
Java
Raw Normal View History

2015-07-31 03:24:01 +10:00
package com.plotsquared.sponge.object;
import java.util.Date;
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;
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;
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-09-11 20:09:22 +10:00
public class SpongePlayer extends PlotPlayer
{
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-11 20:09:22 +10:00
public SpongePlayer(final Player player)
{
this.player = player;
}
2015-09-11 20:09:22 +10:00
@Override
2015-09-11 20:09:22 +10:00
public void sendMessage(final C c, final String... args)
{
MainUtil.sendMessage(this, c, args);
}
@Override
2015-09-11 20:09:22 +10:00
public RequiredType getSuperCaller()
{
return RequiredType.PLAYER;
}
@Override
2015-09-11 20:09:22 +10:00
public long getPreviousLogin()
{
final Value<Date> data = player.getJoinData().lastPlayed();
if (data.exists()) { return last = data.get().getSeconds() * 1000; }
return 0;
}
@Override
2015-09-11 20:09:22 +10:00
public Location getLocation()
{
final Location loc = super.getLocation();
return loc == null ? SpongeUtil.getLocation(player) : loc;
}
@Override
2015-09-11 20:09:22 +10:00
public Location getLocationFull()
{
return SpongeUtil.getLocationFull(player);
}
@Override
2015-09-11 20:09:22 +10:00
public UUID getUUID()
{
if (uuid == null)
{
uuid = UUIDHandler.getUUID(this);
}
return uuid;
}
@Override
2015-09-11 20:09:22 +10:00
public boolean hasPermission(final String perm)
{
if (Settings.PERMISSION_CACHING)
{
if (noPerm.contains(perm)) { return false; }
if (hasPerm.contains(perm)) { return true; }
final boolean result = player.hasPermission(perm);
if (!result)
{
noPerm.add(perm);
return false;
}
2015-09-11 20:09:22 +10:00
hasPerm.add(perm);
return true;
}
2015-09-11 20:09:22 +10:00
final boolean value = player.hasPermission(perm);
return value;
}
@Override
2015-09-11 20:09:22 +10:00
public void sendMessage(final String message)
{
2015-08-23 11:36:41 +01:00
player.sendMessage(ChatTypes.CHAT, Texts.of(message));
}
@Override
2015-09-11 20:09:22 +10:00
public void teleport(final Location loc)
{
if ((Math.abs(loc.getX()) >= 30000000) || (Math.abs(loc.getZ()) >= 30000000)) { return; }
final String world = player.getWorld().getName();
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-11 20:09:22 +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);
}
}
@Override
2015-09-11 20:09:22 +10:00
public boolean isOnline()
{
return player.isOnline();
}
@Override
2015-09-11 20:09:22 +10:00
public String getName()
{
if (name == null)
{
name = player.getName();
}
2015-09-11 20:09:22 +10:00
return name;
}
@Override
2015-09-11 20:09:22 +10:00
public void setCompassTarget(final Location loc)
{
final TargetedLocationData target = player.getOrCreate(TargetedLocationData.class).get();
2015-08-14 08:52:31 +10:00
target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(loc));
}
@Override
2015-09-11 20:09:22 +10:00
public void loadData()
{
// TODO Auto-generated method stub
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
@Override
2015-09-11 20:09:22 +10:00
public void saveData()
{
// TODO Auto-generated method stub
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
@Override
2015-09-11 20:09:22 +10:00
public void setAttribute(String key)
{
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);
}
@Override
2015-09-11 20:09:22 +10:00
public boolean getAttribute(String key)
{
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
}
@Override
2015-09-11 20:09:22 +10:00
public void removeAttribute(String key)
{
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-31 00:25:16 +10:00
@Override
2015-09-11 20:09:22 +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");
}
@Override
2015-09-11 20:09:22 +10:00
public PlotGamemode getGamemode()
{
final GameMode gamemode = player.getGameModeData().type().get();
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");
}
@Override
2015-09-11 20:09:22 +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;
// }
}
@Override
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");
}
@Override
2015-09-11 20:09:22 +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");
}
@Override
2015-09-11 20:09:22 +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");
}
@Override
2015-09-11 20:09:22 +10:00
public void kick(final String message)
{
2015-07-31 00:25:16 +10:00
player.kick(SpongeMain.THIS.getText(message));
}
}