Skip to content

Commit

Permalink
* The shop visit items within the visit menu now will remove buy/sell…
Browse files Browse the repository at this point in the history
… price lines if the price is set below zero.

* Shops with a sell price will now show in the visit menu regardless of current stock.
* Added the "not-applicable" message to the lang.yml for global usage.

Signed-off-by: Jeremiah Osborne <[email protected]>
  • Loading branch information
XZot1K committed Jul 22, 2023
1 parent 3dd9e91 commit 8d736c7
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 98 deletions.
2 changes: 1 addition & 1 deletion Core/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
<properties>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
<core.build>5</core.build>
<core.build>6</core.build>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
2 changes: 1 addition & 1 deletion Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>

<core.build>5</core.build>
<core.build>6</core.build>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion Core/src/main/java/xzot1k/plugins/ds/api/DManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2427,7 +2427,7 @@ public Inventory getBaseBlockSelectionMenu(Player player, Shop shop) {
private boolean checkShopAgainstFilters(@NotNull Shop shop, @Nullable OfflinePlayer offlinePlayer, @Nullable String currentFilterType, @Nullable String filter) {

if (shop.getBaseLocation() == null || (!getPluginInstance().getMenusConfig().getBoolean("shop-visit-menu.show-admin-shops") && shop.isAdminShop())
|| shop.getShopItem() == null || shop.getStock() == 0 || shop.getStock() < shop.getShopItemAmount())
|| shop.getShopItem() == null || ((shop.getStock() == 0 || shop.getStock() < shop.getShopItemAmount()) && shop.getSellPrice(shop.canDynamicPriceChange()) < 0))
return false;

if (currentFilterType != null && !currentFilterType.isEmpty()) {
Expand Down
166 changes: 87 additions & 79 deletions Core/src/main/java/xzot1k/plugins/ds/api/objects/CustomItem.java

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions Core/src/main/java/xzot1k/plugins/ds/core/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,19 @@ private void runAdvertise(CommandSender commandSender) {
}
}

String message = getPluginInstance().getLangConfig().getString("shop-advertisement.message");
final String message = getPluginInstance().getLangConfig().getString("shop-advertisement.message");
if (message != null && !message.isEmpty()) {

final String notApplicable = getPluginInstance().getLangConfig().getString("not-applicable");
final boolean naNotEmpty = (notApplicable != null && !notApplicable.isEmpty());

final double buyPrice = shop.getBuyPrice(shop.canDynamicPriceChange()),
sellPrice = shop.getSellPrice(shop.canDynamicPriceChange());

TextComponent textComponent = new TextComponent(getPluginInstance().getManager().color(message.replace("{player}", player.getName())
.replace("{item}", getPluginInstance().getManager().getItemName(shop.getShopItem()))
.replace("{buy}", getPluginInstance().getManager().formatNumber(shop.getBuyPrice(true), true))
.replace("{sell}", getPluginInstance().getManager().formatNumber(shop.getSellPrice(true), true))));
.replace("{buy}", ((buyPrice < 0 && naNotEmpty) ? notApplicable : getPluginInstance().getManager().formatNumber(buyPrice, true)))
.replace("{sell}", ((sellPrice < 0 && naNotEmpty) ? notApplicable : getPluginInstance().getManager().formatNumber(sellPrice, true)))));
if (shop.getShopItem() != null) {
final ItemTag itemTag = ItemTag.ofNbt(shop.getShopItem().getItemMeta() == null ? null :
(getPluginInstance().getServerVersion() > 1_17 ? shop.getShopItem().getItemMeta().getAsString()
Expand All @@ -802,7 +809,7 @@ private void runAdvertise(CommandSender commandSender) {
Math.min(shop.getShopItemAmount(), shop.getShopItem().getType().getMaxStackSize()), itemTag)));
}

String visitClickable = getPluginInstance().getLangConfig().getString("shop-advertisement.visit-clickable");
final String visitClickable = getPluginInstance().getLangConfig().getString("shop-advertisement.visit-clickable");
if (visitClickable != null && !visitClickable.isEmpty()) {
TextComponent visitClickableComponent = new TextComponent(getPluginInstance().getManager().color(visitClickable));
visitClickableComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, ("/displayshops visit " + shop.getShopId())));
Expand Down Expand Up @@ -1903,7 +1910,9 @@ private void runGive(CommandSender commandSender, String[] args) {

enteredAmount = Integer.parseInt(args[2]);

ItemStack itemStack = getPluginInstance().getManager().buildShopCreationItem(player, enteredAmount);
ItemStack itemStack = getPluginInstance().getListeners().creationItem.clone();
itemStack.setAmount(enteredAmount);

if (player.getInventory().firstEmpty() == -1)
player.getWorld().dropItemNaturally(player.getLocation(), itemStack);
else
Expand Down
3 changes: 2 additions & 1 deletion Core/src/main/java/xzot1k/plugins/ds/core/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public Listeners(DisplayShops pluginInstance) {
}

private boolean isCreationItem(BlockPlaceEvent e) {
return (e.getItemInHand().isSimilar(creationItem));
final String nbtResult = getPluginInstance().getPacketManager().getNBT(e.getItemInHand(), "DisplayShops");
return (nbtResult != null && nbtResult.equals("Creation Item"));
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ private ItemStack buildItem(@NotNull Shop shop) {
continue;
}

if ((line.contains("{buy}") && shop.getBuyPrice(shop.canDynamicPriceChange()) < 0)
|| (line.contains("{sell}") && shop.getSellPrice(shop.canDynamicPriceChange()) < 0)) continue;

add(INSTANCE.getManager().color(line.replace("{owner}", ((shop.getOwnerUniqueId() != null && offlinePlayer != null
&& offlinePlayer.getName() != null) ? offlinePlayer.getName() : ""))
.replace("{balance}", (shop.getStoredBalance() < 0 ? "∞" : INSTANCE.getManager().formatNumber(shop.getStoredBalance(), true)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class SUtil implements SerializeUtil {

private DisplayShops INSTANCE;
private final DisplayShops INSTANCE;

public SUtil(DisplayShops instance) {this.INSTANCE = instance;}

Expand Down Expand Up @@ -68,7 +68,7 @@ public String toJSON(@NotNull ItemStack itemStack) {
public String getNBT(@NotNull ItemStack itemStack, @NotNull String nbtTag) {
final net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(itemStack);
final NBTTagCompound tag = item.t(); // getOrCreateTag()
return tag.l(nbtTag); // getString()
return (tag != null ? tag.l(nbtTag) : null); // getString()
}

public ItemStack updateNBT(@NotNull ItemStack itemStack, @NotNull String nbtTag, @NotNull String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class SUtil implements SerializeUtil {

private DisplayShops INSTANCE;
private final DisplayShops INSTANCE;

public SUtil(DisplayShops instance) {this.INSTANCE = instance;}

Expand Down Expand Up @@ -68,7 +68,7 @@ public String toJSON(@NotNull ItemStack itemStack) {
public String getNBT(@NotNull ItemStack itemStack, @NotNull String nbtTag) {
final net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(itemStack);
final NBTTagCompound tag = item.u(); // getOrCreateTag()
return tag.l(nbtTag); // getString()
return (tag != null ? tag.l(nbtTag) : null); // getString()
}

public ItemStack updateNBT(@NotNull ItemStack itemStack, @NotNull String nbtTag, @NotNull String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class SUtil implements SerializeUtil {

private DisplayShops INSTANCE;
private final DisplayShops INSTANCE;

public SUtil(DisplayShops instance) {this.INSTANCE = instance;}

Expand Down Expand Up @@ -70,7 +70,7 @@ public String toJSON(@NotNull ItemStack itemStack) {
public String getNBT(@NotNull ItemStack itemStack, @NotNull String nbtTag) {
final net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(itemStack);
final NBTTagCompound tag = item.v();
return tag.l(nbtTag);
return (tag != null ? tag.l(nbtTag) : null);
}

public ItemStack updateNBT(@NotNull ItemStack itemStack, @NotNull String nbtTag, @NotNull String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class SUtil implements SerializeUtil {

private DisplayShops INSTANCE;
private final DisplayShops INSTANCE;

public SUtil(DisplayShops instance) {this.INSTANCE = instance;}

Expand Down Expand Up @@ -70,7 +70,7 @@ public String toJSON(@NotNull ItemStack itemStack) {
public String getNBT(@NotNull ItemStack itemStack, @NotNull String nbtTag) {
final net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(itemStack);
final NBTTagCompound tag = item.v();
return tag.l(nbtTag);
return (tag != null ? tag.l(nbtTag) : null);
}

public ItemStack updateNBT(@NotNull ItemStack itemStack, @NotNull String nbtTag, @NotNull String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public String toJSON(@NotNull ItemStack itemStack) {
public String getNBT(@NotNull ItemStack itemStack, @NotNull String nbtTag) {
final net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(itemStack);
final NBTTagCompound tag = item.v();
return tag.l(nbtTag);
return (tag != null ? tag.l(nbtTag) : null);
}

public ItemStack updateNBT(@NotNull ItemStack itemStack, @NotNull String nbtTag, @NotNull String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public String toJSON(@NotNull ItemStack itemStack) {
public String getNBT(@NotNull ItemStack itemStack, @NotNull String nbtTag) {
final net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(itemStack);
final NBTTagCompound tag = item.v();
return tag.l(nbtTag);
return (tag != null ? tag.l(nbtTag) : null);
}

public ItemStack updateNBT(@NotNull ItemStack itemStack, @NotNull String nbtTag, @NotNull String value) {
Expand Down

0 comments on commit 8d736c7

Please sign in to comment.