Skip to content

Commit

Permalink
Merge pull request #107 from Tradeshop/tweak-hopper-protection
Browse files Browse the repository at this point in the history
Restrain power of TSAF (addons cannot override protection config)
  • Loading branch information
SparklingComet authored Nov 8, 2021
2 parents 1f92c58 + f6dd668 commit 06fed29
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ public enum HopperDirection {
* @param source The source {@link org.bukkit.inventory.Inventory} object.
* @param destination The source {@link org.bukkit.inventory.Inventory} object.
* @param itm The {@link org.bukkit.inventory.ItemStack} object representing the item in transaction.
* @param isForbidden Whether or not the trade is meant to happen.
*/
public HopperShopAccessEvent(Shop s, Inventory source, Inventory destination, ItemStack itm, boolean isForbidden, HopperDirection dir) {
public HopperShopAccessEvent(Shop s, Inventory source, Inventory destination, ItemStack itm, HopperDirection dir) {
super(source, itm, destination, false);
this.isForbidden = isForbidden;
this.isForbidden = false;
this.dir = dir;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,28 @@ else if (plugin.getListManager().isInventory(destLoc.getBlock())) {

((TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop")).setFrozen(true);
Shop shop = new ShopChest(invBlock.getLocation()).getShop();

boolean isForbidden = !Setting.findSetting(shop.getShopType().name() + (fromHopper ? "SHOP_HOPPER_IMPORT" : "SHOP_HOPPER_EXPORT")).getBoolean();
if (isForbidden) {
event.setCancelled(true);
return;
}

debugger.log("ShopProtectionListener: Triggered > " + (fromHopper ? "FROM_HOPPER" : "TO_HOPPER"), DebugLevels.PROTECTION);
debugger.log("ShopProtectionListener: Shop Location as SL > " + shop.getInventoryLocationAsSL().serialize(), DebugLevels.PROTECTION);
boolean isForbidden = !Setting.findSetting(shop.getShopType().name() + (fromHopper ? "SHOP_HOPPER_IMPORT" : "SHOP_HOPPER_EXPORT")).getBoolean();
debugger.log("ShopProtectionListener: isForbidden > " + isForbidden, DebugLevels.PROTECTION);
debugger.log("ShopProtectionListener: checked hopper setting > " + shop.getShopType().name() + "SHOP_HOPPER_EXPORT", DebugLevels.PROTECTION);
HopperShopAccessEvent hopperEvent = new HopperShopAccessEvent(
shop,
event.getSource(),
event.getDestination(),
event.getItem(),
isForbidden,
fromHopper ? HopperShopAccessEvent.HopperDirection.FROM_HOPPER : HopperShopAccessEvent.HopperDirection.TO_HOPPER
);
debugger.log("ShopProtectionListener: (TSAF) HopperEvent fired! ", DebugLevels.PROTECTION);
Bukkit.getPluginManager().callEvent(hopperEvent);
debugger.log("ShopProtectionListener: (TSAF) HopperEvent recovered! ", DebugLevels.PROTECTION);
event.setCancelled(hopperEvent.isForbidden());
debugger.log("ShopProtectionListener: (TSAF) HopperEvent isCancelled: " + hopperEvent.isForbidden(), DebugLevels.PROTECTION);
debugger.log("ShopProtectionListener: (TSAF) HopperEvent isForbidden: " + isForbidden, DebugLevels.PROTECTION);
debugger.log("ShopProtectionListener: (TSAF) HopperEvent isForbidden: " + hopperEvent.isForbidden(), DebugLevels.PROTECTION);
((TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop")).setFrozen(false);
}

Expand Down

0 comments on commit 06fed29

Please sign in to comment.