TF-PlotSquared/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java

122 lines
3.1 KiB
Java
Raw Normal View History

2015-02-20 22:23:48 +11:00
package com.intellectualcrafters.plot.object;
2015-02-21 17:42:30 +11:00
import java.util.HashSet;
2015-02-20 22:23:48 +11:00
import java.util.UUID;
import org.bukkit.entity.Player;
2015-03-12 20:28:08 +11:00
import com.intellectualcrafters.plot.config.Settings;
2015-02-20 22:23:48 +11:00
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class BukkitPlayer implements PlotPlayer {
2015-02-23 12:32:27 +11:00
2015-02-20 22:23:48 +11:00
public final Player player;
UUID uuid;
String name;
2015-02-25 18:50:17 +11:00
public HashSet<String> hasPerm = new HashSet<>();
public HashSet<String> noPerm = new HashSet<>();
2015-02-21 17:42:30 +11:00
private int op = 0;
2015-04-06 22:16:24 +10:00
private long last = 0;
2015-02-23 12:32:27 +11:00
2015-02-21 22:38:44 +11:00
/**
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
* @param player
*/
2015-02-23 12:32:27 +11:00
public BukkitPlayer(final Player player) {
2015-02-20 22:23:48 +11:00
this.player = player;
}
2015-04-06 22:16:24 +10:00
public long getPreviousLogin() {
if (last == 0) {
last = player.getLastPlayed();
}
return last;
}
2015-02-23 12:32:27 +11:00
2015-02-20 22:23:48 +11:00
@Override
public Location getLocation() {
return BukkitUtil.getLocation(this.player);
}
2015-02-23 12:32:27 +11:00
2015-02-20 22:23:48 +11:00
@Override
public UUID getUUID() {
if (this.uuid == null) {
2015-02-21 23:52:50 +11:00
this.uuid = UUIDHandler.getUUID(this);
2015-02-20 22:23:48 +11:00
}
return this.uuid;
}
2015-02-23 12:32:27 +11:00
2015-02-20 22:23:48 +11:00
@Override
2015-02-23 12:32:27 +11:00
public boolean hasPermission(final String perm) {
2015-03-12 20:28:08 +11:00
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);
2015-02-21 17:42:30 +11:00
return true;
}
2015-03-12 20:28:08 +11:00
return this.player.hasPermission(perm);
2015-02-20 22:23:48 +11:00
}
2015-02-23 12:32:27 +11:00
2015-02-20 22:23:48 +11:00
@Override
2015-02-23 12:32:27 +11:00
public void sendMessage(final String message) {
2015-02-20 22:23:48 +11:00
this.player.sendMessage(message);
}
2015-02-23 12:32:27 +11:00
2015-02-20 22:23:48 +11:00
@Override
2015-02-23 12:32:27 +11:00
public void teleport(final Location loc) {
2015-02-20 22:23:48 +11:00
this.player.teleport(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
2015-02-23 12:32:27 +11:00
}
2015-02-20 22:23:48 +11:00
@Override
public boolean isOp() {
2015-02-21 17:42:30 +11:00
if (this.op != 0) {
if (this.op == 1) {
return false;
}
return true;
}
2015-02-23 12:32:27 +11:00
final boolean result = this.player.isOp();
2015-02-21 17:42:30 +11:00
if (!result) {
this.op = 1;
return false;
}
this.op = 2;
return true;
2015-02-20 22:23:48 +11:00
}
2015-02-23 12:32:27 +11:00
2015-02-20 22:23:48 +11:00
@Override
public String getName() {
if (this.name == null) {
2015-02-23 12:32:27 +11:00
this.name = this.player.getName();
2015-02-20 22:23:48 +11:00
}
return this.name;
}
2015-02-23 12:32:27 +11:00
2015-02-20 22:23:48 +11:00
@Override
public boolean isOnline() {
return this.player.isOnline();
}
2015-02-23 12:32:27 +11:00
2015-02-22 23:46:47 +11:00
@Override
2015-02-23 12:32:27 +11:00
public void setCompassTarget(final Location loc) {
this.player.setCompassTarget(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
2015-02-22 23:46:47 +11:00
}
2015-02-23 12:32:27 +11:00
2015-02-23 22:37:36 +11:00
@Override
public Location getLocationFull() {
return BukkitUtil.getLocationFull(this.player);
}
2015-02-20 22:23:48 +11:00
}