From e464217e82f5816477c444b2849c44214f735be4 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Sun, 2 Aug 2020 08:25:24 -0400 Subject: [PATCH] Update API to check for OfflinePlayer World. --- TNE/src/net/tnemc/core/TNE.java | 2 +- .../common/api/Economy_TheNewEconomy.java | 32 +++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/TNE/src/net/tnemc/core/TNE.java b/TNE/src/net/tnemc/core/TNE.java index cd6179b2..cb678d90 100644 --- a/TNE/src/net/tnemc/core/TNE.java +++ b/TNE/src/net/tnemc/core/TNE.java @@ -109,7 +109,7 @@ public class TNE extends TNELib { //constants public static final String coreURL = "https://tnemc.net/files/module-version.xml"; - public static final String build = "0.1.1.10"; + public static final String build = "0.1.1.11"; public final List developers = Collections.singletonList("5bb0dcb3-98ee-47b3-8f66-3eb1cdd1a881"); //Map containing module sub commands to add to our core commands diff --git a/TNE/src/net/tnemc/core/common/api/Economy_TheNewEconomy.java b/TNE/src/net/tnemc/core/common/api/Economy_TheNewEconomy.java index 49a79f41..1907d2ab 100644 --- a/TNE/src/net/tnemc/core/common/api/Economy_TheNewEconomy.java +++ b/TNE/src/net/tnemc/core/common/api/Economy_TheNewEconomy.java @@ -3,7 +3,9 @@ import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.EconomyResponse; import net.tnemc.core.TNE; +import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; import java.math.BigDecimal; import java.util.ArrayList; @@ -117,7 +119,11 @@ public boolean has(OfflinePlayer offlinePlayer, double amount) { TNE.debug("Economy_TheNewEconomy.has(offlinePlayer, amount)"); TNE.debug("username: " + offlinePlayer.getName()); TNE.debug("Amount: " + amount); - return has(IDFinder.getUsername(IDFinder.getID(offlinePlayer).toString()), TNE.instance().defaultWorld, amount); + String world = TNE.instance().defaultWorld; + if(offlinePlayer.isOnline()) { + world = offlinePlayer.getPlayer().getWorld().getName(); + } + return has(offlinePlayer.getName(), world, amount); } @Override @@ -135,17 +141,26 @@ public boolean has(OfflinePlayer offlinePlayer, String world, double amount) { TNE.debug("username: " + offlinePlayer.getName()); TNE.debug("world: " + world); TNE.debug("Amount: " + amount); - return has(IDFinder.getUsername(IDFinder.getID(offlinePlayer).toString()), world, amount); + return has(offlinePlayer.getName(), world, amount); } @Override public EconomyResponse withdrawPlayer(String username, double amount) { - return withdrawPlayer(username, TNE.instance().defaultWorld, amount); + String world = TNE.instance().defaultWorld; + final Player player = Bukkit.getPlayer(username); + if(player != null) { + world = player.getWorld().getName(); + } + return withdrawPlayer(username, world, amount); } @Override public EconomyResponse withdrawPlayer(OfflinePlayer offlinePlayer, double amount) { - return withdrawPlayer(IDFinder.getUsername(IDFinder.getID(offlinePlayer).toString()), TNE.instance().defaultWorld, amount); + String world = TNE.instance().defaultWorld; + if(offlinePlayer.isOnline()) { + world = offlinePlayer.getPlayer().getWorld().getName(); + } + return withdrawPlayer(offlinePlayer.getName(), world, amount); } @Override @@ -170,12 +185,17 @@ public EconomyResponse withdrawPlayer(String username, String world, double amou @Override public EconomyResponse withdrawPlayer(OfflinePlayer offlinePlayer, String world, double amount) { - return withdrawPlayer(IDFinder.getUsername(IDFinder.getID(offlinePlayer).toString()), world, amount); + return withdrawPlayer(offlinePlayer.getName(), world, amount); } @Override public EconomyResponse depositPlayer(String username, double amount) { - return depositPlayer(username, TNE.instance().defaultWorld, amount); + String world = TNE.instance().defaultWorld; + final Player player = Bukkit.getPlayer(username); + if(player != null) { + world = player.getWorld().getName(); + } + return depositPlayer(username, world, amount); } @Override