BLEEDING EDGE 1.3_15

This commit is contained in:
Paldiu 2021-04-11 23:55:55 -05:00
parent 6c800e077c
commit 970709ee2c
7 changed files with 218 additions and 9 deletions

View File

@ -1,4 +1,4 @@
package io.github.simplexdev.simplexcore.sign; package io.github.simplexdev.simplexcore.block;
import io.github.simplexdev.api.IUsableSign; import io.github.simplexdev.api.IUsableSign;
import io.github.simplexdev.api.func.VoidSupplier; import io.github.simplexdev.api.func.VoidSupplier;

View File

@ -0,0 +1,27 @@
package io.github.simplexdev.simplexcore.block;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
public class InteractableBlock {
private final Block block;
private final Location location;
private final Material material;
public InteractableBlock(Location location) {
this.block = location.getBlock();
this.location = block.getLocation();
this.material = block.getType();
}
public InteractableBlock(Block block) {
this.block = block;
this.location = block.getLocation();
this.material = block.getType();
}
public void test() {
}
}

View File

@ -1,4 +1,4 @@
package io.github.simplexdev.simplexcore.sign; package io.github.simplexdev.simplexcore.block;
import io.github.simplexdev.api.IUsableSign; import io.github.simplexdev.api.IUsableSign;
import io.github.simplexdev.api.func.VoidSupplier; import io.github.simplexdev.api.func.VoidSupplier;

View File

@ -19,20 +19,80 @@ public class ItemBuilder {
this.plugin = plugin; this.plugin = plugin;
} }
/**
* Create a new singular ItemStack.
* @param material The material for the item.
* @return A new ItemStack from the provided material.
*/
public ItemStack createNoBounds(Material material) { public ItemStack createNoBounds(Material material) {
return new ItemStack(material, 1); return new ItemStack(material, 1);
} }
/**
* Create a new ItemStack.
* @param material The material for the item.
* @param amount The amount of items the stack should represent.
* @return A new ItemStack from the provided material.
*/
public ItemStack createNoBounds(Material material, int amount) {
return new ItemStack(material, amount);
}
/**
* Create a new singular ItemStack with the specified ItemMeta.
* @param material The material for the item.
* @param metaData The ItemMeta to use for the item.
* @return A new ItemStack from the provided material with the specified ItemMeta.
*/
public ItemStack createWithMeta(Material material, ItemMeta metaData) { public ItemStack createWithMeta(Material material, ItemMeta metaData) {
ItemStack stack = new ItemStack(material, 1); ItemStack stack = new ItemStack(material, 1);
stack.setItemMeta(metaData); stack.setItemMeta(metaData);
return stack; return stack;
} }
public Worker itemBuilder(Material material) { /**
* Create a new ItemStack with the specified ItemMeta.
* @param material The material for the item.
* @param metaData The ItemMeta to use for the item.
* @param amount The amount of items the stack should represent.
* @return A new ItemStack from the provided material with the specified ItemMeta.
*/
public ItemStack createWithMeta(Material material, ItemMeta metaData, int amount) {
ItemStack stack = new ItemStack(material, amount);
stack.setItemMeta(metaData);
return stack;
}
/**
* Create a new ItemBuilder Worker
* @param material The material for the item.
* @return A new appendable ItemBuilder Worker instance based on the given Material.
*/
public Worker newItem(Material material) {
return new Worker(new ItemStack(material, 1)); return new Worker(new ItemStack(material, 1));
} }
/**
* Create a new ItemBuilder Worker
* @param material The material for the item.
* @param amount The amount of items the stack should represent.
* @return A new appendable ItemBuilder Worker instance based on the given Material.
*/
public Worker newItem(Material material, int amount) {
return new Worker(new ItemStack(material, amount));
}
public Worker editItem(ItemStack stack) {
return new Worker(stack);
}
/**
* Create a new AttributeModifier for an ItemStack's ItemMeta.
* @param name The name of the modifier.
* @param amount The amount to add
* @param scalar Whether or not it should add as a number or a magnitude.
* @return A new AttributeModifier.
*/
public AttributeModifier add(String name, double amount, boolean scalar) { public AttributeModifier add(String name, double amount, boolean scalar) {
if (scalar) { if (scalar) {
return new AttributeModifier(name, amount, AttributeModifier.Operation.ADD_SCALAR); return new AttributeModifier(name, amount, AttributeModifier.Operation.ADD_SCALAR);
@ -40,6 +100,12 @@ public class ItemBuilder {
return new AttributeModifier(name, amount, AttributeModifier.Operation.ADD_NUMBER); return new AttributeModifier(name, amount, AttributeModifier.Operation.ADD_NUMBER);
} }
/**
* Create a new AttributeModifier for an ItemStack's ItemMeta.
* @param name The name of the modifier
* @param amount The amount to multiply by
* @return A new AttributeModifier.
*/
public AttributeModifier multiply(String name, double amount) { public AttributeModifier multiply(String name, double amount) {
return new AttributeModifier(name, amount, AttributeModifier.Operation.MULTIPLY_SCALAR_1); return new AttributeModifier(name, amount, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
} }
@ -48,41 +114,94 @@ public class ItemBuilder {
private final ItemStack stack; private final ItemStack stack;
private final ItemMeta meta; private final ItemMeta meta;
/**
* @param stack The item to work from.
*/
public Worker(ItemStack stack) { public Worker(ItemStack stack) {
this.stack = stack; this.stack = stack;
this.meta = stack.getItemMeta(); this.meta = stack.getItemMeta();
} }
/**
* Adds lore to the item. New lines should be separate Strings.
* @param lore The item lore to add.
* @return An appendable worker instance.
*/
public final Worker addLore(String... lore) { public final Worker addLore(String... lore) {
meta.setLore(Arrays.asList(lore)); meta.setLore(Arrays.asList(lore));
stack.setItemMeta(meta); stack.setItemMeta(meta);
return this; return this;
} }
/**
* Change the item's name
* @param customName The new name of the item.
* @return An appendable worker instance.
*/
public final Worker setName(String customName) { public final Worker setName(String customName) {
meta.setDisplayName(customName); meta.setDisplayName(customName);
stack.setItemMeta(meta); stack.setItemMeta(meta);
return this; return this;
} }
/**
* Add an enchantment to the item
* @param enchantment The enchantment to add
* @param level The level of the enchantment. This is non-restrictive.
* @return An appendable worker instance.
*/
public final Worker addEnchant(Enchantment enchantment, int level) { public final Worker addEnchant(Enchantment enchantment, int level) {
meta.addEnchant(enchantment, level, true); meta.addEnchant(enchantment, level, true);
stack.setItemMeta(meta); stack.setItemMeta(meta);
return this; return this;
} }
/**
* Add an attribute to the item.
* @param attribute The attribute to add.
* @param modifier The type of attribute modifier to use.
* @return An appendable worker instance.
*/
public final Worker addAttribute(Attribute attribute, AttributeModifier modifier) { public final Worker addAttribute(Attribute attribute, AttributeModifier modifier) {
meta.addAttributeModifier(attribute, modifier); meta.addAttributeModifier(attribute, modifier);
stack.setItemMeta(meta); stack.setItemMeta(meta);
return this; return this;
} }
/**
* Add item flags to an item.
* @param flags Any amount of ItemFlags to add to the item.
* @return An appendable worker instance.
*/
public final Worker addItemFlags(ItemFlag... flags) { public final Worker addItemFlags(ItemFlag... flags) {
meta.addItemFlags(flags); meta.addItemFlags(flags);
stack.setItemMeta(meta); stack.setItemMeta(meta);
return this; return this;
} }
/**
* Set the amount of items this stack should represent.
* @param amount The amount of items this stack should represent.
* @return An appendable worker instance.
*/
public final Worker setAmount(int amount) {
stack.setAmount(amount);
return this;
}
public final Worker setType(Material material) {
stack.setType(material);
return this;
}
public final Worker setUnbreakable(boolean unbreakable) {
meta.setUnbreakable(unbreakable);
return this;
}
/**
* @return The final item.
*/
public final ItemStack get() { public final ItemStack get() {
return stack; return stack;
} }

View File

@ -30,7 +30,7 @@ public class RBImpl {
} }
public void customWand() { public void customWand() {
ItemStack is = bldr.itemBuilder(Material.BLAZE_ROD) ItemStack is = bldr.newItem(Material.BLAZE_ROD)
.setName("Magic Wand") .setName("Magic Wand")
.addLore("This wand is magical.") .addLore("This wand is magical.")
.addEnchant(Enchantment.KNOCKBACK, 10) .addEnchant(Enchantment.KNOCKBACK, 10)

View File

@ -22,6 +22,14 @@ public final class RecipeBuilder {
this.plugin = plugin; this.plugin = plugin;
} }
/**
* Create a new RecipeBuilder Worker.
* @param result The resulting item.
* @param recipeName The name of the recipe.
* This should be separated by "_" where spaced would be used.
* @param isShaped Whether or not the recipe is shaped or shapeless.
* @return A new appendable RecipeBuilder Worker instance based on the given parameters.
*/
public final Worker of(ItemStack result, String recipeName, boolean isShaped) { public final Worker of(ItemStack result, String recipeName, boolean isShaped) {
return new Worker(result, recipeName, isShaped); return new Worker(result, recipeName, isShaped);
} }
@ -32,8 +40,15 @@ public final class RecipeBuilder {
private final NamespacedKey key; private final NamespacedKey key;
private final boolean shaped; private final boolean shaped;
private final List<Material> materials = new ArrayList<>(); private final List<Material> materials = new ArrayList<>();
private String[] shape = {"aaa", "aaa", "aaa"}; private String[] shape = {"", "", ""};
/**
* @param stack The item to build a recipe for. This may be an item with custom metadata,
* or even an item without a native crafting recipe.
* @param name The recipe name; it should be all lowercase,
* separated by underscores where spaced would be used.
* @param isShaped If the recipe is shaped or shapeless.
*/
public Worker(ItemStack stack, String name, boolean isShaped) { public Worker(ItemStack stack, String name, boolean isShaped) {
this.stack = stack; this.stack = stack;
this.key = new NamespacedKey(plugin, name); this.key = new NamespacedKey(plugin, name);
@ -62,17 +77,28 @@ public final class RecipeBuilder {
} }
/** /**
* This is for shaped crafting. * This is for shaped crafting. Please use {@link Worker#addIngredients(Material...)}
* for shapeless crafting.
* *
* @param identifier The specific identifier * @param identifier The specific identifier
* @param ingredient The ingredient represented by the identifier. * @param ingredient The ingredient represented by the identifier.
* @return * @return An appendable worker instance.
*/ */
public Worker addIngredient(@NotNull Character identifier, @NotNull Material ingredient) { public Worker addIngredient(@NotNull Character identifier, @NotNull Material ingredient) {
ingredients.put(identifier, ingredient); ingredients.put(identifier, ingredient);
return this; return this;
} }
/**
* Sets the shape for the crafting recipe. This is not required if the recipe is shapeless.
* @param top The top three slots represented by "___" where any specific letter
* is represented by the relative ingredient identifier.
* @param middle The middle three slots represented by "___" where any specific letter
* is represented by the relative ingredient identifier.
* @param bottom The bottom three slots represented by "___" where any specific letter
* is represented by the relative ingredient identifier.
* @return An appendable worker instance.
*/
public Worker setShape(@Nullable String top, @Nullable String middle, @Nullable String bottom) { public Worker setShape(@Nullable String top, @Nullable String middle, @Nullable String bottom) {
String a = ""; String a = "";
String b = ""; String b = "";
@ -92,10 +118,11 @@ public final class RecipeBuilder {
} }
/** /**
* This is for shapeless crafting. * This is for shapeless crafting. Please use {@link Worker#addIngredient(Character, Material)}
* for shaped crafting.
* *
* @param ingredients any number (up to nine) of ingredients required to craft this recipe. * @param ingredients any number (up to nine) of ingredients required to craft this recipe.
* @return An appendable instance of this class. * @return An appendable worker instance.
*/ */
public Worker addIngredients(Material... ingredients) { public Worker addIngredients(Material... ingredients) {
Utilities.forEach(ingredients, materials::add); Utilities.forEach(ingredients, materials::add);

View File

@ -0,0 +1,36 @@
package io.github.simplexdev.simplexcore.utils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public final class PlayerTools {
@NotNull
public static String stringUUID(@NotNull Player player) {
return player.getUniqueId().toString();
}
@Nullable
public static Player getPlayer(@NotNull String nameOrUUID) {
if (nameOrUUID.length() > 16) {
UUID uuid = UUID.fromString(nameOrUUID);
return Bukkit.getServer().getPlayer(uuid);
} else {
return Bukkit.getServer().getPlayer(nameOrUUID);
}
}
@NotNull
public static OfflinePlayer getOfflinePlayer(@NotNull String nameOrUUID) {
if (nameOrUUID.length() > 16) {
UUID uuid = UUID.fromString(nameOrUUID);
return Bukkit.getOfflinePlayer(uuid);
}
return Bukkit.getOfflinePlayer(nameOrUUID);
}
}