Better wrapped player usage. Requires latest WorldEdit build.

This commit is contained in:
wizjany 2019-03-30 18:09:27 -04:00
parent e2ffab5ee8
commit c181a86fd1
3 changed files with 152 additions and 131 deletions

View File

@ -39,11 +39,16 @@ class BukkitOfflinePlayer extends BukkitPlayer {
private final OfflinePlayer player;
BukkitOfflinePlayer(OfflinePlayer offlinePlayer) {
super(null, null);
BukkitOfflinePlayer(WorldGuardPlugin plugin, OfflinePlayer offlinePlayer) {
super(plugin, offlinePlayer.getPlayer()); // null if they are offline
this.player = offlinePlayer;
}
/// ========================================
/// These are checked for RegionAssociable
/// (to see if a player belongs to a region)
/// ========================================
@Override
public String getName() {
return player.getName();
@ -56,175 +61,191 @@ public UUID getUniqueId() {
@Override
public boolean hasGroup(String group) {
return false;
}
@Override
public void kick(String msg) {
}
@Override
public void ban(String msg) {
}
@Override
public double getHealth() {
return 0;
}
@Override
public void setHealth(double health) {
}
@Override
public double getMaxHealth() {
return 0;
}
@Override
public double getFoodLevel() {
return 0;
}
@Override
public void setFoodLevel(double foodLevel) {
}
@Override
public double getSaturation() {
return 0;
}
@Override
public void setSaturation(double saturation) {
}
@Override
public float getExhaustion() {
return 0;
}
@Override
public void setExhaustion(float exhaustion) {
}
@Override
public WeatherType getPlayerWeather() {
return WeatherTypes.CLEAR;
}
@Override
public void setPlayerWeather(WeatherType weather) {
}
@Override
public void resetPlayerWeather() {
}
@Override
public boolean isPlayerTimeRelative() {
return false;
}
@Override
public long getPlayerTimeOffset() {
return 0;
}
@Override
public void setPlayerTime(long time, boolean relative) {
}
@Override
public void resetPlayerTime() {
}
@Override
public void printRaw(String msg) {
}
@Override
public void printDebug(String msg) {
}
@Override
public void print(String msg) {
}
@Override
public void printError(String msg) {
return plugin.inGroup(player, group);
}
@Override
public String[] getGroups() {
return new String[0];
return plugin.getGroups(player);
}
/// ==========================================
/// None of the following should ever be used.
/// ==========================================
@Override
public boolean hasPermission(String perm) {
return false;
throw new UnsupportedOperationException();
}
@Override
public World getWorld() {
return null;
public void kick(String msg) {
throw new UnsupportedOperationException();
}
@Override
public void ban(String msg) {
throw new UnsupportedOperationException();
}
@Override
public double getHealth() {
throw new UnsupportedOperationException();
}
@Override
public void setHealth(double health) {
throw new UnsupportedOperationException();
}
@Override
public double getMaxHealth() {
throw new UnsupportedOperationException();
}
@Override
public double getFoodLevel() {
throw new UnsupportedOperationException();
}
@Override
public void setFoodLevel(double foodLevel) {
throw new UnsupportedOperationException();
}
@Override
public double getSaturation()
{
throw new UnsupportedOperationException();
}
@Override
public void setSaturation(double saturation) {
throw new UnsupportedOperationException();
}
@Override
public float getExhaustion()
{
throw new UnsupportedOperationException();
}
@Override
public void setExhaustion(float exhaustion) {
throw new UnsupportedOperationException();
}
@Override
public WeatherType getPlayerWeather()
{
throw new UnsupportedOperationException();
}
@Override
public void setPlayerWeather(WeatherType weather) {
throw new UnsupportedOperationException();
}
@Override
public void resetPlayerWeather() {
throw new UnsupportedOperationException();
}
@Override
public boolean isPlayerTimeRelative()
{
throw new UnsupportedOperationException();
}
@Override
public long getPlayerTimeOffset()
{
throw new UnsupportedOperationException();
}
@Override
public void setPlayerTime(long time, boolean relative) {
throw new UnsupportedOperationException();
}
@Override
public void resetPlayerTime() {
throw new UnsupportedOperationException();
}
@Override
public void printRaw(String msg) {
throw new UnsupportedOperationException();
}
@Override
public void printDebug(String msg) {
throw new UnsupportedOperationException();
}
@Override
public void print(String msg) {
throw new UnsupportedOperationException();
}
@Override
public void printError(String msg) {
throw new UnsupportedOperationException();
}
@Override
public World getWorld()
{
throw new UnsupportedOperationException();
}
@Override
public BaseItemStack getItemInHand(HandSide handSide) {
return null;
throw new UnsupportedOperationException();
}
@Override
public void giveItem(BaseItemStack itemStack) {
throw new UnsupportedOperationException();
}
@Override
public BlockBag getInventoryBlockBag() {
return null;
public BlockBag getInventoryBlockBag()
{
throw new UnsupportedOperationException();
}
@Override
public void setPosition(Vector3 pos, float pitch, float yaw) {
throw new UnsupportedOperationException();
}
@Nullable
@Override
public BaseEntity getState() {
return null;
public BaseEntity getState()
{
throw new UnsupportedOperationException();
}
@Override
public Location getLocation() {
return null;
public Location getLocation()
{
throw new UnsupportedOperationException();
}
@Override
public void setCompassTarget(Location location) {
throw new UnsupportedOperationException();
}
@Override
public SessionKey getSessionKey() {
return null;
throw new UnsupportedOperationException();
}
@Nullable
@Override
public <T> T getFacet(Class<? extends T> cls) {
return null;
throw new UnsupportedOperationException();
}
}

View File

@ -31,7 +31,7 @@
public class BukkitPlayer extends com.sk89q.worldedit.bukkit.BukkitPlayer implements LocalPlayer {
private final WorldGuardPlugin plugin;
protected final WorldGuardPlugin plugin;
private final boolean silenced;
private String name;
@ -40,7 +40,7 @@ public BukkitPlayer(WorldGuardPlugin plugin, Player player) {
}
BukkitPlayer(WorldGuardPlugin plugin, Player player, boolean silenced) {
super((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"), player);
super(player);
this.plugin = plugin;
this.silenced = silenced;
}

View File

@ -255,7 +255,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
* @param group The group
* @return whether {@code player} is in {@code group}
*/
public boolean inGroup(Player player, String group) {
public boolean inGroup(OfflinePlayer player, String group) {
try {
return PermissionsResolverManager.getInstance().inGroup(player, group);
} catch (Throwable t) {
@ -270,7 +270,7 @@ public boolean inGroup(Player player, String group) {
* @param player The player to check
* @return The names of each group the playe is in.
*/
public String[] getGroups(Player player) {
public String[] getGroups(OfflinePlayer player) {
try {
return PermissionsResolverManager.getInstance().getGroups(player);
} catch (Throwable t) {
@ -392,7 +392,7 @@ public CommandSender unwrapActor(Actor sender) {
* @return The wrapped player
*/
public LocalPlayer wrapOfflinePlayer(OfflinePlayer player) {
return new BukkitOfflinePlayer(player);
return new BukkitOfflinePlayer(this, player);
}
/**