package com.plotsquared.bukkit.object; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.PlotGameMode; import com.intellectualcrafters.plot.util.PlotWeather; import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.bukkit.util.BukkitUtil; 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.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 boolean isPermissionSet(String permission) { return this.player.isPermissionSet(permission); } @Override public void sendMessage(String message) { if (!StringMan.isEqual(this.