Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:NyaaCat/HamsterEcoHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
RecursiveG committed Jun 1, 2016
2 parents 90dc82f + 194eed5 commit bfc00b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ public class MarketManager {
public static HashMap<Player, Integer> viewPage;
public static HashMap<Player, UUID> viewSeller;
public static List<Player> viewMailbox;
public static Economy eco = null;
public static long lastBroadcast;
public static int pageSize = 45;

public static void init(HamsterEcoHelper pl) {
plugin = pl;
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
eco = rsp.getProvider();
db = plugin.database;
viewItem = new HashMap<>();
viewPage = new HashMap<>();
Expand All @@ -61,15 +59,15 @@ public static boolean buy(Player player, int itemId, int amount) {
Database.MarketItem item = getItem(itemId);
if (item != null && item.getItemStack().getType() != Material.AIR && item.getAmount() > 0) {
double price = item.getUnitPrice() * amount;
if (eco.has(player, price) || player.getUniqueId().equals(item.getPlayerId())) {
if (plugin.eco.enoughMoney(player, price) || player.getUniqueId().equals(item.getPlayerId())) {
if (!addItemToMailbox(player, item.getItemStack(amount))) {
msg(player, "user.warn.not_enough_space");
playSound(player, Sound.BLOCK_FENCE_GATE_OPEN);
return false;
}
if (!player.getUniqueId().equals(item.getPlayerId())) {
eco.withdrawPlayer(player, price);
eco.depositPlayer(item.getPlayer(), price);
plugin.eco.withdraw(player, price);
plugin.eco.deposit(item.getPlayer(), price);
}
db.marketBuy(player, itemId, amount);
playSound(player, Sound.ENTITY_EXPERIENCE_ORB_TOUCH);
Expand Down Expand Up @@ -170,7 +168,7 @@ public static void view(Player player, int page, UUID seller) {
meta.setDisplayName(ChatColor.AQUA + I18n.get("user.market.my_items") +
(String.format(" (%s/%s)", db.getMarketPlayerItemCount(player), getPlayerSlot(player))));
lore = new ArrayList<>();
lore.add(ChatColor.GREEN + I18n.get("user.info.balance", ChatColor.WHITE + "" + eco.getBalance(player)));
lore.add(ChatColor.GREEN + I18n.get("user.info.balance", ChatColor.WHITE + "" + plugin.eco.balance(player)));
meta.setLore(lore);
myItem.setItemMeta(meta);
inventory.setItem(47, myItem);
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/cat/nyaa/HamsterEcoHelper/utils/EconomyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,28 @@ public double balance(OfflinePlayer p) {
public boolean enoughMoney(OfflinePlayer p, long money) {
return money <= balance(p);
}


public boolean enoughMoney(OfflinePlayer p, double money) {
return money <= balance(p);
}

public boolean withdraw(OfflinePlayer p, long money) {
EconomyResponse rsp = eco.withdrawPlayer(p, money);
return rsp.transactionSuccess();
}


public boolean withdraw(OfflinePlayer p, double money) {
EconomyResponse rsp = eco.withdrawPlayer(p, money);
return rsp.transactionSuccess();
}

public boolean deposit(OfflinePlayer p, long money) {
EconomyResponse rsp = eco.depositPlayer(p, money);
return rsp.transactionSuccess();
}

public boolean deposit(OfflinePlayer p, double money) {
EconomyResponse rsp = eco.depositPlayer(p, money);
return rsp.transactionSuccess();
}
}

0 comments on commit bfc00b2

Please sign in to comment.