Tidy and slightly expand user API

This commit is contained in:
KHobbits 2013-07-14 12:41:27 +01:00
parent 0d2dea41e3
commit 11f87eccb0
2 changed files with 118 additions and 62 deletions

View File

@ -2,44 +2,52 @@ package com.earth2me.essentials;
import com.earth2me.essentials.commands.IEssentialsCommand;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.ess3.api.ITeleport;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public interface IUser
{
long getLastTeleportTimestamp();
boolean isAuthorized(String node);
boolean isAuthorized(IEssentialsCommand cmd);
boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix);
void setLastTeleportTimestamp(long time);
Location getLastLocation();
Player getBase();
BigDecimal getMoney();
void takeMoney(BigDecimal value);
void healCooldown() throws Exception;
void giveMoney(BigDecimal value);
void giveMoney(final BigDecimal value, final CommandSender initiator);
void payUser(final User reciever, final BigDecimal value) throws Exception;
void takeMoney(BigDecimal value);
void takeMoney(final BigDecimal value, final CommandSender initiator);
boolean canAfford(BigDecimal value);
String getGroup();
Boolean canSpawnItem(final int itemId);
void setLastLocation();
Location getHome(String name) throws Exception;
void setLogoutLocation();
Location getHome(Location loc) throws Exception;
void requestTeleport(final User player, final boolean here);
ITeleport getTeleport();
BigDecimal getMoney();
void setMoney(final BigDecimal value);
void setAfk(final boolean set);
/**
* 'Hidden' Represents when a player is hidden from others. This status includes when the player is hidden via other
@ -52,6 +60,22 @@ public interface IUser
void setHidden(boolean vanish);
boolean isGodModeEnabled();
String getGroup();
boolean inGroup(final String group);
boolean canBuild();
long getTeleportRequestTime();
void enableInvulnerabilityAfterTeleport();
void resetInvulnerabilityAfterTeleport();
boolean hasInvulnerabilityAfterTeleport();
/**
* 'Vanished' Represents when a player is hidden from others by Essentials. This status does NOT include when the
* player is hidden via other plugins. Use isHidden() if you want to check if a user is vanished by any supported
@ -64,20 +88,44 @@ public interface IUser
void setVanished(boolean vanish);
ITeleport getTeleport();
void setJail(String jail);
boolean isIgnoreExempt();
boolean isAfk();
public void sendMessage(String message);
void setAfk(final boolean set);
/*
* UserData
*/
Location getHome(String name) throws Exception;
void setLogoutLocation();
Location getHome(Location loc) throws Exception;
List<String> getHomes();
void setHome(String name, Location loc);
void delHome(String name) throws Exception;
boolean hasHome();
Location getLastLocation();
Location getLogoutLocation();
long getLastTeleportTimestamp();
void setLastTeleportTimestamp(long time);
String getJail();
void setJail(String jail);
List<String> getMails();
void addMail(String mail);
boolean isAfk();
void setConfigProperty(String node, Object object);
Set<String> getConfigKeys();
@ -85,8 +133,12 @@ public interface IUser
Map<String, Object> getConfigMap();
Map<String, Object> getConfigMap(String node);
public void sendMessage(String message);
/*
* PlayerExtension
*/
Player getBase();
public String getName();
}

View File

@ -109,6 +109,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
}
}
@Override
public void healCooldown() throws Exception
{
final Calendar now = new GregorianCalendar();
@ -133,6 +134,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
giveMoney(value, null);
}
@Override
public void giveMoney(final BigDecimal value, final CommandSender initiator)
{
if (value.signum() == 0)
@ -147,6 +149,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
}
}
@Override
public void payUser(final User reciever, final BigDecimal value) throws Exception
{
if (value.signum() == 0)
@ -172,6 +175,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
takeMoney(value, null);
}
@Override
public void takeMoney(final BigDecimal value, final CommandSender initiator)
{
if (value.signum() == 0)
@ -212,50 +216,11 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
}
@Override
public void setReplyTo(final CommandSender user)
{
replyTo = user;
}
@Override
public CommandSender getReplyTo()
{
return replyTo;
}
@Override
public int compareTo(final User other)
{
return FormatUtil.stripFormat(this.getDisplayName()).compareToIgnoreCase(FormatUtil.stripFormat(other.getDisplayName()));
}
@Override
public boolean equals(final Object object)
{
if (!(object instanceof User))
{
return false;
}
return this.getName().equalsIgnoreCase(((User)object).getName());
}
@Override
public int hashCode()
{
return this.getName().hashCode();
}
public Boolean canSpawnItem(final int itemId)
{
return !ess.getSettings().itemSpawnBlacklist().contains(itemId);
}
public Location getHome() throws Exception
{
return getHome(getHomes().get(0));
}
@Override
public void setLastLocation()
{
@ -633,11 +598,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
return ess.getPermissionsHandler().getGroup(base);
}
@Override
public boolean inGroup(final String group)
{
return ess.getPermissionsHandler().inGroup(base, group);
}
@Override
public boolean canBuild()
{
if (isOp())
@ -673,6 +640,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
}
private transient long teleportInvulnerabilityTimestamp = 0;
@Override
public void enableInvulnerabilityAfterTeleport()
{
final long time = ess.getSettings().getTeleportInvulnerability();
@ -682,6 +650,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
}
}
@Override
public void resetInvulnerabilityAfterTeleport()
{
if (teleportInvulnerabilityTimestamp != 0
@ -790,4 +759,39 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
base.sendMessage(message);
}
}
@Override
public void setReplyTo(final CommandSender user)
{
replyTo = user;
}
@Override
public CommandSender getReplyTo()
{
return replyTo;
}
@Override
public int compareTo(final User other)
{
return FormatUtil.stripFormat(this.getDisplayName()).compareToIgnoreCase(FormatUtil.stripFormat(other.getDisplayName()));
}
@Override
public boolean equals(final Object object)
{
if (!(object instanceof User))
{
return false;
}
return this.getName().equalsIgnoreCase(((User)object).getName());
}
@Override
public int hashCode()
{
return this.getName().hashCode();
}
}