Fixed WorldGuard's player not inheriting properly from WorldEdit.

This commit is contained in:
Matthew Miller 2018-09-26 14:01:25 +10:00
parent e43daa726a
commit 87e5770405
4 changed files with 46 additions and 138 deletions

View File

@ -19,7 +19,7 @@
package com.sk89q.worldguard;
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldguard.domains.Association;
import com.sk89q.worldguard.protection.association.RegionAssociable;
@ -27,7 +27,7 @@
import java.util.List;
public abstract class LocalPlayer extends AbstractPlayerActor implements RegionAssociable {
public interface LocalPlayer extends Player, RegionAssociable {
/**
* Returns true if this player is inside a group.
@ -35,24 +35,24 @@ public abstract class LocalPlayer extends AbstractPlayerActor implements RegionA
* @param group The group to check
* @return Whether this player is in {@code group}
*/
public abstract boolean hasGroup(String group);
boolean hasGroup(String group);
/**
* Kick this player.
*
* @param msg The message to kick the player with
*/
public abstract void kick(String msg);
void kick(String msg);
/**
* Ban this player.
*
* @param msg The message to ban the player with
*/
public abstract void ban(String msg);
void ban(String msg);
@Override
public Association getAssociation(List<ProtectedRegion> regions) {
default Association getAssociation(List<ProtectedRegion> regions) {
boolean member = false;
for (ProtectedRegion region : regions) {
@ -71,82 +71,82 @@ public Association getAssociation(List<ProtectedRegion> regions) {
*
* @return The health
*/
public abstract double getHealth();
double getHealth();
/**
* Sets the health of this player.
*
* @param health The health
*/
public abstract void setHealth(double health);
void setHealth(double health);
/**
* Gets the max health of this player.
*
* @return The max health
*/
public abstract double getMaxHealth();
double getMaxHealth();
/**
* Gets the food level of this player.
*
* @return The food level
*/
public abstract double getFoodLevel();
double getFoodLevel();
/**
* Sets the food level of this player.
*
* @param foodLevel The food level
*/
public abstract void setFoodLevel(double foodLevel);
void setFoodLevel(double foodLevel);
/**
* Gets the saturation of this player.
*
* @return The saturation
*/
public abstract double getSaturation();
double getSaturation();
/**
* Sets the saturation of this player.
*
* @param saturation The saturation
*/
public abstract void setSaturation(double saturation);
void setSaturation(double saturation);
/**
* Gets the players weather
*
* @return The players weather
*/
public abstract WeatherType getPlayerWeather();
WeatherType getPlayerWeather();
/**
* Sets the players WeatherType
*
* @param weather The weather type
*/
public abstract void setPlayerWeather(WeatherType weather);
void setPlayerWeather(WeatherType weather);
/**
* Resets the players weather to normal.
*/
public abstract void resetPlayerWeather();
void resetPlayerWeather();
/**
* Gets if the players time is relative.
*
* @return If the time is relative
*/
public abstract boolean isPlayerTimeRelative();
boolean isPlayerTimeRelative();
/**
* Gets the time offset of the player.
*
* @return The players time offset
*/
public abstract long getPlayerTimeOffset();
long getPlayerTimeOffset();
/**
* Sets the players time.
@ -154,10 +154,10 @@ public Association getAssociation(List<ProtectedRegion> regions) {
* @param time The players time
* @param relative If it's relative
*/
public abstract void setPlayerTime(long time, boolean relative);
void setPlayerTime(long time, boolean relative);
/**
* Resets the players time to normal.
*/
public abstract void resetPlayerTime();
void resetPlayerTime();
}

View File

@ -29,18 +29,18 @@
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
import com.sk89q.worldguard.LocalPlayer;
import org.bukkit.OfflinePlayer;
import java.util.UUID;
import javax.annotation.Nullable;
class BukkitOfflinePlayer extends LocalPlayer {
class BukkitOfflinePlayer extends BukkitPlayer {
private final OfflinePlayer player;
BukkitOfflinePlayer(OfflinePlayer offlinePlayer) {
super(null, null);
this.player = offlinePlayer;
}

View File

@ -19,34 +19,17 @@
package com.sk89q.worldguard.bukkit;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
import com.sk89q.worldguard.LocalPlayer;
import org.bukkit.BanList.Type;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.UUID;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
public class BukkitPlayer extends LocalPlayer {
public class BukkitPlayer extends com.sk89q.worldedit.bukkit.BukkitPlayer implements LocalPlayer {
private final WorldGuardPlugin plugin;
private final Player player;
private final com.sk89q.worldedit.bukkit.BukkitPlayer worldEditPlayer;
private final String name;
private final boolean silenced;
@ -55,15 +38,11 @@ public BukkitPlayer(WorldGuardPlugin plugin, Player player) {
}
BukkitPlayer(WorldGuardPlugin plugin, Player player, boolean silenced) {
checkNotNull(plugin);
checkNotNull(player);
super((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"), player);
this.plugin = plugin;
this.player = player;
// getName() takes longer than before in newer versions of Minecraft
this.name = player.getName();
this.silenced = silenced;
this.worldEditPlayer = new com.sk89q.worldedit.bukkit.BukkitPlayer((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"), player);
}
@Override
@ -71,64 +50,59 @@ public String getName() {
return name;
}
@Override
public UUID getUniqueId() {
return player.getUniqueId();
}
@Override
public boolean hasGroup(String group) {
return plugin.inGroup(player, group);
return plugin.inGroup(getPlayer(), group);
}
@Override
public void kick(String msg) {
if (!silenced) {
player.kickPlayer(msg);
getPlayer().kickPlayer(msg);
}
}
@Override
public void ban(String msg) {
if (!silenced) {
Bukkit.getBanList(Type.NAME).addBan(player.getName(), null, null, null);
player.kickPlayer(msg);
Bukkit.getBanList(Type.NAME).addBan(getName(), null, null, null);
getPlayer().kickPlayer(msg);
}
}
@Override
public double getHealth() {
return player.getHealth();
return getPlayer().getHealth();
}
@Override
public void setHealth(double health) {
player.setHealth(health);
getPlayer().setHealth(health);
}
@Override
public double getMaxHealth() {
return player.getMaxHealth();
return getPlayer().getMaxHealth();
}
@Override
public double getFoodLevel() {
return player.getFoodLevel();
return getPlayer().getFoodLevel();
}
@Override
public void setFoodLevel(double foodLevel) {
player.setFoodLevel((int) foodLevel);
getPlayer().setFoodLevel((int) foodLevel);
}
@Override
public double getSaturation() {
return player.getSaturation();
return getPlayer().getSaturation();
}
@Override
public void setSaturation(double saturation) {
player.setSaturation((float) saturation);
getPlayer().setSaturation((float) saturation);
}
@Override
@ -138,115 +112,48 @@ public WeatherType getPlayerWeather() {
@Override
public void setPlayerWeather(WeatherType weather) {
player.setPlayerWeather(weather == WeatherTypes.CLEAR ? org.bukkit.WeatherType.CLEAR : org.bukkit.WeatherType.DOWNFALL);
getPlayer().setPlayerWeather(weather == WeatherTypes.CLEAR ? org.bukkit.WeatherType.CLEAR : org.bukkit.WeatherType.DOWNFALL);
}
@Override
public void resetPlayerWeather() {
player.resetPlayerWeather();
getPlayer().resetPlayerWeather();
}
@Override
public boolean isPlayerTimeRelative() {
return player.isPlayerTimeRelative();
return getPlayer().isPlayerTimeRelative();
}
@Override
public long getPlayerTimeOffset() {
return player.getPlayerTimeOffset();
return getPlayer().getPlayerTimeOffset();
}
@Override
public void setPlayerTime(long time, boolean relative) {
player.setPlayerTime(time, relative);
getPlayer().setPlayerTime(time, relative);
}
@Override
public void resetPlayerTime() {
player.resetPlayerTime();
getPlayer().resetPlayerTime();
}
@Override
public String[] getGroups() {
return plugin.getGroups(player);
return plugin.getGroups(getPlayer());
}
@Override
public void printRaw(String msg) {
if (!silenced) {
player.sendMessage(msg);
getPlayer().sendMessage(msg);
}
}
@Override
public void printDebug(String msg) {
worldEditPlayer.printDebug(msg);
}
@Override
public void print(String msg) {
worldEditPlayer.print(msg);
}
@Override
public void printError(String msg) {
worldEditPlayer.printError(msg);
}
@Override
public boolean hasPermission(String perm) {
return plugin.hasPermission(player, perm);
}
public Player getPlayer() {
return player;
}
@Override
public World getWorld() {
return BukkitAdapter.adapt(player.getWorld());
}
@Override
public BaseItemStack getItemInHand(HandSide handSide) {
return worldEditPlayer.getItemInHand(handSide);
}
@Override
public void giveItem(BaseItemStack itemStack) {
worldEditPlayer.giveItem(itemStack);
}
@Override
public BlockBag getInventoryBlockBag() {
return worldEditPlayer.getInventoryBlockBag();
}
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
worldEditPlayer.setPosition(pos, pitch, yaw);
}
@Nullable
@Override
public BaseEntity getState() {
return worldEditPlayer.getState();
}
@Override
public com.sk89q.worldedit.util.Location getLocation() {
Location loc = player.getLocation();
return BukkitAdapter.adapt(loc);
}
@Override
public SessionKey getSessionKey() {
return worldEditPlayer.getSessionKey();
}
@Nullable
@Override
public <T> T getFacet(Class<? extends T> cls) {
return worldEditPlayer.getFacet(cls);
return plugin.hasPermission(getPlayer(), perm);
}
}

View File

@ -22,6 +22,7 @@
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
@ -36,7 +37,7 @@
import javax.annotation.Nullable;
@org.junit.Ignore
public class TestPlayer extends LocalPlayer {
public class TestPlayer extends AbstractPlayerActor implements LocalPlayer {
private final UUID uuid = UUID.randomUUID();
private final String name;