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; private final OfflinePlayer player;
BukkitOfflinePlayer(OfflinePlayer offlinePlayer) { BukkitOfflinePlayer(WorldGuardPlugin plugin, OfflinePlayer offlinePlayer) {
super(null, null); super(plugin, offlinePlayer.getPlayer()); // null if they are offline
this.player = offlinePlayer; this.player = offlinePlayer;
} }
/// ========================================
/// These are checked for RegionAssociable
/// (to see if a player belongs to a region)
/// ========================================
@Override @Override
public String getName() { public String getName() {
return player.getName(); return player.getName();
@ -56,175 +61,191 @@ public UUID getUniqueId() {
@Override @Override
public boolean hasGroup(String group) { public boolean hasGroup(String group) {
return false; return plugin.inGroup(player, group);
}
@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) {
} }
@Override @Override
public String[] getGroups() { public String[] getGroups() {
return new String[0]; return plugin.getGroups(player);
} }
/// ==========================================
/// None of the following should ever be used.
/// ==========================================
@Override @Override
public boolean hasPermission(String perm) { public boolean hasPermission(String perm) {
return false; throw new UnsupportedOperationException();
} }
@Override @Override
public World getWorld() { public void kick(String msg) {
return null; 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 @Override
public BaseItemStack getItemInHand(HandSide handSide) { public BaseItemStack getItemInHand(HandSide handSide) {
return null; throw new UnsupportedOperationException();
} }
@Override @Override
public void giveItem(BaseItemStack itemStack) { public void giveItem(BaseItemStack itemStack) {
throw new UnsupportedOperationException();
} }
@Override @Override
public BlockBag getInventoryBlockBag() { public BlockBag getInventoryBlockBag()
return null; {
throw new UnsupportedOperationException();
} }
@Override @Override
public void setPosition(Vector3 pos, float pitch, float yaw) { public void setPosition(Vector3 pos, float pitch, float yaw) {
throw new UnsupportedOperationException();
} }
@Nullable @Nullable
@Override @Override
public BaseEntity getState() { public BaseEntity getState()
return null; {
throw new UnsupportedOperationException();
} }
@Override @Override
public Location getLocation() { public Location getLocation()
return null; {
throw new UnsupportedOperationException();
} }
@Override @Override
public void setCompassTarget(Location location) { public void setCompassTarget(Location location) {
throw new UnsupportedOperationException();
} }
@Override @Override
public SessionKey getSessionKey() { public SessionKey getSessionKey() {
return null; throw new UnsupportedOperationException();
} }
@Nullable @Nullable
@Override @Override
public <T> T getFacet(Class<? extends T> cls) { 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 { public class BukkitPlayer extends com.sk89q.worldedit.bukkit.BukkitPlayer implements LocalPlayer {
private final WorldGuardPlugin plugin; protected final WorldGuardPlugin plugin;
private final boolean silenced; private final boolean silenced;
private String name; private String name;
@ -40,7 +40,7 @@ public BukkitPlayer(WorldGuardPlugin plugin, Player player) {
} }
BukkitPlayer(WorldGuardPlugin plugin, Player player, boolean silenced) { BukkitPlayer(WorldGuardPlugin plugin, Player player, boolean silenced) {
super((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"), player); super(player);
this.plugin = plugin; this.plugin = plugin;
this.silenced = silenced; this.silenced = silenced;
} }

View File

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