Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: SlimefunTranslation integration #9

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading