2015-07-26 16:51:12 +02:00
|
|
|
package com.plotsquared.bukkit.object;
|
2015-02-20 12:23:48 +01:00
|
|
|
|
2016-02-25 15:17:07 +01:00
|
|
|
import com.intellectualcrafters.plot.config.C;
|
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.util.EconHandler;
|
|
|
|
import com.intellectualcrafters.plot.util.PlotGamemode;
|
|
|
|
import com.intellectualcrafters.plot.util.PlotWeather;
|
|
|
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
2015-07-30 16:25:16 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Effect;
|
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.WeatherType;
|
|
|
|
import org.bukkit.entity.Player;
|
2015-09-05 03:35:43 +02:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
2015-07-30 16:25:16 +02:00
|
|
|
import org.bukkit.permissions.Permission;
|
2015-09-03 07:45:25 +02:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
2015-07-30 16:25:16 +02:00
|
|
|
|
2016-02-25 15:17:07 +01:00
|
|
|
import java.util.UUID;
|
2015-02-20 12:23:48 +01:00
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
public class BukkitPlayer extends PlotPlayer {
|
|
|
|
|
2015-02-20 12:23:48 +01:00
|
|
|
public final Player player;
|
2016-02-14 02:01:18 +01:00
|
|
|
public boolean offline;
|
2015-07-28 13:38:49 +02:00
|
|
|
private UUID uuid;
|
|
|
|
private String name;
|
2015-04-06 14:16:24 +02:00
|
|
|
private long last = 0;
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-02-21 12:38:44 +01:00
|
|
|
/**
|
|
|
|
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
|
|
|
|
* @param player
|
|
|
|
*/
|
2015-09-13 06:04:31 +02:00
|
|
|
public BukkitPlayer(final Player player) {
|
2015-02-20 12:23:48 +01:00
|
|
|
this.player = player;
|
2016-01-16 17:07:42 +01:00
|
|
|
super.populatePersistentMetaMap();
|
2015-02-20 12:23:48 +01:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
|
|
|
public BukkitPlayer(final Player player, final boolean offline) {
|
2015-08-01 22:11:28 +02:00
|
|
|
this.player = player;
|
|
|
|
this.offline = offline;
|
2016-01-16 17:07:42 +01:00
|
|
|
super.populatePersistentMetaMap();
|
2015-08-01 22:11:28 +02:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-09-11 12:09:22 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public long getPreviousLogin() {
|
|
|
|
if (last == 0) {
|
2015-04-06 14:16:24 +02:00
|
|
|
last = player.getLastPlayed();
|
|
|
|
}
|
|
|
|
return last;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-02-20 12:23:48 +01:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public Location getLocation() {
|
2015-09-11 12:09:22 +02:00
|
|
|
final Location loc = super.getLocation();
|
|
|
|
return loc == null ? BukkitUtil.getLocation(player) : loc;
|
2015-02-20 12:23:48 +01:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-02-20 12:23:48 +01:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public UUID getUUID() {
|
|
|
|
if (uuid == null) {
|
2015-09-11 12:09:22 +02:00
|
|
|
uuid = UUIDHandler.getUUID(this);
|
2015-02-20 12:23:48 +01:00
|
|
|
}
|
2015-09-11 12:09:22 +02:00
|
|
|
return uuid;
|
2015-02-20 12:23:48 +01:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-02-20 12:23:48 +01:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public boolean hasPermission(final String node) {
|
2016-02-14 02:01:18 +01:00
|
|
|
if (offline && EconHandler.manager != null) {
|
2015-09-13 06:04:31 +02:00
|
|
|
return EconHandler.manager.hasPermission(getName(), node);
|
2015-08-20 06:56:25 +02:00
|
|
|
}
|
2015-11-29 09:21:32 +01:00
|
|
|
return player.hasPermission(node);
|
2015-02-20 12:23:48 +01:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
|
|
|
public Permission getPermission(final String node) {
|
2015-09-11 12:09:22 +02:00
|
|
|
final PluginManager manager = Bukkit.getPluginManager();
|
2015-09-03 07:45:25 +02:00
|
|
|
Permission perm = manager.getPermission(node);
|
2015-09-13 06:04:31 +02:00
|
|
|
if (perm == null) {
|
2015-09-11 12:09:22 +02:00
|
|
|
final String[] nodes = node.split("\\.");
|
2015-09-03 07:45:25 +02:00
|
|
|
perm = new Permission(node);
|
|
|
|
final StringBuilder n = new StringBuilder();
|
2016-02-14 02:01:18 +01:00
|
|
|
for (int i = 0; i < nodes.length - 1; i++) {
|
|
|
|
n.append(nodes[i]).append(".");
|
2015-09-13 06:04:31 +02:00
|
|
|
if (!node.equals(n + C.PERMISSION_STAR.s())) {
|
2015-09-11 12:09:22 +02:00
|
|
|
final Permission parent = getPermission(n + C.PERMISSION_STAR.s());
|
2015-09-13 06:04:31 +02:00
|
|
|
if (parent != null) {
|
2015-09-03 07:45:25 +02:00
|
|
|
perm.addParent(parent, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
manager.addPermission(perm);
|
|
|
|
}
|
|
|
|
manager.recalculatePermissionDefaults(perm);
|
|
|
|
perm.recalculatePermissibles();
|
|
|
|
return perm;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-02-20 12:23:48 +01:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void sendMessage(final String message) {
|
2015-09-11 12:09:22 +02:00
|
|
|
player.sendMessage(message);
|
2015-02-20 12:23:48 +01:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-02-20 12:23:48 +01:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void teleport(final Location loc) {
|
2016-02-14 02:01:18 +01:00
|
|
|
if (Math.abs(loc.getX()) >= 30000000 || Math.abs(loc.getZ()) >= 30000000) {
|
2015-09-13 06:04:31 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-09-11 12:09:22 +02:00
|
|
|
player.teleport(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX() + 0.5, loc.getY(), loc.getZ() + 0.5, loc.getYaw(), loc.getPitch()), TeleportCause.COMMAND);
|
2015-02-23 02:32:27 +01:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-02-20 12:23:48 +01:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public String getName() {
|
|
|
|
if (name == null) {
|
2015-09-11 12:09:22 +02:00
|
|
|
name = player.getName();
|
2015-02-20 12:23:48 +01:00
|
|
|
}
|
2015-09-11 12:09:22 +02:00
|
|
|
return name;
|
2015-02-20 12:23:48 +01:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-02-20 12:23:48 +01:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public boolean isOnline() {
|
2015-09-11 12:09:22 +02:00
|
|
|
return !offline && player.isOnline();
|
2015-02-20 12:23:48 +01:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-02-22 13:46:47 +01:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void setCompassTarget(final Location loc) {
|
2015-09-11 12:09:22 +02:00
|
|
|
player.setCompassTarget(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-02-22 13:46:47 +01:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-02-23 12:37:36 +01:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public Location getLocationFull() {
|
2015-09-11 12:09:22 +02:00
|
|
|
return BukkitUtil.getLocationFull(player);
|
2015-02-23 12:37:36 +01:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-06-23 13:13:48 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void loadData() {
|
|
|
|
if (!player.isOnline()) {
|
2015-06-23 13:13:48 +02:00
|
|
|
player.loadData();
|
|
|
|
}
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-06-23 13:13:48 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void saveData() {
|
2015-06-23 13:13:48 +02:00
|
|
|
player.saveData();
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void setWeather(final PlotWeather weather) {
|
|
|
|
switch (weather) {
|
2015-07-30 16:25:16 +02:00
|
|
|
case CLEAR:
|
|
|
|
player.setPlayerWeather(WeatherType.CLEAR);
|
|
|
|
return;
|
2016-02-14 02:01:18 +01:00
|
|
|
case RAIN:
|
2015-07-30 16:25:16 +02:00
|
|
|
player.setPlayerWeather(WeatherType.DOWNFALL);
|
|
|
|
return;
|
|
|
|
case RESET:
|
|
|
|
player.resetPlayerWeather();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public PlotGamemode getGamemode() {
|
|
|
|
switch (player.getGameMode()) {
|
2015-07-30 16:25:16 +02:00
|
|
|
case ADVENTURE:
|
|
|
|
return PlotGamemode.ADVENTURE;
|
|
|
|
case CREATIVE:
|
|
|
|
return PlotGamemode.CREATIVE;
|
|
|
|
case SPECTATOR:
|
|
|
|
return PlotGamemode.SPECTATOR;
|
|
|
|
case SURVIVAL:
|
|
|
|
return PlotGamemode.SURVIVAL;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void setGamemode(final PlotGamemode gamemode) {
|
|
|
|
switch (gamemode) {
|
2015-07-30 16:25:16 +02:00
|
|
|
case ADVENTURE:
|
|
|
|
player.setGameMode(GameMode.ADVENTURE);
|
2015-08-07 01:30:08 +02:00
|
|
|
return;
|
2015-07-30 16:25:16 +02:00
|
|
|
case CREATIVE:
|
|
|
|
player.setGameMode(GameMode.CREATIVE);
|
2015-08-07 01:30:08 +02:00
|
|
|
return;
|
2015-07-30 16:25:16 +02:00
|
|
|
case SPECTATOR:
|
|
|
|
player.setGameMode(GameMode.SPECTATOR);
|
2015-08-07 01:30:08 +02:00
|
|
|
return;
|
2015-07-30 16:25:16 +02:00
|
|
|
case SURVIVAL:
|
|
|
|
player.setGameMode(GameMode.SURVIVAL);
|
2015-08-07 01:30:08 +02:00
|
|
|
return;
|
2015-07-30 16:25:16 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void setTime(final long time) {
|
2015-11-15 03:30:52 +01:00
|
|
|
if (time != Long.MAX_VALUE) {
|
|
|
|
player.setPlayerTime(time, false);
|
|
|
|
} else {
|
|
|
|
player.resetPlayerTime();
|
|
|
|
}
|
2015-07-30 16:25:16 +02:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void setFlight(final boolean fly) {
|
2015-07-30 16:25:16 +02:00
|
|
|
player.setAllowFlight(fly);
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void playMusic(final Location loc, final int id) {
|
2015-08-06 18:05:15 +02:00
|
|
|
player.playEffect(BukkitUtil.getLocation(loc), Effect.RECORD_PLAY, id);
|
2015-07-30 16:25:16 +02:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void kick(final String message) {
|
2015-07-30 16:25:16 +02:00
|
|
|
player.kickPlayer(message);
|
|
|
|
}
|
2016-02-28 02:11:18 +01:00
|
|
|
|
|
|
|
@Override public void stopSpectating() {
|
|
|
|
if (getGamemode() == PlotGamemode.SPECTATOR) {
|
|
|
|
player.setSpectatorTarget(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-07 08:33:33 +02:00
|
|
|
@Override
|
|
|
|
public boolean isBanned() {
|
|
|
|
return player.isBanned();
|
|
|
|
}
|
2015-02-20 12:23:48 +01:00
|
|
|
}
|