diff --git a/src/main/java/sh/okx/rankup/gui/Gui.java b/src/main/java/sh/okx/rankup/gui/Gui.java index c0bbebe..05f7102 100644 --- a/src/main/java/sh/okx/rankup/gui/Gui.java +++ b/src/main/java/sh/okx/rankup/gui/Gui.java @@ -52,7 +52,8 @@ public class Gui implements InventoryHolder { return null; } - ItemStack[] items = new ItemStack[config.getInt("rows", 1) * 9]; + Integer rows = Gui.getInt(config, "rows"); + ItemStack[] items = new ItemStack[(rows == null ? 1 : rows) * 9]; ItemStack fill = getItem(plugin, plugin.getSection(oldRank, basePath + ".fill"), player, oldRank, rank); @@ -167,6 +168,19 @@ public class Gui implements InventoryHolder { } } + public static Integer getInt(ConfigurationSection section, String key) { + String string = section.getString(key); + if (string == null) { + return null; + } else { + try { + return Integer.parseInt(string); + } catch (IllegalArgumentException ex) { + return null; + } + } + } + public void open(Player player) { player.openInventory(inventory); } diff --git a/src/main/java/sh/okx/rankup/ranksgui/RanksGui.java b/src/main/java/sh/okx/rankup/ranksgui/RanksGui.java index 4e94a62..c792865 100644 --- a/src/main/java/sh/okx/rankup/ranksgui/RanksGui.java +++ b/src/main/java/sh/okx/rankup/ranksgui/RanksGui.java @@ -35,9 +35,9 @@ public class RanksGui { ConfigurationSection basePath = plugin.getMessages().getConfigurationSection("rankup.ranksgui"); String title = get(ConfigurationSection::getString, "title", playerPath, basePath, "Ranks"); - int rows = get(this::getInt, "rows", playerPath, basePath, 3); - int offset = get(this::getInt, "offset", playerPath, basePath, 10); - int width = get(this::getInt, "width", playerPath, basePath, 7); + int rows = get(Gui::getInt, "rows", playerPath, basePath, 3); + int offset = get(Gui::getInt, "offset", playerPath, basePath, 10); + int width = get(Gui::getInt, "width", playerPath, basePath, 7); inventory = Bukkit.createInventory(null, rows * 9, Colour.translate(title)); @@ -87,18 +87,6 @@ public class RanksGui { player.openInventory(inventory); } - private Integer getInt(ConfigurationSection section, String key) { - String string = section.getString(key); - if (string == null) { - return null; - } else { - try { - return Integer.parseInt(string); - } catch (IllegalArgumentException ex) { - return null; - } - } - } private T get(BiFunction fun, String path, ConfigurationSection primary, ConfigurationSection secondary, T def) { T get = null; diff --git a/src/test/java/sh/okx/rankup/RankupTest.java b/src/test/java/sh/okx/rankup/RankupTest.java index ed68026..80b7d5a 100644 --- a/src/test/java/sh/okx/rankup/RankupTest.java +++ b/src/test/java/sh/okx/rankup/RankupTest.java @@ -10,6 +10,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import sh.okx.rankup.providers.TestEconomyProvider; import sh.okx.rankup.hook.GroupProvider; @@ -76,7 +77,7 @@ public abstract class RankupTest { } } - @BeforeEach + @AfterEach public void tearDown() { MockBukkit.unmock(); System.clearProperty("RANKUP_TEST");