Skip to content

Commit

Permalink
refactor!: rename builder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeldev committed Jul 1, 2022
1 parent 87f92d6 commit c43e051
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 86 deletions.
34 changes: 17 additions & 17 deletions item/api/src/main/java/team/unnamed/gui/item/ItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,47 @@

public interface ItemBuilder {

ItemBuilder setName(String name);
ItemBuilder name(String name);

ItemBuilder setLore(List<String> lore);
ItemBuilder lore(List<String> lore);

ItemBuilder setLore(String... lines);
ItemBuilder lore(String... lines);

ItemBuilder setEnchantments(Map<Enchantment, Integer> enchantments);
ItemBuilder enchantments(Map<Enchantment, Integer> enchantments);

ItemBuilder addEnchant(Enchantment enchantment, int level);
ItemBuilder enchant(Enchantment enchantment, int level);

ItemBuilder setFlags(List<ItemFlag> flags);
ItemBuilder flags(List<ItemFlag> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> lore) {
public ItemBuilder lore(List<String> 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<Enchantment, Integer> enchantments) {
public ItemBuilder enchantments(Map<Enchantment, Integer> 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<ItemFlag> flags) {
public ItemBuilder flags(List<ItemFlag> 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();
}
Expand All @@ -86,7 +86,7 @@ public ItemBuilder grow() {
}

@Override
public ItemBuilder setUnbreakable(boolean unbreakable) {
public ItemBuilder unbreakable(boolean unbreakable) {
this.unbreakable = unbreakable;
return back();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ 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<ItemClickableActionBuilder.Multiple> action) {
public ItemClickableBuilder multipleAction(Consumer<ItemClickableActionBuilder.Multiple> action) {
ItemClickableActionBuilder.Multiple actionBuilder = ItemClickableAction.builder()
.multipleAction();
action.accept(actionBuilder);
this.action = actionBuilder.build();
return this;
}

public ItemClickableBuilder setAction(Predicate<Inventory> action) {
public ItemClickableBuilder action(Predicate<Inventory> action) {
isNotNull(action, "Action cannot be null.");
this.action = ItemClickableAction.single(action);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Multiple() {
this.actions = new HashMap<>();
}

public Multiple linkClickType(ClickType clickType, Predicate<Inventory> action) {
public Multiple link(ClickType clickType, Predicate<Inventory> action) {
actions.put(
isNotNull(clickType, "Click type cannot be null."),
isNotNull(action, "Action cannot be null.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public interface MenuInventoryBuilder {

MenuInventoryBuilder fillBorders(ItemClickable item);

MenuInventoryBuilder setItems(List<ItemClickable> items);
MenuInventoryBuilder items(List<ItemClickable> items);

MenuInventoryBuilder addItem(ItemClickable item, int... slots);
MenuInventoryBuilder item(ItemClickable item, int... slots);

MenuInventoryBuilder addItem(ItemClickable item);
MenuInventoryBuilder item(ItemClickable item);

MenuInventoryBuilder setOpenAction(Predicate<Inventory> action);
MenuInventoryBuilder openAction(Predicate<Inventory> action);

MenuInventoryBuilder setCloseAction(Predicate<Inventory> action);
MenuInventoryBuilder closeAction(Predicate<Inventory> action);

MenuInventoryBuilder setIntroduceItems(boolean canIntroduceItems);
MenuInventoryBuilder introduceItems(boolean canIntroduceItems);

Inventory build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ public T fillBorders(ItemClickable item) {
}

@Override
public T setItems(List<ItemClickable> items) {
public T items(List<ItemClickable> 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) {
Expand All @@ -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);
Expand All @@ -119,23 +119,23 @@ public T addItem(ItemClickable item) {
}

@Override
public T setOpenAction(Predicate<Inventory> action) {
public T openAction(Predicate<Inventory> action) {
isNotNull(action, "Open action cannot be null.");
this.openAction = action;

return back();
}

@Override
public T setCloseAction(Predicate<Inventory> action) {
public T closeAction(Predicate<Inventory> action) {
isNotNull(action, "Close action cannot be null.");
this.closeAction = action;

return back();
}

@Override
public T setIntroduceItems(boolean canIntroduceItems) {
public T introduceItems(boolean canIntroduceItems) {
this.canIntroduceItems = canIntroduceItems;
return back();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,54 +35,54 @@ protected PaginatedMenuInventoryBuilder(String title, int rows) {
super(title, rows);
}

public PaginatedMenuInventoryBuilder<E> setBounds(int entitySlotFrom, int entitySlotTo) {
public PaginatedMenuInventoryBuilder<E> bounds(int entitySlotFrom, int entitySlotTo) {
this.entitySlotFrom = entitySlotFrom;
this.entitySlotTo = entitySlotTo;
return this;
}

public PaginatedMenuInventoryBuilder<E> setItemsPerRow(int itemsPerRow) {
public PaginatedMenuInventoryBuilder<E> itemsPerRow(int itemsPerRow) {
this.itemsPerRow = itemsPerRow;
return this;
}

public PaginatedMenuInventoryBuilder<E> setSkippedSlots(int... skippedSlots) {
public PaginatedMenuInventoryBuilder<E> skipSlots(int... skippedSlots) {
this.skippedSlots = skippedSlots;
return this;
}

public PaginatedMenuInventoryBuilder<E> setEntities(Collection<E> entities) {
public PaginatedMenuInventoryBuilder<E> entities(Collection<E> entities) {
this.entities = new ArrayList<>(entities);
return this;
}

public PaginatedMenuInventoryBuilder<E> setEntityParser(Function<E, ItemClickable> entityParser) {
public PaginatedMenuInventoryBuilder<E> entityParser(Function<E, ItemClickable> entityParser) {
this.entityParser = entityParser;
return this;
}

public PaginatedMenuInventoryBuilder<E> setNextPageItem(Function<Integer, ItemClickable> nextPageItem) {
public PaginatedMenuInventoryBuilder<E> nextPageItem(Function<Integer, ItemClickable> nextPageItem) {
this.nextPageItem = nextPageItem;
return this;
}

public PaginatedMenuInventoryBuilder<E> setPreviousPageItem(Function<Integer, ItemClickable> previousPageItem) {
public PaginatedMenuInventoryBuilder<E> previousPageItem(Function<Integer, ItemClickable> previousPageItem) {
this.previousPageItem = previousPageItem;
return this;
}

public PaginatedMenuInventoryBuilder<E> setItemIfNoEntities(ItemClickable itemIfNoEntities) {
public PaginatedMenuInventoryBuilder<E> itemIfNoEntities(ItemClickable itemIfNoEntities) {
this.itemIfNoEntities = isNotNull(itemIfNoEntities, "Item if no entities cannot be null.");
return this;
}

public PaginatedMenuInventoryBuilder<E> setItemIfNoPreviousPage(ItemClickable itemIfNoPreviousPage) {
public PaginatedMenuInventoryBuilder<E> itemIfNoPreviousPage(ItemClickable itemIfNoPreviousPage) {
this.itemIfNoPreviousPage = isNotNull(itemIfNoPreviousPage,
"Item if no previos page cannot be null.");
return this;
}

public PaginatedMenuInventoryBuilder<E> setItemIfNoNextPage(ItemClickable itemIfNoNextPage) {
public PaginatedMenuInventoryBuilder<E> itemIfNoNextPage(ItemClickable itemIfNoNextPage) {
this.itemIfNoNextPage = isNotNull(itemIfNoNextPage,
"Item if no next page cannot be null.");
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -54,7 +54,7 @@ public Inventory build() {
continue;
}

addItem(itemClickable.clone(slotIndex));
item(itemClickable.clone(slotIndex));
}
}

Expand Down
Loading

0 comments on commit c43e051

Please sign in to comment.