mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-25 08:11:20 +01:00
Fix a few NPE's caused by null accounts
Thanks @mibby
This commit is contained in:
parent
218e3b4acd
commit
a13b2c9070
@ -61,10 +61,15 @@ public class VaultListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
double balance = provider.getBalance(NameManager.getLastSeenName(event.getAccount()), event.getWorld().getName());
|
||||
double balance = 0;
|
||||
String lastSeen = NameManager.getLastSeenName(event.getAccount());
|
||||
|
||||
if (balance > Double.MAX_VALUE) {
|
||||
balance = Double.MAX_VALUE;
|
||||
if (lastSeen != null) {
|
||||
balance = provider.getBalance(lastSeen, event.getWorld().getName());
|
||||
|
||||
if (balance > Double.MAX_VALUE) {
|
||||
balance = Double.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
event.setAmount(balance);
|
||||
@ -77,9 +82,14 @@ public class VaultListener implements Listener {
|
||||
}
|
||||
|
||||
World world = event.getWorld();
|
||||
String lastSeen = NameManager.getLastSeenName(event.getAccount());
|
||||
|
||||
if (provider.has(NameManager.getLastSeenName(event.getAccount()), world.getName(), event.getDoubleAmount())) {
|
||||
event.hasEnough(true);
|
||||
if (lastSeen != null) {
|
||||
if (provider.has(lastSeen, world.getName(), event.getDoubleAmount())) {
|
||||
event.hasEnough(true);
|
||||
}
|
||||
} else {
|
||||
event.hasEnough(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,10 +100,8 @@ public class VaultListener implements Listener {
|
||||
}
|
||||
|
||||
World world = event.getWorld();
|
||||
|
||||
if (!provider.hasAccount(NameManager.getLastSeenName(event.getAccount()), world.getName())) {
|
||||
event.hasAccount(false);
|
||||
}
|
||||
String lastSeen = NameManager.getLastSeenName(event.getAccount());
|
||||
event.hasAccount(lastSeen != null && provider.hasAccount(lastSeen, world.getName()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -103,7 +111,6 @@ public class VaultListener implements Listener {
|
||||
}
|
||||
|
||||
String formatted = provider.format(event.getDoubleAmount());
|
||||
|
||||
event.setFormattedAmount(formatted);
|
||||
}
|
||||
|
||||
@ -114,8 +121,11 @@ public class VaultListener implements Listener {
|
||||
}
|
||||
|
||||
World world = event.getWorld();
|
||||
String lastSeen = NameManager.getLastSeenName(event.getTarget());
|
||||
|
||||
provider.depositPlayer(NameManager.getLastSeenName(event.getTarget()), world.getName(), event.getDoubleAmount());
|
||||
if (lastSeen != null) {
|
||||
provider.depositPlayer(lastSeen, world.getName(), event.getDoubleAmount());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -125,8 +135,11 @@ public class VaultListener implements Listener {
|
||||
}
|
||||
|
||||
World world = event.getWorld();
|
||||
String lastSeen = NameManager.getLastSeenName(event.getTarget());
|
||||
|
||||
provider.withdrawPlayer(NameManager.getLastSeenName(event.getTarget()), world.getName(), event.getDoubleAmount());
|
||||
if (lastSeen != null) {
|
||||
provider.withdrawPlayer(NameManager.getLastSeenName(event.getTarget()), world.getName(), event.getDoubleAmount());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -152,18 +165,26 @@ public class VaultListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!provider.hasAccount(NameManager.getLastSeenName(event.getAccount()), event.getWorld().getName())) {
|
||||
String lastSeen = NameManager.getLastSeenName(event.getAccount());
|
||||
String world = event.getWorld().getName();
|
||||
|
||||
if (lastSeen == null) {
|
||||
event.canHold(false);
|
||||
return;
|
||||
}
|
||||
|
||||
EconomyResponse response = provider.depositPlayer(NameManager.getLastSeenName(event.getAccount()), event.getWorld().getName(), event.getDoubleAmount());
|
||||
if (!provider.hasAccount(lastSeen, world)) {
|
||||
event.canHold(false);
|
||||
return;
|
||||
}
|
||||
|
||||
EconomyResponse response = provider.depositPlayer(lastSeen, world, event.getDoubleAmount());
|
||||
|
||||
if (!response.transactionSuccess()) {
|
||||
event.canHold(false);
|
||||
return;
|
||||
}
|
||||
|
||||
provider.withdrawPlayer(NameManager.getLastSeenName(event.getAccount()), event.getWorld().getName(), event.getDoubleAmount());
|
||||
provider.withdrawPlayer(lastSeen, world, event.getDoubleAmount());
|
||||
}
|
||||
}
|
||||
|
@ -10,19 +10,21 @@ import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Lets you save/cache username and UUID relations
|
||||
*
|
||||
* @author Andrzej Pomirski (Acrobot)
|
||||
*/
|
||||
@SuppressWarnings("UnusedAssignment") //I deliberately set the variables to null while initializing
|
||||
@SuppressWarnings("UnusedAssignment") // I deliberately set the variables to null while initializing
|
||||
public class NameManager {
|
||||
private static Dao<Account, String> accounts;
|
||||
|
||||
@ -35,9 +37,9 @@ public class NameManager {
|
||||
return lastSeenName.get(uuid);
|
||||
}
|
||||
|
||||
if (Bukkit.getOfflinePlayer(uuid).getName() != null) {
|
||||
String lastSeen = Bukkit.getOfflinePlayer(uuid).getName();
|
||||
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||
String lastSeen = player.getName();
|
||||
if (lastSeen != null) {
|
||||
lastSeenName.put(uuid, lastSeen);
|
||||
return lastSeen;
|
||||
}
|
||||
@ -46,22 +48,27 @@ public class NameManager {
|
||||
|
||||
try {
|
||||
account = accounts.queryBuilder().selectColumns("lastSeenName", "name").where().eq("uuid", uuid).queryForFirst();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (SQLException ex) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "[ChestShop] Failed to find last seen name for " + uuid + ":", ex);
|
||||
}
|
||||
|
||||
if (account == null) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
if (account.getLastSeenName() != null) {
|
||||
lastSeenName.put(uuid, account.getLastSeenName());
|
||||
} else if (account.getName() != null) {
|
||||
lastSeenName.put(uuid, account.getName());
|
||||
lastSeen = account.getLastSeenName();
|
||||
if (lastSeen != null) {
|
||||
lastSeenName.put(uuid, lastSeen);
|
||||
return lastSeen;
|
||||
}
|
||||
|
||||
return account.getLastSeenName();
|
||||
lastSeen = account.getName();
|
||||
if (lastSeen != null) {
|
||||
lastSeenName.put(uuid, lastSeen);
|
||||
return lastSeen;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static UUID getUUID(String username) {
|
||||
|
Loading…
Reference in New Issue
Block a user