Skip to content

Commit de30faa

Browse files
Merge pull request #46 from D0gmaDev/patch-1
Add more item methods
2 parents 7e683ed + 8957b65 commit de30faa

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

inventoryaccess/inventory-access/src/main/java/xyz/xenondevs/inventoryaccess/component/AdventureComponentWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public AdventureComponentWrapper(Component component) {
2929
}
3030

3131
@Override
32-
public @NotNull ComponentWrapper withoutPreFormatting() {
32+
public @NotNull AdventureComponentWrapper withoutPreFormatting() {
3333
return new AdventureComponentWrapper(AdventureComponentUtils.withoutPreFormatting(component));
3434
}
3535

invui-core/src/main/java/xyz/xenondevs/invui/item/builder/AbstractItemBuilder.java

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public abstract class AbstractItemBuilder<S> implements ItemProvider {
3232
protected int amount = 1;
3333
protected int damage;
3434
protected int customModelData;
35+
protected Boolean unbreakable;
3536
protected ComponentWrapper displayName;
3637
protected List<ComponentWrapper> lore;
3738
protected List<ItemFlag> itemFlags;
@@ -116,6 +117,10 @@ public AbstractItemBuilder(@NotNull ItemStack base) {
116117
if (customModelData != 0)
117118
itemMeta.setCustomModelData(customModelData);
118119

120+
// unbreakable
121+
if (unbreakable != null)
122+
itemMeta.setUnbreakable(unbreakable);
123+
119124
// enchantments
120125
if (enchantments != null) {
121126
if (base != null)
@@ -201,6 +206,16 @@ public int getCustomModelData() {
201206
return (S) this;
202207
}
203208

209+
public @Nullable Boolean isUnbreakable() {
210+
return unbreakable;
211+
}
212+
213+
@Contract("_ -> this")
214+
public @NotNull S setUnbreakable(boolean unbreakable) {
215+
this.unbreakable = unbreakable;
216+
return (S) this;
217+
}
218+
204219
public @Nullable ComponentWrapper getDisplayName() {
205220
return displayName;
206221
}
@@ -229,15 +244,15 @@ public int getCustomModelData() {
229244
}
230245

231246
@Contract("_ -> this")
232-
public @NotNull S setLore(List<ComponentWrapper> lore) {
247+
public @NotNull S setLore(@NotNull List<@NotNull ComponentWrapper> lore) {
233248
this.lore = lore.stream()
234249
.map(ComponentWrapper::withoutPreFormatting)
235250
.collect(Collectors.toList());
236251
return (S) this;
237252
}
238253

239254
@Contract("_ -> this")
240-
public @NotNull S setLegacyLore(@NotNull List<String> lore) {
255+
public @NotNull S setLegacyLore(@NotNull List<@NotNull String> lore) {
241256
this.lore = lore.stream()
242257
.map(line -> new BungeeComponentWrapper(TextComponent.fromLegacyText(line)).withoutPreFormatting())
243258
.collect(Collectors.toList());
@@ -273,6 +288,26 @@ public int getCustomModelData() {
273288

274289
return (S) this;
275290
}
291+
292+
@Contract("_ -> this")
293+
public @NotNull S addLoreLines(@NotNull List<@NotNull ComponentWrapper> lines) {
294+
if (lore == null) lore = new ArrayList<>();
295+
296+
for (ComponentWrapper line : lines)
297+
lore.add(line.withoutPreFormatting());
298+
299+
return (S) this;
300+
}
301+
302+
@Contract("_ -> this")
303+
public @NotNull S addLegacyLoreLines(@NotNull List<@NotNull String> lines) {
304+
if (lore == null) lore = new ArrayList<>();
305+
306+
for (String line : lines)
307+
lore.add(new BungeeComponentWrapper(TextComponent.fromLegacyText(line)).withoutPreFormatting());
308+
309+
return (S) this;
310+
}
276311
//</editor-fold>
277312

278313
//<editor-fold desc="item flags">
@@ -293,6 +328,12 @@ public int getCustomModelData() {
293328
return (S) this;
294329
}
295330

331+
@Contract("-> this")
332+
public @NotNull S addAllItemFlags() {
333+
this.itemFlags = new ArrayList<>(Arrays.asList(ItemFlag.values()));
334+
return (S) this;
335+
}
336+
296337
@Contract("_ -> this")
297338
public @NotNull S removeItemFlags(@NotNull ItemFlag... itemFlags) {
298339
if (this.itemFlags != null)
@@ -327,8 +368,7 @@ public int getCustomModelData() {
327368

328369
@Contract("_ -> this")
329370
public @NotNull S removeEnchantment(Enchantment enchantment) {
330-
if (enchantments == null) enchantments = new HashMap<>();
331-
enchantments.remove(enchantment);
371+
if (enchantments != null) enchantments.remove(enchantment);
332372
return (S) this;
333373
}
334374

invui-core/src/main/java/xyz/xenondevs/invui/item/builder/FireworkBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
import org.jetbrains.annotations.Contract;
88
import org.jetbrains.annotations.NotNull;
99
import org.jetbrains.annotations.Nullable;
10+
import org.jetbrains.annotations.Range;
1011

1112
import java.util.ArrayList;
1213
import java.util.List;
1314

1415
public final class FireworkBuilder extends AbstractItemBuilder<FireworkBuilder> {
1516

17+
private int power = -1;
1618
private List<FireworkEffect> effects = new ArrayList<>();
1719

1820
public FireworkBuilder() {
@@ -27,6 +29,12 @@ public FireworkBuilder(@NotNull ItemStack base) {
2729
super(base);
2830
}
2931

32+
@Contract("_ -> this")
33+
public @NotNull FireworkBuilder setPower(@Range(from = 0, to = 127) int power) {
34+
this.power = power;
35+
return this;
36+
}
37+
3038
@Contract("_ -> this")
3139
public @NotNull FireworkBuilder addFireworkEffect(@NotNull FireworkEffect effect) {
3240
effects.add(effect);
@@ -57,6 +65,7 @@ public FireworkBuilder(@NotNull ItemStack base) {
5765
ItemStack item = super.get(lang);
5866
FireworkMeta meta = (FireworkMeta) item.getItemMeta();
5967

68+
if (power != -1) meta.setPower(power);
6069
meta.clearEffects();
6170
meta.addEffects(effects);
6271

0 commit comments

Comments
 (0)