1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-15 11:04:29 +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.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

View File

@@ -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);
}

View File

@@ -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());
}
}

View File

@@ -544,20 +544,4 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
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,
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)

View File

@@ -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.");
}
}

View File

@@ -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