From c43e0513bbeae539ca2635e9015479563a6c3755 Mon Sep 17 00:00:00 2001 From: pixeldev Date: Thu, 30 Jun 2022 20:29:16 -0500 Subject: [PATCH] refactor!: rename builder methods --- .../team/unnamed/gui/item/ItemBuilder.java | 34 ++++++------- .../unnamed/gui/item/ItemBuilderLayout.java | 16 +++---- .../unnamed/gui/item/SkullItemBuilder.java | 4 +- .../gui/item/util/DecorateItemUtils.java | 10 ++-- .../unnamed/gui/item/util/DyeItemUtils.java | 2 +- .../gui/menu/item/ItemClickableBuilder.java | 6 +-- .../action/ItemClickableActionBuilder.java | 2 +- .../gui/menu/type/MenuInventoryBuilder.java | 12 ++--- .../menu/type/MenuInventoryBuilderLayout.java | 12 ++--- .../type/PaginatedMenuInventoryBuilder.java | 20 ++++---- .../StringLayoutMenuInventoryBuilder.java | 6 +-- .../unnamed/gui/menu/plugin/MenuPlugin.java | 48 +++++++++---------- 12 files changed, 86 insertions(+), 86 deletions(-) diff --git a/item/api/src/main/java/team/unnamed/gui/item/ItemBuilder.java b/item/api/src/main/java/team/unnamed/gui/item/ItemBuilder.java index 7eff8d3..68ce2da 100644 --- a/item/api/src/main/java/team/unnamed/gui/item/ItemBuilder.java +++ b/item/api/src/main/java/team/unnamed/gui/item/ItemBuilder.java @@ -11,47 +11,47 @@ public interface ItemBuilder { - ItemBuilder setName(String name); + ItemBuilder name(String name); - ItemBuilder setLore(List lore); + ItemBuilder lore(List lore); - ItemBuilder setLore(String... lines); + ItemBuilder lore(String... lines); - ItemBuilder setEnchantments(Map enchantments); + ItemBuilder enchantments(Map enchantments); - ItemBuilder addEnchant(Enchantment enchantment, int level); + ItemBuilder enchant(Enchantment enchantment, int level); - ItemBuilder setFlags(List flags); + ItemBuilder flags(List flags); - ItemBuilder addFlag(ItemFlag... flags); + ItemBuilder flag(ItemFlag... flags); ItemBuilder grow(); - ItemBuilder setUnbreakable(boolean unbreakable); + ItemBuilder unbreakable(boolean unbreakable); ItemStack build(); - static ItemBuilder newBuilder(Material material) { - return newBuilder(material, 1); + static ItemBuilder builder(Material material) { + return builder(material, 1); } - static ItemBuilder newBuilder(Material material, int amount) { - return newBuilder(material, amount, (byte) 0); + static ItemBuilder builder(Material material, int amount) { + return builder(material, amount, (byte) 0); } - static ItemBuilder newBuilder(Material material, int amount, byte data) { + static ItemBuilder builder(Material material, int amount, byte data) { return new DefaultItemBuilder(material, amount, data); } - static SkullItemBuilder newSkullBuilder(int amount) { + static SkullItemBuilder skullBuilder(int amount) { return new SkullItemBuilder(amount); } - static ItemBuilder newDyeBuilder(String materialKey, DyeColor dyeColor) { - return newDyeBuilder(materialKey, dyeColor, 1); + static ItemBuilder dyeBuilder(String materialKey, DyeColor dyeColor) { + return dyeBuilder(materialKey, dyeColor, 1); } - static ItemBuilder newDyeBuilder(String materialKey, DyeColor dyeColor, int amount) { + static ItemBuilder dyeBuilder(String materialKey, DyeColor dyeColor, int amount) { return DyeItemUtils.createBuilder(materialKey, dyeColor, amount); } diff --git a/item/api/src/main/java/team/unnamed/gui/item/ItemBuilderLayout.java b/item/api/src/main/java/team/unnamed/gui/item/ItemBuilderLayout.java index 7044754..62cbd99 100644 --- a/item/api/src/main/java/team/unnamed/gui/item/ItemBuilderLayout.java +++ b/item/api/src/main/java/team/unnamed/gui/item/ItemBuilderLayout.java @@ -37,43 +37,43 @@ protected ItemBuilderLayout(Material material, int amount, byte data) { } @Override - public ItemBuilder setName(String name) { + public ItemBuilder name(String name) { this.name = isNotNull(name, "Item name cannot be null."); return back(); } @Override - public ItemBuilder setLore(List lore) { + public ItemBuilder lore(List lore) { this.lore = isNotNull(lore, "Item lore cannot be null."); return back(); } @Override - public ItemBuilder setLore(String... lines) { + public ItemBuilder lore(String... lines) { this.lore = Arrays.asList(isNotNull(lines, "Item lore cannot be null.")); return back(); } @Override - public ItemBuilder setEnchantments(Map enchantments) { + public ItemBuilder enchantments(Map enchantments) { this.enchantments = isNotNull(enchantments, "Item enchantments cannot be null."); return back(); } @Override - public ItemBuilder addEnchant(Enchantment enchantment, int level) { + public ItemBuilder enchant(Enchantment enchantment, int level) { this.enchantments.put(isNotNull(enchantment, "Item enchantment cannot be null."), level); return back(); } @Override - public ItemBuilder setFlags(List flags) { + public ItemBuilder flags(List flags) { this.flags = isNotNull(flags, "Item flags cannot be null."); return back(); } @Override - public ItemBuilder addFlag(ItemFlag... flags) { + public ItemBuilder flag(ItemFlag... flags) { this.flags.addAll(Arrays.asList(flags)); return back(); } @@ -86,7 +86,7 @@ public ItemBuilder grow() { } @Override - public ItemBuilder setUnbreakable(boolean unbreakable) { + public ItemBuilder unbreakable(boolean unbreakable) { this.unbreakable = unbreakable; return back(); } diff --git a/item/api/src/main/java/team/unnamed/gui/item/SkullItemBuilder.java b/item/api/src/main/java/team/unnamed/gui/item/SkullItemBuilder.java index 76b1274..09dce23 100644 --- a/item/api/src/main/java/team/unnamed/gui/item/SkullItemBuilder.java +++ b/item/api/src/main/java/team/unnamed/gui/item/SkullItemBuilder.java @@ -47,13 +47,13 @@ protected SkullItemBuilder(int amount) { super(SKULL_MATERIAL, amount, DATA); } - public SkullItemBuilder setOwner(String owner) { + public SkullItemBuilder owner(String owner) { this.owner = owner; return this; } - public SkullItemBuilder setUrl(String url) { + public SkullItemBuilder url(String url) { this.url = url; return this; diff --git a/item/api/src/main/java/team/unnamed/gui/item/util/DecorateItemUtils.java b/item/api/src/main/java/team/unnamed/gui/item/util/DecorateItemUtils.java index 1d1a0cb..1b4fd1d 100644 --- a/item/api/src/main/java/team/unnamed/gui/item/util/DecorateItemUtils.java +++ b/item/api/src/main/java/team/unnamed/gui/item/util/DecorateItemUtils.java @@ -10,13 +10,13 @@ private DecorateItemUtils() { throw new UnsupportedOperationException(); } - public static ItemBuilder newStainedPaneBuilder(DyeColor dyeColor) { - return ItemBuilder.newDyeBuilder("STAINED_GLASS_PANE", dyeColor) - .setName(" "); + public static ItemBuilder stainedPaneBuilder(DyeColor dyeColor) { + return ItemBuilder.dyeBuilder("STAINED_GLASS_PANE", dyeColor) + .name(" "); } - public static ItemStack newStainedPane(DyeColor dyeColor) { - return newStainedPaneBuilder(dyeColor).build(); + public static ItemStack stainedPane(DyeColor dyeColor) { + return stainedPaneBuilder(dyeColor).build(); } } diff --git a/item/api/src/main/java/team/unnamed/gui/item/util/DyeItemUtils.java b/item/api/src/main/java/team/unnamed/gui/item/util/DyeItemUtils.java index 1b37b23..0dbaf16 100644 --- a/item/api/src/main/java/team/unnamed/gui/item/util/DyeItemUtils.java +++ b/item/api/src/main/java/team/unnamed/gui/item/util/DyeItemUtils.java @@ -57,7 +57,7 @@ public static ItemBuilder createBuilder(String materialKey, DyeColor dyeColor, i data = 0; } - return ItemBuilder.newBuilder(material, amount, data); + return ItemBuilder.builder(material, amount, data); } } diff --git a/menu/api/src/main/java/team/unnamed/gui/menu/item/ItemClickableBuilder.java b/menu/api/src/main/java/team/unnamed/gui/menu/item/ItemClickableBuilder.java index 00fb5ac..12c6713 100644 --- a/menu/api/src/main/java/team/unnamed/gui/menu/item/ItemClickableBuilder.java +++ b/menu/api/src/main/java/team/unnamed/gui/menu/item/ItemClickableBuilder.java @@ -20,12 +20,12 @@ protected ItemClickableBuilder(int slot) { this.slot = slot; } - public ItemClickableBuilder setItem(ItemStack item) { + public ItemClickableBuilder item(ItemStack item) { this.item = isNotNull(item, "Item cannot be null."); return this; } - public ItemClickableBuilder setMultipleAction(Consumer action) { + public ItemClickableBuilder multipleAction(Consumer action) { ItemClickableActionBuilder.Multiple actionBuilder = ItemClickableAction.builder() .multipleAction(); action.accept(actionBuilder); @@ -33,7 +33,7 @@ public ItemClickableBuilder setMultipleAction(Consumer action) { + public ItemClickableBuilder action(Predicate action) { isNotNull(action, "Action cannot be null."); this.action = ItemClickableAction.single(action); return this; diff --git a/menu/api/src/main/java/team/unnamed/gui/menu/item/action/ItemClickableActionBuilder.java b/menu/api/src/main/java/team/unnamed/gui/menu/item/action/ItemClickableActionBuilder.java index b289cc0..5c5972a 100644 --- a/menu/api/src/main/java/team/unnamed/gui/menu/item/action/ItemClickableActionBuilder.java +++ b/menu/api/src/main/java/team/unnamed/gui/menu/item/action/ItemClickableActionBuilder.java @@ -33,7 +33,7 @@ public Multiple() { this.actions = new HashMap<>(); } - public Multiple linkClickType(ClickType clickType, Predicate action) { + public Multiple link(ClickType clickType, Predicate action) { actions.put( isNotNull(clickType, "Click type cannot be null."), isNotNull(action, "Action cannot be null.") diff --git a/menu/api/src/main/java/team/unnamed/gui/menu/type/MenuInventoryBuilder.java b/menu/api/src/main/java/team/unnamed/gui/menu/type/MenuInventoryBuilder.java index a373468..55765ed 100644 --- a/menu/api/src/main/java/team/unnamed/gui/menu/type/MenuInventoryBuilder.java +++ b/menu/api/src/main/java/team/unnamed/gui/menu/type/MenuInventoryBuilder.java @@ -16,17 +16,17 @@ public interface MenuInventoryBuilder { MenuInventoryBuilder fillBorders(ItemClickable item); - MenuInventoryBuilder setItems(List items); + MenuInventoryBuilder items(List items); - MenuInventoryBuilder addItem(ItemClickable item, int... slots); + MenuInventoryBuilder item(ItemClickable item, int... slots); - MenuInventoryBuilder addItem(ItemClickable item); + MenuInventoryBuilder item(ItemClickable item); - MenuInventoryBuilder setOpenAction(Predicate action); + MenuInventoryBuilder openAction(Predicate action); - MenuInventoryBuilder setCloseAction(Predicate action); + MenuInventoryBuilder closeAction(Predicate action); - MenuInventoryBuilder setIntroduceItems(boolean canIntroduceItems); + MenuInventoryBuilder introduceItems(boolean canIntroduceItems); Inventory build(); } diff --git a/menu/api/src/main/java/team/unnamed/gui/menu/type/MenuInventoryBuilderLayout.java b/menu/api/src/main/java/team/unnamed/gui/menu/type/MenuInventoryBuilderLayout.java index 6c1ef7f..37ca71d 100644 --- a/menu/api/src/main/java/team/unnamed/gui/menu/type/MenuInventoryBuilderLayout.java +++ b/menu/api/src/main/java/team/unnamed/gui/menu/type/MenuInventoryBuilderLayout.java @@ -93,13 +93,13 @@ public T fillBorders(ItemClickable item) { } @Override - public T setItems(List items) { + public T items(List items) { this.items = isNotNull(items, "Items cannot be null."); return back(); } @Override - public T addItem(ItemClickable item, int... slots) { + public T item(ItemClickable item, int... slots) { isNotNull(item, "Item cannot be null."); for (int slot : slots) { @@ -110,7 +110,7 @@ public T addItem(ItemClickable item, int... slots) { } @Override - public T addItem(ItemClickable item) { + public T item(ItemClickable item) { isNotNull(item, "Item cannot be null."); this.items.set(item.getSlot(), item); @@ -119,7 +119,7 @@ public T addItem(ItemClickable item) { } @Override - public T setOpenAction(Predicate action) { + public T openAction(Predicate action) { isNotNull(action, "Open action cannot be null."); this.openAction = action; @@ -127,7 +127,7 @@ public T setOpenAction(Predicate action) { } @Override - public T setCloseAction(Predicate action) { + public T closeAction(Predicate action) { isNotNull(action, "Close action cannot be null."); this.closeAction = action; @@ -135,7 +135,7 @@ public T setCloseAction(Predicate action) { } @Override - public T setIntroduceItems(boolean canIntroduceItems) { + public T introduceItems(boolean canIntroduceItems) { this.canIntroduceItems = canIntroduceItems; return back(); } diff --git a/menu/api/src/main/java/team/unnamed/gui/menu/type/PaginatedMenuInventoryBuilder.java b/menu/api/src/main/java/team/unnamed/gui/menu/type/PaginatedMenuInventoryBuilder.java index deb55b6..1bfa82f 100644 --- a/menu/api/src/main/java/team/unnamed/gui/menu/type/PaginatedMenuInventoryBuilder.java +++ b/menu/api/src/main/java/team/unnamed/gui/menu/type/PaginatedMenuInventoryBuilder.java @@ -35,54 +35,54 @@ protected PaginatedMenuInventoryBuilder(String title, int rows) { super(title, rows); } - public PaginatedMenuInventoryBuilder setBounds(int entitySlotFrom, int entitySlotTo) { + public PaginatedMenuInventoryBuilder bounds(int entitySlotFrom, int entitySlotTo) { this.entitySlotFrom = entitySlotFrom; this.entitySlotTo = entitySlotTo; return this; } - public PaginatedMenuInventoryBuilder setItemsPerRow(int itemsPerRow) { + public PaginatedMenuInventoryBuilder itemsPerRow(int itemsPerRow) { this.itemsPerRow = itemsPerRow; return this; } - public PaginatedMenuInventoryBuilder setSkippedSlots(int... skippedSlots) { + public PaginatedMenuInventoryBuilder skipSlots(int... skippedSlots) { this.skippedSlots = skippedSlots; return this; } - public PaginatedMenuInventoryBuilder setEntities(Collection entities) { + public PaginatedMenuInventoryBuilder entities(Collection entities) { this.entities = new ArrayList<>(entities); return this; } - public PaginatedMenuInventoryBuilder setEntityParser(Function entityParser) { + public PaginatedMenuInventoryBuilder entityParser(Function entityParser) { this.entityParser = entityParser; return this; } - public PaginatedMenuInventoryBuilder setNextPageItem(Function nextPageItem) { + public PaginatedMenuInventoryBuilder nextPageItem(Function nextPageItem) { this.nextPageItem = nextPageItem; return this; } - public PaginatedMenuInventoryBuilder setPreviousPageItem(Function previousPageItem) { + public PaginatedMenuInventoryBuilder previousPageItem(Function previousPageItem) { this.previousPageItem = previousPageItem; return this; } - public PaginatedMenuInventoryBuilder setItemIfNoEntities(ItemClickable itemIfNoEntities) { + public PaginatedMenuInventoryBuilder itemIfNoEntities(ItemClickable itemIfNoEntities) { this.itemIfNoEntities = isNotNull(itemIfNoEntities, "Item if no entities cannot be null."); return this; } - public PaginatedMenuInventoryBuilder setItemIfNoPreviousPage(ItemClickable itemIfNoPreviousPage) { + public PaginatedMenuInventoryBuilder itemIfNoPreviousPage(ItemClickable itemIfNoPreviousPage) { this.itemIfNoPreviousPage = isNotNull(itemIfNoPreviousPage, "Item if no previos page cannot be null."); return this; } - public PaginatedMenuInventoryBuilder setItemIfNoNextPage(ItemClickable itemIfNoNextPage) { + public PaginatedMenuInventoryBuilder itemIfNoNextPage(ItemClickable itemIfNoNextPage) { this.itemIfNoNextPage = isNotNull(itemIfNoNextPage, "Item if no next page cannot be null."); return this; diff --git a/menu/api/src/main/java/team/unnamed/gui/menu/type/StringLayoutMenuInventoryBuilder.java b/menu/api/src/main/java/team/unnamed/gui/menu/type/StringLayoutMenuInventoryBuilder.java index 3de9bb3..ba40280 100644 --- a/menu/api/src/main/java/team/unnamed/gui/menu/type/StringLayoutMenuInventoryBuilder.java +++ b/menu/api/src/main/java/team/unnamed/gui/menu/type/StringLayoutMenuInventoryBuilder.java @@ -27,12 +27,12 @@ protected StringLayoutMenuInventoryBuilder(String title, int rows) { this.layoutItems = new HashMap<>(); } - public StringLayoutMenuInventoryBuilder setLayoutItem(char identifier, ItemClickable item) { + public StringLayoutMenuInventoryBuilder layoutItem(char identifier, ItemClickable item) { this.layoutItems.put(identifier, isNotNull(item)); return back(); } - public StringLayoutMenuInventoryBuilder setLayoutLines(String... lines) { + public StringLayoutMenuInventoryBuilder layoutLines(String... lines) { for (String line : lines) { isState(line.length() == 9, "Cannot add layout line '" + line + "' because length is minor than 9"); @@ -54,7 +54,7 @@ public Inventory build() { continue; } - addItem(itemClickable.clone(slotIndex)); + item(itemClickable.clone(slotIndex)); } } diff --git a/menu/plugin/src/main/java/team/unnamed/gui/menu/plugin/MenuPlugin.java b/menu/plugin/src/main/java/team/unnamed/gui/menu/plugin/MenuPlugin.java index 393ff4e..ab7df51 100644 --- a/menu/plugin/src/main/java/team/unnamed/gui/menu/plugin/MenuPlugin.java +++ b/menu/plugin/src/main/java/team/unnamed/gui/menu/plugin/MenuPlugin.java @@ -17,7 +17,7 @@ import java.util.ArrayList; import java.util.List; -import static team.unnamed.gui.item.util.DecorateItemUtils.newStainedPane; +import static team.unnamed.gui.item.util.DecorateItemUtils.stainedPane; public class MenuPlugin extends JavaPlugin { @@ -34,20 +34,20 @@ public void onEnable() { switch (args[0]) { case "default": { player.openInventory(MenuInventory.newBuilder("Test") - .fillBorders(ItemClickable.onlyItem(newStainedPane(DyeColor.PINK))) - .addItem(ItemClickable.builder(22) - .setItem(new ItemStack(Material.ENDER_PEARL)) - .setAction(inventory -> { + .fillBorders(ItemClickable.onlyItem(stainedPane(DyeColor.PINK))) + .item(ItemClickable.builder(22) + .item(new ItemStack(Material.ENDER_PEARL)) + .action(inventory -> { player.sendMessage("Testing"); player.closeInventory(); return true; }) .build()) - .setOpenAction(inventory -> { + .openAction(inventory -> { player.sendMessage("Opening..."); return false; }) - .setCloseAction(inventory -> { + .closeAction(inventory -> { player.sendMessage("Closing..."); return false; @@ -59,32 +59,32 @@ public void onEnable() { List entities = new ArrayList<>(); for (int i = 0; i <= 90; i++) { - entities.add(ItemBuilder.newBuilder(Material.ENDER_PEARL) - .setName("Item #" + i) + entities.add(ItemBuilder.builder(Material.ENDER_PEARL) + .name("Item #" + i) .build() ); } ItemClickable decorationItem = ItemClickable.onlyItem( - newStainedPane(DyeColor.PINK) + stainedPane(DyeColor.PINK) ); player.openInventory(MenuInventory .newPaginatedBuilder(ItemStack.class, "Paginated Test") - .setEntities(entities) - .setItemsPerRow(7) - .setEntityParser(ItemClickable::onlyItem) - .setSkippedSlots(10, 16, 28, 34, 37, 38, 42, 43) - .setBounds(10, 44) - .setItemIfNoPreviousPage(decorationItem) - .setItemIfNoNextPage(decorationItem) - .setNextPageItem(page -> ItemClickable.onlyItem(ItemBuilder.newBuilder(Material.ARROW) - .setName("Next page - " + page) + .entities(entities) + .itemsPerRow(7) + .entityParser(ItemClickable::onlyItem) + .skipSlots(10, 16, 28, 34, 37, 38, 42, 43) + .bounds(10, 44) + .itemIfNoPreviousPage(decorationItem) + .itemIfNoNextPage(decorationItem) + .nextPageItem(page -> ItemClickable.onlyItem(ItemBuilder.builder(Material.ARROW) + .name("Next page - " + page) .build())) - .setPreviousPageItem(page -> ItemClickable.onlyItem(ItemBuilder.newBuilder(Material.ARROW) - .setName("Previous page - " + page) + .previousPageItem(page -> ItemClickable.onlyItem(ItemBuilder.builder(Material.ARROW) + .name("Previous page - " + page) .build())) - .setLayoutLines( + .layoutLines( "xxxxxxxxx", "xseeeeesx", "xeeeeeeex", @@ -92,8 +92,8 @@ public void onEnable() { "xsseeessx", "xpxxxxxnx" ) - .setLayoutItem('s', ItemClickable.onlyItem(newStainedPane(DyeColor.WHITE))) - .setLayoutItem('x', decorationItem) + .layoutItem('s', ItemClickable.onlyItem(stainedPane(DyeColor.WHITE))) + .layoutItem('x', decorationItem) .build()); break; }