Skip to content

Commit

Permalink
Merge pull request #90 from Tradeshop/2.2.3
Browse files Browse the repository at this point in the history
2.2.3+2.2.4
  • Loading branch information
KillerOfPie authored Oct 23, 2020
2 parents 25a605d + 4dc7dd8 commit 3bc59df
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 132 deletions.
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Compiled binaries
/target/
*.class
/bin/

# Package files
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar

# Redundant Gradle files
/.gradle/
/build/

# IntelliJ IDEA project files
/.idea/
*.iml

# Eclipse project files
/.settings/
.classpath
.project

# Redundant Maven files
dependency-reduced-pom.xml

# Temporary and log files
**/temp.**
*.log
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<groupId>org.shanerx</groupId>
<artifactId>tradeshop</artifactId>
<version>2.2.2-STABLE</version>
<version>2.2.4-STABLE</version>
<packaging>jar</packaging>
<name>TradeShop</name>
<url>https://tradeshop.github.io/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@

public class CommandTabCompleter extends Utils {

private TradeShop plugin;
private CommandPass command;
private final TradeShop plugin;
private final CommandPass command;
private Player pSender;

public CommandTabCompleter(TradeShop instance, CommandPass command) {
Expand Down Expand Up @@ -71,7 +71,7 @@ public List<String> help() {

public List<String> addSet() {
if (command.argsSize() == 2) {
return Arrays.asList("1", "2", "4", "8", "16", "32", "64", "96", "128");
return Arrays.asList("1", "2", "4", "8", "16", "32", "64", "80", "96", "128");
} else if (command.argsSize() == 3) {
return partialGameMats(command.getArgAt(2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,43 +58,48 @@

public class ShopProtectionListener extends Utils implements Listener {

private TradeShop plugin;
private final TradeShop plugin;

public ShopProtectionListener(TradeShop instance) {
plugin = instance;
}
public ShopProtectionListener(TradeShop instance) {
plugin = instance;
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onInventoryMoveItem(InventoryMoveItemEvent event) {
public void onInventoryMoveItem(InventoryMoveItemEvent event) {

if (event.isCancelled())
return;
try {
if (event.isCancelled()) {
return;
}

if (event instanceof HopperShopAccessEvent)
return;
if (event instanceof HopperShopAccessEvent) {
return;
}

if (!(event.getInitiator().getType().equals(InventoryType.HOPPER) &&
plugin.getListManager().isInventory(event.getSource().getLocation().getBlock()))) {
return;
}
if (!(event.getInitiator().getType().equals(InventoryType.HOPPER) &&
plugin.getListManager().isInventory(event.getSource().getLocation().getBlock()))) {
return;
}

Block invBlock = event.getSource().getLocation().getBlock();

Nameable fromContainer = (Nameable) invBlock.getState();

if (ShopChest.isShopChest(invBlock)) {
Shop shop = new ShopChest(invBlock.getLocation()).getShop();
debugger.log("ShopProtectionListener: Shop Location as SL > " + shop.getInventoryLocationAsSL().serialize(), DebugLevels.PROTECTION);
boolean isForbidden = !Setting.findSetting(shop.getShopType().name() + "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);
Bukkit.getPluginManager().callEvent(hopperEvent);
debugger.log("ShopProtectionListener: HopperEvent thrown! ", DebugLevels.PROTECTION);
event.setCancelled(hopperEvent.isForbidden());
debugger.log("ShopProtectionListener: HopperEvent isCancelled: " + hopperEvent.isForbidden(), DebugLevels.PROTECTION);
debugger.log("ShopProtectionListener: HopperEvent isCancelled: " + isForbidden, DebugLevels.PROTECTION);
}
Block invBlock = event.getSource().getLocation().getBlock();

Nameable fromContainer = (Nameable) invBlock.getState();

if (ShopChest.isShopChest(invBlock)) {
Shop shop = new ShopChest(invBlock.getLocation()).getShop();
debugger.log("ShopProtectionListener: Shop Location as SL > " + shop.getInventoryLocationAsSL().serialize(), DebugLevels.PROTECTION);
boolean isForbidden = !Setting.findSetting(shop.getShopType().name() + "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);
Bukkit.getPluginManager().callEvent(hopperEvent);
debugger.log("ShopProtectionListener: HopperEvent thrown! ", DebugLevels.PROTECTION);
event.setCancelled(hopperEvent.isForbidden());
debugger.log("ShopProtectionListener: HopperEvent isCancelled: " + hopperEvent.isForbidden(), DebugLevels.PROTECTION);
debugger.log("ShopProtectionListener: HopperEvent isForbidden: " + isForbidden, DebugLevels.PROTECTION);
}
} catch (NullPointerException ignored) {
} // Fix for random NPE triggering from this event that shows no stack trace
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
Expand Down Expand Up @@ -217,7 +222,7 @@ public void onChestOpen(PlayerInteractEvent e) {

Block block = e.getClickedBlock();

if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK && plugin.getListManager().isInventory(block))) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || !plugin.getListManager().isInventory(block)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

public class ShopRestockListener extends Utils implements Listener {

private TradeShop plugin;
private final TradeShop plugin;

public ShopRestockListener(TradeShop instance) {
plugin = instance;
Expand All @@ -49,8 +49,10 @@ public ShopRestockListener(TradeShop instance) {
public void onInventoryClose(InventoryCloseEvent event) {
if (ShopChest.isShopChest(event.getInventory())) {
Shop shop = new ShopChest(event.getInventory().getLocation()).getShop();
shop.updateSign();
shop.saveShop();
if (shop != null) {
shop.updateSign();
shop.saveShop();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void onBlockInteract(PlayerInteractEvent e) {

private boolean tradeAllItems(Shop shop, int multiplier, Action action, Player buyer) {
ArrayList<ItemStack> costItems = new ArrayList<>(), productItems = new ArrayList<>();
Inventory shopInventory = shop.getChestAsSC().getInventory();
Inventory shopInventory = shop.hasStorage() ? shop.getChestAsSC().getInventory() : null;
Inventory playerInventory = buyer.getInventory();

if (shop.getShopType() == ShopType.ITRADE && action.equals(Action.RIGHT_CLICK_BLOCK)) { //ITrade trade
Expand Down
35 changes: 19 additions & 16 deletions src/main/java/org/shanerx/tradeshop/objects/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ public class Shop implements Serializable {
private ShopUser owner;
private List<UUID> managers, members;
private ShopType shopType;
private ShopLocation shopLoc, chestLoc;
private List<ShopItemStack> product, cost;
private final ShopLocation shopLoc;
private final List<ShopItemStack> product;
private final List<ShopItemStack> cost;
private ShopLocation chestLoc;
private transient SignChangeEvent signChangeEvent;
private transient Inventory storageInv;
private transient Utils utils;
private ShopStatus status = ShopStatus.INCOMPLETE;
private ShopStatus status = ShopStatus.INCOMPLETE;

/**
* Creates a Shop object
Expand Down Expand Up @@ -639,7 +641,8 @@ public void updateSign() {
String[] signLines = updateSignLines();

for (int i = 0; i < 4; i++) {
s.setLine(i, signLines[i]);
if (signLines[i] != null && s != null)
s.setLine(i, signLines[i]);
}

s.update();
Expand Down Expand Up @@ -676,16 +679,16 @@ private String[] updateSignLines() {
if (product.isEmpty()) {
signLines[1] = "";
} else if (product.size() == 1) {
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder();

ShopItemStack item = product.get(0);
ShopItemStack item = product.get(0);

sb.append(item.getItemStack().getAmount());
sb.append(" ");
sb.append(item.getItemStack().getAmount());
sb.append(" ");

sb.append(item.getItemName());
sb.append(item.getItemName());

signLines[1] = sb.toString().substring(0, Math.min(sb.length(), 15));
signLines[1] = sb.substring(0, Math.min(sb.length(), 15));

} else {
signLines[1] = Setting.MULTIPLE_ITEMS_ON_SIGN.getString();
Expand All @@ -694,16 +697,16 @@ private String[] updateSignLines() {
if (cost.isEmpty()) {
signLines[2] = "";
} else if (cost.size() == 1) {
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder();

ShopItemStack item = cost.get(0);
ShopItemStack item = cost.get(0);

sb.append(item.getItemStack().getAmount());
sb.append(" ");
sb.append(item.getItemStack().getAmount());
sb.append(" ");

sb.append(item.getItemName());
sb.append(item.getItemName());

signLines[2] = sb.toString().substring(0, Math.min(sb.length(), 15));
signLines[2] = sb.substring(0, Math.min(sb.length(), 15));
} else {
signLines[2] = Setting.MULTIPLE_ITEMS_ON_SIGN.getString();
}
Expand Down
Loading

0 comments on commit 3bc59df

Please sign in to comment.