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:
@@ -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
|
||||||
|
@@ -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);
|
|
||||||
}
|
}
|
||||||
|
@@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -544,20 +544,4 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
|||||||
{
|
{
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -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)
|
||||||
|
@@ -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.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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
|
||||||
|
Reference in New Issue
Block a user