diff --git a/ci-pom.xml b/ci-pom.xml index e50f28b7..b788fe83 100644 --- a/ci-pom.xml +++ b/ci-pom.xml @@ -7,7 +7,7 @@ us.mytheria BlobLib - 1.697.41 + 1.697.47 pom.xml bloblib diff --git a/local-pom.xml b/local-pom.xml index a7741cc7..1776194e 100644 --- a/local-pom.xml +++ b/local-pom.xml @@ -5,7 +5,7 @@ us.mytheria BlobLib - 1.697.41 + 1.697.47 pom.xml bloblib diff --git a/pom.xml b/pom.xml index 704e92c1..0b8f8b06 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 us.mytheria BlobLib - 1.697.41 + 1.697.47 pom diff --git a/src/main/java/us/mytheria/bloblib/BlobLib.java b/src/main/java/us/mytheria/bloblib/BlobLib.java index a6d61310..5ddafd69 100644 --- a/src/main/java/us/mytheria/bloblib/BlobLib.java +++ b/src/main/java/us/mytheria/bloblib/BlobLib.java @@ -50,7 +50,6 @@ public class BlobLib extends JavaPlugin { private SerializationLib serializationLib; private InventoryTrackerManager inventoryTrackerManager; private TranslatableManager translatableManager; - private TranslatablePH translatablePH; private LocalizableDataAssetManager translatableItemManager; private DataAssetManager tagSetManager; diff --git a/src/main/java/us/mytheria/bloblib/entities/BuilderManager.java b/src/main/java/us/mytheria/bloblib/entities/BuilderManager.java new file mode 100644 index 00000000..b017c293 --- /dev/null +++ b/src/main/java/us/mytheria/bloblib/entities/BuilderManager.java @@ -0,0 +1,145 @@ +package us.mytheria.bloblib.entities; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.Inventory; +import org.jetbrains.annotations.NotNull; +import us.mytheria.bloblib.api.BlobLibInventoryAPI; +import us.mytheria.bloblib.entities.inventory.BlobInventory; +import us.mytheria.bloblib.entities.inventory.BlobObjectBuilder; +import us.mytheria.bloblib.managers.*; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; + +public abstract class BuilderManager> extends Manager implements Listener { + protected String title; + + protected Map builders; + protected Map inventories; + private final ChatListenerManager chatManager; + private final DropListenerManager dropListenerManager; + private final SelectorListenerManager selectorListenerManager; + private final SelPosListenerManager selPosListenerManager; + private final String fileKey; + + public BuilderManager(ManagerDirector managerDirector, + String fileKey) { + super(managerDirector); + Bukkit.getPluginManager().registerEvents(this, getPlugin()); + selPosListenerManager = getManagerDirector().getPositionListenerManager(); + chatManager = getManagerDirector().getChatListenerManager(); + dropListenerManager = getManagerDirector().getDropListenerManager(); + selectorListenerManager = getManagerDirector().getSelectorManager(); + this.fileKey = Objects.requireNonNull(fileKey, "File key cannot be null."); + update(); + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + removeBuilder(event.getPlayer()); + } + + @EventHandler + public void onClick(InventoryClickEvent event) { + Inventory clicked = event.getClickedInventory(); + if (clicked == null) + return; + if (clicked.getType() == InventoryType.PLAYER) + return; + if (!inventories.containsKey(clicked)) + return; + int slot = event.getRawSlot(); + Player player = (Player) event.getWhoClicked(); + BlobObjectBuilder builder = getOrDefault(player.getUniqueId()); + if (slot >= builder.getSize()) { + return; + } + event.setCancelled(true); + builder.handle(slot, player); + } + + @Override + public void reload() { + update(); + } + + public void update() { + this.builders = new HashMap<>(); + this.inventories = new HashMap<>(); + BlobInventory inventory = BlobLibInventoryAPI.getInstance().getBlobInventory(fileKey); + if (inventory == null) + throw new RuntimeException("Inventory file '" + fileKey + "' not found."); + this.title = inventory.getTitle(); + } + + @NotNull + public abstract B getOrDefault(UUID uuid); + + @NotNull + public B getOrDefault(Player player) { + return getOrDefault(player.getUniqueId()); + } + + @NotNull + public BuilderManager addBuilder(UUID uuid, B builder) { + builders.put(uuid, builder); + inventories.put(builder.getInventory(), builder); + return this; + } + + @NotNull + public BuilderManager addBuilder(Player player, B builder) { + addBuilder(player.getUniqueId(), builder); + return this; + } + + @NotNull + public BuilderManager removeBuilder(UUID uuid) { + B builder = builders.get(uuid); + if (builder == null) + return this; + Inventory key = builder.getInventory(); + inventories.remove(key); + builders.remove(uuid); + return this; + } + + @NotNull + public BuilderManager removeBuilder(Player player) { + removeBuilder(player.getUniqueId()); + return this; + } + + @NotNull + public String getFileKey() { + return fileKey; + } + + @NotNull + public DropListenerManager getDropListenerManager() { + return dropListenerManager; + } + + @NotNull + public ChatListenerManager getChatManager() { + return chatManager; + } + + @NotNull + public SelectorListenerManager getSelectorListenerManager() { + return selectorListenerManager; + } + + @NotNull + public SelPosListenerManager getSelPosListenerManager() { + return selPosListenerManager; + } +} diff --git a/src/main/java/us/mytheria/bloblib/entities/CommandDirector.java b/src/main/java/us/mytheria/bloblib/entities/CommandDirector.java new file mode 100644 index 00000000..accc77ba --- /dev/null +++ b/src/main/java/us/mytheria/bloblib/entities/CommandDirector.java @@ -0,0 +1,96 @@ +package us.mytheria.bloblib.entities; + +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; + +public class CommandDirector { + private final BlobExecutor executor; + private final List> nonAdminChildCommands; + private final List> adminChildCommands; + private final List>> nonAdminChildTabCompleter; + private final List>> adminChildTabCompleter; + + public CommandDirector(JavaPlugin plugin, String commandName) { + this.executor = new BlobExecutor(plugin, commandName); + this.nonAdminChildCommands = new ArrayList<>(); + this.adminChildCommands = new ArrayList<>(); + this.nonAdminChildTabCompleter = new ArrayList<>(); + this.adminChildTabCompleter = new ArrayList<>(); + setDefaultCommands(); + setDefaultTabCompleter(); + } + + public BlobExecutor getExecutor() { + return executor; + } + + public void addNonAdminChildCommand(Function nonAdminChildCommand) { + this.nonAdminChildCommands.add(nonAdminChildCommand); + } + + public void addAdminChildCommand(Function adminChildCommand) { + this.adminChildCommands.add(adminChildCommand); + } + + public void addNonAdminChildTabCompleter(Function> nonAdminChildTabCompleter) { + this.nonAdminChildTabCompleter.add(nonAdminChildTabCompleter); + } + + public void addAdminChildTabCompleter(Function> adminChildTabCompleter) { + this.adminChildTabCompleter.add(adminChildTabCompleter); + } + + public List> getAdminChildCommands() { + return adminChildCommands; + } + + public List> getNonAdminChildCommands() { + return nonAdminChildCommands; + } + + public List>> getAdminChildTabCompleter() { + return adminChildTabCompleter; + } + + public List>> getNonAdminChildTabCompleter() { + return nonAdminChildTabCompleter; + } + + protected void setDefaultCommands() { + executor.setCommand((sender, args) -> { + for (Function childCommand : nonAdminChildCommands) { + if (childCommand.apply(new ExecutorData(executor, args, sender))) + return true; + } + if (!executor.hasAdminPermission(sender)) + return true; + for (Function childCommand : adminChildCommands) { + if (childCommand.apply(new ExecutorData(executor, args, sender))) + return true; + } + return false; + }); + } + + protected void setDefaultTabCompleter() { + executor.setTabCompleter((sender, args) -> { + List suggestions = new ArrayList<>(); + for (Function> childTabCompleter : nonAdminChildTabCompleter) { + List childTabCompletion = childTabCompleter.apply(new ExecutorData(executor, args, sender)); + if (childTabCompletion != null && !childTabCompletion.isEmpty()) + suggestions.addAll(childTabCompletion); + } + if (!executor.hasAdminPermission(sender, null)) + return suggestions; + for (Function> childTabCompleter : adminChildTabCompleter) { + List childTabCompletion = childTabCompleter.apply(new ExecutorData(executor, args, sender)); + if (childTabCompletion != null && !childTabCompletion.isEmpty()) + suggestions.addAll(childTabCompletion); + } + return suggestions; + }); + } +} \ No newline at end of file diff --git a/src/main/java/us/mytheria/bloblib/entities/IndependentBuilderManager.java b/src/main/java/us/mytheria/bloblib/entities/IndependentBuilderManager.java new file mode 100644 index 00000000..ffc0e8c2 --- /dev/null +++ b/src/main/java/us/mytheria/bloblib/entities/IndependentBuilderManager.java @@ -0,0 +1,65 @@ +package us.mytheria.bloblib.entities; + +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import us.mytheria.bloblib.entities.inventory.BlobObjectBuilder; +import us.mytheria.bloblib.managers.ManagerDirector; + +import java.util.UUID; +import java.util.function.Function; + +public class IndependentBuilderManager extends BuilderManager> { + + private Function> function; + + public IndependentBuilderManager(ManagerDirector managerDirector, + String fileKey) { + super(managerDirector, fileKey); + } + + @Override + @NotNull + public BlobObjectBuilder getOrDefault(UUID uuid) { + BlobObjectBuilder objectBuilder = this.builders.get(uuid); + if (objectBuilder == null) { + objectBuilder = function.apply(uuid); + builders.put(uuid, objectBuilder); + inventories.put(objectBuilder.getInventory(), objectBuilder); + } + return objectBuilder; + } + + @Override + @NotNull + public IndependentBuilderManager addBuilder(UUID uuid, BlobObjectBuilder builder) { + super.addBuilder(uuid, builder); + return this; + } + + @Override + @NotNull + public IndependentBuilderManager addBuilder(Player player, BlobObjectBuilder builder) { + super.addBuilder(player, builder); + return this; + } + + @Override + @NotNull + public IndependentBuilderManager removeBuilder(UUID uuid) { + super.removeBuilder(uuid); + return this; + } + + @Override + @NotNull + public IndependentBuilderManager removeBuilder(Player player) { + super.removeBuilder(player); + return this; + } + + @NotNull + public IndependentBuilderManager setBuilderFunction(Function> function) { + this.function = function; + return this; + } +} \ No newline at end of file diff --git a/src/main/java/us/mytheria/bloblib/entities/ObjectBuilderManager.java b/src/main/java/us/mytheria/bloblib/entities/ObjectBuilderManager.java index 5f3836a8..37074a15 100644 --- a/src/main/java/us/mytheria/bloblib/entities/ObjectBuilderManager.java +++ b/src/main/java/us/mytheria/bloblib/entities/ObjectBuilderManager.java @@ -1,73 +1,22 @@ package us.mytheria.bloblib.entities; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.Inventory; import org.jetbrains.annotations.NotNull; -import us.mytheria.bloblib.api.BlobLibInventoryAPI; -import us.mytheria.bloblib.entities.inventory.BlobInventory; import us.mytheria.bloblib.entities.inventory.ObjectBuilder; -import us.mytheria.bloblib.managers.*; +import us.mytheria.bloblib.managers.ManagerDirector; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; import java.util.UUID; import java.util.function.BiFunction; -public class ObjectBuilderManager extends Manager implements Listener { - protected String title; +public class ObjectBuilderManager extends BuilderManager> { - private Map> builders; - private Map> inventories; - private ChatListenerManager chatManager; - private DropListenerManager dropListenerManager; - private SelectorListenerManager selectorListenerManager; - private SelPosListenerManager selPosListenerManager; - private final String fileKey; private BiFunction, ObjectBuilder> builderBiFunction; private final ObjectDirector objectDirector; public ObjectBuilderManager(ManagerDirector managerDirector, String fileKey, ObjectDirector objectDirector) { - super(managerDirector); - Bukkit.getPluginManager().registerEvents(this, getPlugin()); - selPosListenerManager = getManagerDirector().getPositionListenerManager(); - chatManager = getManagerDirector().getChatListenerManager(); - dropListenerManager = getManagerDirector().getDropListenerManager(); - selectorListenerManager = getManagerDirector().getSelectorManager(); - this.objectDirector = Objects.requireNonNull(objectDirector, "Object director cannot be null."); - this.fileKey = Objects.requireNonNull(fileKey, "File key cannot be null."); - update(); - } - - @EventHandler - public void onQuit(PlayerQuitEvent event) { - removeBuilder(event.getPlayer()); - } - - @EventHandler - public void onClick(InventoryClickEvent event) { - Inventory clicked = event.getClickedInventory(); - if (clicked == null) - return; - if (clicked.getType() == InventoryType.PLAYER) - return; - if (!inventories.containsKey(clicked)) - return; - int slot = event.getRawSlot(); - Player player = (Player) event.getWhoClicked(); - ObjectBuilder builder = getOrDefault(player.getUniqueId()); - if (slot >= builder.getSize()) { - return; - } - event.setCancelled(true); - builder.handle(slot, player); + super(managerDirector, fileKey); + this.objectDirector = objectDirector; } @NotNull @@ -76,19 +25,6 @@ public ObjectDirector getObjectDirector() { } @Override - public void reload() { - update(); - } - - public void update() { - this.builders = new HashMap<>(); - this.inventories = new HashMap<>(); - BlobInventory inventory = BlobLibInventoryAPI.getInstance().getBlobInventory(fileKey); - if (inventory == null) - throw new RuntimeException("Inventory file '" + fileKey + "' not found."); - this.title = inventory.getTitle(); - } - @NotNull public ObjectBuilder getOrDefault(UUID uuid) { ObjectBuilder objectBuilder = builders.get(uuid); @@ -100,38 +36,31 @@ public ObjectBuilder getOrDefault(UUID uuid) { return objectBuilder; } - @NotNull - public ObjectBuilder getOrDefault(Player player) { - return getOrDefault(player.getUniqueId()); - } - + @Override @NotNull public ObjectBuilderManager addBuilder(UUID uuid, ObjectBuilder builder) { - builders.put(uuid, builder); - inventories.put(builder.getInventory(), builder); + super.addBuilder(uuid, builder); return this; } + @Override @NotNull public ObjectBuilderManager addBuilder(Player player, ObjectBuilder builder) { - addBuilder(player.getUniqueId(), builder); + super.addBuilder(player, builder); return this; } + @Override @NotNull public ObjectBuilderManager removeBuilder(UUID uuid) { - ObjectBuilder builder = builders.get(uuid); - if (builder == null) - return this; - Inventory key = builder.getInventory(); - inventories.remove(key); - builders.remove(uuid); + super.removeBuilder(uuid); return this; } + @Override @NotNull public ObjectBuilderManager removeBuilder(Player player) { - removeBuilder(player.getUniqueId()); + super.removeBuilder(player); return this; } @@ -141,28 +70,4 @@ public ObjectBuilderManager setBuilderBiFunction(BiFunction extends Manager implements Listener { private final ObjectBuilderManager objectBuilderManager; private final ObjectManager objectManager; - private final BlobExecutor executor; - private final List> nonAdminChildCommands; - private final List> adminChildCommands; - private final List>> nonAdminChildTabCompleter; - private final List>> adminChildTabCompleter; + private final CommandDirector commandDirector; protected final String objectName; private final boolean hasObjectBuilderManager; private boolean objectIsEditable; - protected CompletableFuture loadFilesFuture; - private final Consumer addConsumer; public ObjectDirector(ManagerDirector managerDirector, ObjectDirectorData objectDirectorData, @@ -48,16 +42,14 @@ public ObjectDirector(ManagerDirector managerDirector, ObjectDirectorData objectDirectorData, Function readFunction, boolean hasObjectBuilderManager) { super(managerDirector); + this.commandDirector = new CommandDirector(managerDirector.getPlugin(), objectDirectorData.objectName()); objectIsEditable = false; this.hasObjectBuilderManager = hasObjectBuilderManager; if (hasObjectBuilderManager) { this.objectBuilderManager = new ObjectBuilderManager<>(managerDirector, objectDirectorData.objectBuilderKey(), this); - this.addConsumer = objectBuilderManager::getOrDefault; } else { this.objectBuilderManager = null; - this.addConsumer = player -> { - }; } Optional loadFilesDirectory = managerDirector.getRealFileManager().searchFile(objectDirectorData.objectDirectory()); if (loadFilesDirectory.isEmpty()) { @@ -96,11 +88,6 @@ public void loadFiles(File path, CompletableFuture mainFuture) { } }; Bukkit.getPluginManager().registerEvents(this, managerDirector.getPlugin()); - nonAdminChildCommands = new ArrayList<>(); - adminChildCommands = new ArrayList<>(); - nonAdminChildTabCompleter = new ArrayList<>(); - adminChildTabCompleter = new ArrayList<>(); - executor = new BlobExecutor(getPlugin(), objectDirectorData.objectName()); objectName = objectDirectorData.objectName(); setDefaultCommands().setDefaultTabCompleter(); if (hasObjectBuilderManager) { @@ -119,7 +106,7 @@ public void loadFiles(File path, CompletableFuture mainFuture) { Result result = data.executor() .isChildCommand("add", data.args()); if (result.isValid()) { - return getExecutor().ifInstanceOfPlayer(data.sender(), player -> { + return commandDirector.getExecutor().ifInstanceOfPlayer(data.sender(), player -> { ObjectBuilder builder = objectBuilderManager.getOrDefault(player.getUniqueId()); builder.openInventory(); }); @@ -130,7 +117,7 @@ public void loadFiles(File path, CompletableFuture mainFuture) { Result result = data.executor() .isChildCommand("remove", data.args()); if (result.isValid()) { - return getExecutor().ifInstanceOfPlayer(data.sender(), this::removeObject); + return commandDirector.getExecutor().ifInstanceOfPlayer(data.sender(), this::removeObject); } return false; }); @@ -142,7 +129,7 @@ public void loadFiles(File path, CompletableFuture mainFuture) { if (args.length != 2) return false; String input = args[1]; - return getExecutor().ifInstanceOfPlayer(data.sender(), player -> editObject(player, input)); + return commandDirector.getExecutor().ifInstanceOfPlayer(data.sender(), player -> editObject(player, input)); } return false; }); @@ -186,7 +173,7 @@ public void reload() { * @param nonAdminChildCommand the BlobChildCommands that CAN BE EXECUTED WITHOUT 'YOURPLUGIN.admin' permission. */ public void addNonAdminChildCommand(Function nonAdminChildCommand) { - this.nonAdminChildCommands.add(nonAdminChildCommand); + this.commandDirector.addNonAdminChildCommand(nonAdminChildCommand); } /** @@ -219,7 +206,7 @@ public void addNonAdminChildCommand(Function nonAdminChil * @param adminChildCommand the BlobChildCommands that can ONLY be executed with 'YOURPLUGIN.admin' permission. */ public void addAdminChildCommand(Function adminChildCommand) { - this.adminChildCommands.add(adminChildCommand); + this.commandDirector.addAdminChildCommand(adminChildCommand); } /** @@ -234,7 +221,7 @@ public void addAdminChildCommand(Function adminChildComma * @param nonAdminChildTabCompleter the BlobChildCommands that CAN BE EXECUTED WITHOUT 'YOURPLUGIN.admin' permission. */ public void addNonAdminChildTabCompleter(Function> nonAdminChildTabCompleter) { - this.nonAdminChildTabCompleter.add(nonAdminChildTabCompleter); + this.commandDirector.addNonAdminChildTabCompleter(nonAdminChildTabCompleter); } /** @@ -249,23 +236,23 @@ public void addNonAdminChildTabCompleter(Function> no * @param adminChildTabCompleter the BlobChildCommands that can ONLY be executed with 'YOURPLUGIN.admin' permission. */ public void addAdminChildTabCompleter(Function> adminChildTabCompleter) { - this.adminChildTabCompleter.add(adminChildTabCompleter); + this.commandDirector.addAdminChildTabCompleter(adminChildTabCompleter); } public List> getAdminChildCommands() { - return adminChildCommands; + return this.commandDirector.getAdminChildCommands(); } public List> getNonAdminChildCommands() { - return nonAdminChildCommands; + return this.commandDirector.getNonAdminChildCommands(); } public List>> getAdminChildTabCompleter() { - return adminChildTabCompleter; + return this.commandDirector.getAdminChildTabCompleter(); } public List>> getNonAdminChildTabCompleter() { - return nonAdminChildTabCompleter; + return this.commandDirector.getNonAdminChildTabCompleter(); } public ObjectBuilderManager getBuilderManager() { @@ -280,47 +267,13 @@ public ObjectManager getObjectManager() { return objectManager; } - private BlobExecutor getExecutor() { - return executor; - } - private ObjectDirector setDefaultCommands() { - getExecutor().setCommand((sender, args) -> { - if (executor.hasNoArguments(sender, args)) - return true; - for (Function childCommand : nonAdminChildCommands) { - if (childCommand.apply(new ExecutorData(executor, args, sender))) - return true; - } - if (!executor.hasAdminPermission(sender)) - return true; - for (Function childCommand : adminChildCommands) { - if (childCommand.apply(new ExecutorData(executor, args, sender))) - return true; - } - return false; - } - ); + commandDirector.setDefaultCommands(); return this; } private void setDefaultTabCompleter() { - getExecutor().setTabCompleter((sender, args) -> { - List suggestions = new ArrayList<>(); - for (Function> childTabCompleter : nonAdminChildTabCompleter) { - List childTabCompletion = childTabCompleter.apply(new ExecutorData(executor, args, sender)); - if (childTabCompletion != null && !childTabCompletion.isEmpty()) - suggestions.addAll(childTabCompletion); - } - if (!executor.hasAdminPermission(sender, null)) - return suggestions; - for (Function> childTabCompleter : adminChildTabCompleter) { - List childTabCompletion = childTabCompleter.apply(new ExecutorData(executor, args, sender)); - if (childTabCompletion != null && !childTabCompletion.isEmpty()) - suggestions.addAll(childTabCompletion); - } - return suggestions; - }); + commandDirector.setDefaultTabCompleter(); } /** diff --git a/src/main/java/us/mytheria/bloblib/entities/inventory/BlobObjectBuilder.java b/src/main/java/us/mytheria/bloblib/entities/inventory/BlobObjectBuilder.java new file mode 100644 index 00000000..ad2f2d4a --- /dev/null +++ b/src/main/java/us/mytheria/bloblib/entities/inventory/BlobObjectBuilder.java @@ -0,0 +1,566 @@ +package us.mytheria.bloblib.entities.inventory; + +import me.anjoismysign.anjo.entities.Uber; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import us.mytheria.bloblib.entities.BlobObject; +import us.mytheria.bloblib.entities.message.BlobMessage; +import us.mytheria.bloblib.entities.message.BlobSound; +import us.mytheria.bloblib.itemstack.ItemStackModder; + +import java.util.*; +import java.util.function.Consumer; +import java.util.function.Function; + +/** + * @param the type of object to build + * @author anjoismysign + *

+ * A BlobObjectBuilder is an inventory that allows the user to build an object. + * The idea behind it is that through the Minecraft client, while connected + * to the Minecraft server, the user can build an object by interacting with + * a Bukkit Inventory / GUI. + */ +public abstract class BlobObjectBuilder extends BlobInventory { + private final UUID builderId; + private final HashMap> objectBuilderButtons; + private Function, T> function; + + /** + * Constructs a new ObjectBuilder. + * + * @param blobInventory the inventory to use + * @param builderId the builder's UUID + */ + public BlobObjectBuilder(@NotNull BlobInventory blobInventory, + @NotNull UUID builderId) { + super(Objects.requireNonNull(blobInventory, + "blobInventory cannot be null").getTitle(), + blobInventory.getSize(), blobInventory.getButtonManager()); + this.builderId = Objects.requireNonNull(builderId, + "builderId cannot be null"); + this.objectBuilderButtons = new HashMap<>(); + } + + /** + * Retrieves an ObjectBuilderButton. + * + * @param key the key that points to the button + * @return the ObjectBuilderButton + */ + public ObjectBuilderButton getObjectBuilderButton(String key) { + return objectBuilderButtons.get(key); + } + + /** + * @return player matching builderId. + * null if no player is found. + */ + @Nullable + public Player getPlayer() { + return Bukkit.getPlayer(builderId); + } + + /** + * Retrieves builder's UUID + * + * @return builder's UUID + */ + public UUID getBuilderId() { + return builderId; + } + + /** + * Opens the inventory for the player. + */ + public void openInventory() { + getPlayer().openInventory(getInventory()); + } + + /** + * Updates a default button. + * + * @param key the key of the button + * @param regex the regex to replace + * @param replacement the replacement + */ + public void updateDefaultButton(String key, String regex, String replacement) { + modifyDefaultButton(key, modder -> modder.replace(regex, replacement)); + } + + /** + * Modifies a default button. + * + * @param key the key of the button + * @param function the function to modify the button + */ + public void modifyDefaultButton(String key, + Function function) { + Set slots = getSlots(key); + if (slots == null) + throw new NullPointerException("'" + key + "' is not a valid button key " + + "inside '" + getTitle() + "' inventory"); + slots.forEach(i -> { + ItemStack itemStack = cloneDefaultButton(key); + ItemStackModder modder = ItemStackModder.mod(itemStack); + function.apply(modder); + this.setButton(i, itemStack); + }); + } + + /** + * Will attempt to build the object + * using the function. The idea is + * that the function will + * + * @return the object + */ + public T build() { + if (function != null) + return function.apply(this); + return null; + } + + public abstract T construct(); + + /** + * Checks if it's a build button. + * + * @param slot the slot to check + * @return true if it's a build button + */ + public boolean isBuildButton(int slot) { + return getSlots("Build").contains(slot); + } + + /** + * Checks if it's an ObjectBuilderButton. + * + * @param slot the slot to check + * @return true if it's an ObjectBuilderButton + */ + public boolean isObjectBuilderButton(int slot) { + Uber is = new Uber<>(false); + objectBuilderButtons.values().forEach(button -> { + if (getSlots(button.getButtonKey()).contains(slot)) + is.talk(true); + }); + return is.thanks(); + } + + /** + * If the slot is an object builder button, adds the listener. + * + * @param slot the slot + * @param player the player + * @param sound the sound + */ + public void ifObjectBuilderButtonAddListener(int slot, Player player, + BlobSound sound) { + objectBuilderButtons.values().forEach(button -> { + if (getSlots(button.getButtonKey()).contains(slot)) + button.addListener(player, Optional.ofNullable(sound)); + }); + } + + /** + * If the slot is an object builder button, adds the listener. + * + * @param slot the slot + * @param player the player + */ + public boolean ifObjectBuilderButtonAddListener(int slot, Player player) { + for (ObjectBuilderButton button : objectBuilderButtons.values()) { + String key = button.getButtonKey(); + Set set = getSlots(key); + if (set == null) { + continue; + } + if (getSlots(button.getButtonKey()).contains(slot)) { + button.addListener(player); + return true; + } + } + return false; + } + + /** + * Handles all buttons, including build button. + * Used in InventoryClickEvent, slot parameter + * should be event.getRawSlot(). + * + * @param slot the slot + * @param player the player + */ + public void handle(int slot, Player player) { + boolean isObjectBuilderButton = ifObjectBuilderButtonAddListener(slot, player); + if (isObjectBuilderButton) + return; + if (isBuildButton(slot)) + build(); + } + + /** + * Adds an object builder button. + * + * @param builderButton the button + * @return this + */ + public BlobObjectBuilder addObjectBuilderButton(ObjectBuilderButton builderButton) { + objectBuilderButtons.put(builderButton.getButtonKey(), builderButton); + return this; + } + + /** + * Add a quick String button. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addQuickStringButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_STRING(buttonKey, timeout, this)); + } + + /** + * Add a quick byte button. Accepts negative values. + * If input equalsIgnoreCase 'null', button's value will be set null. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addQuickByteButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_BYTE(buttonKey, timeout, this)); + } + + /** + * Add a quick short button. Accepts negative values. + * If input equalsIgnoreCase 'null', button's value will be set null. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addQuickShortButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_SHORT(buttonKey, timeout, this)); + } + + /** + * Add a quick integer button. Accepts negative values. + * If input equalsIgnoreCase 'null', button's value will be set null. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addQuickIntegerButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_INTEGER(buttonKey, timeout, this)); + } + + /** + * Add a quick long button. Accepts negative values. + * If input equalsIgnoreCase 'null', button's value will be set null. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addQuickLongButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_LONG(buttonKey, timeout, this)); + } + + /** + * Add a quick float button. Accepts negative values. + * If input equalsIgnoreCase 'null', button's value will be set null. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addQuickFloatButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_FLOAT(buttonKey, timeout, this)); + } + + /** + * Add a quick double button. Accepts negative values. + * If input equalsIgnoreCase 'null', button's value will be set null. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addQuickDoubleButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_DOUBLE(buttonKey, timeout, this)); + } + + /** + * Add a quick block button. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addQuickBlockButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_BLOCK(buttonKey, timeout, this)); + } + + /** + * Add a quick block button. + * Will use the block above selection. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addQuickAboveBlockButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ABOVE_BLOCK(buttonKey, timeout, this)); + } + + /** + * Add a quick item button. + * + * @param buttonKey the button key + * @return this + */ + public BlobObjectBuilder addQuickItemButton(String buttonKey) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ITEM(buttonKey, this)); + } + + /** + * Add a quick selector button. + * + * @param buttonKey the button key + * @param selector the selector + * @param ifAvailable the if available + * @return this + */ + public BlobObjectBuilder addQuickSelectorButton(String buttonKey, + VariableSelector selector, + Function ifAvailable) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_SELECTOR(buttonKey, selector, ifAvailable, this)); + } + + /** + * Add a quick message button. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addQuickMessageButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_MESSAGE(buttonKey, timeout, this)); + } + + /** + * Add a quick world button. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addQuickWorldButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_WORLD(buttonKey, timeout, this)); + } + + /** + * Add a quick action block button which accepts a consumer when input is given. + * + * @param buttonKey the button key + * @param timeout the timeout + * @param consumer the consumer (which is of Block type) + * @return The button + */ + public BlobObjectBuilder addQuickActionBlockButton(String buttonKey, long timeout, Consumer consumer) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ACTION_BLOCK( + buttonKey, timeout, this, consumer)); + } + + /** + * Add a quick action item button which accepts a consumer when input is given. + * + * @param buttonKey the button key + * @param consumer the consumer (which is of ItemStack type) + * @return The button + */ + public BlobObjectBuilder addQuickActionItemButton(String buttonKey, Consumer consumer) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ACTION_ITEM( + buttonKey, this, consumer)); + } + + /** + * Add a quick action selector button which accepts a consumer when input is given. + * + * @param buttonKey The key of the button + * @param selector The selector + * @param ifAvailable The if available + * @param consumer The consumer (which is of T type) + * @return The button + */ + public BlobObjectBuilder addQuickActionSelectorButton(String buttonKey, + VariableSelector selector, + Function ifAvailable, + Consumer consumer) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ACTION_SELECTOR( + buttonKey, selector, ifAvailable, this, consumer)); + } + + /** + * Add a quick world button which accepts a consumer when input is given. + * + * @param buttonKey The key of the button + * @param timeout The timeout + * @param consumer The consumer (which is a ReferenceBlobMessage) + * @return The button + */ + public BlobObjectBuilder addQuickActionMessageButton(String buttonKey, long timeout, Consumer consumer) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ACTION_MESSAGE( + buttonKey, timeout, this, consumer)); + } + + /** + * A quick ObjectBuilderButton for Worlds that accepts + * a consumer when input is given. + * + * @param buttonKey The key of the button + * @param timeout The timeout + * @param consumer The consumer (which is a World) + * @return The button + */ + public BlobObjectBuilder addQuickActionWorldButton(String buttonKey, long timeout, Consumer consumer) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ACTION_WORLD( + buttonKey, timeout, this, consumer)); + } + + + /** + * Add a positive byte button. + * if input is lower than 0, button + * will be empty. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addPositiveByteButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.POSITIVE_BYTE(buttonKey, timeout, this)); + } + + /** + * Add a positive short button. + * if input is lower than 0, button + * will be empty. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addPositiveShortButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.POSITIVE_SHORT(buttonKey, timeout, this)); + } + + /** + * Add a positive integer button. + * if input is lower than 0, button + * will be empty. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addPositiveIntegerButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.POSITIVE_INTEGER(buttonKey, timeout, this)); + } + + /** + * Add a positive long button. + * if input is lower than 0, button + * will be empty. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addPositiveLongButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.POSITIVE_LONG(buttonKey, timeout, this)); + } + + /** + * Add a positive float button. + * if input is lower than 0, button + * will be empty. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addPositiveFloatButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.POSITIVE_FLOAT(buttonKey, timeout, this)); + } + + /** + * Add a positive double button. + * if input is lower than 0, button + * will be empty. + * + * @param buttonKey the button key + * @param timeout the timeout + * @return this + */ + public BlobObjectBuilder addPositiveDoubleButton(String buttonKey, long timeout) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.POSITIVE_DOUBLE(buttonKey, timeout, this)); + } + + /** + * A quick navigator for booleans. + * Value cannot be empty nor null. + * By default, the value is false. + * + * @param buttonKey The key of the button + * @return The button + */ + public BlobObjectBuilder addBoolean(String buttonKey) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.BOOLEAN(buttonKey, this)); + } + + /** + * A quick navigator for booleans. + * Value cannot be empty nor null. + * By default, the value is true. + * + * @param buttonKey The key of the button + * @return The button + */ + public BlobObjectBuilder addBooleanDefaultTrue(String buttonKey) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.BOOLEAN_DEFAULT_TRUE(buttonKey, this)); + } + + /** + * A quick navigator for any type of array. + * Value cannot be empty nor null. + * By default, the value is the first element of the array. + * + * @param buttonKey The key of the button + * @param enumClass The enum class + * @return The button + */ + public > BlobObjectBuilder addEnumNavigator(String buttonKey, Class enumClass) { + return addObjectBuilderButton(ObjectBuilderButtonBuilder.ENUM_NAVIGATOR(buttonKey, enumClass, this)); + } + + /** + * Set the function to be called when the build button is clicked + * + * @param function the function to be called + * @return this + */ + public BlobObjectBuilder setFunction(Function, T> function) { + this.function = function; + return this; + } +} diff --git a/src/main/java/us/mytheria/bloblib/entities/inventory/ObjectBuilder.java b/src/main/java/us/mytheria/bloblib/entities/inventory/ObjectBuilder.java index 7a495af9..7eeeb1ee 100644 --- a/src/main/java/us/mytheria/bloblib/entities/inventory/ObjectBuilder.java +++ b/src/main/java/us/mytheria/bloblib/entities/inventory/ObjectBuilder.java @@ -1,22 +1,10 @@ package us.mytheria.bloblib.entities.inventory; -import me.anjoismysign.anjo.entities.Uber; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import us.mytheria.bloblib.entities.BlobObject; import us.mytheria.bloblib.entities.ObjectDirector; -import us.mytheria.bloblib.entities.message.BlobMessage; -import us.mytheria.bloblib.entities.message.BlobSound; -import us.mytheria.bloblib.itemstack.ItemStackModder; -import java.util.*; -import java.util.function.Consumer; -import java.util.function.Function; +import java.util.UUID; /** * @param the type of object to build @@ -27,10 +15,7 @@ * to the Minecraft server, the user can build an object by interacting with * a Bukkit Inventory / GUI. */ -public abstract class ObjectBuilder extends BlobInventory { - private final UUID builderId; - private final HashMap> objectBuilderButtons; - private Function, T> function; +public abstract class ObjectBuilder extends BlobObjectBuilder { private final ObjectDirector objectDirector; /** @@ -43,14 +28,8 @@ public abstract class ObjectBuilder extends BlobInventory public ObjectBuilder(@NotNull BlobInventory blobInventory, @NotNull UUID builderId, @NotNull ObjectDirector objectDirector) { - super(Objects.requireNonNull(blobInventory, - "blobInventory cannot be null").getTitle(), - blobInventory.getSize(), blobInventory.getButtonManager()); - this.objectDirector = Objects.requireNonNull(objectDirector, - "objectDirector cannot be null"); - this.builderId = Objects.requireNonNull(builderId, - "builderId cannot be null"); - this.objectBuilderButtons = new HashMap<>(); + super(blobInventory, builderId); + this.objectDirector = objectDirector; } /** @@ -62,521 +41,4 @@ public ObjectBuilder(@NotNull BlobInventory blobInventory, public ObjectDirector getObjectDirector() { return objectDirector; } - - /** - * Retrieves an ObjectBuilderButton. - * - * @param key the key that points to the button - * @return the ObjectBuilderButton - */ - public ObjectBuilderButton getObjectBuilderButton(String key) { - return objectBuilderButtons.get(key); - } - - /** - * @return player matching builderId. - * null if no player is found. - */ - @Nullable - public Player getPlayer() { - return Bukkit.getPlayer(builderId); - } - - /** - * Retrieves builder's UUID - * - * @return builder's UUID - */ - public UUID getBuilderId() { - return builderId; - } - - /** - * Opens the inventory for the player. - */ - public void openInventory() { - getPlayer().openInventory(getInventory()); - } - - /** - * Updates a default button. - * - * @param key the key of the button - * @param regex the regex to replace - * @param replacement the replacement - */ - public void updateDefaultButton(String key, String regex, String replacement) { - modifyDefaultButton(key, modder -> modder.replace(regex, replacement)); - } - - /** - * Modifies a default button. - * - * @param key the key of the button - * @param function the function to modify the button - */ - public void modifyDefaultButton(String key, - Function function) { - Set slots = getSlots(key); - if (slots == null) - throw new NullPointerException("'" + key + "' is not a valid button key " + - "inside '" + getTitle() + "' inventory"); - slots.forEach(i -> { - ItemStack itemStack = cloneDefaultButton(key); - ItemStackModder modder = ItemStackModder.mod(itemStack); - function.apply(modder); - this.setButton(i, itemStack); - }); - } - - /** - * Will attempt to build the object - * using the function. The idea is - * that the function will - * - * @return the object - */ - public T build() { - if (function != null) - return function.apply(this); - return null; - } - - public abstract T construct(); - - /** - * Checks if it's a build button. - * - * @param slot the slot to check - * @return true if it's a build button - */ - public boolean isBuildButton(int slot) { - return getSlots("Build").contains(slot); - } - - /** - * Checks if it's an ObjectBuilderButton. - * - * @param slot the slot to check - * @return true if it's an ObjectBuilderButton - */ - public boolean isObjectBuilderButton(int slot) { - Uber is = new Uber<>(false); - objectBuilderButtons.values().forEach(button -> { - if (getSlots(button.getButtonKey()).contains(slot)) - is.talk(true); - }); - return is.thanks(); - } - - /** - * If the slot is an object builder button, adds the listener. - * - * @param slot the slot - * @param player the player - * @param sound the sound - */ - public void ifObjectBuilderButtonAddListener(int slot, Player player, - BlobSound sound) { - objectBuilderButtons.values().forEach(button -> { - if (getSlots(button.getButtonKey()).contains(slot)) - button.addListener(player, Optional.ofNullable(sound)); - }); - } - - /** - * If the slot is an object builder button, adds the listener. - * - * @param slot the slot - * @param player the player - */ - public boolean ifObjectBuilderButtonAddListener(int slot, Player player) { - for (ObjectBuilderButton button : objectBuilderButtons.values()) { - String key = button.getButtonKey(); - Set set = getSlots(key); - if (set == null) { - continue; - } - if (getSlots(button.getButtonKey()).contains(slot)) { - button.addListener(player); - return true; - } - } - return false; - } - - /** - * Handles all buttons, including build button. - * Used in InventoryClickEvent, slot parameter - * should be event.getRawSlot(). - * - * @param slot the slot - * @param player the player - */ - public void handle(int slot, Player player) { - boolean isObjectBuilderButton = ifObjectBuilderButtonAddListener(slot, player); - if (isObjectBuilderButton) - return; - if (isBuildButton(slot)) - build(); - } - - /** - * Adds an object builder button. - * - * @param builderButton the button - * @return this - */ - public ObjectBuilder addObjectBuilderButton(ObjectBuilderButton builderButton) { - objectBuilderButtons.put(builderButton.getButtonKey(), builderButton); - return this; - } - - /** - * Add a quick String button. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addQuickStringButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_STRING(buttonKey, timeout, this)); - } - - /** - * Add a quick byte button. Accepts negative values. - * If input equalsIgnoreCase 'null', button's value will be set null. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addQuickByteButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_BYTE(buttonKey, timeout, this)); - } - - /** - * Add a quick short button. Accepts negative values. - * If input equalsIgnoreCase 'null', button's value will be set null. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addQuickShortButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_SHORT(buttonKey, timeout, this)); - } - - /** - * Add a quick integer button. Accepts negative values. - * If input equalsIgnoreCase 'null', button's value will be set null. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addQuickIntegerButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_INTEGER(buttonKey, timeout, this)); - } - - /** - * Add a quick long button. Accepts negative values. - * If input equalsIgnoreCase 'null', button's value will be set null. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addQuickLongButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_LONG(buttonKey, timeout, this)); - } - - /** - * Add a quick float button. Accepts negative values. - * If input equalsIgnoreCase 'null', button's value will be set null. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addQuickFloatButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_FLOAT(buttonKey, timeout, this)); - } - - /** - * Add a quick double button. Accepts negative values. - * If input equalsIgnoreCase 'null', button's value will be set null. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addQuickDoubleButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_DOUBLE(buttonKey, timeout, this)); - } - - /** - * Add a quick block button. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addQuickBlockButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_BLOCK(buttonKey, timeout, this)); - } - - /** - * Add a quick block button. - * Will use the block above selection. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addQuickAboveBlockButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ABOVE_BLOCK(buttonKey, timeout, this)); - } - - /** - * Add a quick item button. - * - * @param buttonKey the button key - * @return this - */ - public ObjectBuilder addQuickItemButton(String buttonKey) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ITEM(buttonKey, this)); - } - - /** - * Add a quick selector button. - * - * @param buttonKey the button key - * @param selector the selector - * @param ifAvailable the if available - * @return this - */ - public ObjectBuilder addQuickSelectorButton(String buttonKey, - VariableSelector selector, - Function ifAvailable) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_SELECTOR(buttonKey, selector, ifAvailable, this)); - } - - /** - * Add a quick message button. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addQuickMessageButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_MESSAGE(buttonKey, timeout, this)); - } - - /** - * Add a quick world button. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addQuickWorldButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_WORLD(buttonKey, timeout, this)); - } - - /** - * Add a quick action block button which accepts a consumer when input is given. - * - * @param buttonKey the button key - * @param timeout the timeout - * @param consumer the consumer (which is of Block type) - * @return The button - */ - public ObjectBuilder addQuickActionBlockButton(String buttonKey, long timeout, Consumer consumer) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ACTION_BLOCK( - buttonKey, timeout, this, consumer)); - } - - /** - * Add a quick action item button which accepts a consumer when input is given. - * - * @param buttonKey the button key - * @param consumer the consumer (which is of ItemStack type) - * @return The button - */ - public ObjectBuilder addQuickActionItemButton(String buttonKey, Consumer consumer) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ACTION_ITEM( - buttonKey, this, consumer)); - } - - /** - * Add a quick action selector button which accepts a consumer when input is given. - * - * @param buttonKey The key of the button - * @param selector The selector - * @param ifAvailable The if available - * @param consumer The consumer (which is of T type) - * @return The button - */ - public ObjectBuilder addQuickActionSelectorButton(String buttonKey, - VariableSelector selector, - Function ifAvailable, - Consumer consumer) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ACTION_SELECTOR( - buttonKey, selector, ifAvailable, this, consumer)); - } - - /** - * Add a quick world button which accepts a consumer when input is given. - * - * @param buttonKey The key of the button - * @param timeout The timeout - * @param consumer The consumer (which is a ReferenceBlobMessage) - * @return The button - */ - public ObjectBuilder addQuickActionMessageButton(String buttonKey, long timeout, Consumer consumer) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ACTION_MESSAGE( - buttonKey, timeout, this, consumer)); - } - - /** - * A quick ObjectBuilderButton for Worlds that accepts - * a consumer when input is given. - * - * @param buttonKey The key of the button - * @param timeout The timeout - * @param consumer The consumer (which is a World) - * @return The button - */ - public ObjectBuilder addQuickActionWorldButton(String buttonKey, long timeout, Consumer consumer) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.QUICK_ACTION_WORLD( - buttonKey, timeout, this, consumer)); - } - - - /** - * Add a positive byte button. - * if input is lower than 0, button - * will be empty. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addPositiveByteButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.POSITIVE_BYTE(buttonKey, timeout, this)); - } - - /** - * Add a positive short button. - * if input is lower than 0, button - * will be empty. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addPositiveShortButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.POSITIVE_SHORT(buttonKey, timeout, this)); - } - - /** - * Add a positive integer button. - * if input is lower than 0, button - * will be empty. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addPositiveIntegerButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.POSITIVE_INTEGER(buttonKey, timeout, this)); - } - - /** - * Add a positive long button. - * if input is lower than 0, button - * will be empty. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addPositiveLongButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.POSITIVE_LONG(buttonKey, timeout, this)); - } - - /** - * Add a positive float button. - * if input is lower than 0, button - * will be empty. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addPositiveFloatButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.POSITIVE_FLOAT(buttonKey, timeout, this)); - } - - /** - * Add a positive double button. - * if input is lower than 0, button - * will be empty. - * - * @param buttonKey the button key - * @param timeout the timeout - * @return this - */ - public ObjectBuilder addPositiveDoubleButton(String buttonKey, long timeout) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.POSITIVE_DOUBLE(buttonKey, timeout, this)); - } - - /** - * A quick navigator for booleans. - * Value cannot be empty nor null. - * By default, the value is false. - * - * @param buttonKey The key of the button - * @return The button - */ - public ObjectBuilder addBoolean(String buttonKey) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.BOOLEAN(buttonKey, this)); - } - - /** - * A quick navigator for booleans. - * Value cannot be empty nor null. - * By default, the value is true. - * - * @param buttonKey The key of the button - * @return The button - */ - public ObjectBuilder addBooleanDefaultTrue(String buttonKey) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.BOOLEAN_DEFAULT_TRUE(buttonKey, this)); - } - - /** - * A quick navigator for any type of array. - * Value cannot be empty nor null. - * By default, the value is the first element of the array. - * - * @param buttonKey The key of the button - * @param enumClass The enum class - * @return The button - */ - public > ObjectBuilder addEnumNavigator(String buttonKey, Class enumClass) { - return addObjectBuilderButton(ObjectBuilderButtonBuilder.ENUM_NAVIGATOR(buttonKey, enumClass, this)); - } - - /** - * Set the function to be called when the build button is clicked - * - * @param function the function to be called - * @return this - */ - public ObjectBuilder setFunction(Function, T> function) { - this.function = function; - return this; - } } diff --git a/src/main/java/us/mytheria/bloblib/entities/inventory/ObjectBuilderButtonBuilder.java b/src/main/java/us/mytheria/bloblib/entities/inventory/ObjectBuilderButtonBuilder.java index 93502dc6..cab8bb07 100644 --- a/src/main/java/us/mytheria/bloblib/entities/inventory/ObjectBuilderButtonBuilder.java +++ b/src/main/java/us/mytheria/bloblib/entities/inventory/ObjectBuilderButtonBuilder.java @@ -86,7 +86,7 @@ public static ObjectBuilderButton SIMPLE_STRING(String buttonKey, long t * @return The button */ public static ObjectBuilderButton QUICK_STRING(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return STRING(buttonKey, timeout, "Builder." + buttonKey + "-Timeout", "Builder." + buttonKey, @@ -173,7 +173,7 @@ public static ObjectBuilderButton SIMPLE_BYTE(String buttonKey, long timeo * @return The button */ public static ObjectBuilderButton QUICK_BYTE(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return BYTE(buttonKey, timeout, "Builder." + buttonKey @@ -206,7 +206,7 @@ public static ObjectBuilderButton QUICK_BYTE(String buttonKey, long timeou * @return The button */ public static ObjectBuilderButton POSITIVE_BYTE(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); Function function = value -> { objectBuilder.updateDefaultButton(buttonKey, "%" + placeholderRegex + "%", @@ -306,7 +306,7 @@ public static ObjectBuilderButton SIMPLE_SHORT(String buttonKey, long tim * @return The button */ public static ObjectBuilderButton QUICK_SHORT(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return SHORT(buttonKey, timeout, "Builder." + buttonKey @@ -338,7 +338,7 @@ public static ObjectBuilderButton QUICK_SHORT(String buttonKey, long time * @return The button */ public static ObjectBuilderButton POSITIVE_SHORT(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); Function function = value -> { objectBuilder.updateDefaultButton(buttonKey, "%" + placeholderRegex + "%", @@ -438,7 +438,7 @@ public static ObjectBuilderButton SIMPLE_INTEGER(String buttonKey, long * @return The button */ public static ObjectBuilderButton QUICK_INTEGER(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return INTEGER(buttonKey, timeout, "Builder." + buttonKey @@ -470,7 +470,7 @@ public static ObjectBuilderButton QUICK_INTEGER(String buttonKey, long * @return The button */ public static ObjectBuilderButton POSITIVE_INTEGER(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); Function function = value -> { @@ -571,7 +571,7 @@ public static ObjectBuilderButton SIMPLE_LONG(String buttonKey, long timeo * @return The button */ public static ObjectBuilderButton QUICK_LONG(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return LONG(buttonKey, timeout, "Builder." + buttonKey @@ -603,7 +603,7 @@ public static ObjectBuilderButton QUICK_LONG(String buttonKey, long timeou * @return The button */ public static ObjectBuilderButton POSITIVE_LONG(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); Function function = value -> { @@ -704,7 +704,7 @@ public static ObjectBuilderButton SIMPLE_FLOAT(String buttonKey, long tim * @return The button */ public static ObjectBuilderButton QUICK_FLOAT(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return FLOAT(buttonKey, timeout, "Builder." + buttonKey @@ -736,7 +736,7 @@ public static ObjectBuilderButton QUICK_FLOAT(String buttonKey, long time * @return The button */ public static ObjectBuilderButton POSITIVE_FLOAT(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); Function function = value -> { @@ -837,7 +837,7 @@ public static ObjectBuilderButton SIMPLE_DOUBLE(String buttonKey, long t * @return The button */ public static ObjectBuilderButton QUICK_DOUBLE(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return DOUBLE(buttonKey, timeout, "Builder." + buttonKey @@ -869,7 +869,7 @@ public static ObjectBuilderButton QUICK_DOUBLE(String buttonKey, long ti * @return The button */ public static ObjectBuilderButton POSITIVE_DOUBLE(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); Function function = value -> { objectBuilder.updateDefaultButton(buttonKey, "%" + placeholderRegex + "%", @@ -977,7 +977,7 @@ public static ObjectBuilderButton SIMPLE_BLOCK(String buttonKey, long tim * @return The button */ public static ObjectBuilderButton QUICK_BLOCK(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return BLOCK(buttonKey, timeout, "Builder." + buttonKey @@ -1011,7 +1011,7 @@ public static ObjectBuilderButton QUICK_BLOCK(String buttonKey, long time * @return The button */ public static ObjectBuilderButton QUICK_ABOVE_BLOCK(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return ABOVE_BLOCK(buttonKey, timeout, "Builder." + buttonKey @@ -1036,7 +1036,7 @@ public static ObjectBuilderButton QUICK_ABOVE_BLOCK(String buttonKey, lon */ public static ObjectBuilderButton QUICK_ACTION_BLOCK(String buttonKey, long timeout, - ObjectBuilder objectBuilder, + BlobObjectBuilder objectBuilder, Consumer consumer) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return BLOCK(buttonKey, timeout, "Builder." + buttonKey @@ -1097,7 +1097,7 @@ public static ObjectBuilderButton SIMPLE_ITEM(String buttonKey, * @return The button */ public static ObjectBuilderButton QUICK_ITEM(String buttonKey, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return ITEM(buttonKey, "Builder.ItemStack", itemStack -> { objectBuilder.updateDefaultButton(buttonKey, "%" + placeholderRegex + "%", @@ -1117,7 +1117,7 @@ public static ObjectBuilderButton QUICK_ITEM(String buttonKey, * @return The button */ public static ObjectBuilderButton QUICK_ACTION_ITEM(String buttonKey, - ObjectBuilder objectBuilder, + BlobObjectBuilder objectBuilder, Consumer consumer) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return ITEM(buttonKey, "Builder.ItemStack", itemStack -> { @@ -1189,7 +1189,7 @@ public static ObjectBuilderButton SIMPLE_SELECTOR(String buttonKey, public static ObjectBuilderButton QUICK_SELECTOR(String buttonKey, VariableSelector selector, Function ifAvailable, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return SELECTOR(buttonKey, "Builder." + buttonKey, t -> { objectBuilder.updateDefaultButton(buttonKey, "%" + placeholderRegex + "%", @@ -1214,7 +1214,7 @@ public static ObjectBuilderButton QUICK_SELECTOR(String buttonKey, public static ObjectBuilderButton QUICK_ACTION_SELECTOR(String buttonKey, VariableSelector selector, Function ifAvailable, - ObjectBuilder objectBuilder, + BlobObjectBuilder objectBuilder, Consumer consumer) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return SELECTOR(buttonKey, "Builder." + buttonKey, t -> { @@ -1286,7 +1286,7 @@ public static ObjectBuilderButton SIMPLE_MESSAGE(String buttonKey, */ public static ObjectBuilderButton QUICK_MESSAGE(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return MESSAGE(buttonKey, timeout, "Builder." + buttonKey + "-Timeout", "Builder." + buttonKey, message -> { @@ -1309,7 +1309,7 @@ public static ObjectBuilderButton QUICK_MESSAGE(String buttonKey, */ public static ObjectBuilderButton QUICK_ACTION_MESSAGE(String buttonKey, long timeout, - ObjectBuilder objectBuilder, + BlobObjectBuilder objectBuilder, Consumer consumer) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return MESSAGE(buttonKey, timeout, "Builder." + buttonKey + "-Timeout", @@ -1382,7 +1382,7 @@ public static ObjectBuilderButton SIMPLE_WORLD(String buttonKey, long tim */ public static ObjectBuilderButton QUICK_WORLD(String buttonKey, long timeout, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return WORLD(buttonKey, timeout, "Builder." + buttonKey + "-Timeout", "Builder." + buttonKey, world -> { @@ -1405,7 +1405,7 @@ public static ObjectBuilderButton QUICK_WORLD(String buttonKey, */ public static ObjectBuilderButton QUICK_ACTION_WORLD(String buttonKey, long timeout, - ObjectBuilder objectBuilder, + BlobObjectBuilder objectBuilder, Consumer consumer) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return WORLD(buttonKey, timeout, "Builder." + buttonKey + "-Timeout", @@ -1428,7 +1428,7 @@ public static ObjectBuilderButton QUICK_ACTION_WORLD(String buttonKey, * @return The button */ public static ObjectBuilderButton BOOLEAN(String buttonKey, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return NAVIGATOR(buttonKey, new Boolean[]{false, true}, value -> { objectBuilder.updateDefaultButton(buttonKey, "%" + placeholderRegex + "%", @@ -1448,7 +1448,7 @@ public static ObjectBuilderButton BOOLEAN(String buttonKey, * @return The button */ public static ObjectBuilderButton BOOLEAN_DEFAULT_TRUE(String buttonKey, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); return NAVIGATOR(buttonKey, new Boolean[]{true, false}, value -> { objectBuilder.updateDefaultButton(buttonKey, "%" + placeholderRegex + "%", @@ -1498,7 +1498,7 @@ public static ObjectBuilderButton NAVIGATOR(String buttonKey, */ public static > ObjectBuilderButton ENUM_NAVIGATOR(String buttonKey, Class enumClass, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); T[] array = enumClass.getEnumConstants(); return NAVIGATOR(buttonKey, array, value -> { @@ -1520,7 +1520,7 @@ public static > ObjectBuilderButton ENUM_NAVIGATOR(String b */ public static ObjectBuilderButton BLOB_EDITOR(String buttonKey, BlobEditor blobEditor, - ObjectBuilder objectBuilder) { + BlobObjectBuilder objectBuilder) { String placeholderRegex = NamingConventions.toCamelCase(buttonKey); diff --git a/src/main/resources/CurrencyBuilder.yml b/src/main/resources/CurrencyBuilder.yml index e71435a7..1b2d97bb 100644 --- a/src/main/resources/CurrencyBuilder.yml +++ b/src/main/resources/CurrencyBuilder.yml @@ -61,6 +61,6 @@ Buttons: CustomModelData: 0 DisplayName: "&6Build" Lore: - - "&7Click to add reward" + - "&7Click to add currency" - "&7to the files." Slot: 22 \ No newline at end of file