Permalink
Browse files

Economy fixes, fix for dmulloy2#11

  • Loading branch information...
L4BORG committed Oct 13, 2016
1 parent 24df17f commit 24eb1b1e1970e0222021cfd4a94c7865d5f53232
@@ -6,6 +6,7 @@
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -20,11 +21,11 @@
* @author Acrobot
*/
public class VaultListener implements Listener {
private final Economy provider;
private static Economy provider;
private VaultListener(Economy provider) {
this.provider = provider;
}
private VaultListener(Economy provider) { this.provider = provider; }
public static Economy getProvider() { return provider; }
public boolean transactionCanFail() {
return provider.getName().equals("Gringotts") || provider.getName().equals("GoldIsMoney") || provider.getName().equals("MultiCurrency");
@@ -62,7 +63,8 @@ public void onAmountCheck(CurrencyAmountEvent event) {
}
double balance = 0;
String lastSeen = NameManager.getLastSeenName(event.getAccount());
//String lastSeen = NameManager.getLastSeenName(event.getAccount());
OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount());
if (lastSeen != null) {
balance = provider.getBalance(lastSeen, event.getWorld().getName());
@@ -82,7 +84,8 @@ public void onCurrencyCheck(CurrencyCheckEvent event) {
}
World world = event.getWorld();
String lastSeen = NameManager.getLastSeenName(event.getAccount());
//String lastSeen = NameManager.getLastSeenName(event.getAccount());
OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount());
if (lastSeen != null) {
if (provider.has(lastSeen, world.getName(), event.getDoubleAmount())) {
@@ -100,7 +103,9 @@ public void onAccountCheck(AccountCheckEvent event) {
}
World world = event.getWorld();
String lastSeen = NameManager.getLastSeenName(event.getAccount());
//String lastSeen = NameManager.getLastSeenName(event.getAccount());
OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount());
event.hasAccount(lastSeen != null && provider.hasAccount(lastSeen, world.getName()));
}
@@ -121,7 +126,8 @@ public void onCurrencyAdd(CurrencyAddEvent event) {
}
World world = event.getWorld();
String lastSeen = NameManager.getLastSeenName(event.getTarget());
//String lastSeen = NameManager.getLastSeenName(event.getTarget());
OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getTarget());
if (lastSeen != null) {
provider.depositPlayer(lastSeen, world.getName(), event.getDoubleAmount());
@@ -135,10 +141,11 @@ public void onCurrencySubtraction(CurrencySubtractEvent event) {
}
World world = event.getWorld();
String lastSeen = NameManager.getLastSeenName(event.getTarget());
//String lastSeen = NameManager.getLastSeenName(event.getTarget());
OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getTarget());
if (lastSeen != null) {
provider.withdrawPlayer(NameManager.getLastSeenName(event.getTarget()), world.getName(), event.getDoubleAmount());
provider.withdrawPlayer(lastSeen, world.getName(), event.getDoubleAmount());
}
}
@@ -165,7 +172,8 @@ public void onCurrencyHoldCheck(CurrencyHoldEvent event) {
return;
}
String lastSeen = NameManager.getLastSeenName(event.getAccount());
//String lastSeen = NameManager.getLastSeenName(event.getAccount());
OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount());
String world = event.getWorld().getName();
if (lastSeen == null) {
@@ -6,6 +6,7 @@
import com.Acrobot.ChestShop.Containers.AdminInventory;
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
import com.Acrobot.ChestShop.Events.TransactionEvent;
import com.Acrobot.ChestShop.Listeners.Economy.Plugins.VaultListener;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Plugins.ChestShop;
import com.Acrobot.ChestShop.Security;
@@ -45,12 +46,11 @@
public class PlayerInteract implements Listener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public static void onInteract(PlayerInteractEvent event) {
public static void onInteract(PlayerInteractEvent event)
{
Block block = event.getClickedBlock();
if (block == null) {
if (block == null)
return;
}
Action action = event.getAction();
Player player = event.getPlayer();
@@ -68,12 +68,10 @@ public static void onInteract(PlayerInteractEvent event) {
return;
}
if (!isSign(block) || player.getItemInHand().getType() == Material.SIGN) { // Blocking accidental sign edition
if (!isSign(block) || player.getItemInHand().getType() == Material.SIGN) // Blocking accidental sign edition
return;
}
Sign sign = (Sign) block.getState();
if (!ChestShopSign.isValid(sign)) {
return;
}
@@ -95,17 +93,14 @@ public static void onInteract(PlayerInteractEvent event) {
event.setCancelled(true);
}
//Bukkit.getLogger().info("ChestShop - DEBUG - "+block.getWorld().getName()+": "+block.getLocation().getBlockX()+", "+block.getLocation().getBlockY()+", "+block.getLocation().getBlockZ());
PreTransactionEvent pEvent = preparePreTransactionEvent(sign, player, action);
if (pEvent == null) {
if (pEvent == null)
return;
}
Bukkit.getPluginManager().callEvent(pEvent);
if (pEvent.isCancelled()) {
if (pEvent.isCancelled())
return;
}
TransactionEvent tEvent = new TransactionEvent(pEvent, sign);
Bukkit.getPluginManager().callEvent(tEvent);
@@ -118,25 +113,26 @@ private static PreTransactionEvent preparePreTransactionEvent(Sign sign, Player
String material = sign.getLine(ITEM_LINE);
String ownerName = NameManager.getFullUsername(name);
if (ownerName == null || ownerName.isEmpty()) {
if (ownerName == null || ownerName.isEmpty())
return null;
}
UUID uuid = NameManager.getUUID(ownerName);
if (uuid == null) {
if (uuid == null)
return null;
}
OfflinePlayer owner = Bukkit.getOfflinePlayer(uuid);
// check if player exists in economy
if(owner == null || owner.getName() == null || !VaultListener.getProvider().hasAccount(owner))
return null;
Action buy = Properties.REVERSE_BUTTONS ? LEFT_CLICK_BLOCK : RIGHT_CLICK_BLOCK;
double price = (action == buy ? PriceUtil.getBuyPrice(prices) : PriceUtil.getSellPrice(prices));
Chest chest = uBlock.findConnectedChest(sign);
Inventory ownerInventory = (ChestShopSign.isAdminShop(sign) ? new AdminInventory() : chest != null ? chest.getInventory() : null);
ItemStack item = MaterialUtil.getItem(material);
if (item == null || !NumberUtil.isInteger(quantity)) {
player.sendMessage(Messages.prefix(Messages.INVALID_SHOP_DETECTED));
return null;
@@ -25,7 +25,7 @@ public static void onBuyTransaction(TransactionEvent event) {
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(BigDecimal.valueOf(event.getPrice()),
event.getOwner().getUniqueId(),
event.getSign().getWorld());
ChestShop.callEvent(currencyAddEvent);
ChestShop.callEvent(currencyAddEvent); // java.lang.StackOverflowError
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(BigDecimal.valueOf(event.getPrice()), event.getClient());
ChestShop.callEvent(currencySubtractEvent);
@@ -76,7 +76,10 @@ public String getItemCode(ItemStack item) {
* @param code Item code
* @return ItemStack represented by this code
*/
public ItemStack getFromCode(String code) {
public ItemStack getFromCode(String code)
{
// TODO java.lang.StackOverflowError - http://pastebin.com/eRD8wUFM - Corrupt item DB?
try {
int id = Base62.decode(code);
Item item = itemDao.queryBuilder().where().eq("id", id).queryForFirst();
@@ -205,6 +205,7 @@ public static void storeUsername(final PlayerDTO player) {
account = new Account(player.getName(), player.getUniqueId());
if (!usernameToUUID.inverse().containsKey(uuid)) {
usernameToUUID.remove(player.getName()); // https://github.com/dmulloy2/ChestShop-3/issues/11
usernameToUUID.inverse().put(uuid, player.getName());
}
@@ -1,17 +1,8 @@
name: ChestShop
main: com.Acrobot.ChestShop.ChestShop
version: ${project.version}
#for CButD
dev-url: http://dev.bukkit.org/server-mods/chestshop/
author: Acrobot
description: >
A chest shop for economy plugins.
author: [Acrobot, dmulloy2, L4BORG]
description: A chest shop for economy plugins.
depend: [Vault]
softdepend: [LWC, Lockette, Deadbolt, OddItem, WorldGuard, Heroes, SimpleChestLock, Residence]

7 comments on commit 24eb1b1

@mibby

This comment has been minimized.

mibby replied Oct 25, 2016

Is this something that should be PR'd to dmully's fork?

@L4BORG

This comment has been minimized.

Owner

L4BORG replied Oct 25, 2016

IMO yeah, it would fix some StackOverflowError issues...

dmulloy2#10 and dmulloy2#11

I didn't bother to fix invalid entries in items.db because I have no idea how they've got there (we've been running old / custom versions of CS before - which could be the reason) and just removing items.db file and letting CS regenerate it would solve that issue (IIRC there open issue somewhere for that and I left // TODO comment there).

@mibby

This comment has been minimized.

mibby replied Nov 2, 2016

@dmulloy2 Thoughts on pulling?

@dmulloy2

This comment has been minimized.

dmulloy2 replied Nov 2, 2016

@mibby If it works, I'd pull a request

@L4BORG

This comment has been minimized.

Owner

L4BORG replied Nov 2, 2016

@mibby

This comment has been minimized.

mibby replied Nov 2, 2016

I'm not sure what I would test, since I haven't experienced your specific problem myself. :P Just if it is a noteworthy fix to have in the main branch, should probably be something considered.

@dmulloy2

This comment has been minimized.

dmulloy2 replied Nov 6, 2016

@L4BORG Can you create a pull request?

Please sign in to comment.