diff --git a/ci-pom.xml b/ci-pom.xml
index 6a112dcb..03158908 100644
--- a/ci-pom.xml
+++ b/ci-pom.xml
@@ -7,7 +7,7 @@
us.mytheria
BlobLib
- 1.697.4
+ 1.697.6
pom.xml
bloblib
diff --git a/local-pom.xml b/local-pom.xml
index d91e96c9..a0e4348d 100644
--- a/local-pom.xml
+++ b/local-pom.xml
@@ -5,7 +5,7 @@
us.mytheria
BlobLib
- 1.697.4
+ 1.697.6
pom.xml
bloblib
diff --git a/pom.xml b/pom.xml
index fb4648be..3c07794c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
us.mytheria
BlobLib
- 1.697.4
+ 1.697.6
pom
diff --git a/src/main/java/us/mytheria/bloblib/api/BlobLibInventoryAPI.java b/src/main/java/us/mytheria/bloblib/api/BlobLibInventoryAPI.java
index 0eab7951..82373d75 100644
--- a/src/main/java/us/mytheria/bloblib/api/BlobLibInventoryAPI.java
+++ b/src/main/java/us/mytheria/bloblib/api/BlobLibInventoryAPI.java
@@ -334,6 +334,38 @@ public MetaBlobInventory buildMetaInventory(@NotNull String key,
return buildMetaInventory(key, player.getLocale());
}
+ /**
+ * Will make Player to select from a list of elements.
+ * The selector will be placed in the inventory at the specified buttonRangeKey.
+ * The inventory will open automatically.
+ * Clicking the return button will close the selector inventory.
+ *
+ * @param blobInventoryKey the key of the BlobInventory
+ * @param player the player
+ * @param buttonRangeKey the button from the BlobInventory which contains the slots (per page) into which the selector will place the elements
+ * @param dataType the data type of the selector
+ * @param selectorList the list of elements to select from
+ * @param onSelect what's consumed when an element is selected
+ * @param display the function to display an element, needs to return the ItemStack to display
+ * @param the type of the selector
+ * @return the selector
+ */
+ public BlobSelector customSelector(@NotNull String blobInventoryKey,
+ @NotNull Player player,
+ @NotNull String buttonRangeKey,
+ @NotNull String dataType,
+ @NotNull Supplier> selectorList,
+ @NotNull Consumer onSelect,
+ @Nullable Function display) {
+ return customSelector(blobInventoryKey,
+ player,
+ buttonRangeKey,
+ dataType,
+ selectorList,
+ onSelect,
+ display, null);
+ }
+
/**
* Will make Player to select from a list of elements.
* The selector will be placed in the inventory at the specified buttonRangeKey.
@@ -404,6 +436,48 @@ public BlobSelector selector(@NotNull Player player,
display, null);
}
+ /**
+ * Will allow player to edit a collection of elements.
+ * The editor will be placed in the inventory at the specified buttonRangeKey.
+ * The inventory will open automatically.
+ * Clicking the return button will close the editor inventory.
+ *
+ * @param blobInventoryKey the key of the BlobInventory
+ * @param player the player
+ * @param buttonRangeKey the button from the BlobInventory which contains the slots (per page) into which the editor will place the elements
+ * @param dataType the data type of the editor
+ * @param addCollection the collection of elements to add to
+ * @param onAdd what's consumed when an element is added
+ * @param addDisplay the function to display an element, needs to return the ItemStack to display
+ * @param viewCollection the collection of elements to view
+ * @param removeDisplay the function to display an element, needs to return the ItemStack to display
+ * @param onRemove what's consumed when an element is removed
+ * @param the type of the editor
+ * @return the editor
+ */
+ @Nullable
+ public BlobEditor customEditor(@NotNull String blobInventoryKey,
+ @NotNull Player player,
+ @NotNull String buttonRangeKey,
+ @NotNull String dataType,
+ @NotNull Supplier> addCollection,
+ @NotNull Consumer onAdd,
+ @Nullable Function addDisplay,
+ @NotNull Supplier> viewCollection,
+ @NotNull Function removeDisplay,
+ @NotNull Consumer onRemove) {
+ return customEditor(blobInventoryKey,
+ player,
+ buttonRangeKey,
+ dataType,
+ addCollection,
+ onAdd,
+ addDisplay,
+ viewCollection,
+ removeDisplay,
+ onRemove, null);
+ }
+
/**
* Will allow player to edit a collection of elements.
* The editor will be placed in the inventory at the specified buttonRangeKey.
diff --git a/src/main/java/us/mytheria/bloblib/entities/BlobFileManager.java b/src/main/java/us/mytheria/bloblib/entities/BlobFileManager.java
index 1ca6f107..1537125b 100644
--- a/src/main/java/us/mytheria/bloblib/entities/BlobFileManager.java
+++ b/src/main/java/us/mytheria/bloblib/entities/BlobFileManager.java
@@ -119,12 +119,27 @@ public void addFile(String key, File file) {
* @return if it's a fresh file / was just created.
*/
public boolean updateYAML(File file) {
+ return updateYAML(file, null);
+ }
+
+ /**
+ * It will auto update it with the most recent
+ * version that's embedded in the plugin jar.
+ *
+ * @param file the YAML file to update
+ * @param path the path to the embedded file
+ * @return if it's a fresh file / was just created.
+ */
+ public boolean updateYAML(File file, String path) {
+ if (path == null)
+ path = file.getName();
String fileName = FilenameUtils.removeExtension(file.getName());
+ file.getParentFile().mkdirs();
try {
boolean isFresh = file.createNewFile();
ResourceUtil.updateYml(file.getParentFile(),
"/temp" + fileName + ".yml",
- fileName + ".yml", file, getPlugin());
+ path, file, getPlugin());
return isFresh;
} catch (IOException e) {
e.printStackTrace();
diff --git a/src/main/java/us/mytheria/bloblib/entities/FileDetachment.java b/src/main/java/us/mytheria/bloblib/entities/FileDetachment.java
new file mode 100644
index 00000000..eaab340b
--- /dev/null
+++ b/src/main/java/us/mytheria/bloblib/entities/FileDetachment.java
@@ -0,0 +1,6 @@
+package us.mytheria.bloblib.entities;
+
+import java.io.File;
+
+public record FileDetachment(File file, boolean isFresh) {
+}
diff --git a/src/main/java/us/mytheria/bloblib/entities/ObjectDirector.java b/src/main/java/us/mytheria/bloblib/entities/ObjectDirector.java
index ed843ae2..86c02b60 100644
--- a/src/main/java/us/mytheria/bloblib/entities/ObjectDirector.java
+++ b/src/main/java/us/mytheria/bloblib/entities/ObjectDirector.java
@@ -11,6 +11,7 @@
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import us.mytheria.bloblib.api.BlobLibMessageAPI;
+import us.mytheria.bloblib.api.BlobLibTranslatableAPI;
import us.mytheria.bloblib.entities.inventory.ObjectBuilder;
import us.mytheria.bloblib.itemstack.ItemStackBuilder;
import us.mytheria.bloblib.managers.Manager;
@@ -369,7 +370,8 @@ public void removeObject(Player player) {
String key = object.getKey();
ItemStackBuilder builder = ItemStackBuilder.build(Material.COMMAND_BLOCK);
builder.displayName(key);
- builder.lore();
+ builder.lore(BlobLibTranslatableAPI.getInstance()
+ .getTranslatableBlock("BlobLib.Remove-Element", player).get());
if (ItemStack.class.isInstance(object.getClass())) {
ItemStack itemStack = (ItemStack) object;
builder.displayName(ItemStackUtil.display(itemStack));
diff --git a/src/main/java/us/mytheria/bloblib/entities/inventory/InventoryDataRegistry.java b/src/main/java/us/mytheria/bloblib/entities/inventory/InventoryDataRegistry.java
index e998a9c3..242b74c9 100644
--- a/src/main/java/us/mytheria/bloblib/entities/inventory/InventoryDataRegistry.java
+++ b/src/main/java/us/mytheria/bloblib/entities/inventory/InventoryDataRegistry.java
@@ -19,7 +19,7 @@ public class InventoryDataRegistry {
@NotNull
private final String defaultLocale, key;
private final Map> carriers;
- private final Map> clickEvents;
+ private final Map> buttonClickEvents;
/**
* Will instantiate a new InventoryDataRegistry with the specified default locale.
@@ -39,7 +39,7 @@ private InventoryDataRegistry(@NotNull String defaultLocale, @NotNull String key
this.defaultLocale = defaultLocale;
this.key = key;
this.carriers = new HashMap<>();
- this.clickEvents = new HashMap<>();
+ this.buttonClickEvents = new HashMap<>();
}
/**
@@ -51,9 +51,9 @@ private InventoryDataRegistry(@NotNull String defaultLocale, @NotNull String key
public boolean process(@NotNull InventoryBuilderCarrier carrier) {
Objects.requireNonNull(carrier, "carrier cannot be null");
String locale = carrier.locale();
- if (this.carriers.containsKey(locale))
+ if (carriers.containsKey(locale))
return false;
- this.carriers.put(locale, carrier);
+ carriers.put(locale, carrier);
return true;
}
@@ -93,7 +93,7 @@ public String getKey() {
* @param event the click event
*/
public void onClick(String button, Consumer event) {
- this.clickEvents.put(button, event);
+ this.buttonClickEvents.put(button, event);
}
/**
@@ -103,7 +103,7 @@ public void onClick(String button, Consumer event) {
* @param event the click event
*/
public void processClickEvent(String button, InventoryClickEvent event) {
- Consumer clickEvent = this.clickEvents.get(button);
+ Consumer clickEvent = this.buttonClickEvents.get(button);
if (clickEvent == null)
return;
clickEvent.accept(event);
diff --git a/src/main/java/us/mytheria/bloblib/managers/ManagerDirector.java b/src/main/java/us/mytheria/bloblib/managers/ManagerDirector.java
index 1e3586ce..42c133c3 100644
--- a/src/main/java/us/mytheria/bloblib/managers/ManagerDirector.java
+++ b/src/main/java/us/mytheria/bloblib/managers/ManagerDirector.java
@@ -1,7 +1,6 @@
package us.mytheria.bloblib.managers;
import me.anjoismysign.anjo.logger.Logger;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
@@ -17,11 +16,7 @@
import us.mytheria.bloblib.utilities.ResourceUtil;
import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
+import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -448,209 +443,232 @@ public BlobPlugin getPlugin() {
/**
* Will detach an embedded file/asset from the plugin jar to
* the corresponding directory.
- * It won't replace the file if it already exists.
+ * If file extension is '.yml', it won't replace the file if it already exists.
* If file does not exist, it will create it and then copy the
* embedded file/asset to it.
+ * Allows custom output directory based on fileName.
+ * "detachAsset("es_es/lang.yml", false, new File("plugins"))"
+ * Would detach the file to "plugins/es_es/lang.yml".
*
* @param fileName The name of the file to detach. Needs to include the extension.
* @param debug Whether to print debug messages
* @param path The path to the directory
* @return The ManagerDirector instance for method chaining
*/
- public ManagerDirector detachAsset(String fileName, boolean debug, File path) {
+ public FileDetachment detachAsset(String fileName, boolean debug, File path) {
Logger logger = getPlugin().getAnjoLogger();
+ String[] split = fileName.split("/");
+ String original = fileName;
+ if (split.length > 1) {
+ String end = split[split.length - 1];
+ path = new File(path + "/" + fileName.replace(end, ""));
+ fileName = end;
+ }
File file = new File(path + "/" + fileName);
boolean successful = false;
- String extenstion = FilenameUtils.getExtension(fileName);
- if (extenstion.equals("yml")) {
- if (!file.exists()) {
- try {
- file.createNewFile();
- successful = true;
- } catch (IOException e) {
- if (debug)
- logger.debug(" asset " + fileName + " was not detached");
- e.printStackTrace();
- return this;
- }
- }
- ResourceUtil.updateYml(path, "/temp" + fileName + ".yml", fileName + ".yml", file, plugin);
- successful = MessageManager.loadAndRegisterYamlConfiguration(file, plugin);
+ String extension = FilenameUtils.getExtension(fileName);
+ boolean isFresh = !file.exists();
+ if (extension.equals("yml")) {
+ blobFileManager.updateYAML(file, original);
} else {
if (!file.exists())
successful = true;
- ResourceUtil.moveResource(file, plugin.getResource(fileName));
+ ResourceUtil.moveResource(file, plugin.getResource(original));
}
if (debug && successful)
- logger.debug(" asset " + fileName + ".yml successfully detached");
- return this;
+ logger.debug(" asset " + original + " successfully detached");
+ return new FileDetachment(file, isFresh);
+ }
+
+ private String[] addYml(String... fileNames) {
+ for (int i = 0; i < fileNames.length; i++) {
+ fileNames[i] = fileNames[i] + ".yml";
+ }
+ return fileNames;
+ }
+
+ private File[] freshFiles(boolean debug, File path, String... fileNames) {
+ List files = new ArrayList<>();
+ for (String fileName : fileNames) {
+ FileDetachment detachment = detachAsset(fileName, debug, path);
+ if (detachment.isFresh())
+ files.add(detachment.file());
+ }
+ return files.toArray(new File[0]);
}
/**
- * Will detach an embedded BlobMessage file/asset from the plugin jar to
- * the corresponding directory in the plugin data folder.
+ * Will detach all MetaInventories provided.
+ * If they already exist, they won't be replaced.
*
- * @param fileName The name of the file to detach
- * @param debug Whether to print debug messages
+ * @param debug Whether to print debug messages
+ * @param fileNames The names of the files to detach. Needs to include the extension.
* @return The ManagerDirector instance for method chaining
*/
- public ManagerDirector detachMessageAsset(String fileName, boolean debug) {
- File path = getRealFileManager().messagesDirectory();
- return detachAsset(fileName + ".yml", debug, path);
+ public ManagerDirector registerMetaBlobInventory(boolean debug, String... fileNames) {
+ String[] yaml = addYml(fileNames);
+ File[] freshFiles = freshFiles(debug, getRealFileManager().metaInventoriesDirectory(), yaml);
+ InventoryManager.continueLoadingMetaInventories(plugin, freshFiles);
+ if (debug)
+ getPlugin().getAnjoLogger().debug(" inventory asset " + Arrays.toString(fileNames) + " successfully registered");
+ return this;
}
/**
- * Will detach an embedded BlobMessage file/asset from the plugin jar to
- * the corresponding directory in the plugin data folder.
- * Will not print debug messages.
+ * Will detach all MetaInventories provided.
+ * If they already exist, they won't be replaced.
+ * It won't print debug messages.
*
- * @param fileName The name of the file to detach
+ * @param fileNames The names of the files to detach. Needs to include the extension.
* @return The ManagerDirector instance for method chaining
*/
- public ManagerDirector detachMessageAsset(String fileName) {
- return detachMessageAsset(fileName, false);
+ public ManagerDirector registerMetaBlobInventory(String... fileNames) {
+ return registerMetaBlobInventory(false, fileNames);
}
/**
- * Will detach an embedded BlobSound file/asset from the plugin jar to
- * the corresponding directory in the plugin data folder.
+ * Will detach all BlobInventories provided.
+ * If they already exist, they won't be replaced.
*
- * @param fileName The name of the file to detach
- * @param debug Whether to print debug messages
+ * @param debug Whether to print debug messages
+ * @param fileNames The names of the files to detach. Needs to include the extension.
* @return The ManagerDirector instance for method chaining
*/
- public ManagerDirector detachSoundAsset(String fileName, boolean debug) {
- File path = getRealFileManager().soundsDirectory();
- return detachAsset(fileName + ".yml", debug, path);
+ public ManagerDirector registerBlobInventory(boolean debug, String... fileNames) {
+ String[] yaml = addYml(fileNames);
+ File[] freshFiles = freshFiles(debug, getRealFileManager().inventoriesDirectory(), yaml);
+ InventoryManager.continueLoadingBlobInventories(plugin, freshFiles);
+ if (debug)
+ getPlugin().getAnjoLogger().debug(" inventory asset " + Arrays.toString(fileNames) + ".yml successfully registered");
+ return this;
}
/**
- * Will detach an embedded BlobSound file/asset from the plugin jar to
- * the corresponding directory in the plugin data folder.
- * Will not print debug messages.
+ * Will detach all BlobInventories provided.
+ * If they already exist, they won't be replaced.
+ * It won't print debug messages.
*
- * @param fileName The name of the file to detach
+ * @param fileNames The names of the files to detach. Needs to include the extension.
* @return The ManagerDirector instance for method chaining
*/
- public ManagerDirector detachSoundAsset(String fileName) {
- return detachSoundAsset(fileName, false);
+ public ManagerDirector registerBlobInventory(String... fileNames) {
+ return registerBlobInventory(false, fileNames);
}
/**
- * Will detach an embedded Inventory file/asset from the plugin jar to
- * the corresponding directory in the plugin data folder.
+ * Will detach all BlobMessages provided.
+ * If they already exist, they won't be replaced.
*
- * @param fileName The name of the file to detach
- * @param debug Whether to print debug messages
+ * @param debug Whether to print debug messages
+ * @param fileNames The names of the files to detach. Needs to include the extension.
* @return The ManagerDirector instance for method chaining
*/
- public ManagerDirector registerAndUpdateBlobInventory(String fileName, boolean debug) {
- File path = getRealFileManager().inventoriesDirectory();
- File file = new File(path + "/" + fileName + ".yml");
- if (!blobFileManager.updateYAML(file))
- return this;
- InventoryManager.continueLoadingBlobInventories(plugin, file);
+ public ManagerDirector registerBlobMessage(boolean debug, String... fileNames) {
+ String[] yaml = addYml(fileNames);
+ File[] freshFiles = freshFiles(debug, getRealFileManager().messagesDirectory(), yaml);
+ MessageManager.continueLoadingMessages(plugin, true, freshFiles);
if (debug)
- getPlugin().getAnjoLogger().debug(" inventory asset " + fileName + ".yml successfully registered");
+ getPlugin().getAnjoLogger().debug(" message asset " + Arrays.toString(fileNames) + " successfully registered");
return this;
}
/**
- * Will detach an embedded Inventory file/asset from the plugin jar to
- * the corresponding directory in the plugin data folder.
- * Will not print debug messages.
+ * Will detach all BlobMessages provided.
+ * If they already exist, they won't be replaced.
+ * It won't print debug messages.
*
- * @param fileName The name of the file to detach
+ * @param fileNames The names of the files to detach. Needs to include the extension.
* @return The ManagerDirector instance for method chaining
*/
- public ManagerDirector registerAndUpdateBlobInventory(String fileName) {
- return registerAndUpdateBlobInventory(fileName, false);
+ public ManagerDirector registerBlobMessage(String... fileNames) {
+ return registerBlobMessage(false, fileNames);
}
/**
- * Will detach an embedded Inventory file/asset from the plugin jar to
- * the corresponding directory in the plugin data folder.
+ * Will detach all BlobSounds provided.
+ * If they already exist, they won't be replaced.
*
- * @param fileName The name of the file to detach
- * @param debug Whether to print debug messages
+ * @param debug Whether to print debug messages
+ * @param fileNames The names of the files to detach. Needs to include the extension.
* @return The ManagerDirector instance for method chaining
*/
- public ManagerDirector registerAndUpdateMetaBlobInventory(String fileName, boolean debug) {
- File path = getRealFileManager().metaInventoriesDirectory();
- File file = new File(path + "/" + fileName + ".yml");
- if (!blobFileManager.updateYAML(file))
- return this;
- InventoryManager.continueLoadingMetaInventories(plugin, file);
+ public ManagerDirector registerBlobSound(boolean debug, String... fileNames) {
+ String[] yaml = addYml(fileNames);
+ File[] freshFiles = freshFiles(debug, getRealFileManager().soundsDirectory(), yaml);
+ SoundManager.continueLoadingSounds(plugin, true, freshFiles);
if (debug)
- getPlugin().getAnjoLogger().debug(" inventory asset " + fileName + ".yml successfully registered");
+ getPlugin().getAnjoLogger().debug(" sound asset " + Arrays.toString(fileNames) + " successfully registered");
return this;
}
/**
- * Will detach an embedded Inventory file/asset from the plugin jar to
- * the corresponding directory in the plugin data folder.
- * Will not print debug messages.
+ * Will detach all BlobSounds provided.
+ * If they already exist, they won't be replaced.
+ * It won't print debug messages.
*
- * @param fileName The name of the file to detach
+ * @param fileNames The names of the files to detach. Needs to include the extension.
* @return The ManagerDirector instance for method chaining
*/
- public ManagerDirector registerAndUpdateMetaBlobInventory(String fileName) {
- return registerAndUpdateMetaBlobInventory(fileName, false);
- }
-
- private ManagerDirector registerAsset(String fileName, boolean debug,
- File path, String type) {
- BlobPlugin plugin = getPlugin();
- fileName = fileName + ".yml";
- File file = new File(path + "/" + fileName);
- if (file.exists()) {
- if (debug)
- getPlugin().getAnjoLogger().debug(" " + type + " asset " +
- fileName + ".yml was not registered, already exists");
- return this;
- }
- try {
- FileUtils.copyToFile(plugin.getResource(fileName), file);
- if (debug)
- getPlugin().getAnjoLogger().debug(" " + type + " asset " +
- fileName + ".yml successfully registered");
- return this;
- } catch (IOException e) {
- e.printStackTrace();
- return this;
- }
- }
-
- public ManagerDirector registerMetaBlobInventory(String fileName, boolean debug) {
- return registerAsset(fileName, debug, getRealFileManager().metaInventoriesDirectory(), "inventory");
- }
-
- public ManagerDirector registerMetaBlobInventory(String fileName) {
- return registerMetaBlobInventory(fileName, false);
+ public ManagerDirector registerBlobSound(String... fileNames) {
+ return registerBlobSound(false, fileNames);
}
- public ManagerDirector registerBlobInventory(String fileName, boolean debug) {
- return registerAsset(fileName, debug, getRealFileManager().inventoriesDirectory(), "inventory");
- }
-
- public ManagerDirector registerBlobInventory(String fileName) {
- return registerBlobInventory(fileName, false);
- }
-
- public ManagerDirector registerBlobMessage(String fileName, boolean debug) {
- return registerAsset(fileName, debug, getRealFileManager().messagesDirectory(), "message");
+ /**
+ * Will detach all TranslatableBlocks provided.
+ * If they already exist, they won't be replaced.
+ *
+ * @param debug Whether to print debug messages
+ * @param fileNames The names of the files to detach. Needs to include the extension.
+ * @return The ManagerDirector instance for method chaining
+ */
+ public ManagerDirector registerTranslatableBlock(boolean debug, String... fileNames) {
+ String[] yaml = addYml(fileNames);
+ File[] freshFiles = freshFiles(debug, getRealFileManager().translatableBlocksDirectory(), yaml);
+ TranslatableManager.continueLoadingBlocks(plugin, true, freshFiles);
+ if (debug)
+ getPlugin().getAnjoLogger().debug(" translatable block asset " + Arrays.toString(fileNames) + " successfully registered");
+ return this;
}
- public ManagerDirector registerBlobMessage(String fileName) {
- return registerBlobMessage(fileName, false);
+ /**
+ * Will detach all TranslatableBlocks provided.
+ * If they already exist, they won't be replaced.
+ * It won't print debug messages.
+ *
+ * @param fileNames The names of the files to detach. Needs to include the extension.
+ * @return The ManagerDirector instance for method chaining
+ */
+ public ManagerDirector registerTranslatableBlock(String... fileNames) {
+ return registerTranslatableBlock(false, fileNames);
}
- public ManagerDirector registerBlobSound(String fileName, boolean debug) {
- return registerAsset(fileName, debug, getRealFileManager().soundsDirectory(), "sound");
+ /**
+ * Will detach all TranslatableSnippets provided.
+ * If they already exist, they won't be replaced.
+ *
+ * @param debug Whether to print debug messages
+ * @param fileNames The names of the files to detach. Needs to include the extension.
+ * @return The ManagerDirector instance for method chaining
+ */
+ public ManagerDirector registerTranslatableSnippet(boolean debug, String... fileNames) {
+ String[] yaml = addYml(fileNames);
+ File[] freshFiles = freshFiles(debug, getRealFileManager().translatableSnippetsDirectory(), yaml);
+ TranslatableManager.continueLoadingSnippets(plugin, true, freshFiles);
+ if (debug)
+ getPlugin().getAnjoLogger().debug(" translatable block asset " + Arrays.toString(fileNames) + " successfully registered");
+ return this;
}
- public ManagerDirector registerBlobSound(String fileName) {
- return registerBlobSound(fileName, false);
+ /**
+ * Will detach all TranslatableSnippets provided.
+ * If they already exist, they won't be replaced.
+ * It won't print debug messages.
+ *
+ * @param fileNames The names of the files to detach. Needs to include the extension.
+ * @return The ManagerDirector instance for method chaining
+ */
+ public ManagerDirector registerTranslatableSnippet(String... fileNames) {
+ return registerTranslatableSnippet(false, fileNames);
}
protected Set> getManagerEntry() {
diff --git a/src/main/java/us/mytheria/bloblib/managers/MessageManager.java b/src/main/java/us/mytheria/bloblib/managers/MessageManager.java
index d8f2d95e..ab974bf6 100644
--- a/src/main/java/us/mytheria/bloblib/managers/MessageManager.java
+++ b/src/main/java/us/mytheria/bloblib/managers/MessageManager.java
@@ -132,24 +132,14 @@ private boolean addOrCreateLocale(SerialBlobMessage message, String reference) {
return true;
}
- /**
- * Loads a YamlConfiguration from a file and registers it to the plugin.
- * Will return false if the plugin has not been loaded.
- * Will print duplicates.
- * NOTE: Printing duplicates runs for each time you call this method!
- *
- * @param file The file to load
- * @param plugin The plugin to register the messages to
- * @return Whether the plugin has been loaded
- */
- public static boolean loadAndRegisterYamlConfiguration(File file, BlobPlugin plugin) {
+ public static void continueLoadingMessages(BlobPlugin plugin, boolean warnDuplicates, File... files) {
MessageManager manager = BlobLib.getInstance().getMessageManager();
- if (!manager.pluginMessages.containsKey(plugin.getName()))
- return false;
- manager.loadYamlConfiguration(file, plugin);
- manager.duplicates.forEach((key, value) -> BlobLib.getAnjoLogger()
- .log("Duplicate BlobMessage: '" + key + "' (found " + value + " instances)"));
- return true;
+ manager.duplicates.clear();
+ for (File file : files)
+ manager.loadYamlConfiguration(file, plugin);
+ if (warnDuplicates)
+ manager.duplicates.forEach((key, value) -> plugin.getAnjoLogger()
+ .log("Duplicate BlobMessage: '" + key + "' (found " + value + " instances)"));
}
private void addDuplicate(String key) {
@@ -172,8 +162,11 @@ public ReferenceBlobMessage getMessage(String key) {
public ReferenceBlobMessage getMessage(String key, String locale) {
Map localeMap = locales.get(locale);
if (localeMap == null)
+ localeMap = locales.get("en_us");
+ SerialBlobMessage message = localeMap.get(key);
+ if (message == null)
return null;
- return new ReferenceBlobMessage(localeMap.get(key), key);
+ return new ReferenceBlobMessage(message, key);
}
public void playAndSend(Player player, String key) {
diff --git a/src/main/java/us/mytheria/bloblib/managers/SoundManager.java b/src/main/java/us/mytheria/bloblib/managers/SoundManager.java
index 9e018b7c..651936e5 100644
--- a/src/main/java/us/mytheria/bloblib/managers/SoundManager.java
+++ b/src/main/java/us/mytheria/bloblib/managers/SoundManager.java
@@ -132,6 +132,16 @@ private void loadYamlConfiguration(File file) {
});
}
+ public static void continueLoadingSounds(BlobPlugin plugin, boolean warnDuplicates, File... files) {
+ SoundManager manager = BlobLib.getInstance().getSoundManager();
+ manager.duplicates.clear();
+ for (File file : files)
+ manager.loadYamlConfiguration(plugin, file);
+ if (warnDuplicates)
+ manager.duplicates.forEach((key, value) -> plugin.getAnjoLogger()
+ .log("Duplicate BlobSound: '" + key + "' (found " + value + " instances)"));
+ }
+
private void addDuplicate(String key) {
if (duplicates.containsKey(key))
duplicates.put(key, duplicates.get(key) + 1);
diff --git a/src/main/java/us/mytheria/bloblib/managers/VariableSelectorManager.java b/src/main/java/us/mytheria/bloblib/managers/VariableSelectorManager.java
index ab10d922..95e4de10 100644
--- a/src/main/java/us/mytheria/bloblib/managers/VariableSelectorManager.java
+++ b/src/main/java/us/mytheria/bloblib/managers/VariableSelectorManager.java
@@ -62,6 +62,10 @@ public void onEditorClick(InventoryClickEvent event) {
blobEditor.removeElement(player);
return;
}
+ if (blobEditor.isReturnButton(slot)) {
+ blobEditor.processReturn();
+ return;
+ }
return;
}
listener.setInputFromSlot(blobEditor, event.getRawSlot());
@@ -86,9 +90,11 @@ public void onSelectorClick(InventoryClickEvent e) {
}
if (variableSelector.isPreviousPageButton(slot)) {
variableSelector.previousPage();
+ return;
}
if (variableSelector.isReturnButton(slot)) {
variableSelector.processReturn();
+ return;
}
return;
}