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;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
|
|
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
|
|
|
|
|
|
|
public class BukkitPlayer implements PlotPlayer {
|
|
|
|
|
|
|
|
public final Player player;
|
|
|
|
UUID uuid;
|
|
|
|
String name;
|
2015-02-23 11:05:25 +11:00
|
|
|
public HashSet<String> hasPerm;
|
|
|
|
public HashSet<String> noPerm;
|
2015-02-21 17:42:30 +11:00
|
|
|
private int op = 0;
|
2015-02-20 22:23:48 +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-20 22:23:48 +11:00
|
|
|
public BukkitPlayer(Player player) {
|
|
|
|
this.player = player;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Location getLocation() {
|
|
|
|
return BukkitUtil.getLocation(this.player);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasPermission(String perm) {
|
2015-02-21 17:42:30 +11:00
|
|
|
if (noPerm.contains(perm)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (hasPerm.contains(perm)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
boolean result = player.hasPermission(perm);
|
|
|
|
if (!result) {
|
|
|
|
noPerm.add(perm);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
hasPerm.add(perm);
|
|
|
|
return true;
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendMessage(String message) {
|
|
|
|
this.player.sendMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void teleport(Location loc) {
|
|
|
|
this.player.teleport(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOp() {
|
2015-02-21 17:42:30 +11:00
|
|
|
if (this.op != 0) {
|
|
|
|
if (this.op == 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
boolean result = this.player.isOp();
|
|
|
|
if (!result) {
|
|
|
|
this.op = 1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.op = 2;
|
|
|
|
return true;
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
if (this.name == null) {
|
|
|
|
this.name = player.getName();
|
|
|
|
}
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOnline() {
|
|
|
|
return this.player.isOnline();
|
|
|
|
}
|
2015-02-22 23:46:47 +11:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setCompassTarget(Location loc) {
|
|
|
|
player.setCompassTarget(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
|
|
|
|
|
|
|
|
}
|
2015-02-20 22:23:48 +11:00
|
|
|
|
|
|
|
}
|