1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-16 03:24:31 +02:00

Better exp fix and allow exp on buy and sell signs.

This commit is contained in:
snowleo
2011-12-13 08:38:15 +01:00
parent e021360613
commit 590c184433
8 changed files with 118 additions and 118 deletions

View File

@@ -1,5 +1,5 @@
annotation.processing.enabled=true annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false annotation.processing.enabled.in.editor=true
annotation.processing.processors.list=lombok.core.AnnotationProcessor annotation.processing.processors.list=lombok.core.AnnotationProcessor
annotation.processing.run.all.processors=false annotation.processing.run.all.processors=false
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output

View File

@@ -11,16 +11,8 @@ import org.bukkit.inventory.PlayerInventory;
* @deprecated This will be moved to the api package soon * @deprecated This will be moved to the api package soon
*/ */
@Deprecated @Deprecated
public interface IUser public interface IUser extends Player
{ {
int getHealth();
Location getLocation();
boolean isOnline();
void sendMessage(String string);
long getLastTeleportTimestamp(); long getLastTeleportTimestamp();
boolean isAuthorized(String node); boolean isAuthorized(String node);
@@ -41,10 +33,6 @@ public interface IUser
void giveMoney(double value); void giveMoney(double value);
PlayerInventory getInventory();
void updateInventory();
String getGroup(); String getGroup();
void setLastLocation(); void setLastLocation();
@@ -53,19 +41,9 @@ public interface IUser
Location getHome(Location loc) throws Exception; Location getHome(Location loc) throws Exception;
String getName();
InetSocketAddress getAddress();
String getDisplayName();
boolean isHidden(); boolean isHidden();
Teleport getTeleport(); Teleport getTeleport();
void setJail(String jail); void setJail(String jail);
public int getXP();
public void setXP(int l);
} }

View File

@@ -1,6 +1,7 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.earth2me.essentials.craftbukkit.SetExpFix;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@@ -40,8 +41,7 @@ public class Trade
public Trade(final int exp, final IEssentials ess) public Trade(final int exp, final IEssentials ess)
{ {
//TODO: Revert this change, when exp is fixed in Bukkit this(null, null, null, exp, ess);
this(null, (double)exp, null, null, ess);
} }
private Trade(final String command, final Double money, final ItemStack item, final Integer exp, final IEssentials ess) private Trade(final String command, final Double money, final ItemStack item, final Integer exp, final IEssentials ess)
@@ -81,7 +81,7 @@ public class Trade
} }
if (exp != null && exp > 0 if (exp != null && exp > 0
&& user.getXP() < exp) { && user.getTotalExperience() < exp) {
throw new ChargeException(_("notEnoughExperience")); throw new ChargeException(_("notEnoughExperience"));
} }
} }
@@ -116,7 +116,7 @@ public class Trade
} }
if (getExperience() != null) if (getExperience() != null)
{ {
user.setXP(user.getXP() + getExperience()); SetExpFix.setTotalExperience(user, user.getTotalExperience() + getExperience());
} }
return success; return success;
} }
@@ -155,12 +155,12 @@ public class Trade
} }
if (getExperience() != null) if (getExperience() != null)
{ {
final int experience = user.getXP(); final int experience = user.getTotalExperience();
if (experience < getExperience() && getExperience() > 0) if (experience < getExperience() && getExperience() > 0)
{ {
throw new ChargeException(_("notEnoughExperience")); throw new ChargeException(_("notEnoughExperience"));
} }
user.setXP(experience - getExperience()); SetExpFix.setTotalExperience(user, experience - getExperience());
} }
} }

View File

@@ -25,32 +25,32 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
private boolean hidden = false; private boolean hidden = false;
private transient Location afkPosition; private transient Location afkPosition;
private static final Logger logger = Logger.getLogger("Minecraft"); private static final Logger logger = Logger.getLogger("Minecraft");
User(final Player base, final IEssentials ess) User(final Player base, final IEssentials ess)
{ {
super(base, ess); super(base, ess);
teleport = new Teleport(this, ess); teleport = new Teleport(this, ess);
afkPosition = getLocation(); afkPosition = getLocation();
} }
User update(final Player base) User update(final Player base)
{ {
setBase(base); setBase(base);
return this; return this;
} }
@Override @Override
public boolean isAuthorized(final IEssentialsCommand cmd) public boolean isAuthorized(final IEssentialsCommand cmd)
{ {
return isAuthorized(cmd, "essentials."); return isAuthorized(cmd, "essentials.");
} }
@Override @Override
public boolean isAuthorized(final IEssentialsCommand cmd, final String permissionPrefix) public boolean isAuthorized(final IEssentialsCommand cmd, final String permissionPrefix)
{ {
return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName())); return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName()));
} }
@Override @Override
public boolean isAuthorized(final String node) public boolean isAuthorized(final String node)
{ {
@@ -58,20 +58,20 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{ {
return false; return false;
} }
if (isOp()) if (isOp())
{ {
return true; return true;
} }
if (isJailed()) if (isJailed())
{ {
return false; return false;
} }
return ess.getPermissionsHandler().hasPermission(base, node); return ess.getPermissionsHandler().hasPermission(base, node);
} }
public void healCooldown() throws Exception public void healCooldown() throws Exception
{ {
final Calendar now = new GregorianCalendar(); final Calendar now = new GregorianCalendar();
@@ -89,13 +89,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
setLastHealTimestamp(now.getTimeInMillis()); setLastHealTimestamp(now.getTimeInMillis());
} }
@Override @Override
public void giveMoney(final double value) public void giveMoney(final double value)
{ {
giveMoney(value, null); giveMoney(value, null);
} }
public void giveMoney(final double value, final CommandSender initiator) public void giveMoney(final double value, final CommandSender initiator)
{ {
if (value == 0) if (value == 0)
@@ -109,7 +109,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
initiator.sendMessage(_("addedToOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName())); initiator.sendMessage(_("addedToOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName()));
} }
} }
public void payUser(final User reciever, final double value) throws Exception public void payUser(final User reciever, final double value) throws Exception
{ {
if (value == 0) if (value == 0)
@@ -128,13 +128,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
throw new Exception(_("notEnoughMoney")); throw new Exception(_("notEnoughMoney"));
} }
} }
@Override @Override
public void takeMoney(final double value) public void takeMoney(final double value)
{ {
takeMoney(value, null); takeMoney(value, null);
} }
public void takeMoney(final double value, final CommandSender initiator) public void takeMoney(final double value, final CommandSender initiator)
{ {
if (value == 0) if (value == 0)
@@ -148,36 +148,36 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
initiator.sendMessage(_("takenFromOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName())); initiator.sendMessage(_("takenFromOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName()));
} }
} }
public boolean canAfford(final double cost) public boolean canAfford(final double cost)
{ {
final double mon = getMoney(); final double mon = getMoney();
return mon >= cost || isAuthorized("essentials.eco.loan"); return mon >= cost || isAuthorized("essentials.eco.loan");
} }
public void dispose() public void dispose()
{ {
this.base = new OfflinePlayer(getName(), ess); this.base = new OfflinePlayer(getName(), ess);
} }
@Override @Override
public void setReplyTo(final CommandSender user) public void setReplyTo(final CommandSender user)
{ {
replyTo = user; replyTo = user;
} }
@Override @Override
public CommandSender getReplyTo() public CommandSender getReplyTo()
{ {
return replyTo; return replyTo;
} }
@Override @Override
public int compareTo(final User other) public int compareTo(final User other)
{ {
return Util.stripColor(this.getDisplayName()).compareToIgnoreCase(Util.stripColor(other.getDisplayName())); return Util.stripColor(this.getDisplayName()).compareToIgnoreCase(Util.stripColor(other.getDisplayName()));
} }
@Override @Override
public boolean equals(final Object object) public boolean equals(final Object object)
{ {
@@ -186,58 +186,58 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return false; return false;
} }
return this.getName().equalsIgnoreCase(((User)object).getName()); return this.getName().equalsIgnoreCase(((User)object).getName());
} }
@Override @Override
public int hashCode() public int hashCode()
{ {
return this.getName().hashCode(); return this.getName().hashCode();
} }
public Boolean canSpawnItem(final int itemId) public Boolean canSpawnItem(final int itemId)
{ {
return !ess.getSettings().itemSpawnBlacklist().contains(itemId); return !ess.getSettings().itemSpawnBlacklist().contains(itemId);
} }
public Location getHome() throws Exception public Location getHome() throws Exception
{ {
return getHome(getHomes().get(0)); return getHome(getHomes().get(0));
} }
public void setHome() public void setHome()
{ {
setHome("home", getLocation()); setHome("home", getLocation());
} }
public void setHome(final String name) public void setHome(final String name)
{ {
setHome(name, getLocation()); setHome(name, getLocation());
} }
@Override @Override
public void setLastLocation() public void setLastLocation()
{ {
setLastLocation(getLocation()); setLastLocation(getLocation());
} }
public void requestTeleport(final User player, final boolean here) public void requestTeleport(final User player, final boolean here)
{ {
teleportRequestTime = System.currentTimeMillis(); teleportRequestTime = System.currentTimeMillis();
teleportRequester = player; teleportRequester = player;
teleportRequestHere = here; teleportRequestHere = here;
} }
public User getTeleportRequest() public User getTeleportRequest()
{ {
return teleportRequester; return teleportRequester;
} }
public boolean isTeleportRequestHere() public boolean isTeleportRequestHere()
{ {
return teleportRequestHere; return teleportRequestHere;
} }
public String getNick(boolean addprefixsuffix) public String getNick(boolean addprefixsuffix)
{ {
final StringBuilder nickname = new StringBuilder(); final StringBuilder nickname = new StringBuilder();
@@ -261,7 +261,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{ {
} }
} }
if (addprefixsuffix && ess.getSettings().addPrefixSuffix()) if (addprefixsuffix && ess.getSettings().addPrefixSuffix())
{ {
if (!ess.getSettings().disablePrefix()) if (!ess.getSettings().disablePrefix())
@@ -283,10 +283,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
nickname.append("§f"); nickname.append("§f");
} }
} }
return nickname.toString(); return nickname.toString();
} }
public void setDisplayNick() public void setDisplayNick()
{ {
String name = getNick(true); String name = getNick(true);
@@ -308,7 +308,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
logger.log(Level.INFO, "Playerlist for " + name + " was not updated. Use a shorter displayname prefix."); logger.log(Level.INFO, "Playerlist for " + name + " was not updated. Use a shorter displayname prefix.");
} }
} }
@Override @Override
public String getDisplayName() public String getDisplayName()
{ {
@@ -318,22 +318,22 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
return super.getDisplayName() == null ? super.getName() : super.getDisplayName(); return super.getDisplayName() == null ? super.getName() : super.getDisplayName();
} }
public Teleport getTeleport() public Teleport getTeleport()
{ {
return teleport; return teleport;
} }
public long getLastOnlineActivity() public long getLastOnlineActivity()
{ {
return lastOnlineActivity; return lastOnlineActivity;
} }
public void setLastOnlineActivity(final long timestamp) public void setLastOnlineActivity(final long timestamp)
{ {
lastOnlineActivity = timestamp; lastOnlineActivity = timestamp;
} }
@Override @Override
public double getMoney() public double getMoney()
{ {
@@ -355,7 +355,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
return super.getMoney(); return super.getMoney();
} }
@Override @Override
public void setMoney(final double value) public void setMoney(final double value)
{ {
@@ -377,7 +377,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
super.setMoney(value); super.setMoney(value);
} }
@Override @Override
public void setAfk(final boolean set) public void setAfk(final boolean set)
{ {
@@ -388,7 +388,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
super.setAfk(set); super.setAfk(set);
} }
@Override @Override
public boolean toggleAfk() public boolean toggleAfk()
{ {
@@ -396,13 +396,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : now); this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : now);
return now; return now;
} }
@Override @Override
public boolean isHidden() public boolean isHidden()
{ {
return hidden; return hidden;
} }
public void setHidden(final boolean hidden) public void setHidden(final boolean hidden)
{ {
this.hidden = hidden; this.hidden = hidden;
@@ -453,7 +453,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
return false; return false;
} }
public void updateActivity(final boolean broadcast) public void updateActivity(final boolean broadcast)
{ {
if (isAfk()) if (isAfk())
@@ -466,7 +466,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
lastActivity = System.currentTimeMillis(); lastActivity = System.currentTimeMillis();
} }
public void checkActivity() public void checkActivity()
{ {
final long autoafkkick = ess.getSettings().getAutoAfkKick(); final long autoafkkick = ess.getSettings().getAutoAfkKick();
@@ -476,8 +476,8 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
final String kickReason = _("autoAfkKickReason", autoafkkick / 60.0); final String kickReason = _("autoAfkKickReason", autoafkkick / 60.0);
lastActivity = 0; lastActivity = 0;
kickPlayer(kickReason); kickPlayer(kickReason);
for (Player player : ess.getServer().getOnlinePlayers()) for (Player player : ess.getServer().getOnlinePlayers())
{ {
final User user = ess.getUser(player); final User user = ess.getUser(player);
@@ -497,12 +497,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
} }
} }
public Location getAfkPosition() public Location getAfkPosition()
{ {
return afkPosition; return afkPosition;
} }
@Override @Override
public boolean toggleGodModeEnabled() public boolean toggleGodModeEnabled()
{ {
@@ -512,7 +512,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
return super.toggleGodModeEnabled(); return super.toggleGodModeEnabled();
} }
@Override @Override
public boolean isGodModeEnabled() public boolean isGodModeEnabled()
{ {
@@ -524,17 +524,17 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{ {
return super.isGodModeEnabled(); return super.isGodModeEnabled();
} }
public String getGroup() public String getGroup()
{ {
return ess.getPermissionsHandler().getGroup(base); return ess.getPermissionsHandler().getGroup(base);
} }
public boolean inGroup(final String group) public boolean inGroup(final String group)
{ {
return ess.getPermissionsHandler().inGroup(base, group); return ess.getPermissionsHandler().inGroup(base, group);
} }
public boolean canBuild() public boolean canBuild()
{ {
return ess.getPermissionsHandler().canBuild(base, getGroup()); return ess.getPermissionsHandler().canBuild(base, getGroup());
@@ -543,21 +543,5 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
public long getTeleportRequestTime() public long getTeleportRequestTime()
{ {
return teleportRequestTime; return teleportRequestTime;
} }
@Override
public int getXP() {
return base.getTotalExperience();
}
@Override
public void setXP(final int exp) {
base.setExp(0);
base.setLevel(0);
base.setTotalExperience(0);
for(int i=0;i<exp; ++i) {
base.giveExp(1);
}
}
} }

View File

@@ -0,0 +1,41 @@
package com.earth2me.essentials.craftbukkit;
import org.bukkit.entity.Player;
public class SetExpFix
{
public static void setTotalExperience(final Player player, final int exp)
{
if (exp < 0)
{
throw new IllegalArgumentException("Experience is negative!");
}
player.setExp(0);
player.setLevel(0);
player.setTotalExperience(0);
int amount = exp;
while (amount > 0)
{
final int expToLevel = getExpTolevel(player);
amount -= expToLevel;
if (amount >= 0)
{
// give until next level
player.giveExp(expToLevel);
}
else
{
// give the rest
amount += expToLevel;
player.giveExp(amount);
amount = 0;
}
}
}
private static int getExpTolevel(final Player player)
{
return 7 + (player.getLevel() * 7 >> 1);
}
}

View File

@@ -273,6 +273,12 @@ public class EssentialsSign
protected final void validateTrade(final ISign sign, final int amountIndex, final int itemIndex, protected final void validateTrade(final ISign sign, final int amountIndex, final int itemIndex,
final User player, final IEssentials ess) throws SignException final User player, final IEssentials ess) throws SignException
{ {
if (sign.getLine(itemIndex).equalsIgnoreCase("exp") || sign.getLine(itemIndex).equalsIgnoreCase("xp"))
{
int amount = getIntegerPositive(sign.getLine(amountIndex));
sign.setLine(amountIndex, Integer.toString(amount));
sign.setLine(itemIndex, "exp");
}
final Trade trade = getTrade(sign, amountIndex, itemIndex, player, ess); final Trade trade = getTrade(sign, amountIndex, itemIndex, player, ess);
final ItemStack item = trade.getItemStack(); final ItemStack item = trade.getItemStack();
sign.setLine(amountIndex, Integer.toString(item.getAmount())); sign.setLine(amountIndex, Integer.toString(item.getAmount()));
@@ -282,7 +288,11 @@ public class EssentialsSign
protected final Trade getTrade(final ISign sign, final int amountIndex, final int itemIndex, protected final Trade getTrade(final ISign sign, final int amountIndex, final int itemIndex,
final User player, final IEssentials ess) throws SignException final User player, final IEssentials ess) throws SignException
{ {
if (sign.getLine(itemIndex).equalsIgnoreCase("exp") || sign.getLine(itemIndex).equalsIgnoreCase("xp"))
{
final int amount = getIntegerPositive(sign.getLine(amountIndex));
return new Trade(amount, ess);
}
final ItemStack item = getItemStack(sign.getLine(itemIndex), 1, ess); final ItemStack item = getItemStack(sign.getLine(itemIndex), 1, ess);
final int amount = Math.min(getIntegerPositive(sign.getLine(amountIndex)), item.getType().getMaxStackSize() * player.getInventory().getSize()); final int amount = Math.min(getIntegerPositive(sign.getLine(amountIndex)), item.getType().getMaxStackSize() * player.getInventory().getSize());
if (item.getTypeId() == 0 || amount < 1) if (item.getTypeId() == 0 || amount < 1)

View File

@@ -196,17 +196,4 @@ public class User extends UserBase implements IUser
unlock(); unlock();
} }
} }
@Override
public int getXP()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setXP(int l)
{
throw new UnsupportedOperationException("Not supported yet.");
}
} }

View File

@@ -63,11 +63,11 @@ dist.jar=${dist.dir}/EssentialsUpdate.jar
dist.javadoc.dir=${dist.dir}/javadoc dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath= endorsed.classpath=
excludes= excludes=
file.reference.bukkit-1.0.0-R1-SNAPSHOT.jar=../lib/bukkit-1.0.0-R1-SNAPSHOT.jar file.reference.bukkit.jar=../lib/bukkit.jar
includes=** includes=**
jar.compress=true jar.compress=true
javac.classpath=\ javac.classpath=\
${file.reference.bukkit-1.0.0-R1-SNAPSHOT.jar} ${file.reference.bukkit.jar}
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs= javac.compilerargs=
javac.deprecation=false javac.deprecation=false