mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 11:49:12 +00:00
Economy API: Attempt to find users by UUID if username not present (#2432)
Attempt to find user by UUID if username not present. Fixes (maybe) #2400. https://github.com/EssentialsX/Essentials/issues/2400#issuecomment-466043896
This commit is contained in:
parent
31b98fb9f3
commit
dde4a36df0
2 changed files with 26 additions and 3 deletions
|
@ -8,6 +8,7 @@ import com.earth2me.essentials.utils.StringUtil;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import net.ess3.api.MaxMoneyException;
|
import net.ess3.api.MaxMoneyException;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
@ -18,7 +19,7 @@ import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instead of using this api directly, we recommend to use the register plugin: http://bit.ly/RegisterMethod
|
* You should use Vault instead of directly using this class.
|
||||||
*/
|
*/
|
||||||
public class Economy {
|
public class Economy {
|
||||||
public Economy() {
|
public Economy() {
|
||||||
|
@ -64,7 +65,24 @@ public class Economy {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
throw new RuntimeException("Economy username cannot be null");
|
throw new RuntimeException("Economy username cannot be null");
|
||||||
}
|
}
|
||||||
return ess.getUser(name);
|
|
||||||
|
User user = ess.getUser(name);
|
||||||
|
if (user == null) {
|
||||||
|
/*
|
||||||
|
Attempt lookup using UUID - this prevents balance resets when accessing economy
|
||||||
|
via Vault during player join.
|
||||||
|
See: https://github.com/EssentialsX/Essentials/issues/2400
|
||||||
|
*/
|
||||||
|
Player player = ess.getServer().getPlayerExact(name);
|
||||||
|
if (player != null) {
|
||||||
|
user = ess.getUser(player.getUniqueId());
|
||||||
|
if (user != null) {
|
||||||
|
logger.info(String.format("[Economy] Found player %s by UUID %s but not by their actual name - they may have changed their username", name, player.getUniqueId().toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -500,7 +500,12 @@ public class FakeServer implements Server {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player getPlayerExact(String string) {
|
public Player getPlayerExact(String string) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
for (Player player : players) {
|
||||||
|
if (player.getName().equals(string)) {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue