Skip to content

Commit 970709e

Browse files
committed
BLEEDING EDGE 1.3_15
1 parent 6c800e0 commit 970709e

7 files changed

Lines changed: 218 additions & 9 deletions

File tree

src/main/java/io/github/simplexdev/simplexcore/sign/AbstractSign.java renamed to src/main/java/io/github/simplexdev/simplexcore/block/AbstractSign.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.simplexdev.simplexcore.sign;
1+
package io.github.simplexdev.simplexcore.block;
22

33
import io.github.simplexdev.api.IUsableSign;
44
import io.github.simplexdev.api.func.VoidSupplier;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.github.simplexdev.simplexcore.block;
2+
3+
import org.bukkit.Location;
4+
import org.bukkit.Material;
5+
import org.bukkit.block.Block;
6+
7+
public class InteractableBlock {
8+
private final Block block;
9+
private final Location location;
10+
private final Material material;
11+
12+
public InteractableBlock(Location location) {
13+
this.block = location.getBlock();
14+
this.location = block.getLocation();
15+
this.material = block.getType();
16+
}
17+
18+
public InteractableBlock(Block block) {
19+
this.block = block;
20+
this.location = block.getLocation();
21+
this.material = block.getType();
22+
}
23+
24+
public void test() {
25+
26+
}
27+
}

src/main/java/io/github/simplexdev/simplexcore/sign/SignFactory.java renamed to src/main/java/io/github/simplexdev/simplexcore/block/SignFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.simplexdev.simplexcore.sign;
1+
package io.github.simplexdev.simplexcore.block;
22

33
import io.github.simplexdev.api.IUsableSign;
44
import io.github.simplexdev.api.func.VoidSupplier;

src/main/java/io/github/simplexdev/simplexcore/crafting/ItemBuilder.java

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,93 @@ public ItemBuilder(SimplexModule<?> plugin) {
1919
this.plugin = plugin;
2020
}
2121

22+
/**
23+
* Create a new singular ItemStack.
24+
* @param material The material for the item.
25+
* @return A new ItemStack from the provided material.
26+
*/
2227
public ItemStack createNoBounds(Material material) {
2328
return new ItemStack(material, 1);
2429
}
2530

31+
/**
32+
* Create a new ItemStack.
33+
* @param material The material for the item.
34+
* @param amount The amount of items the stack should represent.
35+
* @return A new ItemStack from the provided material.
36+
*/
37+
public ItemStack createNoBounds(Material material, int amount) {
38+
return new ItemStack(material, amount);
39+
}
40+
41+
/**
42+
* Create a new singular ItemStack with the specified ItemMeta.
43+
* @param material The material for the item.
44+
* @param metaData The ItemMeta to use for the item.
45+
* @return A new ItemStack from the provided material with the specified ItemMeta.
46+
*/
2647
public ItemStack createWithMeta(Material material, ItemMeta metaData) {
2748
ItemStack stack = new ItemStack(material, 1);
2849
stack.setItemMeta(metaData);
2950
return stack;
3051
}
3152

32-
public Worker itemBuilder(Material material) {
53+
/**
54+
* Create a new ItemStack with the specified ItemMeta.
55+
* @param material The material for the item.
56+
* @param metaData The ItemMeta to use for the item.
57+
* @param amount The amount of items the stack should represent.
58+
* @return A new ItemStack from the provided material with the specified ItemMeta.
59+
*/
60+
public ItemStack createWithMeta(Material material, ItemMeta metaData, int amount) {
61+
ItemStack stack = new ItemStack(material, amount);
62+
stack.setItemMeta(metaData);
63+
return stack;
64+
}
65+
66+
/**
67+
* Create a new ItemBuilder Worker
68+
* @param material The material for the item.
69+
* @return A new appendable ItemBuilder Worker instance based on the given Material.
70+
*/
71+
public Worker newItem(Material material) {
3372
return new Worker(new ItemStack(material, 1));
3473
}
3574

75+
/**
76+
* Create a new ItemBuilder Worker
77+
* @param material The material for the item.
78+
* @param amount The amount of items the stack should represent.
79+
* @return A new appendable ItemBuilder Worker instance based on the given Material.
80+
*/
81+
public Worker newItem(Material material, int amount) {
82+
return new Worker(new ItemStack(material, amount));
83+
}
84+
85+
public Worker editItem(ItemStack stack) {
86+
return new Worker(stack);
87+
}
88+
89+
/**
90+
* Create a new AttributeModifier for an ItemStack's ItemMeta.
91+
* @param name The name of the modifier.
92+
* @param amount The amount to add
93+
* @param scalar Whether or not it should add as a number or a magnitude.
94+
* @return A new AttributeModifier.
95+
*/
3696
public AttributeModifier add(String name, double amount, boolean scalar) {
3797
if (scalar) {
3898
return new AttributeModifier(name, amount, AttributeModifier.Operation.ADD_SCALAR);
3999
}
40100
return new AttributeModifier(name, amount, AttributeModifier.Operation.ADD_NUMBER);
41101
}
42102

103+
/**
104+
* Create a new AttributeModifier for an ItemStack's ItemMeta.
105+
* @param name The name of the modifier
106+
* @param amount The amount to multiply by
107+
* @return A new AttributeModifier.
108+
*/
43109
public AttributeModifier multiply(String name, double amount) {
44110
return new AttributeModifier(name, amount, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
45111
}
@@ -48,41 +114,94 @@ protected final class Worker {
48114
private final ItemStack stack;
49115
private final ItemMeta meta;
50116

117+
/**
118+
* @param stack The item to work from.
119+
*/
51120
public Worker(ItemStack stack) {
52121
this.stack = stack;
53122
this.meta = stack.getItemMeta();
54123
}
55124

125+
/**
126+
* Adds lore to the item. New lines should be separate Strings.
127+
* @param lore The item lore to add.
128+
* @return An appendable worker instance.
129+
*/
56130
public final Worker addLore(String... lore) {
57131
meta.setLore(Arrays.asList(lore));
58132
stack.setItemMeta(meta);
59133
return this;
60134
}
61135

136+
/**
137+
* Change the item's name
138+
* @param customName The new name of the item.
139+
* @return An appendable worker instance.
140+
*/
62141
public final Worker setName(String customName) {
63142
meta.setDisplayName(customName);
64143
stack.setItemMeta(meta);
65144
return this;
66145
}
67146

147+
/**
148+
* Add an enchantment to the item
149+
* @param enchantment The enchantment to add
150+
* @param level The level of the enchantment. This is non-restrictive.
151+
* @return An appendable worker instance.
152+
*/
68153
public final Worker addEnchant(Enchantment enchantment, int level) {
69154
meta.addEnchant(enchantment, level, true);
70155
stack.setItemMeta(meta);
71156
return this;
72157
}
73158

159+
/**
160+
* Add an attribute to the item.
161+
* @param attribute The attribute to add.
162+
* @param modifier The type of attribute modifier to use.
163+
* @return An appendable worker instance.
164+
*/
74165
public final Worker addAttribute(Attribute attribute, AttributeModifier modifier) {
75166
meta.addAttributeModifier(attribute, modifier);
76167
stack.setItemMeta(meta);
77168
return this;
78169
}
79170

171+
/**
172+
* Add item flags to an item.
173+
* @param flags Any amount of ItemFlags to add to the item.
174+
* @return An appendable worker instance.
175+
*/
80176
public final Worker addItemFlags(ItemFlag... flags) {
81177
meta.addItemFlags(flags);
82178
stack.setItemMeta(meta);
83179
return this;
84180
}
85181

182+
/**
183+
* Set the amount of items this stack should represent.
184+
* @param amount The amount of items this stack should represent.
185+
* @return An appendable worker instance.
186+
*/
187+
public final Worker setAmount(int amount) {
188+
stack.setAmount(amount);
189+
return this;
190+
}
191+
192+
public final Worker setType(Material material) {
193+
stack.setType(material);
194+
return this;
195+
}
196+
197+
public final Worker setUnbreakable(boolean unbreakable) {
198+
meta.setUnbreakable(unbreakable);
199+
return this;
200+
}
201+
202+
/**
203+
* @return The final item.
204+
*/
86205
public final ItemStack get() {
87206
return stack;
88207
}

src/main/java/io/github/simplexdev/simplexcore/crafting/RBImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void chainMailBoots() {
3030
}
3131

3232
public void customWand() {
33-
ItemStack is = bldr.itemBuilder(Material.BLAZE_ROD)
33+
ItemStack is = bldr.newItem(Material.BLAZE_ROD)
3434
.setName("Magic Wand")
3535
.addLore("This wand is magical.")
3636
.addEnchant(Enchantment.KNOCKBACK, 10)

src/main/java/io/github/simplexdev/simplexcore/crafting/RecipeBuilder.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ public RecipeBuilder(SimplexModule<?> plugin) {
2222
this.plugin = plugin;
2323
}
2424

25+
/**
26+
* Create a new RecipeBuilder Worker.
27+
* @param result The resulting item.
28+
* @param recipeName The name of the recipe.
29+
* This should be separated by "_" where spaced would be used.
30+
* @param isShaped Whether or not the recipe is shaped or shapeless.
31+
* @return A new appendable RecipeBuilder Worker instance based on the given parameters.
32+
*/
2533
public final Worker of(ItemStack result, String recipeName, boolean isShaped) {
2634
return new Worker(result, recipeName, isShaped);
2735
}
@@ -32,8 +40,15 @@ protected final class Worker {
3240
private final NamespacedKey key;
3341
private final boolean shaped;
3442
private final List<Material> materials = new ArrayList<>();
35-
private String[] shape = {"aaa", "aaa", "aaa"};
43+
private String[] shape = {"", "", ""};
3644

45+
/**
46+
* @param stack The item to build a recipe for. This may be an item with custom metadata,
47+
* or even an item without a native crafting recipe.
48+
* @param name The recipe name; it should be all lowercase,
49+
* separated by underscores where spaced would be used.
50+
* @param isShaped If the recipe is shaped or shapeless.
51+
*/
3752
public Worker(ItemStack stack, String name, boolean isShaped) {
3853
this.stack = stack;
3954
this.key = new NamespacedKey(plugin, name);
@@ -62,17 +77,28 @@ public void create() {
6277
}
6378

6479
/**
65-
* This is for shaped crafting.
80+
* This is for shaped crafting. Please use {@link Worker#addIngredients(Material...)}
81+
* for shapeless crafting.
6682
*
6783
* @param identifier The specific identifier
6884
* @param ingredient The ingredient represented by the identifier.
69-
* @return
85+
* @return An appendable worker instance.
7086
*/
7187
public Worker addIngredient(@NotNull Character identifier, @NotNull Material ingredient) {
7288
ingredients.put(identifier, ingredient);
7389
return this;
7490
}
7591

92+
/**
93+
* Sets the shape for the crafting recipe. This is not required if the recipe is shapeless.
94+
* @param top The top three slots represented by "___" where any specific letter
95+
* is represented by the relative ingredient identifier.
96+
* @param middle The middle three slots represented by "___" where any specific letter
97+
* is represented by the relative ingredient identifier.
98+
* @param bottom The bottom three slots represented by "___" where any specific letter
99+
* is represented by the relative ingredient identifier.
100+
* @return An appendable worker instance.
101+
*/
76102
public Worker setShape(@Nullable String top, @Nullable String middle, @Nullable String bottom) {
77103
String a = "";
78104
String b = "";
@@ -92,10 +118,11 @@ public Worker setShape(@Nullable String top, @Nullable String middle, @Nullable
92118
}
93119

94120
/**
95-
* This is for shapeless crafting.
121+
* This is for shapeless crafting. Please use {@link Worker#addIngredient(Character, Material)}
122+
* for shaped crafting.
96123
*
97124
* @param ingredients any number (up to nine) of ingredients required to craft this recipe.
98-
* @return An appendable instance of this class.
125+
* @return An appendable worker instance.
99126
*/
100127
public Worker addIngredients(Material... ingredients) {
101128
Utilities.forEach(ingredients, materials::add);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.github.simplexdev.simplexcore.utils;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.OfflinePlayer;
5+
import org.bukkit.entity.Player;
6+
import org.jetbrains.annotations.NotNull;
7+
import org.jetbrains.annotations.Nullable;
8+
9+
import java.util.UUID;
10+
11+
public final class PlayerTools {
12+
13+
@NotNull
14+
public static String stringUUID(@NotNull Player player) {
15+
return player.getUniqueId().toString();
16+
}
17+
18+
@Nullable
19+
public static Player getPlayer(@NotNull String nameOrUUID) {
20+
if (nameOrUUID.length() > 16) {
21+
UUID uuid = UUID.fromString(nameOrUUID);
22+
return Bukkit.getServer().getPlayer(uuid);
23+
} else {
24+
return Bukkit.getServer().getPlayer(nameOrUUID);
25+
}
26+
}
27+
28+
@NotNull
29+
public static OfflinePlayer getOfflinePlayer(@NotNull String nameOrUUID) {
30+
if (nameOrUUID.length() > 16) {
31+
UUID uuid = UUID.fromString(nameOrUUID);
32+
return Bukkit.getOfflinePlayer(uuid);
33+
}
34+
return Bukkit.getOfflinePlayer(nameOrUUID);
35+
}
36+
}

0 commit comments

Comments
 (0)