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

100 lines
2.3 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;
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-21 17:42:30 +11:00
private HashSet<String> hasPerm;
private HashSet<String> noPerm;
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) {
this.uuid = UUIDHandler.getUUID(this.player);
}
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();
}
}