Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Update API to check for OfflinePlayer World.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Aug 2, 2020
1 parent f98dbe4 commit e464217
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion TNE/src/net/tnemc/core/TNE.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> developers = Collections.singletonList("5bb0dcb3-98ee-47b3-8f66-3eb1cdd1a881");

//Map containing module sub commands to add to our core commands
Expand Down
32 changes: 26 additions & 6 deletions TNE/src/net/tnemc/core/common/api/Economy_TheNewEconomy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e464217

Please sign in to comment.