Use of lomboks delegate on player wrapping

This commit is contained in:
snowleo 2011-10-21 01:23:35 +02:00
parent 022b8caa18
commit 1a020698d1
4 changed files with 59 additions and 849 deletions

View File

@ -3,9 +3,9 @@ package com.earth2me.essentials;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import lombok.Delegate;
import org.bukkit.Achievement; import org.bukkit.Achievement;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -36,40 +36,32 @@ import org.bukkit.util.Vector;
public class OfflinePlayer implements Player public class OfflinePlayer implements Player
{ {
private final String name; private final transient IEssentials ess;
final transient IEssentials ess;
private Location location = new Location(null, 0, 0, 0, 0, 0); private Location location = new Location(null, 0, 0, 0, 0, 0);
private World world; private World world;
private UUID uniqueId = UUID.randomUUID(); private UUID uniqueId = UUID.randomUUID();
private org.bukkit.OfflinePlayer base; @Delegate(types=org.bukkit.OfflinePlayer.class)
private final org.bukkit.OfflinePlayer base;
public OfflinePlayer(String name, IEssentials ess) public OfflinePlayer(final String name, final IEssentials ess)
{ {
this.name = name;
this.ess = ess; this.ess = ess;
this.world = ess.getServer().getWorlds().get(0); this.world = ess.getServer().getWorlds().get(0);
this.base = ess.getServer().getOfflinePlayer(name); this.base = ess.getServer().getOfflinePlayer(name);
} }
public boolean isOnline() @Override
{ public void sendMessage(final String string)
return base.isOnline();
}
public boolean isOp()
{
return base.isOp();
}
public void sendMessage(String string)
{ {
} }
@Override
public String getDisplayName() public String getDisplayName()
{ {
return name; return base.getName();
} }
@Override
public void setDisplayName(String string) public void setDisplayName(String string)
{ {
} }
@ -87,11 +79,6 @@ public class OfflinePlayer implements Player
{ {
} }
public String getName()
{
return name;
}
public PlayerInventory getInventory() public PlayerInventory getInventory()
{ {
return null; return null;
@ -577,42 +564,13 @@ public class OfflinePlayer implements Player
{ {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
public void setOp(boolean bln)
{
base.setOp(bln);
}
@Override @Override
public void sendMap(MapView mv) public void sendMap(MapView mv)
{ {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
@Override
public boolean isBanned()
{
return base.isBanned();
}
@Override
public void setBanned(boolean bln)
{
base.setBanned(bln);
}
@Override
public boolean isWhitelisted()
{
return base.isWhitelisted();
}
@Override
public void setWhitelisted(boolean bln)
{
base.setWhitelisted(bln);
}
@Override @Override
public GameMode getGameMode() public GameMode getGameMode()
{ {
@ -738,10 +696,4 @@ public class OfflinePlayer implements Player
{ {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
@Override
public Map<String, Object> serialize()
{
throw new UnsupportedOperationException("Not supported yet.");
}
} }

View File

@ -1,28 +1,53 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import lombok.Delegate;
import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.entity.CraftPlayer;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.IInventory; import net.minecraft.server.IInventory;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer; import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible;
import org.bukkit.permissions.ServerOperator;
public class PlayerExtension extends PlayerWrapper public class PlayerExtension implements Player
{ {
protected final IEssentials ess; protected final transient IEssentials ess;
@Delegate(types =
public PlayerExtension(Player base, IEssentials ess)
{ {
super(base); Player.class, Entity.class, CommandSender.class, ServerOperator.class,
HumanEntity.class, ConfigurationSerializable.class, LivingEntity.class,
Permissible.class
})
protected Player base;
public PlayerExtension(final Player base, final IEssentials ess)
{
this.base = base;
this.ess = ess; this.ess = ess;
} }
public void showInventory(IInventory inventory) public final Player getBase()
{
return base;
}
public final Player setBase(final Player base)
{
return this.base = base;
}
public void showInventory(final IInventory inventory)
{ {
getHandle().a(inventory); getHandle().a(inventory);
} }
public void showInventory(CraftInventoryPlayer inventory) public void showInventory(final CraftInventoryPlayer inventory)
{ {
showInventory((IInventory)inventory.getInventory()); showInventory((IInventory)inventory.getInventory());
} }
@ -37,7 +62,7 @@ public class PlayerExtension extends PlayerWrapper
return ess.getPermissionsHandler().getGroup(base); return ess.getPermissionsHandler().getGroup(base);
} }
public boolean inGroup(String group) public boolean inGroup(final String group)
{ {
return ess.getPermissionsHandler().inGroup(base, group); return ess.getPermissionsHandler().inGroup(base, group);
} }

View File

@ -1,777 +0,0 @@
package com.earth2me.essentials;
import java.net.InetSocketAddress;
import java.util.*;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.*;
import org.bukkit.map.MapView;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
public class PlayerWrapper implements Player
{
protected Player base;
public PlayerWrapper(Player base)
{
this.base = base;
}
public final Player getBase()
{
return base;
}
public final Player setBase(Player base)
{
return this.base = base;
}
@Override
public void setDisplayName(String string)
{
base.setDisplayName(string);
}
@Override
public void setCompassTarget(Location lctn)
{
base.setCompassTarget(lctn);
}
@Override
public InetSocketAddress getAddress()
{
return base.getAddress();
}
@Override
public void kickPlayer(String string)
{
base.kickPlayer(string);
}
@Override
public String getName()
{
return base.getName();
}
@Override
public PlayerInventory getInventory()
{
return base.getInventory();
}
@Override
public ItemStack getItemInHand()
{
return base.getItemInHand();
}
@Override
public void setItemInHand(ItemStack is)
{
base.setItemInHand(is);
}
@Override
public int getHealth()
{
return base.getHealth();
}
@Override
public void setHealth(int i)
{
base.setHealth(i);
}
@Override
public Egg throwEgg()
{
return base.throwEgg();
}
@Override
public Snowball throwSnowball()
{
return base.throwSnowball();
}
@Override
public Arrow shootArrow()
{
return base.shootArrow();
}
@Override
public boolean isInsideVehicle()
{
return base.isInsideVehicle();
}
@Override
public boolean leaveVehicle()
{
return base.leaveVehicle();
}
@Override
public Vehicle getVehicle()
{
return base.getVehicle();
}
@Override
public Location getLocation()
{
return base.getLocation();
}
@Override
public World getWorld()
{
return base.getWorld();
}
@Override
public Server getServer()
{
return base.getServer();
}
@Override
public boolean isOnline()
{
return base.isOnline();
}
@Override
public boolean isOp()
{
return base.isOp();
}
@Override
public boolean teleport(Location lctn)
{
return base.teleport(lctn);
}
@Override
public boolean teleport(Entity entity)
{
return base.teleport(entity);
}
@Override
public void sendMessage(String string)
{
base.sendMessage(string);
}
@Override
public void setVelocity(Vector vector)
{
base.setVelocity(vector);
}
@Override
public Vector getVelocity()
{
return base.getVelocity();
}
@Override
public double getEyeHeight()
{
return base.getEyeHeight();
}
@Override
public double getEyeHeight(boolean bln)
{
return base.getEyeHeight(bln);
}
@Override
public List<Block> getLineOfSight(HashSet<Byte> hs, int i)
{
return base.getLineOfSight(hs, i);
}
@Override
public Block getTargetBlock(HashSet<Byte> hs, int i)
{
return base.getTargetBlock(hs, i);
}
@Override
public List<Block> getLastTwoTargetBlocks(HashSet<Byte> hs, int i)
{
return base.getLastTwoTargetBlocks(hs, i);
}
@Override
public int getFireTicks()
{
return base.getFireTicks();
}
@Override
public int getMaxFireTicks()
{
return base.getMaxFireTicks();
}
@Override
public void setFireTicks(int i)
{
base.setFireTicks(i);
}
@Override
public void remove()
{
base.remove();
}
/**
* This is not deprecated because the underlying method isn't really deprecated; rather, it's just "imperfect". By
* We will continue to use this method even after the underlying CraftBukkit method is changed, so do not deprecate
* it. Chances are Bukkit will also choose to un-deprecate this method at some point.
*/
@Override
public void updateInventory()
{
base.updateInventory();
}
@Override
public void chat(String string)
{
base.chat(string);
}
@Override
public boolean isSneaking()
{
return base.isSneaking();
}
@Override
public void setSneaking(boolean bln)
{
base.setSneaking(bln);
}
@Override
public int getEntityId()
{
return base.getEntityId();
}
@Override
public boolean performCommand(String string)
{
return base.performCommand(string);
}
@Override
public int getRemainingAir()
{
return base.getRemainingAir();
}
@Override
public void setRemainingAir(int i)
{
base.setRemainingAir(i);
}
@Override
public int getMaximumAir()
{
return base.getMaximumAir();
}
@Override
public void setMaximumAir(int i)
{
base.setMaximumAir(i);
}
@Override
public String getDisplayName()
{
if (base.getDisplayName() != null)
return base.getDisplayName();
else
return base.getName();
}
@Override
public void damage(int i)
{
base.damage(i);
}
@Override
public void damage(int i, Entity entity)
{
base.damage(i, entity);
}
@Override
public Location getEyeLocation()
{
return base.getEyeLocation();
}
@Override
public void sendRawMessage(String string) {
base.sendRawMessage(string);
}
@Override
public Location getCompassTarget()
{
return base.getCompassTarget();
}
@Override
public int getMaximumNoDamageTicks()
{
return base.getMaximumNoDamageTicks();
}
@Override
public void setMaximumNoDamageTicks(int i)
{
base.setMaximumNoDamageTicks(i);
}
@Override
public int getLastDamage()
{
return base.getLastDamage();
}
@Override
public void setLastDamage(int i)
{
base.setLastDamage(i);
}
@Override
public int getNoDamageTicks()
{
return base.getNoDamageTicks();
}
@Override
public void setNoDamageTicks(int i)
{
base.setNoDamageTicks(i);
}
@Override
public Entity getPassenger()
{
return base.getPassenger();
}
@Override
public boolean setPassenger(Entity entity)
{
return base.setPassenger(entity);
}
@Override
public boolean isEmpty()
{
return base.isEmpty();
}
@Override
public boolean eject()
{
return base.eject();
}
public void saveData()
{
base.saveData();
}
public void loadData()
{
base.loadData();
}
public boolean isSleeping()
{
return base.isSleeping();
}
public int getSleepTicks()
{
return base.getSleepTicks();
}
public List<Entity> getNearbyEntities(double d, double d1, double d2)
{
return base.getNearbyEntities(d, d1, d2);
}
public boolean isDead()
{
return base.isDead();
}
public float getFallDistance()
{
return base.getFallDistance();
}
public void setFallDistance(float f)
{
base.setFallDistance(f);
}
public void setSleepingIgnored(boolean bln)
{
base.setSleepingIgnored(bln);
}
public boolean isSleepingIgnored()
{
return base.isSleepingIgnored();
}
public void awardAchievement(Achievement a)
{
base.awardAchievement(a);
}
public void incrementStatistic(Statistic ststc)
{
base.incrementStatistic(ststc);
}
public void incrementStatistic(Statistic ststc, int i)
{
base.incrementStatistic(ststc, i);
}
public void incrementStatistic(Statistic ststc, Material mtrl)
{
base.incrementStatistic(ststc, mtrl);
}
public void incrementStatistic(Statistic ststc, Material mtrl, int i)
{
base.incrementStatistic(ststc, mtrl, i);
}
public void playNote(Location lctn, byte b, byte b1)
{
base.playNote(lctn, b, b1);
}
public void sendBlockChange(Location lctn, Material mtrl, byte b)
{
base.sendBlockChange(lctn, mtrl, b);
}
public void sendBlockChange(Location lctn, int i, byte b)
{
base.sendBlockChange(lctn, i, b);
}
public void setLastDamageCause(EntityDamageEvent ede)
{
base.setLastDamageCause(ede);
}
public EntityDamageEvent getLastDamageCause()
{
return base.getLastDamageCause();
}
public void playEffect(Location lctn, Effect effect, int i)
{
base.playEffect(lctn, effect, i);
}
public boolean sendChunkChange(Location lctn, int i, int i1, int i2, byte[] bytes)
{
return base.sendChunkChange(lctn, i, i1, i2, bytes);
}
public UUID getUniqueId()
{
return base.getUniqueId();
}
public void playNote(Location lctn, Instrument i, Note note)
{
base.playNote(lctn, i, note);
}
public void setPlayerTime(long l, boolean bln)
{
base.setPlayerTime(l, bln);
}
public long getPlayerTime()
{
return base.getPlayerTime();
}
public long getPlayerTimeOffset()
{
return base.getPlayerTimeOffset();
}
public boolean isPlayerTimeRelative()
{
return base.isPlayerTimeRelative();
}
public void resetPlayerTime()
{
base.resetPlayerTime();
}
public boolean isPermissionSet(String string)
{
return base.isPermissionSet(string);
}
public boolean isPermissionSet(Permission prmsn)
{
return base.isPermissionSet(prmsn);
}
public boolean hasPermission(String string)
{
return base.hasPermission(string);
}
public boolean hasPermission(Permission prmsn)
{
return base.hasPermission(prmsn);
}
public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln)
{
return base.addAttachment(plugin, string, bln);
}
public PermissionAttachment addAttachment(Plugin plugin)
{
return base.addAttachment(plugin);
}
public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln, int i)
{
return base.addAttachment(plugin, string, bln, i);
}
public PermissionAttachment addAttachment(Plugin plugin, int i)
{
return base.addAttachment(plugin, i);
}
public void removeAttachment(PermissionAttachment pa)
{
throw new UnsupportedOperationException("Not supported yet.");
}
public void recalculatePermissions()
{
base.recalculatePermissions();
}
public Set<PermissionAttachmentInfo> getEffectivePermissions()
{
return base.getEffectivePermissions();
}
public void setOp(boolean bln)
{
base.setOp(bln);
}
@Override
public void sendMap(MapView mv)
{
base.sendMap(mv);
}
@Override
public boolean isBanned()
{
return base.isBanned();
}
@Override
public void setBanned(boolean bln)
{
base.setBanned(bln);
}
@Override
public boolean isWhitelisted()
{
return base.isWhitelisted();
}
@Override
public void setWhitelisted(boolean bln)
{
base.setWhitelisted(bln);
}
@Override
public GameMode getGameMode()
{
return base.getGameMode();
}
@Override
public void setGameMode(GameMode gm)
{
base.setGameMode(gm);
}
@Override
public int getExperience()
{
return base.getExperience();
}
@Override
public void setExperience(int i)
{
base.setExperience(i);
}
@Override
public int getLevel()
{
return base.getLevel();
}
@Override
public void setLevel(int i)
{
base.setLevel(i);
}
@Override
public int getTotalExperience()
{
return base.getTotalExperience();
}
@Override
public void setTotalExperience(int i)
{
base.setTotalExperience(i);
}
@Override
public float getExhaustion()
{
return base.getExhaustion();
}
@Override
public void setExhaustion(float f)
{
base.setExhaustion(f);
}
@Override
public float getSaturation()
{
return base.getSaturation();
}
@Override
public void setSaturation(float f)
{
base.setSaturation(f);
}
@Override
public int getFoodLevel()
{
return base.getFoodLevel();
}
@Override
public void setFoodLevel(int i)
{
base.setFoodLevel(i);
}
@Override
public Location getBedSpawnLocation()
{
return base.getBedSpawnLocation();
}
@Override
public boolean isSprinting()
{
return base.isSprinting();
}
@Override
public void setSprinting(boolean bln)
{
base.setSprinting(bln);
}
@Override
public void setPlayerListName(String name)
{
base.setPlayerListName(name);
}
@Override
public String getPlayerListName()
{
return base.getPlayerListName();
}
@Override
public int getTicksLived()
{
return base.getTicksLived();
}
@Override
public void setTicksLived(int i)
{
base.setTicksLived(i);
}
@Override
public Map<String, Object> serialize()
{
return base.serialize();
}
}

View File

@ -282,16 +282,23 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return nickname.toString(); return nickname.toString();
} }
public void setDisplayNick(String name) public void setDisplayNick(String name)
{ {
setDisplayName(name); setDisplayName(name);
//TODO: Maybe we need to limit nick length, or try use a string trim. //TODO: Maybe we need to limit nick length, or try use a string trim.
if (name.length() <= 16) { if (name.length() <= 16)
{
setPlayerListName(name); setPlayerListName(name);
} }
} }
@Override
public String getDisplayName()
{
return super.getDisplayName() == null ? super.getName() : super.getDisplayName();
}
public Teleport getTeleport() public Teleport getTeleport()
{ {
return teleport; return teleport;
@ -355,7 +362,8 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
public void setAfk(final boolean set) public void setAfk(final boolean set)
{ {
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set); this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set);
if (set && !isAfk()) { if (set && !isAfk())
{
afkPosition = getLocation(); afkPosition = getLocation();
} }
super.setAfk(set); super.setAfk(set);
@ -461,7 +469,8 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
if (!isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && isAuthorized("essentials.afk")) if (!isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && isAuthorized("essentials.afk"))
{ {
setAfk(true); setAfk(true);
if (!isHidden()) { if (!isHidden())
{
ess.broadcastMessage(this, Util.format("userIsAway", getDisplayName())); ess.broadcastMessage(this, Util.format("userIsAway", getDisplayName()));
} }
} }
@ -475,7 +484,8 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
@Override @Override
public boolean toggleGodModeEnabled() public boolean toggleGodModeEnabled()
{ {
if (!isGodModeEnabled()) { if (!isGodModeEnabled())
{
setFoodLevel(20); setFoodLevel(20);
} }
return super.toggleGodModeEnabled(); return super.toggleGodModeEnabled();