package com.plotsquared.bukkit.object; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.*; import com.plotsquared.bukkit.util.BukkitUtil; import org.apache.commons.lang.StringUtils; import org.bukkit.Effect; import org.bukkit.GameMode; import org.bukkit.WeatherType; import org.bukkit.entity.Player; import org.bukkit.event.EventException; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import java.util.UUID; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.RegisteredListener; public class BukkitPlayer extends PlotPlayer { public final Player player; public boolean offline; private UUID uuid; private String name; /** *
Please do not use this method. Instead use * BukkitUtil.getPlayer(Player), as it caches player objects.
* @param player */ public BukkitPlayer(Player player) { this.player = player; super.populatePersistentMetaMap(); } public BukkitPlayer(Player player, boolean offline) { this.player = player; this.offline = offline; super.populatePersistentMetaMap(); } @Override public Location getLocation() { Location location = super.getLocation(); return location == null ? BukkitUtil.getLocation(this.player) : location; } @Override public UUID getUUID() { if (this.uuid == null) { this.uuid = UUIDHandler.getUUID(this); } return this.uuid; } @Override public long getLastPlayed() { return this.player.getLastPlayed(); } @Override public boolean canTeleport(Location loc) { org.bukkit.Location to = BukkitUtil.getLocation(loc); org.bukkit.Location from = player.getLocation(); PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to); RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners(); for (RegisteredListener listener : listeners) { if (listener.getPlugin().getName().equals(PS.imp().getPluginName())) { continue; } try { listener.callEvent(event); } catch (EventException e) { e.printStackTrace(); } } if (event.isCancelled() || !event.getTo().equals(to)) { return false; } event = new PlayerTeleportEvent(player, to, from); for (RegisteredListener listener : listeners) { if (listener.getPlugin().getName().equals(PS.imp().getPluginName())) { continue; } try { listener.callEvent(event); } catch (EventException e) { e.printStackTrace(); } } return true; } @Override public boolean hasPermission(String permission) { if (this.offline && EconHandler.manager != null) { return EconHandler.manager.hasPermission(getName(), permission); } return this.player.hasPermission(permission); } @Override public int hasPermissionRange(String stub, int range) { if (hasPermission(C.PERMISSION_ADMIN.s())) { return Integer.MAX_VALUE; } String[] nodes = stub.split("\\."); StringBuilder n = new StringBuilder(); for (int i = 0; i < (nodes.length - 1); i++) { n.append(nodes[i]).append("."); if (!stub.equals(n + C.PERMISSION_STAR.s())) { if (hasPermission(n + C.PERMISSION_STAR.s())) { return Integer.MAX_VALUE; } } } if (hasPermission(stub + ".*")) { return Integer.MAX_VALUE; } int max = 0; String stubPlus = stub + "."; for (PermissionAttachmentInfo attach : player.getEffectivePermissions()) { String perm = attach.getPermission(); if (perm.startsWith(stubPlus)) { String end = perm.substring(stubPlus.length()); if (MathMan.isInteger(end)) { int val = Integer.parseInt(end); if (val > range) return val; if (val > max) max = val; } } } return max; } @Override public boolean isPermissionSet(String permission) { return this.player.isPermissionSet(permission); } @Override public void sendMessage(String message) { if (!StringMan.isEqual(this.