summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-12-13 08:38:15 +0100
committersnowleo <schneeleo@gmail.com>2011-12-13 08:38:15 +0100
commit15ce04b53952228180052c620211b6f8803f2c36 (patch)
treea75cb21d31278bb442f61cff3944ff7517451746
parent907f6c611652dd4d6c92bfd44e79a4389ed390b8 (diff)
downloadEssentials-15ce04b53952228180052c620211b6f8803f2c36.tar
Essentials-15ce04b53952228180052c620211b6f8803f2c36.tar.gz
Essentials-15ce04b53952228180052c620211b6f8803f2c36.tar.lz
Essentials-15ce04b53952228180052c620211b6f8803f2c36.tar.xz
Essentials-15ce04b53952228180052c620211b6f8803f2c36.zip
Better exp fix and allow exp on buy and sell signs.
-rw-r--r--Essentials/nbproject/project.properties2
-rw-r--r--Essentials/src/com/earth2me/essentials/IUser.java24
-rw-r--r--Essentials/src/com/earth2me/essentials/Trade.java12
-rw-r--r--Essentials/src/com/earth2me/essentials/User.java128
-rw-r--r--Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java41
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java12
-rw-r--r--Essentials/src/com/earth2me/essentials/user/User.java13
-rw-r--r--EssentialsUpdate/nbproject/project.properties4
8 files changed, 118 insertions, 118 deletions
diff --git a/Essentials/nbproject/project.properties b/Essentials/nbproject/project.properties
index 87e522254..8fe72adb3 100644
--- a/Essentials/nbproject/project.properties
+++ b/Essentials/nbproject/project.properties
@@ -1,5 +1,5 @@
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.run.all.processors=false
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java
index c7038e905..bff556ab4 100644
--- a/Essentials/src/com/earth2me/essentials/IUser.java
+++ b/Essentials/src/com/earth2me/essentials/IUser.java
@@ -11,16 +11,8 @@ import org.bukkit.inventory.PlayerInventory;
* @deprecated This will be moved to the api package soon
*/
@Deprecated
-public interface IUser
+public interface IUser extends Player
{
- int getHealth();
-
- Location getLocation();
-
- boolean isOnline();
-
- void sendMessage(String string);
-
long getLastTeleportTimestamp();
boolean isAuthorized(String node);
@@ -41,10 +33,6 @@ public interface IUser
void giveMoney(double value);
- PlayerInventory getInventory();
-
- void updateInventory();
-
String getGroup();
void setLastLocation();
@@ -53,19 +41,9 @@ public interface IUser
Location getHome(Location loc) throws Exception;
- String getName();
-
- InetSocketAddress getAddress();
-
- String getDisplayName();
-
boolean isHidden();
Teleport getTeleport();
void setJail(String jail);
-
- public int getXP();
-
- public void setXP(int l);
}
diff --git a/Essentials/src/com/earth2me/essentials/Trade.java b/Essentials/src/com/earth2me/essentials/Trade.java
index 5e9f82b88..ca9db12a7 100644
--- a/Essentials/src/com/earth2me/essentials/Trade.java
+++ b/Essentials/src/com/earth2me/essentials/Trade.java
@@ -1,6 +1,7 @@
package com.earth2me.essentials;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
+import com.earth2me.essentials.craftbukkit.SetExpFix;
import static com.earth2me.essentials.I18n._;
import java.io.File;
import java.io.FileWriter;
@@ -40,8 +41,7 @@ public class Trade
public Trade(final int exp, final IEssentials ess)
{
- //TODO: Revert this change, when exp is fixed in Bukkit
- this(null, (double)exp, null, null, ess);
+ this(null, null, null, exp, 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
- && user.getXP() < exp) {
+ && user.getTotalExperience() < exp) {
throw new ChargeException(_("notEnoughExperience"));
}
}
@@ -116,7 +116,7 @@ public class Trade
}
if (getExperience() != null)
{
- user.setXP(user.getXP() + getExperience());
+ SetExpFix.setTotalExperience(user, user.getTotalExperience() + getExperience());
}
return success;
}
@@ -155,12 +155,12 @@ public class Trade
}
if (getExperience() != null)
{
- final int experience = user.getXP();
+ final int experience = user.getTotalExperience();
if (experience < getExperience() && getExperience() > 0)
{
throw new ChargeException(_("notEnoughExperience"));
}
- user.setXP(experience - getExperience());
+ SetExpFix.setTotalExperience(user, experience - getExperience());
}
}
diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java
index b16570374..daf756e5b 100644
--- a/Essentials/src/com/earth2me/essentials/User.java
+++ b/Essentials/src/com/earth2me/essentials/User.java
@@ -25,32 +25,32 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
private boolean hidden = false;
private transient Location afkPosition;
private static final Logger logger = Logger.getLogger("Minecraft");
-
+
User(final Player base, final IEssentials ess)
{
super(base, ess);
teleport = new Teleport(this, ess);
afkPosition = getLocation();
}
-
+
User update(final Player base)
{
setBase(base);
return this;
}
-
+
@Override
public boolean isAuthorized(final IEssentialsCommand cmd)
{
return isAuthorized(cmd, "essentials.");
}
-
+
@Override
public boolean isAuthorized(final IEssentialsCommand cmd, final String permissionPrefix)
{
return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName()));
}
-
+
@Override
public boolean isAuthorized(final String node)
{
@@ -58,20 +58,20 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
return false;
}
-
+
if (isOp())
{
return true;
}
-
+
if (isJailed())
{
return false;
}
-
+
return ess.getPermissionsHandler().hasPermission(base, node);
}
-
+
public void healCooldown() throws Exception
{
final Calendar now = new GregorianCalendar();
@@ -89,13 +89,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
setLastHealTimestamp(now.getTimeInMillis());
}
-
+
@Override
public void giveMoney(final double value)
{
giveMoney(value, null);
}
-
+
public void giveMoney(final double value, final CommandSender initiator)
{
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()));
}
}
-
+
public void payUser(final User reciever, final double value) throws Exception
{
if (value == 0)
@@ -128,13 +128,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
throw new Exception(_("notEnoughMoney"));
}
}
-
+
@Override
public void takeMoney(final double value)
{
takeMoney(value, null);
}
-
+
public void takeMoney(final double value, final CommandSender initiator)
{
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()));
}
}
-
+
public boolean canAfford(final double cost)
{
final double mon = getMoney();
return mon >= cost || isAuthorized("essentials.eco.loan");
}
-
+
public void dispose()
{
this.base = new OfflinePlayer(getName(), ess);
}
-
+
@Override
public void setReplyTo(final CommandSender user)
{
replyTo = user;
}
-
+
@Override
public CommandSender getReplyTo()
{
return replyTo;
}
-
+
@Override
public int compareTo(final User other)
{
return Util.stripColor(this.getDisplayName()).compareToIgnoreCase(Util.stripColor(other.getDisplayName()));
}
-
+
@Override
public boolean equals(final Object object)
{
@@ -186,58 +186,58 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return false;
}
return this.getName().equalsIgnoreCase(((User)object).getName());
-
+
}
-
+
@Override
public int hashCode()
{
- return this.getName().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));
}
-
+
public void setHome()
{
setHome("home", getLocation());
}
-
+
public void setHome(final String name)
{
setHome(name, getLocation());
}
-
+
@Override
public void setLastLocation()
{
setLastLocation(getLocation());
}
-
+
public void requestTeleport(final User player, final boolean here)
{
teleportRequestTime = System.currentTimeMillis();
teleportRequester = player;
teleportRequestHere = here;
}
-
+
public User getTeleportRequest()
{
return teleportRequester;
}
-
+
public boolean isTeleportRequestHere()
{
return teleportRequestHere;
}
-
+
public String getNick(boolean addprefixsuffix)
{
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 (!ess.getSettings().disablePrefix())
@@ -283,10 +283,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
nickname.append("§f");
}
}
-
+
return nickname.toString();
}
-
+
public void setDisplayNick()
{
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.");
}
}
-
+
@Override
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();
}
-
+
public Teleport getTeleport()
{
return teleport;
}
-
+
public long getLastOnlineActivity()
{
return lastOnlineActivity;
}
-
+
public void setLastOnlineActivity(final long timestamp)
{
lastOnlineActivity = timestamp;
}
-
+
@Override
public double getMoney()
{
@@ -355,7 +355,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
return super.getMoney();
}
-
+
@Override
public void setMoney(final double value)
{
@@ -377,7 +377,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
super.setMoney(value);
}
-
+
@Override
public void setAfk(final boolean set)
{
@@ -388,7 +388,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
super.setAfk(set);
}
-
+
@Override
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);
return now;
}
-
+
@Override
public boolean isHidden()
{
return hidden;
}
-
+
public void setHidden(final boolean hidden)
{
this.hidden = hidden;
@@ -453,7 +453,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
return false;
}
-
+
public void updateActivity(final boolean broadcast)
{
if (isAfk())
@@ -466,7 +466,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
lastActivity = System.currentTimeMillis();
}
-
+
public void checkActivity()
{
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);
lastActivity = 0;
kickPlayer(kickReason);
-
-
+
+
for (Player player : ess.getServer().getOnlinePlayers())
{
final User user = ess.getUser(player);
@@ -497,12 +497,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
}
}
-
+
public Location getAfkPosition()
{
return afkPosition;
}
-
+
@Override
public boolean toggleGodModeEnabled()
{
@@ -512,7 +512,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
return super.toggleGodModeEnabled();
}
-
+
@Override
public boolean isGodModeEnabled()
{
@@ -524,17 +524,17 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
return super.isGodModeEnabled();
}
-
+
public String getGroup()
{
return ess.getPermissionsHandler().getGroup(base);
}
-
+
public boolean inGroup(final String group)
{
return ess.getPermissionsHandler().inGroup(base, group);
}
-
+
public boolean canBuild()
{
return ess.getPermissionsHandler().canBuild(base, getGroup());
@@ -543,21 +543,5 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
public long getTeleportRequestTime()
{
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);
- }
- }
-
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java b/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java
new file mode 100644
index 000000000..caf6e71c7
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java
@@ -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);
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
index 1e62a6097..5fe6c9ac0 100644
--- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
+++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
@@ -273,6 +273,12 @@ public class EssentialsSign
protected final void validateTrade(final ISign sign, final int amountIndex, final int itemIndex,
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 ItemStack item = trade.getItemStack();
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,
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 int amount = Math.min(getIntegerPositive(sign.getLine(amountIndex)), item.getType().getMaxStackSize() * player.getInventory().getSize());
if (item.getTypeId() == 0 || amount < 1)
diff --git a/Essentials/src/com/earth2me/essentials/user/User.java b/Essentials/src/com/earth2me/essentials/user/User.java
index 724920b38..0e544ae06 100644
--- a/Essentials/src/com/earth2me/essentials/user/User.java
+++ b/Essentials/src/com/earth2me/essentials/user/User.java
@@ -196,17 +196,4 @@ public class User extends UserBase implements IUser
unlock();
}
}
-
- @Override
- public int getXP()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public void setXP(int l)
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
}
diff --git a/EssentialsUpdate/nbproject/project.properties b/EssentialsUpdate/nbproject/project.properties
index b73c58ae9..88315dfa0 100644
--- a/EssentialsUpdate/nbproject/project.properties
+++ b/EssentialsUpdate/nbproject/project.properties
@@ -63,11 +63,11 @@ dist.jar=${dist.dir}/EssentialsUpdate.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
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=**
jar.compress=true
javac.classpath=\
- ${file.reference.bukkit-1.0.0-R1-SNAPSHOT.jar}
+ ${file.reference.bukkit.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false