From 078c6104d53cc39512e83d9bdd50f9290654fb41 Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 17 May 2017 17:13:31 +0200 Subject: [PATCH] Various changes to shop signs, see details. Details: - Now showing price as formatted by the economy plugin (be sure to keep it short). Closes #115 - The shop sign [QuickShop] line was changed with the owner name. Closes #53 - The shop sign item line can now be customized --- .../quickshop/Shop/ContainerShop.java | 28 +++++++++++++++---- .../org/maxgamer/quickshop/Shop/Shop.java | 2 ++ .../org/maxgamer/quickshop/Util/MsgUtil.java | 2 +- src/main/resources/messages.yml | 8 ++++-- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index a8fe0a230..40d9e928a 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -3,12 +3,11 @@ package org.maxgamer.quickshop.Shop; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.UUID; import java.util.Map.Entry; +import java.util.UUID; import java.util.logging.Level; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -462,15 +461,15 @@ public class ContainerShop implements Shop { if (Util.isLoaded(this.getLocation()) == false) return; String[] lines = new String[4]; - lines[0] = ChatColor.RED + "[QuickShop]"; + lines[0] = MsgUtil.getMessage("signs.header", this.ownerName()); if (this.isBuying()) { lines[1] = MsgUtil.getMessage("signs.buying", "" + this.getRemainingSpace()); } if (this.isSelling()) { lines[1] = MsgUtil.getMessage("signs.selling", "" + this.getRemainingStock()); } - lines[2] = Util.getNameForSign(this.item); - lines[3] = MsgUtil.getMessage("signs.price", "" + this.getPrice()); + lines[2] = MsgUtil.getMessage("signs.item", Util.getNameForSign(this.item)); + lines[3] = MsgUtil.getMessage("signs.price", Util.format(this.getPrice())); this.setSignText(lines); } @@ -682,11 +681,28 @@ public class ContainerShop implements Shop { public void onClick() { this.setSignText(); } + + public String ownerName() { + if (this.isUnlimited()) { + return MsgUtil.getMessage("admin-shop"); + } + + if (this.getOwner() == null) { + return MsgUtil.getMessage("unknown-owner"); + } + + final String name = Bukkit.getOfflinePlayer(this.getOwner()).getName(); + if (name == null) { + return MsgUtil.getMessage("unknown-owner"); + } + + return name; + } @Override public String toString() { StringBuilder sb = new StringBuilder("Shop " + (loc.getWorld() == null ? "unloaded world" : loc.getWorld().getName()) + "(" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ")"); - sb.append(" Owner: " + getOwner().toString()); + sb.append(" Owner: " + this.ownerName() + " - " + getOwner().toString()); if (isUnlimited()) sb.append(" Unlimited: true"); sb.append(" Price: " + getPrice()); diff --git a/src/main/java/org/maxgamer/quickshop/Shop/Shop.java b/src/main/java/org/maxgamer/quickshop/Shop/Shop.java index 67aa1c104..21e802087 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/Shop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/Shop.java @@ -75,4 +75,6 @@ public abstract interface Shop { public abstract void onLoad(); public abstract void onClick(); + + public abstract String ownerName(); } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java index 336a27e9b..c07ce40da 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java +++ b/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java @@ -143,7 +143,7 @@ public class MsgUtil { p.sendMessage(""); p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.shop-information")); - p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.owner", Bukkit.getOfflinePlayer(shop.getOwner()).getName()==null ? (shop.isUnlimited() ? "AdminShop" : "Unknown") : Bukkit.getOfflinePlayer(shop.getOwner()).getName())); + p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.owner", shop.ownerName())); p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.item", shop.getDataName())); if (NMS.isPotion(items.getType())) { String effects = CustomPotionsName.getEffects(items); diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 1eb82539c..352460313 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -40,6 +40,8 @@ buying-more-than-selling: "&cWARNING: You are buying items for more than you are not-enough-space: "&cYou only have room for {0} more of that!" refill-success: "&aRefill success" empty-success: "&aEmpty success" +admin-shop: "AdminShop" +unknown-owner: "Unknown" menu: successful-purchase: "&aSuccessfully Purchased:" @@ -99,8 +101,8 @@ command: create: "&eCreates a new shop at the target chest" signs: - #Line 1 is used as an identifier at the moment, so I kind of need it to work, thats why I won't let you change it - #Line 3 is the item name... There really isnt anything to change. + header: "&c{0}" selling: "Selling {0}" buying: "Buying {0}" - price: "For {0} each" \ No newline at end of file + item: "{0}" + price: "{0} each" \ No newline at end of file