Skip to content

Commit

Permalink
More Unification of message sending
Browse files Browse the repository at this point in the history
  • Loading branch information
KillerOfPie committed Nov 20, 2021
1 parent e030cec commit 8febbeb
Showing 1 changed file with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void onBlockInteract(PlayerInteractEvent e) {
}

if (!shop.getShopType().equals(ShopType.ITRADE) && shop.getUsersUUID().contains(buyer.getUniqueId()) && !Setting.ALLOW_USER_PURCHASING.getBoolean()) {
buyer.sendMessage(Message.SELF_OWNED.getPrefixed());
Message.SELF_OWNED.sendMessage(buyer);
return;
}

Expand All @@ -96,13 +96,13 @@ public void onBlockInteract(PlayerInteractEvent e) {

chestState = shop.getStorage();
if (!shop.getShopType().equals(ShopType.ITRADE) && chestState == null) {
buyer.sendMessage(Message.MISSING_CHEST.getPrefixed());
Message.MISSING_CHEST.sendMessage(buyer);
shop.updateStatus();
return;
}

if (!(shop.areProductsValid() && shop.areCostsValid())) {
buyer.sendMessage(Message.ILLEGAL_ITEM.getPrefixed());
Message.ILLEGAL_ITEM.sendMessage(buyer);
return;
}

Expand All @@ -129,10 +129,10 @@ public void onBlockInteract(PlayerInteractEvent e) {

switch (shop.getStatus()) {
case CLOSED:
buyer.sendMessage(Message.SHOP_CLOSED.getPrefixed());
Message.SHOP_CLOSED.sendMessage(buyer);
return;
case INCOMPLETE:
buyer.sendMessage(Message.SHOP_EMPTY.getPrefixed());
Message.SHOP_EMPTY.sendMessage(buyer);
case OUT_OF_STOCK:
if (shop.getShopType() == ShopType.BITRADE && e.getAction() == Action.LEFT_CLICK_BLOCK) {
Message.SHOP_INSUFFICIENT_ITEMS.sendMessage(buyer, new Tuple<>("{ITEM}", costName), new Tuple<>("{AMOUNT}", String.valueOf(amountCost)));
Expand Down Expand Up @@ -191,12 +191,12 @@ public void onBlockInteract(PlayerInteractEvent e) {
owner = "-Unknown-";

if (tradeAllItems(shop, multiplier, e, buyer)) {
buyer.sendMessage(Message.ON_TRADE.getPrefixed()
.replace("{AMOUNT1}", String.valueOf(amountProduct))
.replace("{AMOUNT2}", String.valueOf(amountCost))
.replace("{ITEM1}", productName.toLowerCase())
.replace("{ITEM2}", costName.toLowerCase())
.replace("{SELLER}", shop.getShopType().isITrade() ? Setting.ITRADESHOP_OWNER.getString() : owner));
Message.ON_TRADE.sendMessage(buyer,
new Tuple<>("{AMOUNT1}", String.valueOf(amountProduct)),
new Tuple<>("{AMOUNT2}", String.valueOf(amountCost)),
new Tuple<>("{ITEM1}", productName.toLowerCase()),
new Tuple<>("{ITEM2}", costName.toLowerCase()),
new Tuple<>("{SELLER}", shop.getShopType().isITrade() ? Setting.ITRADESHOP_OWNER.getString() : owner));
}

shop.updateSign();
Expand All @@ -215,9 +215,9 @@ private boolean tradeAllItems(Shop shop, int multiplier, PlayerInteractEvent eve
costItems = getItems(playerInventory, shop.getCost(), multiplier);
if (costItems.get(0) == null) {
ItemStack item = costItems.get(1);
buyer.sendMessage(Message.INSUFFICIENT_ITEMS.getPrefixed()
.replace("{ITEM}", item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : item.getType().toString())
.replace("{AMOUNT}", String.valueOf(item.getAmount() * multiplier)));
Message.INSUFFICIENT_ITEMS.sendMessage(buyer,
new Tuple<>("{ITEM}", item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : item.getType().toString()),
new Tuple<>("{AMOUNT}", String.valueOf(item.getAmount() * multiplier)));
return false;
}

Expand All @@ -238,9 +238,9 @@ private boolean tradeAllItems(Shop shop, int multiplier, PlayerInteractEvent eve
costItems = getItems(playerInventory, shop.getProduct(), multiplier); //Reverse BiTrade, Product is Cost
if (costItems.get(0) == null) {
ItemStack item = costItems.get(1);
buyer.sendMessage(Message.INSUFFICIENT_ITEMS.getPrefixed()
.replace("{ITEM}", item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : item.getType().toString())
.replace("{AMOUNT}", String.valueOf(item.getAmount() * multiplier)));
Message.INSUFFICIENT_ITEMS.sendMessage(buyer,
new Tuple<>("{ITEM}", item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : item.getType().toString()),
new Tuple<>("{AMOUNT}", String.valueOf(item.getAmount() * multiplier)));
return false;
}

Expand All @@ -249,9 +249,9 @@ private boolean tradeAllItems(Shop shop, int multiplier, PlayerInteractEvent eve
if (productItems.get(0) == null) {
ItemStack item = productItems.get(1);
shop.updateStatus();
buyer.sendMessage(Message.SHOP_INSUFFICIENT_ITEMS.getPrefixed()
.replace("{ITEM}", item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : item.getType().toString())
.replace("{AMOUNT}", String.valueOf(item.getAmount() * multiplier)));
Message.SHOP_INSUFFICIENT_ITEMS.sendMessage(buyer,
new Tuple<>("{ITEM}", item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : item.getType().toString()),
new Tuple<>("{AMOUNT}", String.valueOf(item.getAmount() * multiplier)));
return false;
}
} else if (action.equals(Action.RIGHT_CLICK_BLOCK)) { // Normal Trade
Expand All @@ -260,9 +260,9 @@ private boolean tradeAllItems(Shop shop, int multiplier, PlayerInteractEvent eve
costItems = getItems(playerInventory, shop.getCost(), multiplier);
if (costItems.get(0) == null) {
ItemStack item = costItems.get(1);
buyer.sendMessage(Message.INSUFFICIENT_ITEMS.getPrefixed()
.replace("{ITEM}", item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : item.getType().toString())
.replace("{AMOUNT}", String.valueOf(item.getAmount() * multiplier)));
Message.INSUFFICIENT_ITEMS.sendMessage(buyer,
new Tuple<>("{ITEM}", item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : item.getType().toString()),
new Tuple<>("{AMOUNT}", String.valueOf(item.getAmount() * multiplier)));
return false;
}

Expand All @@ -271,9 +271,9 @@ private boolean tradeAllItems(Shop shop, int multiplier, PlayerInteractEvent eve
if (productItems.get(0) == null) {
ItemStack item = productItems.get(1);
shop.updateStatus();
buyer.sendMessage(Message.SHOP_INSUFFICIENT_ITEMS.getPrefixed()
.replace("{ITEM}", item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : item.getType().toString())
.replace("{AMOUNT}", String.valueOf(item.getAmount() * multiplier)));
Message.SHOP_INSUFFICIENT_ITEMS.sendMessage(buyer,
new Tuple<>("{ITEM}", item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : item.getType().toString()),
new Tuple<>("{AMOUNT}", String.valueOf(item.getAmount() * multiplier)));
return false;
}

Expand Down

0 comments on commit 8febbeb

Please sign in to comment.