Skip to content

Commit 716a141

Browse files
Add files via upload
1 parent dbf82bf commit 716a141

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+5970
-45
lines changed

core.iml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module version="4">
3+
<component name="FacetManager">
4+
<facet type="minecraft" name="Minecraft">
5+
<configuration>
6+
<autoDetectTypes>
7+
<platformType>SPIGOT</platformType>
8+
</autoDetectTypes>
9+
<projectReimportVersion>1</projectReimportVersion>
10+
</configuration>
11+
</facet>
12+
</component>
13+
</module>

dependency-reduced-pom.xml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<parent>
4+
<artifactId>core-project</artifactId>
5+
<groupId>me.flame.menus</groupId>
6+
<version>2.0.0</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
<artifactId>core</artifactId>
10+
<repositories>
11+
<repository>
12+
<id>spigot-repo</id>
13+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
14+
</repository>
15+
</repositories>
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.spigotmc</groupId>
19+
<artifactId>spigot-api</artifactId>
20+
<version>1.16.5-R0.1-SNAPSHOT</version>
21+
<scope>provided</scope>
22+
</dependency>
23+
<dependency>
24+
<groupId>com.mojang</groupId>
25+
<artifactId>authlib</artifactId>
26+
<version>1.5.21</version>
27+
<scope>provided</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.projectlombok</groupId>
31+
<artifactId>lombok</artifactId>
32+
<version>1.18.28</version>
33+
<scope>provided</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.jetbrains</groupId>
37+
<artifactId>annotations</artifactId>
38+
<version>24.0.1</version>
39+
<scope>provided</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>com.google.errorprone</groupId>
43+
<artifactId>error_prone_annotations</artifactId>
44+
<version>2.18.0</version>
45+
<scope>provided</scope>
46+
</dependency>
47+
</dependencies>
48+
<properties>
49+
<maven.compiler.target>11</maven.compiler.target>
50+
<maven.compiler.source>11</maven.compiler.source>
51+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
52+
</properties>
53+
</project>

pom.xml

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,39 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>me.flame.menus</groupId>
8+
<artifactId>core-project</artifactId>
9+
<version>2.0.0</version>
10+
</parent>
611

7-
<groupId>me.flame</groupId>
8-
<artifactId>FlameGUIS</artifactId>
9-
<version>1.2.3</version>
12+
<artifactId>core</artifactId>
1013

1114
<properties>
12-
<maven.compiler.source>8</maven.compiler.source>
13-
<maven.compiler.target>8</maven.compiler.target>
15+
<maven.compiler.source>11</maven.compiler.source>
16+
<maven.compiler.target>11</maven.compiler.target>
1417
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1518
</properties>
1619

1720
<repositories>
1821
<repository>
19-
<id>spigotmc-repo</id>
22+
<id>spigot-repo</id>
2023
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
2124
</repository>
22-
<repository>
23-
<id>sonatype</id>
24-
<url>https://oss.sonatype.org/content/groups/public/</url>
25-
</repository>
26-
<repository>
27-
<id>minecraft</id>
28-
<url>https://libraries.minecraft.net/</url>
29-
</repository>
3025
</repositories>
31-
<build>
32-
<plugins>
33-
<plugin>
34-
<groupId>org.apache.maven.plugins</groupId>
35-
<artifactId>maven-compiler-plugin</artifactId>
36-
<version>3.8.1</version>
37-
<configuration>
38-
<source>8</source>
39-
<target>8</target>
40-
</configuration>
41-
</plugin>
42-
</plugins>
43-
</build>
4426

4527
<dependencies>
4628
<dependency>
4729
<groupId>org.spigotmc</groupId>
4830
<artifactId>spigot-api</artifactId>
49-
<version>1.14.4-R0.1-SNAPSHOT</version>
31+
<version>1.16.5-R0.1-SNAPSHOT</version>
5032
<scope>provided</scope>
5133
</dependency>
5234
<dependency>
53-
<groupId>org.projectlombok</groupId>
54-
<artifactId>lombok</artifactId>
55-
<version>1.18.28</version>
56-
<scope>provided</scope>
57-
</dependency>
58-
<dependency>
59-
<groupId>com.mojang</groupId>
60-
<artifactId>authlib</artifactId>
61-
<version>1.5.21</version>
62-
<scope>provided</scope>
63-
</dependency>
64-
<dependency>
65-
<groupId>org.jetbrains</groupId>
66-
<artifactId>annotations</artifactId>
67-
<version>24.0.1</version>
68-
<scope>provided</scope>
35+
<groupId>me.flame.menus.adventure</groupId>
36+
<artifactId>adventure</artifactId>
37+
<version>2.0.0</version>
38+
<scope>compile</scope>
6939
</dependency>
7040
</dependencies>
71-
</project>
41+
</project>
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
package me.flame.menus.builders.items;
2+
3+
import me.flame.menus.items.MenuItem;
4+
import me.flame.menus.util.ItemResponse;
5+
import me.flame.menus.util.VersionHelper;
6+
7+
import org.bukkit.Material;
8+
import org.bukkit.enchantments.Enchantment;
9+
import org.bukkit.entity.Damageable;
10+
import org.bukkit.inventory.ItemFlag;
11+
import org.bukkit.inventory.ItemStack;
12+
import org.bukkit.inventory.meta.ItemMeta;
13+
14+
import org.jetbrains.annotations.NotNull;
15+
16+
import java.util.Arrays;
17+
import java.util.List;
18+
19+
import static org.bukkit.ChatColor.translateAlternateColorCodes;
20+
21+
@SuppressWarnings({ "unchecked", "unused" })
22+
public abstract class BaseItemBuilder<B extends BaseItemBuilder<B>> {
23+
final ItemStack item;
24+
25+
ItemMeta meta;
26+
27+
private final boolean hasNoItemMeta;
28+
29+
BaseItemBuilder(Material material, int amount) {
30+
this(new ItemStack(material, amount));
31+
}
32+
33+
BaseItemBuilder(@NotNull ItemStack item) {
34+
this.item = item;
35+
this.meta = item.getItemMeta();
36+
this.hasNoItemMeta = this.meta == null;
37+
}
38+
39+
/**
40+
* Sets the glow effect on the item.
41+
*
42+
* @param glow true to add enchantment and hide it, false to remove enchantment and show it
43+
* @apiNote Will hide the enchantments by default.
44+
* @return the builder for chaining
45+
*/
46+
public B setGlow(boolean glow) {
47+
// add enchantment and hide it if "glow" is true
48+
if (this.hasNoItemMeta) return (B) this;
49+
if (!glow) {
50+
this.meta.removeEnchant(Enchantment.DURABILITY);
51+
this.meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS);
52+
return (B) this;
53+
}
54+
this.meta.addEnchant(Enchantment.DURABILITY, 1, true);
55+
this.meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
56+
return (B) this;
57+
}
58+
59+
/**
60+
* Sets the amount of the item.
61+
* @param amount the amount to set
62+
* @return the builder for chaining
63+
*/
64+
public B setAmount(int amount) {
65+
this.item.setAmount(amount);
66+
return (B) this;
67+
}
68+
69+
/**
70+
* Sets the name of the itemStack to whatever the provided name is.
71+
* @param name the new name
72+
* @return the builder for chaining
73+
*/
74+
public B setName(String name) {
75+
if (this.hasNoItemMeta) return (B) this;
76+
this.meta.setDisplayName(translateAlternateColorCodes('&', name));
77+
return (B) this;
78+
}
79+
80+
/**
81+
* Sets the lore of the itemStack to whatever the provided lore is.
82+
* @param lore the new lore
83+
* @return the builder for chaining
84+
*/
85+
public B setLore(String... lore) {
86+
if (this.hasNoItemMeta) return (B) this;
87+
this.meta.setLore(Arrays.asList(lore));
88+
return (B) this;
89+
}
90+
91+
/**
92+
* Sets the lore of the itemStack to whatever the provided lore is.
93+
* @param lore the new lore
94+
* @return the builder for chaining
95+
*/
96+
public B setLore(List<String> lore) {
97+
if (this.hasNoItemMeta) return (B) this;
98+
this.meta.setLore(lore);
99+
return (B) this;
100+
}
101+
102+
/**
103+
* Enchant the itemStack with the provided enchantment
104+
* @param enchant the enchantment to enchant the itemStack with
105+
* @return the builder for chaining
106+
*/
107+
public B addEnchant(Enchantment enchant) {
108+
if (this.hasNoItemMeta) return (B) this;
109+
this.meta.addEnchant(enchant, 1, false);
110+
return (B) this;
111+
}
112+
113+
/**
114+
* Enchant the itemStack with the provided enchantment
115+
* @param enchant the enchantment to enchant the itemStack with
116+
* @param level the level of the enchantment
117+
* @return the builder for chaining
118+
*/
119+
public B addEnchant(Enchantment enchant, int level) {
120+
if (this.hasNoItemMeta) return (B) this;
121+
this.meta.addEnchant(enchant, level, false);
122+
return (B) this;
123+
}
124+
125+
/**
126+
* Enchant the itemStack with the provided enchantment
127+
* @param enchant the enchantment to enchant the itemStack with
128+
* @param level the level of the enchantment
129+
* @param ignore whether to ignore the enchantment restrictions
130+
* @return the builder for chaining
131+
*/
132+
public B addEnchant(Enchantment enchant, int level, boolean ignore) {
133+
if (this.hasNoItemMeta) return (B) this;
134+
this.meta.addEnchant(enchant, level, ignore);
135+
return (B) this;
136+
}
137+
138+
/**
139+
* Apply all the enchantments to the itemStack with the same level & ignore restrictions
140+
* @param level the level of the enchantment
141+
* @param ignore whether to ignore the enchantment restrictions
142+
* @param enchant the enchantments to apply
143+
* @return the builder for chaining
144+
*/
145+
public B addEnchant(int level, boolean ignore, Enchantment... enchant) {
146+
if (this.hasNoItemMeta) return (B) this;
147+
for (Enchantment enchantment : enchant)
148+
this.meta.addEnchant(enchantment, level, ignore);
149+
return (B) this;
150+
}
151+
152+
/**
153+
* Apply all the enchantments to the itemStack with the same level
154+
* @param level the level of the enchantment
155+
* @param enchant the enchantments to apply
156+
* @return the builder for chaining
157+
*/
158+
public B addEnchant(int level, Enchantment... enchant) {
159+
if (this.hasNoItemMeta) return (B) this;
160+
for (Enchantment enchantment : enchant)
161+
this.meta.addEnchant(enchantment, level, false);
162+
return (B) this;
163+
}
164+
165+
/**
166+
* Apply all the enchantments to the itemStack (level 1)
167+
* @param enchant the enchantments to apply
168+
* @return the builder for chaining
169+
*/
170+
public B addEnchant(Enchantment... enchant) {
171+
if (this.hasNoItemMeta) return (B) this;
172+
for (Enchantment enchantment : enchant)
173+
this.meta.addEnchant(enchantment, 1, false);
174+
return (B) this;
175+
}
176+
177+
/**
178+
* Set the itemStack to be unbreakable
179+
* @return the builder for chaining
180+
*/
181+
public B setUnbreakable() {
182+
if (this.hasNoItemMeta || VersionHelper.IS_UNBREAKABLE_LEGACY) return (B) this;
183+
this.meta.setUnbreakable(true);
184+
return (B) this;
185+
}
186+
187+
/**
188+
* Set the itemStack to be unbreakable or not
189+
* @param breakable whether the itemStack is unbreakable
190+
* @return the builder for chaining
191+
*/
192+
public B setUnbreakable(boolean breakable) {
193+
if (this.hasNoItemMeta || VersionHelper.IS_UNBREAKABLE_LEGACY) return (B) this;
194+
this.meta.setUnbreakable(breakable);
195+
return (B) this;
196+
}
197+
198+
/**
199+
* Set the damage to the itemStack
200+
* @param d the damage
201+
* @return the builder for chaining
202+
*/
203+
public B setDamage(int d) {
204+
if (this.hasNoItemMeta || !(meta instanceof Damageable)) return (B) this;
205+
((Damageable) meta).damage(d);
206+
return (B) this;
207+
}
208+
209+
/**
210+
* Build the item into a new ItemStack.
211+
* @return the new ItemStack
212+
*/
213+
public ItemStack build() {
214+
this.item.setItemMeta(meta);
215+
return item;
216+
}
217+
218+
/**
219+
* Build the item into a new MenuItem.
220+
* @return the new MenuItem
221+
*/
222+
public MenuItem buildItem() {
223+
return MenuItem.of(build());
224+
}
225+
226+
/**
227+
* Build the item into a new MenuItem with the provided Click Event.
228+
* @param event the event
229+
* @return the new MenuItem
230+
*/
231+
public MenuItem buildItem(ItemResponse event) {
232+
return MenuItem.of(build(), event);
233+
}
234+
}

0 commit comments

Comments
 (0)