Skip to content

Commit

Permalink
style(prettier): prettified code
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette authored and actions-user committed Aug 9, 2021
1 parent 8836450 commit 3b0458a
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

/**
* Represents a simple builder class with two methods.
*
*
* @param <T> the item type
*/
public interface SimpleBuilder<T> {

T build();

SimpleBuilder<T> copy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.*;
import java.util.function.Consumer;
import java.util.function.UnaryOperator;

import lombok.*;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
Expand All @@ -20,7 +19,7 @@
* A builder class to customize in multiple ways a item stack.
*
* @author /~https://github.com/ArthurFiorette/sink-library/
*
*
* @deprecated in flavor of
* {@link com.github.arthurfiorette.sinklibrary.item.v2.ItemBuilder}
*/
Expand Down Expand Up @@ -85,8 +84,10 @@ public ItemBuilder addEnchantment(final Enchantment ench, final int level) {
* @return itself
*/
public ItemBuilder addEnchantments(final Map<Enchantment, Integer> enchantments) {
return this.addProperties(ItemProperty.ENCHANTMENT,
is -> is.addUnsafeEnchantments(enchantments));
return this.addProperties(
ItemProperty.ENCHANTMENT,
is -> is.addUnsafeEnchantments(enchantments)
);
}

/**
Expand All @@ -95,8 +96,10 @@ public ItemBuilder addEnchantments(final Map<Enchantment, Integer> enchantments)
* @return itself
*/
public ItemBuilder setName(final String name) {
return this.addProperties(ItemProperty.NAME,
is -> SpigotService.updateItemMeta(is, im -> im.setDisplayName(name)));
return this.addProperties(
ItemProperty.NAME,
is -> SpigotService.updateItemMeta(is, im -> im.setDisplayName(name))
);
}

/**
Expand All @@ -114,10 +117,17 @@ public ItemBuilder setItemFlags() {
* @return itself
*/
public ItemBuilder setItemFlags(final ItemFlag... itemFlags) {
return this.addProperties(ItemProperty.ITEM_FLAG, is -> SpigotService.updateItemMeta(is, im -> {
im.removeItemFlags(ItemFlag.values());
im.addItemFlags(itemFlags);
}));
return this.addProperties(
ItemProperty.ITEM_FLAG,
is ->
SpigotService.updateItemMeta(
is,
im -> {
im.removeItemFlags(ItemFlag.values());
im.addItemFlags(itemFlags);
}
)
);
}

/**
Expand All @@ -126,8 +136,10 @@ public ItemBuilder setItemFlags(final ItemFlag... itemFlags) {
* @return itself
*/
public ItemBuilder addItemFlags(final ItemFlag... itemFlags) {
return this.addProperties(ItemProperty.ITEM_FLAG,
is -> SpigotService.updateItemMeta(is, im -> im.addItemFlags(itemFlags)));
return this.addProperties(
ItemProperty.ITEM_FLAG,
is -> SpigotService.updateItemMeta(is, im -> im.addItemFlags(itemFlags))
);
}

/**
Expand All @@ -145,8 +157,10 @@ public ItemBuilder setLores(final String... loreLines) {
* @return itself
*/
public ItemBuilder setLore(final List<String> lore) {
return this.addProperties(ItemProperty.LORE,
is -> SpigotService.updateItemMeta(is, im -> im.setLore(lore)));
return this.addProperties(
ItemProperty.LORE,
is -> SpigotService.updateItemMeta(is, im -> im.setLore(lore))
);
}

/**
Expand All @@ -165,8 +179,10 @@ public ItemBuilder addLores(final String... loreLines) {
*/
public ItemBuilder addLore(final List<String> lore) {
if (this.properties.containsKey(ItemProperty.LORE)) {
return this.addProperties(ItemProperty.LORE,
is -> SpigotService.updateItemMeta(is, im -> im.getLore().addAll(lore)));
return this.addProperties(
ItemProperty.LORE,
is -> SpigotService.updateItemMeta(is, im -> im.getLore().addAll(lore))
);
}
return this.setLore(lore);
}
Expand All @@ -177,8 +193,10 @@ public ItemBuilder addLore(final List<String> lore) {
* @return itself
*/
public ItemBuilder setUnbreakable(final boolean unbreakable) {
return this.addProperties(ItemProperty.CUSTOM_META,
is -> SpigotService.updateItemMeta(is, im -> im.spigot().setUnbreakable(unbreakable)));
return this.addProperties(
ItemProperty.CUSTOM_META,
is -> SpigotService.updateItemMeta(is, im -> im.spigot().setUnbreakable(unbreakable))
);
}

/**
Expand All @@ -187,8 +205,10 @@ public ItemBuilder setUnbreakable(final boolean unbreakable) {
* @return itself
*/
public ItemBuilder addCustomMeta(final UnaryOperator<ItemMeta> customMeta) {
return this.addProperties(ItemProperty.CUSTOM_META,
is -> is.setItemMeta(customMeta.apply(is.getItemMeta())));
return this.addProperties(
ItemProperty.CUSTOM_META,
is -> is.setItemMeta(customMeta.apply(is.getItemMeta()))
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* A static class to help with item builder templates.
*
* @author /~https://github.com/ArthurFiorette/sink-library/
*
*
* @deprecated in flavor of
* {@link com.github.arthurfiorette.sinklibrary.item.v2.SkullBuilder}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
import com.github.arthurfiorette.sinklibrary.interfaces.SimpleBuilder;
import com.github.arthurfiorette.sinklibrary.menu.item.BuilderStack;
import com.github.arthurfiorette.sinklibrary.menu.listener.ClickListener;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;

import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class ItemBuilder implements SimpleBuilder<ItemStack> {

Expand Down Expand Up @@ -48,32 +45,40 @@ public class ItemBuilder implements SimpleBuilder<ItemStack> {
* @return itself
*/
public ItemBuilder material(final Material material) {
return this.addProperties(ItemProperty.MATERIAL, (is, meta) -> {
is.setType(material);
});
return this.addProperties(
ItemProperty.MATERIAL,
(is, meta) -> {
is.setType(material);
}
);
}

/**
* @param durability set item durability
*
* @return itself
*/
public ItemBuilder durability(final short durability) {
return this.addProperties(ItemProperty.DAMAGE, (is, meta) -> {
is.setDurability(durability);
});
return this.addProperties(
ItemProperty.DAMAGE,
(is, meta) -> {
is.setDurability(durability);
}
);
}


/**
* @param amount set the item amount
*
* @return itself
*/
public ItemBuilder amount(final int amount) {
return this.addProperties(ItemProperty.AMOUNT, (is, meta) -> {
is.setAmount(amount);
});
return this.addProperties(
ItemProperty.AMOUNT,
(is, meta) -> {
is.setAmount(amount);
}
);
}

/**
Expand All @@ -82,9 +87,12 @@ public ItemBuilder amount(final int amount) {
* @return itself
*/
public ItemBuilder data(final MaterialData data) {
return this.addProperties(ItemProperty.MATERIAL_DATA, (is, meta) -> {
is.setData(data);
});
return this.addProperties(
ItemProperty.MATERIAL_DATA,
(is, meta) -> {
is.setData(data);
}
);
}

/**
Expand All @@ -94,9 +102,12 @@ public ItemBuilder data(final MaterialData data) {
* @return itself
*/
public ItemBuilder enchantment(final Enchantment ench, final int level) {
return this.addProperties(ItemProperty.ENCHANTMENT, (is, meta) -> {
is.addUnsafeEnchantment(ench, level);
});
return this.addProperties(
ItemProperty.ENCHANTMENT,
(is, meta) -> {
is.addUnsafeEnchantment(ench, level);
}
);
}

/**
Expand All @@ -107,9 +118,12 @@ public ItemBuilder enchantment(final Enchantment ench, final int level) {
* @return itself
*/
public ItemBuilder enchantments(final Map<Enchantment, Integer> enchantments) {
return this.addProperties(ItemProperty.ENCHANTMENT, (is, meta) -> {
is.addUnsafeEnchantments(enchantments);
});
return this.addProperties(
ItemProperty.ENCHANTMENT,
(is, meta) -> {
is.addUnsafeEnchantments(enchantments);
}
);
}

/**
Expand All @@ -118,9 +132,12 @@ public ItemBuilder enchantments(final Map<Enchantment, Integer> enchantments) {
* @return itself
*/
public ItemBuilder name(final String name) {
return this.addProperties(ItemProperty.NAME, (is, meta) -> {
meta.setDisplayName(name);
});
return this.addProperties(
ItemProperty.NAME,
(is, meta) -> {
meta.setDisplayName(name);
}
);
}

/**
Expand All @@ -138,21 +155,27 @@ public ItemBuilder allItemFlags() {
* @return itself
*/
public ItemBuilder itemFlags(final ItemFlag... itemFlags) {
return this.addProperties(ItemProperty.ITEM_FLAG, (is, meta) -> {
meta.addItemFlags(itemFlags);
});
return this.addProperties(
ItemProperty.ITEM_FLAG,
(is, meta) -> {
meta.addItemFlags(itemFlags);
}
);
}

public ItemBuilder lores(final String... lines) {
return this.lores(Arrays.asList(lines));
}

public ItemBuilder lores(final List<String> lines) {
return this.addProperties(ItemProperty.LORE, (is, meta) -> {
final List<String> lore = meta.getLore() == null ? new ArrayList<>() : meta.getLore();
lore.addAll(lines);
meta.setLore(lore);
});
return this.addProperties(
ItemProperty.LORE,
(is, meta) -> {
final List<String> lore = meta.getLore() == null ? new ArrayList<>() : meta.getLore();
lore.addAll(lines);
meta.setLore(lore);
}
);
}

/**
Expand All @@ -161,9 +184,12 @@ public ItemBuilder lores(final List<String> lines) {
* @return itself
*/
public ItemBuilder unbreakable(final boolean unbreakable) {
return this.addProperties(ItemProperty.UNBREAKABLE, (is, meta) -> {
meta.spigot().setUnbreakable(unbreakable);
});
return this.addProperties(
ItemProperty.UNBREAKABLE,
(is, meta) -> {
meta.spigot().setUnbreakable(unbreakable);
}
);
}

/**
Expand All @@ -186,10 +212,10 @@ public ItemStack build() {
if (!this.modified) {
return this.lastBuild;
}

final ItemStack item = new ItemStack(this.material);
this.propertiesMap.apply(item);

this.modified = false;
return this.lastBuild = item;
}
Expand Down Expand Up @@ -232,5 +258,4 @@ private ItemBuilder addProperties(final ItemProperty type, final StackConsumer c
this.modified = true;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

@AllArgsConstructor
public enum ItemProperty {

AMOUNT(false),
CUSTOM_META(true),
DAMAGE(false),
Expand All @@ -23,4 +22,3 @@ public enum ItemProperty {
@Getter
private boolean cumulative;
}

Loading

0 comments on commit 3b0458a

Please sign in to comment.