Skip to content

Commit

Permalink
Merge pull request #9 from SlimefunGuguProject/upstream/feat/slimefun…
Browse files Browse the repository at this point in the history
…-translation

feat: SlimefunTranslation integration
  • Loading branch information
SchnTgaiSpock authored Jan 26, 2024
2 parents b6dc2d5 + 0573cea commit bfdec28
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,12 @@
<version>3.0.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>net.guizhanss</groupId>
<artifactId>SlimefunTranslation</artifactId>
<version>ce9fb1c6f5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
7 changes: 7 additions & 0 deletions src/main/java/io/github/schntgaispock/slimehud/SlimeHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javax.annotation.Nonnull;

import io.github.schntgaispock.slimehud.placeholder.PlaceholderManager;
import io.github.schntgaispock.slimehud.translation.TranslationManager;
import io.github.schntgaispock.slimehud.waila.HudController;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
Expand All @@ -20,6 +21,7 @@ public class SlimeHUD extends AbstractAddon {
@Getter AddonConfig playerData;
static @Getter SlimeHUD instance;
private HudController hudController;
private TranslationManager translationManager;

public SlimeHUD() {
super("SchnTgaiSpock", "SlimeHUD", "master", "options.auto-update");
Expand Down Expand Up @@ -51,6 +53,7 @@ public void enable() {
CommandManager.setup();
PlaceholderManager.setup();
hudController = new HudController();
translationManager = new TranslationManager();
}

@Override
Expand All @@ -63,6 +66,10 @@ public static HudController getHudController() {
return instance.hudController;
}

public static TranslationManager getTranslationManager() {
return instance.translationManager;
}

public static NamespacedKey newNamespacedKey(@Nonnull String name) {
return new NamespacedKey(SlimeHUD.getInstance(), name);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.schntgaispock.slimehud.translation;

import io.github.schntgaispock.slimehud.SlimeHUD;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import net.guizhanss.slimefuntranslation.SlimefunTranslation;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

public class TranslationManager {
private boolean translationEnabled;

public TranslationManager() {
if (SlimeHUD.getInstance().getConfig().getBoolean("options.slimefun-translation-support", true)) {
if (Bukkit.getPluginManager().getPlugin("SlimefunTranslation") != null) {
translationEnabled = true;
} else {
SlimeHUD.getInstance().getLogger().info("SlimefunTranslation is not installed and has been ignored.");
translationEnabled = false;
}
}
}

@Nonnull
@ParametersAreNonnullByDefault
public String getItemName(Player p, SlimefunItem sfItem) {
if (!translationEnabled) {
return sfItem.getItemName();
}
return SlimefunTranslation.getTranslationService().getTranslatedItemName(
SlimefunTranslation.getUserService().getUser(p),
sfItem
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String getFacing() {
return "";

HudRequest request = new HudRequest(item, target, player);
StringBuilder text = new StringBuilder(item.getItemName())
StringBuilder text = new StringBuilder(SlimeHUD.getTranslationManager().getItemName(player, item))
.append(" ")
.append(ChatColor.translateAlternateColorCodes('&',
SlimeHUD.getHudController().processRequest(request)));
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ options:
# Use PlaceholderAPI to get the player's toggle status
placeholder-api-support: true

# Use SlimefunTranslation to display the translated name of items
slimefun-translation-support: true

waila:

# If set to true, will disable waila for all players,
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ depend:

softdepend:
- PlaceholderAPI
- SlimefunTranslation

commands:
slimehud:
Expand Down

0 comments on commit bfdec28

Please sign in to comment.