diff --git a/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java b/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java index 9522819f..14590ce6 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java +++ b/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java @@ -142,6 +142,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String case PLAYER_LEVEL: cmdRnnr.playerLevel(); break; + case STATUS: + cmdRnnr.status(); + break; } return true; diff --git a/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java b/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java index e829e3d2..99ce0753 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java +++ b/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java @@ -852,7 +852,7 @@ else if (amount > Setting.MULTI_TRADE_MAX.getInt()) } } - /* + /** * Changes/Sets the players permission level if internal permissions is enabled */ public void playerLevel() { @@ -881,6 +881,26 @@ public void playerLevel() { } } + /** + * Changes/Sets the players permission level if internal permissions is enabled + */ + public void status() { + if (command.hasArgAt(1)) { + if (!Permissions.hasPermission(pSender, Permissions.ADMIN)) { + Message.NO_COMMAND_PERMISSION.sendMessage(pSender); + return; + } + if (Bukkit.getOfflinePlayer(command.getArgAt(1)).hasPlayedBefore()) { + plugin.getDataStorage().loadPlayer(Bukkit.getOfflinePlayer(command.getArgAt(1)).getUniqueId()) + .getInvolvedStatusesInventory().show(pSender.getPlayer()); + } else { + sendMessage(Message.PLAYER_NOT_FOUND.getMessage()); + } + } else { + plugin.getDataStorage().loadPlayer(pSender.getUniqueId()).getInvolvedStatusesInventory().show(pSender.getPlayer()); + } + } + /** * Returns the Shop the player is looking at * diff --git a/src/main/java/org/shanerx/tradeshop/enumys/Commands.java b/src/main/java/org/shanerx/tradeshop/enumys/Commands.java index 178dba69..c6c3bbd6 100644 --- a/src/main/java/org/shanerx/tradeshop/enumys/Commands.java +++ b/src/main/java/org/shanerx/tradeshop/enumys/Commands.java @@ -45,7 +45,7 @@ public enum Commands { BUGS(Lists.newArrayList("bugs", "bug"), Permissions.NONE, 1, 1, false, "Report bugs to the developers", "/tradeshop $cmd$"), PLAYER_LEVEL(Lists.newArrayList("playerlevel", "pl"), Permissions.MANAGE_PLUGIN, 2, 3, false, "If Internal Permissions is enable this allows the getting and setting of player permission levels.", "/tradeshop $cmd$ "), ADD_MANAGER(Lists.newArrayList("addManager"), Permissions.NONE, 2, 2, true, "Add manager to shop", "/tradeshop $cmd$ "), - REMOVE_USER(Lists.newArrayList("removeUser", "removeManager", "removeMember"), Permissions.NONE, 2, 2, true, "Remove user from shop", "/tradeshop $cmd$ "), + REMOVE_USER(Lists.newArrayList("removeUser", "removeManager", "removeMember"), Permissions.NONE, 2, 2, true, "Remove user from shop", "/tradeshop $cmd$ "), ADD_MEMBER(Lists.newArrayList("addMember"), Permissions.NONE, 2, 2, true, "Add member to shop", "/tradeshop $cmd$ "), ADD_PRODUCT(Lists.newArrayList("addProduct"), Permissions.NONE, 1, 3, true, "Add product to shop", "/tradeshop $cmd$ [Amount] [Material]"), ADD_COST(Lists.newArrayList("addCost"), Permissions.NONE, 1, 3, true, "Add cost to shop", "/tradeshop $cmd$ [Amount] [Material]"), @@ -59,9 +59,10 @@ public enum Commands { CLOSE(Lists.newArrayList("close"), Permissions.NONE, 1, 1, true, "Close shop", "/tradeshop $cmd$"), WHO(Lists.newArrayList("who"), Permissions.INFO, 1, 1, true, "Shop members of shop", "/tradeshop $cmd$"), WHAT(Lists.newArrayList("what", "peek", "shop", "view"), Permissions.INFO, 1, 1, true, "Peek at shop inventory", "/tradeshop $cmd$"), - RELOAD(Lists.newArrayList("reload"), Permissions.ADMIN, 1, 1, false, "Reload configuration files", "/tradeshop $cmd$"), + RELOAD(Lists.newArrayList("reload"), Permissions.MANAGE_PLUGIN, 1, 1, false, "Reload configuration files", "/tradeshop $cmd$"), SWITCH(Lists.newArrayList("switch"), Permissions.EDIT, 1, 1, true, "Switch shop type", "/tradeshop $cmd$"), - MULTI(Lists.newArrayList("multi", "multiply", "many"), Permissions.NONE, 1, 2, true, "Changes trade multiplier for this login", "/tradeshop $cmd$ "); + MULTI(Lists.newArrayList("multi", "multiply", "many"), Permissions.NONE, 1, 2, true, "Changes trade multiplier for this login", "/tradeshop $cmd$ "), + STATUS(Lists.newArrayList("status", "stats", "s"), Permissions.INFO, 1, 2, true, "Displays the status of all shops the player has a relation to", "/tradeshop $cmd$ [Name]"); /** * Name of the permission diff --git a/src/main/java/org/shanerx/tradeshop/enumys/Message.java b/src/main/java/org/shanerx/tradeshop/enumys/Message.java index 864a9174..171b6f9b 100644 --- a/src/main/java/org/shanerx/tradeshop/enumys/Message.java +++ b/src/main/java/org/shanerx/tradeshop/enumys/Message.java @@ -31,12 +31,16 @@ import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; import org.shanerx.tradeshop.TradeShop; import org.yaml.snakeyaml.Yaml; import java.io.*; +import java.util.Collections; +import java.util.Map; import java.util.Set; import java.util.logging.Level; @@ -232,6 +236,41 @@ public String toString() { public String getPrefixed() { return colour(PREFIX + toString()); } + + public void sendMessage(Player player, Map replacements) { + String message = getPrefixed(); + replacements.forEach(message::replaceAll); + + if (getMessage().startsWith("#json ")) { + message.replaceFirst("#json ", ""); + player.sendRawMessage(colour(message)); + } else { + player.sendMessage(colour(message)); + } + } + + public void sendMessage(Player player) { + sendMessage(player, Collections.emptyMap()); + } + + public void sendMessage(CommandSender sender) { + sendMessage(sender, Collections.emptyMap()); + } + + public void sendMessage(CommandSender sender, Map replacements) { + if (sender instanceof Player) { + sendMessage((Player) sender, replacements); + return; + } + String message = getPrefixed(); + replacements.forEach(message::replaceAll); + + if (getMessage().startsWith("#json ")) { + message.replaceFirst("#json ", ""); + } + + sender.sendMessage(colour(message)); + } } enum MessageSectionKeys { diff --git a/src/main/java/org/shanerx/tradeshop/listeners/JoinEventListener.java b/src/main/java/org/shanerx/tradeshop/listeners/JoinEventListener.java index b9500367..87ddd836 100644 --- a/src/main/java/org/shanerx/tradeshop/listeners/JoinEventListener.java +++ b/src/main/java/org/shanerx/tradeshop/listeners/JoinEventListener.java @@ -33,10 +33,7 @@ import org.shanerx.tradeshop.TradeShop; import org.shanerx.tradeshop.enumys.Message; import org.shanerx.tradeshop.enumys.Permissions; -import org.shanerx.tradeshop.enumys.ShopRole; import org.shanerx.tradeshop.objects.PlayerSetting; -import org.shanerx.tradeshop.objects.Shop; -import org.shanerx.tradeshop.objects.ShopLocation; import org.shanerx.tradeshop.utils.BukkitVersion; import org.shanerx.tradeshop.utils.Updater; import org.shanerx.tradeshop.utils.Utils; @@ -66,32 +63,7 @@ public void onJoin(PlayerJoinEvent event) { player.sendMessage(Message.PLUGIN_BEHIND.getPrefixed()); } - StringBuilder sb = new StringBuilder(); - sb.append("%eInventory status of your shops: \n"); - sb.append("&eShop Role &f| &eLocation &f| &eInventory Status\n&b"); - if (playerSetting.getOwnedShops().size() > 0) { - playerSetting.getOwnedShops().forEach(s -> { - Shop shop = plugin.getDataStorage().loadShopFromSign(ShopLocation.deserialize(s)); - if (shop.checkRole(player.getUniqueId()) != ShopRole.SHOPPER) { - sb.append(shop.checkRole(player.getUniqueId()).toString()).append(" &f|&d "); - sb.append(s).append(" &f| "); - sb.append(shop.getStatus().getLine()).append("\n&b"); - } - }); - } - if (playerSetting.getStaffShops().size() > 0) { - playerSetting.getOwnedShops().forEach(s -> { - Shop shop = plugin.getDataStorage().loadShopFromSign(ShopLocation.deserialize(s)); - if (shop.checkRole(player.getUniqueId()) != ShopRole.SHOPPER) { - sb.append(shop.checkRole(player.getUniqueId()).toString()).append(" &f|&d "); - sb.append(s).append(" &f| "); - sb.append(shop.getStatus().getLine()).append("\n&b"); - } - }); - } - - sb.deleteCharAt(sb.lastIndexOf("\n")); - player.sendMessage(colorize(sb.toString())); + player.sendMessage(playerSetting.getInvolvedStatusesString()); } } diff --git a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java index ce850de1..218c508e 100644 --- a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java +++ b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java @@ -176,7 +176,8 @@ public void onBlockBreak(BlockBreakEvent event) { return; } - shop.getChestAsSC().resetName(); + if (shop.getChestAsSC() != null) + shop.getChestAsSC().resetName(); shop.remove(); return; } diff --git a/src/main/java/org/shanerx/tradeshop/objects/PlayerSetting.java b/src/main/java/org/shanerx/tradeshop/objects/PlayerSetting.java index 87d33f7c..a2f65205 100644 --- a/src/main/java/org/shanerx/tradeshop/objects/PlayerSetting.java +++ b/src/main/java/org/shanerx/tradeshop/objects/PlayerSetting.java @@ -27,7 +27,16 @@ import com.google.common.collect.Sets; import com.google.gson.Gson; +import de.themoep.inventorygui.GuiElementGroup; +import de.themoep.inventorygui.GuiPageElement; +import de.themoep.inventorygui.InventoryGui; +import de.themoep.inventorygui.StaticGuiElement; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; import org.shanerx.tradeshop.enumys.Setting; +import org.shanerx.tradeshop.enumys.ShopRole; +import org.shanerx.tradeshop.utils.Utils; import java.io.Serializable; import java.util.Map; @@ -37,11 +46,12 @@ public class PlayerSetting implements Serializable { private transient UUID uuid; - private String uuidString; + private final String uuidString; + private final Set ownedShops; private int type = 0, multi = Setting.MULTI_TRADE_DEFAULT.getInt(); - - private Set ownedShops, staffShops; + private final Set staffShops; + private transient Utils utils = new Utils(); public PlayerSetting(UUID playerUUID, Map data) { this.uuid = playerUUID; @@ -125,10 +135,95 @@ public Set getStaffShops() { public void load() { if (uuid == null) uuid = UUID.fromString(uuidString); if (multi > Setting.MULTI_TRADE_MAX.getInt()) multi = Setting.MULTI_TRADE_MAX.getInt(); + utils = new Utils(); } public String serialize() { return new Gson().toJson(this); } + + public String getInvolvedStatusesString() { + StringBuilder sb = new StringBuilder(); + sb.append("&eStatus of your shops: \n"); + sb.append("&eShop Role &f| &eType &f| &eLocation &f| &eInventory Status\n&b"); + if (getOwnedShops().size() > 0) { + getOwnedShops().forEach(s -> { + Shop shop = utils.plugin.getDataStorage().loadShopFromSign(ShopLocation.deserialize(s)); + if (shop.checkRole(uuid) != ShopRole.SHOPPER) { + sb.append(shop.checkRole(uuid).toString()).append(" &f|&a "); + sb.append(shop.getShopType().toString()).append(" &f|&d "); + sb.append(s).append(" &f| "); + sb.append(shop.getStatus().getLine()).append("\n&b"); + } + }); + } + if (getStaffShops().size() > 0) { + getStaffShops().forEach(s -> { + Shop shop = utils.plugin.getDataStorage().loadShopFromSign(ShopLocation.deserialize(s)); + if (shop.checkRole(uuid) != ShopRole.SHOPPER) { + sb.append(shop.checkRole(uuid).toString()).append(" &f|&a "); + sb.append(shop.getShopType().toString()).append(" &f|&d "); + sb.append(s).append(" &f| "); + sb.append(shop.getStatus().getLine()).append("\n&b"); + } + }); + } + + sb.deleteCharAt(sb.lastIndexOf("\n")); + return utils.colorize(sb.toString()); + } + + public InventoryGui getInvolvedStatusesInventory() { + InventoryGui gui = new InventoryGui(utils.plugin, Bukkit.getOfflinePlayer(uuid).getName() + "'s Shops", new String[]{"ggggggggg", "ggggggggg", " fp ln "}); + GuiElementGroup group = new GuiElementGroup('g'); + if (getOwnedShops().size() > 0) { + getOwnedShops().forEach(s -> { + Shop shop = utils.plugin.getDataStorage().loadShopFromSign(ShopLocation.deserialize(s)); + if (shop.checkRole(uuid) != ShopRole.SHOPPER) { + group.addElement(new StaticGuiElement('e', + new ItemStack(shop.getInventoryLocation() != null ? + shop.getInventoryLocation().getBlock().getType() : + Material.getMaterial(shop.getShopLocation().getBlock().getType().toString().replaceAll("WALL_", ""))), + utils.colorize("&d" + s), + utils.colorize("&a" + shop.getShopType().toString()), + utils.colorize("&b" + shop.checkRole(uuid).toString()), + utils.colorize(shop.getStatus().getLine()))); + } + }); + } + if (getStaffShops().size() > 0) { + getStaffShops().forEach(s -> { + Shop shop = utils.plugin.getDataStorage().loadShopFromSign(ShopLocation.deserialize(s)); + if (shop.checkRole(uuid) != ShopRole.SHOPPER) { + group.addElement(new StaticGuiElement('e', + new ItemStack(shop.getInventoryLocation() != null ? + shop.getInventoryLocation().getBlock().getType() : + Material.getMaterial(shop.getShopLocation().getBlock().getType().toString().replaceAll("WALL_", ""))), + utils.colorize("&d" + s), + utils.colorize("&a" + shop.getShopType().toString()), + utils.colorize("&b" + shop.checkRole(uuid).toString()), + utils.colorize(shop.getStatus().getLine()))); + } + }); + } + gui.addElement(group); + + // First page + gui.addElement(new GuiPageElement('f', new ItemStack(Material.STICK), GuiPageElement.PageAction.FIRST, "Go to first page (current: %page%)")); + + // Previous page + gui.addElement(new GuiPageElement('p', new ItemStack(Material.POTION), GuiPageElement.PageAction.PREVIOUS, "Go to previous page (%prevpage%)")); + + // Next page + gui.addElement(new GuiPageElement('n', new ItemStack(Material.SPLASH_POTION), GuiPageElement.PageAction.NEXT, "Go to next page (%nextpage%)")); + + // Last page + gui.addElement(new GuiPageElement('l', new ItemStack(Material.ARROW), GuiPageElement.PageAction.LAST, "Go to last page (%pages%)")); + + //Blank Item + gui.setFiller(new ItemStack(Material.GRAY_STAINED_GLASS, 1)); + + return gui; + } } diff --git a/src/main/java/org/shanerx/tradeshop/objects/Shop.java b/src/main/java/org/shanerx/tradeshop/objects/Shop.java index 978010c4..aeae4faa 100644 --- a/src/main/java/org/shanerx/tradeshop/objects/Shop.java +++ b/src/main/java/org/shanerx/tradeshop/objects/Shop.java @@ -385,7 +385,7 @@ public List getMembersUUID() { * @return inventory location as Location */ public Location getInventoryLocation() { - return chestLoc.getLocation(); + return chestLoc != null ? chestLoc.getLocation() : null; } /**