Skip to content

Commit

Permalink
Added TagSet
Browse files Browse the repository at this point in the history
Added TranslatableItem
Added static "by" methods to TagSet, TranslatableItem, BlobMessage and BlobSound to allow retrieving assets just by their key
Added "localize" methods to TranslatableItem and BlobMessage to allow caching these assets and later getting their translation just in time
  • Loading branch information
anjoismysign committed Dec 13, 2023
1 parent 414272f commit e736f06
Show file tree
Hide file tree
Showing 59 changed files with 1,468 additions and 330 deletions.
2 changes: 1 addition & 1 deletion ci-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.697.30</version>
<version>1.697.39</version>
<relativePath>pom.xml</relativePath>
</parent>
<artifactId>bloblib</artifactId>
Expand Down
13 changes: 1 addition & 12 deletions local-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.697.30</version>
<version>1.697.39</version>
<relativePath>pom.xml</relativePath>
</parent>
<artifactId>bloblib</artifactId>
Expand Down Expand Up @@ -66,17 +66,6 @@
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>com.fasterxml.jackson</pattern>
<shadedPattern>world.hunger.jackson</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons</pattern>
<shadedPattern>global.warming.commons</shadedPattern>
</relocation>
<!-- doomsday.clock.NNNEEEXXXTTT -->
</relocations>
<shadedArtifactAttached>false</shadedArtifactAttached>
</configuration>
</execution>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.697.30</version>
<version>1.697.39</version>
<packaging>pom</packaging>

<properties>
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/us/mytheria/bloblib/BlobLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import us.mytheria.bloblib.command.BlobLibCmd;
import us.mytheria.bloblib.disguises.DisguiseManager;
import us.mytheria.bloblib.enginehub.EngineHubManager;
import us.mytheria.bloblib.entities.DataAssetType;
import us.mytheria.bloblib.entities.logger.BlobPluginLogger;
import us.mytheria.bloblib.entities.tag.TagSet;
import us.mytheria.bloblib.entities.tag.TagSetReader;
import us.mytheria.bloblib.entities.translatable.TranslatableItem;
import us.mytheria.bloblib.entities.translatable.TranslatableReader;
import us.mytheria.bloblib.hologram.HologramManager;
import us.mytheria.bloblib.managers.*;
import us.mytheria.bloblib.managers.fillermanager.FillerManager;
Expand Down Expand Up @@ -47,6 +52,9 @@ public class BlobLib extends JavaPlugin {
private TranslatableManager translatableManager;
private TranslatablePH translatablePH;

private LocalizableDataAssetManager<TranslatableItem> translatableItemManager;
private DataAssetManager<TagSet> tagSetManager;

private static BlobLib instance;

/**
Expand Down Expand Up @@ -86,6 +94,18 @@ public void onEnable() {
inventoryManager = new InventoryManager();
inventoryTrackerManager = new InventoryTrackerManager();
translatableManager = new TranslatableManager();
tagSetManager = DataAssetManager.of(fileManager.tagSetsDirectory(),
TagSetReader::READ,
DataAssetType.TAG_SET,
section -> !section.getStringList("Inclusions").isEmpty() ||
!section.getStringList("Exclusions").isEmpty() ||
!section.getStringList("Include-Set").isEmpty() ||
!section.getStringList("Exclude-Set").isEmpty());
translatableItemManager = LocalizableDataAssetManager
.of(fileManager.itemsDirectory(),
TranslatableReader::ITEM,
DataAssetType.TRANSLATABLE_ITEM,
section -> section.isConfigurationSection("ItemStack"));
messageManager = new MessageManager();
actionManager = new ActionManager();
soundManager = new SoundManager();
Expand Down Expand Up @@ -124,7 +144,9 @@ public void reload() {
configManager.reload();
listenerManager.reload();
soundManager.reload();
tagSetManager.reload();
translatableManager.reload();
translatableItemManager.reload();
messageManager.reload();
actionManager.reload();
inventoryManager.reload();
Expand Down Expand Up @@ -191,6 +213,14 @@ public TranslatableManager getTranslatableManager() {
return translatableManager;
}

public LocalizableDataAssetManager<TranslatableItem> getTranslatableItemManager() {
return translatableItemManager;
}

public DataAssetManager<TagSet> getTagSetManager() {
return tagSetManager;
}

/**
* Will retrieve the MessageManager
*
Expand Down
31 changes: 6 additions & 25 deletions src/main/java/us/mytheria/bloblib/BlobLibAssetAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import us.mytheria.bloblib.api.*;
import us.mytheria.bloblib.entities.inventory.*;
import us.mytheria.bloblib.entities.message.BlobSound;
import us.mytheria.bloblib.entities.message.ReferenceBlobMessage;
import us.mytheria.bloblib.managers.*;

import java.io.File;
Expand All @@ -21,13 +20,15 @@ public class BlobLibAssetAPI {
private final BlobLibSoundAPI soundAPI;
private final BlobLibInventoryAPI inventoryAPI;
private final BlobLibActionAPI actionAPI;
private final BlobLibTagAPI tagAPI;
private final BlobLibMessageAPI messageAPI;
private final BlobLibTranslatableAPI translatableAPI;

private BlobLibAssetAPI(BlobLib plugin) {
this.soundAPI = BlobLibSoundAPI.getInstance(plugin);
this.inventoryAPI = BlobLibInventoryAPI.getInstance(plugin);
this.actionAPI = BlobLibActionAPI.getInstance(plugin);
this.tagAPI = BlobLibTagAPI.getInstance(plugin);
this.messageAPI = BlobLibMessageAPI.getInstance(plugin);
this.translatableAPI = BlobLibTranslatableAPI.getInstance(plugin);
}
Expand Down Expand Up @@ -57,6 +58,10 @@ public BlobLibActionAPI getActionAPI() {
return actionAPI;
}

public BlobLibTagAPI getTagAPI() {
return tagAPI;
}

public BlobLibMessageAPI getMessageAPI() {
return messageAPI;
}
Expand Down Expand Up @@ -110,30 +115,6 @@ public static Optional<MetaInventoryShard> hasMetaInventoryShard(String type) {
return Optional.ofNullable(getInventoryManager().getMetaInventoryShard(type));
}

@Deprecated
public static ReferenceBlobMessage getMessage(String key) {
return getMessageManager().getMessage(key);
}

@Deprecated
public static ReferenceBlobMessage getMessage(String key, String locale) {
return getMessageManager().getMessage(key, locale);
}

@Deprecated
public static ReferenceBlobMessage getLocaleMessageOrDefault(String key, String locale) {
ReferenceBlobMessage localeMessage = getMessageManager().getMessage(key, locale);
if (localeMessage != null)
return localeMessage;
return getMessageManager().getMessage(key);
}

@Deprecated
public static ReferenceBlobMessage getLocaleMessageOrDefault(String key, Player player) {
String locale = player.getLocale();
return getLocaleMessageOrDefault(key, locale);
}

@Deprecated
@Nullable
public static Action<Entity> getAction(String key) {
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/us/mytheria/bloblib/api/BlobLibMessageAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import us.mytheria.bloblib.BlobLib;
import us.mytheria.bloblib.entities.BlobMessageModder;
import us.mytheria.bloblib.entities.message.BlobMessage;
import us.mytheria.bloblib.entities.message.ReferenceBlobMessage;
import us.mytheria.bloblib.managers.BlobLibConfigManager;
import us.mytheria.bloblib.managers.MessageManager;

Expand Down Expand Up @@ -98,7 +97,7 @@ public void broadcast(String key) {
*/
@Deprecated
@Nullable
public ReferenceBlobMessage getMessage(@NotNull String key) {
public BlobMessage getMessage(@NotNull String key) {
Objects.requireNonNull(key);
return getMessageManager().getMessage(key);
}
Expand All @@ -112,7 +111,7 @@ public ReferenceBlobMessage getMessage(@NotNull String key) {
* @return The message
*/
@Nullable
public ReferenceBlobMessage getMessage(@NotNull String key, @NotNull String locale) {
public BlobMessage getMessage(@NotNull String key, @NotNull String locale) {
Objects.requireNonNull(key);
Objects.requireNonNull(locale);
return getMessageManager().getMessage(key, locale);
Expand All @@ -129,7 +128,7 @@ public ReferenceBlobMessage getMessage(@NotNull String key, @NotNull String loca
*/
@Deprecated
@Nullable
public ReferenceBlobMessage getMessage(@NotNull String key, @NotNull Player player) {
public BlobMessage getMessage(@NotNull String key, @NotNull Player player) {
Objects.requireNonNull(player);
return getMessageManager().getMessage(key, player.getLocale());
}
Expand All @@ -142,7 +141,7 @@ public ReferenceBlobMessage getMessage(@NotNull String key, @NotNull Player play
* @return The message
*/
@Nullable
public ReferenceBlobMessage getMessage(@NotNull String key, @NotNull CommandSender sender) {
public BlobMessage getMessage(@NotNull String key, @NotNull CommandSender sender) {
Objects.requireNonNull(sender);
return getMessageManager().getMessage(key, sender instanceof Player ? ((Player) sender).getLocale() :
BlobLibConfigManager.getInstance().getConsoleLocale());
Expand All @@ -154,8 +153,8 @@ public ReferenceBlobMessage getMessage(@NotNull String key, @NotNull CommandSend
* @return The message, or the default message if not found
*/
@Nullable
public ReferenceBlobMessage getLocaleMessageOrDefault(String key, String locale) {
ReferenceBlobMessage localeMessage = getMessageManager().getMessage(key, locale);
public BlobMessage getLocaleMessageOrDefault(String key, String locale) {
BlobMessage localeMessage = getMessageManager().getMessage(key, locale);
if (localeMessage != null)
return localeMessage;
return getMessageManager().getMessage(key);
Expand All @@ -169,7 +168,7 @@ public ReferenceBlobMessage getLocaleMessageOrDefault(String key, String locale)
* @return The message, or the default message if not found
*/
@Nullable
public ReferenceBlobMessage getLocaleMessageOrDefault(String key, Player player) {
public BlobMessage getLocaleMessageOrDefault(String key, Player player) {
String locale = player.getLocale();
return getLocaleMessageOrDefault(key, locale);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/us/mytheria/bloblib/api/BlobLibSoundAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.BlobLib;
import us.mytheria.bloblib.entities.message.BlobSound;
import us.mytheria.bloblib.managers.SoundManager;
Expand Down Expand Up @@ -40,6 +41,7 @@ public SoundManager getSoundManager() {
* @param key The key of the sound
* @return The sound
*/
@Nullable
public BlobSound getSound(String key) {
return getSoundManager().getSound(key);
}
Expand All @@ -51,7 +53,7 @@ public BlobSound getSound(String key) {
public void playSound(String key, Player player) {
getSoundManager().play(player, key);
}

/**
* @return The sounds file
*/
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/us/mytheria/bloblib/api/BlobLibTagAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package us.mytheria.bloblib.api;

import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.BlobLib;
import us.mytheria.bloblib.entities.tag.TagSet;
import us.mytheria.bloblib.managers.DataAssetManager;

public class BlobLibTagAPI {
private static BlobLibTagAPI instance;
private final BlobLib plugin;

private BlobLibTagAPI(BlobLib plugin) {
this.plugin = plugin;
}

public static BlobLibTagAPI getInstance(BlobLib plugin) {
if (instance == null) {
if (plugin == null)
throw new NullPointerException("injected dependency is null");
BlobLibTagAPI.instance = new BlobLibTagAPI(plugin);
}
return instance;
}

public static BlobLibTagAPI getInstance() {
return getInstance(null);
}

/**
* @return The TagSet manager
*/
public DataAssetManager<TagSet> getTagSetManager() {
return plugin.getTagSetManager();
}

/**
* @param key The key of the TagSet
* @return The TagSet. Null if not found.
*/
@Nullable
public TagSet getTagSet(String key) {
return getTagSetManager().getAsset(key);
}
}
39 changes: 39 additions & 0 deletions src/main/java/us/mytheria/bloblib/api/BlobLibTranslatableAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.BlobLib;
import us.mytheria.bloblib.entities.translatable.TranslatableBlock;
import us.mytheria.bloblib.entities.translatable.TranslatableItem;
import us.mytheria.bloblib.entities.translatable.TranslatableSnippet;
import us.mytheria.bloblib.managers.BlobLibConfigManager;
import us.mytheria.bloblib.managers.TranslatableManager;
Expand Down Expand Up @@ -117,6 +118,44 @@ public TranslatableSnippet getTranslatableSnippet(@NotNull String key,
return getTranslatableManager().getSnippet(key, player.getLocale());
}

/**
* Will get a TranslatableItem by its key and locale.
*
* @param key The key of the translatable
* @param locale The locale of the translatable
* @return The TranslatableItem
*/
@Nullable
public TranslatableItem getTranslatableItem(@NotNull String key,
@NotNull String locale) {
return plugin.getTranslatableItemManager().getAsset(key, locale);
}

/**
* Will get a TranslatableKey by its key and the default locale.
*
* @param key The key of the translatable
* @return The TranslatableItem
*/
@Nullable
public TranslatableItem getTranslatableItem(@NotNull String key) {
return plugin.getTranslatableItemManager().getAsset(key);
}

/**
* Will get a TranslatableItem by its key and the player's locale.
*
* @param key The key of the translatable
* @param player The player to get the locale from
* @return The TranslatableItem
*/
@Nullable
public TranslatableItem getTranslatableItem(@NotNull String key,
@NotNull Player player) {
Objects.requireNonNull(player);
return plugin.getTranslatableItemManager().getAsset(key, player.getLocale());
}

/**
* Will get the real locale from the locale.
*
Expand Down
Loading

0 comments on commit e736f06

Please sign in to comment.