diff --git a/changelog.md b/changelog.md index 4477773..4ab2335 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,12 @@ # Changelog +### v 2.2.1 +- implement option for games to add commands to the gamebox commands +- cancel game invitations when the other player is in a disabled world - make skull display names in top lists configurable - fix ItemStackUtility throwing error on invalid materials, when a data value is given - hide leftover debug messages +- fix high number names loaded from langauge file ### v 2.2.0 - compatibility with minecraft 1.13 diff --git a/core/pom.xml b/core/pom.xml index d5bcc5a..8f6225c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -7,7 +7,7 @@ gamebox me.nikl - 2.2.0 + 2.2.1 gamebox-core diff --git a/core/src/main/java/me/nikl/gamebox/commands/admin/GameAdminCommand.java b/core/src/main/java/me/nikl/gamebox/commands/admin/GameAdminCommand.java index eb976d5..f1768f3 100644 --- a/core/src/main/java/me/nikl/gamebox/commands/admin/GameAdminCommand.java +++ b/core/src/main/java/me/nikl/gamebox/commands/admin/GameAdminCommand.java @@ -7,19 +7,17 @@ import me.nikl.gamebox.utility.Permission; import org.apache.commons.lang.Validate; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; /** * @author Niklas Eicker */ -public abstract class GameAdminCommand extends GameBoxBaseCommand { +public class GameAdminCommand extends GameBoxBaseCommand { private Module module; public GameAdminCommand(GameBox gameBox, Module module) { super(gameBox); Validate.notNull(module, "The GameAdminCommand needs a valid module!"); this.module = module; - gameBox.getCommands().registerCommand(this); } @Override @@ -30,10 +28,6 @@ public boolean preCommand(CommandSender sender) { sender.sendMessage(gameBox.lang.PREFIX + gameBox.lang.CMD_NO_PERM); return true; } - if (sender instanceof Player) { - sender.sendMessage(gameBox.lang.PREFIX + " Only from the console!"); - return true; - } return false; } } diff --git a/core/src/main/java/me/nikl/gamebox/game/Game.java b/core/src/main/java/me/nikl/gamebox/game/Game.java index 5326779..8f7b2e4 100644 --- a/core/src/main/java/me/nikl/gamebox/game/Game.java +++ b/core/src/main/java/me/nikl/gamebox/game/Game.java @@ -86,6 +86,17 @@ public void onEnable() throws GameLoadException { init(); loadGameManager(); hook(); + // load anything that needs the game manager + finish(); + } + + /** + * Load anything that depends on a fully initialized GameManger and a successful hook into GameBox + * + * example: Game commands that need a list of game types + */ + protected void finish() { + // to be Overridden } private void checkRequirements() throws GameLoadException { diff --git a/core/src/main/java/me/nikl/gamebox/inventory/shop/Category.java b/core/src/main/java/me/nikl/gamebox/inventory/shop/Category.java index 5ad5c7e..9441e36 100644 --- a/core/src/main/java/me/nikl/gamebox/inventory/shop/Category.java +++ b/core/src/main/java/me/nikl/gamebox/inventory/shop/Category.java @@ -12,7 +12,6 @@ import me.nikl.gamebox.utility.StringUtility; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -50,21 +49,17 @@ public Category(GameBox plugin, ShopManager shopManager, GUIManager guiManager, loadShopItems(); } - private void loadShopItems() { ConfigurationSection pageSection = shop.getConfigurationSection("shop.categories." + key + ".items"); if (pageSection == null) return; - Map allItems = new HashMap<>(); ItemStack itemStack; ItemMeta meta; List lore = new ArrayList<>(); int counter = 0, token = 0, money = 0, amount = 0; for (String itemKey : pageSection.getKeys(false)) { - // if null no item will be given itemStack = ItemStackUtility.getItemStack(pageSection.getString(itemKey + ".materialData")); - // load the prices of the item if (pageSection.isSet(itemKey + ".tokens") && pageSection.isInt(itemKey + ".tokens")) { token = pageSection.getInt(itemKey + ".tokens"); @@ -79,12 +74,10 @@ private void loadShopItems() { } else { money = pageSection.getInt(itemKey + ".money"); } - // get the amount of the item (default = 1). Check for MaxStackSize! if (itemStack != null) { if (pageSection.isSet(itemKey + ".count") && pageSection.isInt(itemKey + ".count")) { amount = pageSection.getInt(itemKey + ".count"); - if (amount > itemStack.getMaxStackSize()) { itemStack.setAmount(itemStack.getMaxStackSize()); } else { @@ -94,15 +87,12 @@ private void loadShopItems() { if (pageSection.getBoolean(itemKey + ".glow", false)) { itemStack = NmsFactory.getNmsUtility().addGlow(itemStack); } - meta = itemStack.getItemMeta(); if (pageSection.isString(itemKey + ".displayName")) { meta.setDisplayName(StringUtility.color(pageSection.getString(itemKey + ".displayName"))); } - if (pageSection.isList(itemKey + ".lore")) { lore = new ArrayList<>(pageSection.getStringList(itemKey + ".lore")); - for (int i = 0; i < lore.size(); i++) { lore.set(i, StringUtility.color(lore.get(i))); } @@ -117,37 +107,26 @@ private void loadShopItems() { Bukkit.getConsoleSender().sendMessage(plugin.lang.PREFIX + ChatColor.RED + " Skipping..."); continue; } - - // load shop item ShopItem shopItem = new ShopItem(); - if (itemStack != null) { shopItem.setItemStack(new ItemStack(itemStack)); } - if (pageSection.isList(itemKey + ".requirements" + ".permissions")) { shopItem.setPermissions(pageSection.getStringList(itemKey + ".requirements" + ".permissions")); } - if (pageSection.isList(itemKey + ".requirements" + ".noPermissions")) { shopItem.setNoPermissions(pageSection.getStringList(itemKey + ".requirements" + ".noPermissions")); } - if (pageSection.getBoolean(itemKey + ".manipulatesInventory", false)) { shopItem.setManipulatesInventory(true); } - if (pageSection.isList(itemKey + ".commands")) { shopItem.setCommands(pageSection.getStringList(itemKey + ".commands")); } - - // load button Button button = new Button(buttonItem); button.setAction(ClickAction.BUY); - - meta = button.getItemMeta(); lore.clear(); lore.add(""); @@ -159,30 +138,19 @@ private void loadShopItems() { if (money != 0) { lore.add(this.plugin.lang.SHOP_MONEY.replace("%money%", String.valueOf(money))); } - if (meta.hasLore()) lore.addAll(meta.getLore()); - meta.setLore(lore); button.setItemMeta(meta); - button.setArgs(key, String.valueOf(counter), String.valueOf(token), String.valueOf(money)); - allItems.put(counter, button); - shopItems.put(String.valueOf(counter), shopItem); - counter++; } - GameBox.debug("All loaded items of page " + key + ":"); - for (int number : allItems.keySet()) { - GameBox.debug(" " + allItems.get(number).toString()); - } counter++; int pageNum = counter / itemsPerPage + (counter % itemsPerPage == 0 ? 0 : 1); counter = 0; Page page = null; while (!allItems.isEmpty()) { - GameBox.debug(allItems.keySet().size() + " Items left to sort"); if ((counter) % itemsPerPage == 0) { pages.put(counter / itemsPerPage, (page = new Page(plugin, guiManager, slots, counter / itemsPerPage, shopManager, new String[]{key, String.valueOf(counter / itemsPerPage)}))); if (counter / itemsPerPage == 0) { @@ -206,31 +174,24 @@ private ItemStack getButtonItem(ItemStack itemStack, ConfigurationSection pageSe if (presentItem == null && itemStack == null) { return null; } - if (presentItem == null) { presentItem = new ItemStack(itemStack); } - if (pageSection.getBoolean(path + ".glow", false)) { presentItem = NmsFactory.getNmsUtility().addGlow(presentItem); } - if (pageSection.isInt(path + ".count")) { presentItem.setAmount(pageSection.getInt(path + ".count")); } - ItemMeta meta = presentItem.getItemMeta(); - if (pageSection.isString(path + ".displayName")) { meta.setDisplayName(StringUtility.color(pageSection.getString(path + ".displayName"))); } - if (pageSection.isList(path + ".additionalLore")) { List lore = new ArrayList<>(); lore.add(" "); lore.add(ChatColor.GOLD + "- - - - - - - - - - - - - - - - - - -"); lore.add(" "); - List addLore = new ArrayList<>(pageSection.getStringList(path + ".additionalLore")); for (int i = 0; i < addLore.size(); i++) { addLore.set(i, StringUtility.color(addLore.get(i))); @@ -238,10 +199,7 @@ private ItemStack getButtonItem(ItemStack itemStack, ConfigurationSection pageSe lore.addAll(addLore); meta.setLore(lore); } - presentItem.setItemMeta(meta); - - return presentItem; } diff --git a/core/src/main/resources/plugin.yml b/core/src/main/resources/plugin.yml index 21ebe0b..ae914e9 100644 --- a/core/src/main/resources/plugin.yml +++ b/core/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: GameBox author: Nikl main: me.nikl.gamebox.GameBox -version: 2.2.0 +version: 2.2.1 website: nikl.me softdepend: [Vault, PlaceholderAPI, CalendarEvents] diff --git a/distribution/pom.xml b/distribution/pom.xml index c8f95a0..dd94225 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -7,7 +7,7 @@ gamebox me.nikl - 2.2.0 + 2.2.1 gamebox-distribution @@ -68,14 +68,14 @@ me.nikl gamebox-core - 2.2.0 + 2.2.1 compile me.nikl cookieclicker - 2.2.0 + 2.2.1 me.nikl diff --git a/pom.xml b/pom.xml index 2bfe0b3..13e6b7e 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ gamebox gamebox pom - 2.2.0 + 2.2.1 Collection of inventory games https://gamebox.nikl.me