PlotSquared/Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java

202 lines
5.7 KiB
Java
Raw Normal View History

2015-07-26 16:51:12 +02:00
package com.plotsquared.bukkit.object;
2015-02-20 12:23:48 +01:00
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EconHandler;
2016-03-23 02:41:37 +01:00
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.Effect;
import org.bukkit.GameMode;
import org.bukkit.WeatherType;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
2015-07-30 16:25:16 +02: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;
public boolean offline;
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
/**
2016-03-28 19:28:21 +02:00
* <p>Please do not use this method. Instead use
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
2015-02-21 12:38:44 +01:00
* @param player
*/
2016-03-23 02:41:37 +01:00
public BukkitPlayer(Player player) {
2015-02-20 12:23:48 +01:00
this.player = player;
super.populatePersistentMetaMap();
2015-02-20 12:23:48 +01:00
}
2016-03-23 02:41:37 +01:00
public BukkitPlayer(Player player, boolean offline) {
2015-08-01 22:11:28 +02:00
this.player = player;
this.offline = offline;
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() {
2016-03-23 02:41:37 +01:00
if (this.last == 0) {
this.last = this.player.getLastPlayed();
2015-04-06 14:16:24 +02:00
}
2016-03-23 02:41:37 +01:00
return this.last;
2015-04-06 14:16:24 +02: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 Location getLocation() {
2016-03-23 02:41:37 +01:00
Location location = super.getLocation();
return location == null ? BukkitUtil.getLocation(this.player) : location;
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() {
2016-03-23 02:41:37 +01:00
if (this.uuid == null) {
this.uuid = UUIDHandler.getUUID(this);
2015-02-20 12:23:48 +01:00
}
2016-03-23 02:41:37 +01:00
return this.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
2016-03-23 02:41:37 +01:00
public boolean hasPermission(String permission) {
if (this.offline && EconHandler.manager != null) {
return EconHandler.manager.hasPermission(getName(), permission);
}
2016-03-23 02:41:37 +01:00
return this.player.hasPermission(permission);
2015-02-20 12:23:48 +01:00
}
2016-03-23 02:41:37 +01:00
2015-02-20 12:23:48 +01:00
@Override
2016-03-23 02:41:37 +01:00
public void sendMessage(String message) {
this.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
2016-03-23 02:41:37 +01:00
public void teleport(Location location) {
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) {
2015-09-13 06:04:31 +02:00
return;
}
2016-03-23 02:41:37 +01:00
this.player.teleport(
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5, location.getY(), location.getZ() + 0.5,
location.getYaw(), location.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() {
2016-03-23 02:41:37 +01:00
if (this.name == null) {
this.name = this.player.getName();
2015-02-20 12:23:48 +01:00
}
2016-03-23 02:41:37 +01:00
return this.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() {
2016-03-23 02:41:37 +01:00
return !this.offline && this.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
2016-03-23 02:41:37 +01:00
public void setCompassTarget(Location location) {
this.player.setCompassTarget(
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX(), location.getY(), location.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() {
2016-03-23 02:41:37 +01:00
return BukkitUtil.getLocationFull(this.player);
2015-02-23 12:37:36 +01:00
}
2016-03-23 02:41:37 +01:00
2015-07-30 16:25:16 +02:00
@Override
2016-03-23 02:41:37 +01:00
public void setWeather(PlotWeather weather) {
2015-09-13 06:04:31 +02:00
switch (weather) {
2015-07-30 16:25:16 +02:00
case CLEAR:
2016-03-23 02:41:37 +01:00
this.player.setPlayerWeather(WeatherType.CLEAR);
2016-03-23 18:09:13 +01:00
break;
case RAIN:
2016-03-23 02:41:37 +01:00
this.player.setPlayerWeather(WeatherType.DOWNFALL);
2016-03-23 18:09:13 +01:00
break;
2015-07-30 16:25:16 +02:00
case RESET:
2016-03-23 02:41:37 +01:00
this.player.resetPlayerWeather();
2016-03-23 18:09:13 +01:00
break;
default:
this.player.resetPlayerWeather();
break;
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
2016-03-23 02:41:37 +01:00
public PlotGameMode getGameMode() {
switch (this.player.getGameMode()) {
2015-07-30 16:25:16 +02:00
case ADVENTURE:
2016-03-23 02:41:37 +01:00
return PlotGameMode.ADVENTURE;
2015-07-30 16:25:16 +02:00
case CREATIVE:
2016-03-23 02:41:37 +01:00
return PlotGameMode.CREATIVE;
2015-07-30 16:25:16 +02:00
case SPECTATOR:
2016-03-23 02:41:37 +01:00
return PlotGameMode.SPECTATOR;
2015-07-30 16:25:16 +02:00
case SURVIVAL:
2016-03-23 02:41:37 +01:00
return PlotGameMode.SURVIVAL;
2016-03-23 18:09:13 +01:00
default:
2016-03-28 19:28:21 +02:00
return PlotGameMode.NOT_SET;
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
2016-03-23 02:41:37 +01:00
public void setGameMode(PlotGameMode gameMode) {
switch (gameMode) {
2015-07-30 16:25:16 +02:00
case ADVENTURE:
2016-03-23 02:41:37 +01:00
this.player.setGameMode(GameMode.ADVENTURE);
2016-03-23 18:09:13 +01:00
break;
2015-07-30 16:25:16 +02:00
case CREATIVE:
2016-03-23 02:41:37 +01:00
this.player.setGameMode(GameMode.CREATIVE);
2016-03-23 18:09:13 +01:00
break;
2015-07-30 16:25:16 +02:00
case SPECTATOR:
2016-03-23 02:41:37 +01:00
this.player.setGameMode(GameMode.SPECTATOR);
2016-03-23 18:09:13 +01:00
break;
2015-07-30 16:25:16 +02:00
case SURVIVAL:
2016-03-23 02:41:37 +01:00
this.player.setGameMode(GameMode.SURVIVAL);
2016-03-23 18:09:13 +01:00
break;
default:
this.player.setGameMode(GameMode.SURVIVAL);
break;
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
2016-03-23 02:41:37 +01:00
public void setTime(long time) {
if (time != Long.MAX_VALUE) {
2016-03-23 02:41:37 +01:00
this.player.setPlayerTime(time, false);
} else {
2016-03-23 02:41:37 +01:00
this.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
2016-03-23 02:41:37 +01:00
public void setFlight(boolean fly) {
this.player.setAllowFlight(fly);
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
2016-03-23 02:41:37 +01:00
public void playMusic(Location location, int id) {
this.player.playEffect(BukkitUtil.getLocation(location), 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
2016-03-23 02:41:37 +01:00
public void kick(String message) {
this.player.kickPlayer(message);
2015-07-30 16:25:16 +02:00
}
@Override public void stopSpectating() {
2016-03-23 02:41:37 +01:00
if (getGameMode() == PlotGameMode.SPECTATOR) {
this.player.setSpectatorTarget(null);
}
}
2015-10-07 08:33:33 +02:00
@Override
public boolean isBanned() {
2016-03-23 02:41:37 +01:00
return this.player.isBanned();
2015-10-07 08:33:33 +02:00
}
2015-02-20 12:23:48 +01:00
}