diff --git a/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java b/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java index 5ea46993..76bb86b9 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java +++ b/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java @@ -104,7 +104,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String cmdRnnr.switchShop(); break; case WHAT: - cmdRnnr.what(); + new WhatCommand(plugin, cmdPass).what(); break; case WHO: cmdRnnr.who(); diff --git a/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java b/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java index 47c0f7d5..6369a352 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java +++ b/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java @@ -25,7 +25,7 @@ package org.shanerx.tradeshop.commands; -import de.themoep.inventorygui.GuiElementGroup; +import de.themoep.inventorygui.GuiPageElement; import de.themoep.inventorygui.InventoryGui; import de.themoep.inventorygui.StaticGuiElement; import org.bukkit.Bukkit; @@ -46,15 +46,27 @@ import org.shanerx.tradeshop.utils.Utils; import org.shanerx.tradeshop.utils.data.DataType; -import java.util.ArrayList; -import java.util.List; - public class CommandRunner extends Utils { protected final TradeShop plugin; protected final CommandPass command; protected Player pSender; + protected final GuiPageElement PREV_BUTTON = new GuiPageElement('p', new ItemStack(Material.POTION), GuiPageElement.PageAction.PREVIOUS, "Go to previous page (%prevpage%)"), + NEXT_BUTTON = new GuiPageElement('n', new ItemStack(Material.SPLASH_POTION), GuiPageElement.PageAction.NEXT, "Go to next page (%nextpage%)"); + protected final StaticGuiElement CANCEL_BUTTON = new StaticGuiElement('c', new ItemStack(Material.END_CRYSTAL), click3 -> { + InventoryGui.goBack(pSender); + return true; + }, "Cancel Changes"), + BACK_BUTTON = new StaticGuiElement('b', new ItemStack(Material.END_CRYSTAL), click3 -> { + InventoryGui.goBack(pSender); + return true; + }, "Back"); + protected final String[] MENU_LAYOUT = {"a b c"}, + EDIT_LAYOUT = {"aggggggga", "ap c s na"}, + ITEM_LAYOUT = {"aggggggga", "aggggggga", "a cbs a"}, + WHAT_MENU = {"141125333", "1aaa2bbb3", "11p123n33"}; + public CommandRunner(TradeShop instance, CommandPass command) { this.plugin = instance; this.command = command; @@ -621,56 +633,6 @@ public void switchShop() { sendMessage(Message.SHOP_TYPE_SWITCHED.getPrefixed().replace("%newtype%", shop.getShopType().toHeader())); } - /** - * Opens a GUI containing the items to be traded at the shop the player is looking at - */ - public void what() { - Shop shop = findShop(); - - if (shop == null) - return; - - List guiSetup = new ArrayList<>(); - guiSetup.add("141125333"); - for (int i = 1; i < Math.max((int) (Math.ceil(shop.getProduct().size() / 3.0)), (int) (Math.ceil(shop.getCost().size() / 3.0))) + 1; i++) { - guiSetup.add("1aaa2bbb3"); - } - - InventoryGui gui = new InventoryGui(plugin, colorize(shop.getShopType() == ShopType.ITRADE ? - Setting.ITRADESHOP_OWNER.getString() : - Bukkit.getOfflinePlayer(shop.getOwner().getUUID()).getName() + "'s Shop"), - guiSetup.toArray(new String[0])); - - GuiElementGroup costGroup = new GuiElementGroup('a'), productGroup = new GuiElementGroup('b'); - - costGroup.setFiller(new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE, 1)); - productGroup.setFiller(new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE, 1)); - gui.setFiller(new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE, 1)); - - for (ShopItemStack item : shop.getCost()) { - costGroup.addElement(new StaticGuiElement('e', item.getItemStack())); - } - - for (ShopItemStack item : shop.getProduct()) { - productGroup.addElement(new StaticGuiElement('e', item.getItemStack())); - } - - gui.addElement(new StaticGuiElement('1', new ItemStack(Material.LIME_STAINED_GLASS_PANE), - " ")); - gui.addElement(new StaticGuiElement('2', new ItemStack(Material.BLACK_STAINED_GLASS_PANE), - " ")); - gui.addElement(new StaticGuiElement('3', new ItemStack(Material.LIGHT_BLUE_STAINED_GLASS_PANE), - " ")); - gui.addElement(new StaticGuiElement('4', new ItemStack(Material.GOLD_NUGGET), - "Cost", "This is the item", "that you give to", "make the trade.")); - gui.addElement(new StaticGuiElement('5', new ItemStack(Material.GRASS_BLOCK), - "Product", "This is the item", "that you receive", "from the trade.")); - gui.addElement(costGroup); - gui.addElement(productGroup); - - gui.show(pSender); - } - /** * Tells the player who the Owner/Managers/Members that are on the shop are */ diff --git a/src/main/java/org/shanerx/tradeshop/commands/EditCommand.java b/src/main/java/org/shanerx/tradeshop/commands/EditCommand.java index debe240a..8fd8bfcb 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/EditCommand.java +++ b/src/main/java/org/shanerx/tradeshop/commands/EditCommand.java @@ -26,7 +26,10 @@ package org.shanerx.tradeshop.commands; import com.google.common.collect.Iterables; -import de.themoep.inventorygui.*; +import de.themoep.inventorygui.GuiElementGroup; +import de.themoep.inventorygui.GuiStateElement; +import de.themoep.inventorygui.InventoryGui; +import de.themoep.inventorygui.StaticGuiElement; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; @@ -46,17 +49,6 @@ public class EditCommand extends CommandRunner { - private final String[] MENU_LAYOUT = {"a b c"}, - EDIT_LAYOUT = {"aggggggga", "ap c s na"}, - ITEM_LAYOUT = {"aggggggga", "aggggggga", "a c s a"}; - private final GuiPageElement PREV_BUTTON = new GuiPageElement('p', new ItemStack(Material.POTION), GuiPageElement.PageAction.PREVIOUS, "Go to previous page (%prevpage%)"), - NEXT_BUTTON = new GuiPageElement('n', new ItemStack(Material.SPLASH_POTION), GuiPageElement.PageAction.NEXT, "Go to next page (%nextpage%)"); - private final StaticGuiElement CANCEL_BUTTON = new StaticGuiElement('c', new ItemStack(Material.END_CRYSTAL), - click3 -> { - InventoryGui.goBack(pSender); - return true; - }, "Cancel Changes"); - private Shop shop; private InventoryGui mainMenu, userEdit, diff --git a/src/main/java/org/shanerx/tradeshop/commands/WhatCommand.java b/src/main/java/org/shanerx/tradeshop/commands/WhatCommand.java new file mode 100644 index 00000000..9af58ab4 --- /dev/null +++ b/src/main/java/org/shanerx/tradeshop/commands/WhatCommand.java @@ -0,0 +1,166 @@ +/* + * + * Copyright (c) 2016-2019 + * SparklingComet @ http://shanerx.org + * KillerOfPie @ http://killerofpie.github.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * NOTICE: All modifications made by others to the source code belong + * to the respective contributor. No contributor should be held liable for + * any damages of any kind, whether be material or moral, which were + * caused by their contribution(s) to the project. See the full License for more information. + * + */ + +package org.shanerx.tradeshop.commands; + +import de.themoep.inventorygui.GuiElementGroup; +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.bukkit.inventory.meta.BookMeta; +import org.bukkit.inventory.meta.Damageable; +import org.shanerx.tradeshop.TradeShop; +import org.shanerx.tradeshop.enumys.Setting; +import org.shanerx.tradeshop.enumys.ShopType; +import org.shanerx.tradeshop.objects.Shop; +import org.shanerx.tradeshop.objects.ShopItemStack; + +public class WhatCommand extends CommandRunner { + + public WhatCommand(TradeShop instance, CommandPass command) { + super(instance, command); + } + + /** + * Opens a GUI containing the items to be traded at the shop the player is looking at + */ + public void what() { + Shop shop = findShop(); + + if (shop == null) + return; + + InventoryGui gui = new InventoryGui(plugin, colorize(shop.getShopType() == ShopType.ITRADE ? + Setting.ITRADESHOP_OWNER.getString() : + Bukkit.getOfflinePlayer(shop.getOwner().getUUID()).getName() + "'s Shop"), + WHAT_MENU); + + GuiElementGroup costGroup = new GuiElementGroup('a'), productGroup = new GuiElementGroup('b'); + + gui.setFiller(new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE, 1)); + + for (ShopItemStack item : shop.getCost()) { + costGroup.addElement(shopitemViewMenu(item)); + } + + for (ShopItemStack item : shop.getProduct()) { + productGroup.addElement(shopitemViewMenu(item)); + } + + gui.addElement(new StaticGuiElement('1', new ItemStack(Material.LIME_STAINED_GLASS_PANE), + " ")); + gui.addElement(new StaticGuiElement('2', new ItemStack(Material.BLACK_STAINED_GLASS_PANE), + " ")); + gui.addElement(new StaticGuiElement('3', new ItemStack(Material.LIGHT_BLUE_STAINED_GLASS_PANE), + " ")); + gui.addElement(new StaticGuiElement('4', new ItemStack(Material.GOLD_NUGGET), + "Cost", "This is the item", "that you give to", "make the trade.")); + gui.addElement(new StaticGuiElement('5', new ItemStack(Material.GRASS_BLOCK), + "Product", "This is the item", "that you receive", "from the trade.")); + gui.addElement(PREV_BUTTON); + gui.addElement(NEXT_BUTTON); + gui.addElement(costGroup); + gui.addElement(productGroup); + + gui.show(pSender); + } + + private ItemStack settingItem(boolean state) { + return state ? new ItemStack(Material.EMERALD_BLOCK) : new ItemStack(Material.REDSTONE_BLOCK); + } + + private ItemStack settingItem(int state) { + switch (state) { + case -1: + return new ItemStack(Material.REDSTONE_BLOCK); + case 0: + return new ItemStack(Material.IRON_BLOCK); + case 1: + default: + return new ItemStack(Material.EMERALD_BLOCK); + case 2: + return new ItemStack(Material.GOLD_BLOCK); + } + } + + private String stateText(int state) { + switch (state) { + case -1: + return "False"; + case 0: + return "<="; + case 1: + default: + return "=="; + case 2: + return ">="; + } + } + + private StaticGuiElement shopitemViewMenu(ShopItemStack item) { + return new StaticGuiElement('e', item.getItemStack(), click2 -> { + InventoryGui itemView = new InventoryGui(plugin, "Edit Cost Item", ITEM_LAYOUT); + GuiElementGroup itemGroup = new GuiElementGroup('g'); + + itemView.addElement(BACK_BUTTON); + + itemView.addElement(new StaticGuiElement('a', new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); + + itemGroup.addElement(new StaticGuiElement('e', item.getItemStack())); + + itemGroup.addElement(new StaticGuiElement('e', settingItem(item.isCompareName()), "Compare Name", "State: " + item.isCompareName())); + itemGroup.addElement(new StaticGuiElement('e', settingItem(item.isCompareLore()), "Compare Lore", "State: " + item.isCompareLore())); + + if (item.getItemStack().getType().toString().endsWith("SHULKER_BOX")) { + itemGroup.addElement(new StaticGuiElement('e', settingItem(item.isCompareShulkerInventory()), "Compare Shulker Inventory", "State: " + item.isCompareShulkerInventory())); + } + + if (item.getItemStack().getItemMeta() instanceof Damageable) { + itemGroup.addElement(new StaticGuiElement('e', settingItem(item.isCompareDurability()), "Compare Durability", "State: " + stateText(item.isCompareDurability()))); + } + + itemGroup.addElement(new StaticGuiElement('e', settingItem(item.isCompareEnchantments()), "Compare Enchantments", "State: " + item.isCompareEnchantments())); + + itemGroup.addElement(new StaticGuiElement('e', settingItem(item.isCompareUnbreakable()), "Compare Unbreakable", "State: " + item.isCompareUnbreakable())); + + if (item.getItemStack().getItemMeta() instanceof BookMeta) { + itemGroup.addElement(new StaticGuiElement('e', settingItem(item.isCompareBookAuthor()), "Compare Book Author", "State: " + item.isCompareBookAuthor())); + itemGroup.addElement(new StaticGuiElement('e', settingItem(item.isCompareBookPages()), "Compare Book Pages", "State: " + item.isCompareBookPages())); + } + + itemGroup.addElement(new StaticGuiElement('e', settingItem(item.isCompareItemFlags()), "Compare Item Flags", "State: " + item.isCompareItemFlags())); + + itemGroup.addElement(new StaticGuiElement('e', settingItem(item.isCompareCustomModelData()), "Compare Custom Model Data", "State: " + item.isCompareCustomModelData())); + + itemGroup.addElement(new StaticGuiElement('e', settingItem(item.isCompareAttributeModifier()), "Compare Attribute Modifier", "State: " + item.isCompareAttributeModifier())); + + itemView.addElement(itemGroup); + itemView.show(pSender); + return true; + }); + } +}