-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from KartoffelChipss/feature-language-manager
Feature: Language Manager
- Loading branch information
Showing
12 changed files
with
188 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/org/strassburger/lifestealz/util/LanguageManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.strassburger.lifestealz.util; | ||
|
||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.strassburger.lifestealz.LifeStealZ; | ||
|
||
import java.io.File; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
public class LanguageManager { | ||
private final JavaPlugin plugin = LifeStealZ.getInstance(); | ||
public static final List<String> defaultLangs = List.of("en_US", "de_DE"); | ||
|
||
private HashMap<String, String> translationMap; | ||
private FileConfiguration langConfig; | ||
|
||
public LanguageManager() { | ||
loadLanguageConfig(); | ||
} | ||
|
||
public void reload() { | ||
loadLanguageConfig(); | ||
} | ||
|
||
private void loadLanguageConfig() { | ||
File languageDirectory = new File(plugin.getDataFolder(), "lang/"); | ||
if (!languageDirectory.exists() || !languageDirectory.isDirectory()) languageDirectory.mkdir(); | ||
|
||
for (String langString : defaultLangs) { | ||
File langFile = new File("lang/", langString + ".yml"); | ||
if (!new File(languageDirectory, langString + ".yml").exists()) { | ||
plugin.getLogger().info("Saving file " + langFile.getPath()); | ||
plugin.saveResource(langFile.getPath(), false); | ||
} | ||
} | ||
|
||
String langOption = plugin.getConfig().getString("lang") != null ? plugin.getConfig().getString("lang") : "en_US"; | ||
File selectedLangFile = new File(languageDirectory, langOption + ".yml"); | ||
|
||
if (!selectedLangFile.exists()) { | ||
selectedLangFile = new File(languageDirectory, "en_US.yml"); | ||
plugin.getLogger().warning("Language file " + langOption + ".yml (" + selectedLangFile.getPath() + ") not found! Using fallback en_US.yml."); | ||
} | ||
|
||
plugin.getLogger().info("Using language file: " + selectedLangFile.getPath()); | ||
langConfig = YamlConfiguration.loadConfiguration(selectedLangFile); | ||
} | ||
|
||
public String getString(String key) { | ||
return langConfig.getString(key); | ||
} | ||
|
||
public String getString(String key, String fallback) { | ||
return langConfig.getString(key) != null ? langConfig.getString(key) : fallback; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# LifeStealZ language file | ||
# de_DE - by Kartoffelchipss | ||
|
||
prefix: "&8[&cLifeStealZ&8]" | ||
newVersionAvailable: "&7Eine neue Version von LifeStealZ ist verfügbar!\n&c<click:OPEN_URL:https://modrinth.com/plugin/lifestealz/versions>https://modrinth.com/plugin/lifestealz/versions</click>" | ||
usageError: "&cVerwendung: %usage%" | ||
noPermsError: "<red>Du hast keine Berechtigung, diesen Befehl auszuführen!" | ||
playerNotFound: "&cSpieler nicht gefunden!" | ||
worldNotWhitelisted: "&cDiese Welt ist nicht auf der LifeStealZ Whitelist!" | ||
specifyPlayerOrBePlayer: "&cDu musst entweder einen Spieler angeben oder selbst ein Spieler sein!" | ||
noPermissionError: "&cDu hast keine Berechtigung, das zu benutzen!" | ||
noPlayerData: "&cDieser Spieler hat noch nicht auf diesem Server gespielt!" | ||
eliminateSuccess: "&7Du hast &c%player%&7 erfolgreich eliminiert!" | ||
reviveSuccess: "&7Du hast &c%player%&7 erfolgreich wiederbelebt!" | ||
reviveMaxReached: "&cDieser Spieler wurde bereits %amount% mal wiederbelebt!" | ||
onlyReviveElimPlayers: "&cDu kannst nur eliminierte Spieler wiederbeleben!" | ||
eliminatedJoin: "&cDu hast keine Herzen mehr!" | ||
eliminationAnnouncement: "&c%player% &7wurde von &c%killer%&7 eliminiert!" | ||
eliminateionAnnouncementNature: "&c%player% &7wurde eliminiert!" | ||
setHeartsConfirm: "&7Die Herzen von &c%player%&7 wurden erfolgreich auf &c%amount%&7 gesetzt!" | ||
getHearts: "&c%player% &7hat derzeit &c%amount% &7Herzen!" | ||
reloadMsg: "&7Das Plugin wurde erfolgreich neu geladen!" | ||
versionMsg: "&7Du benutzt Version <red>%version%" | ||
noWithdraw: "&cDu würdest eliminiert werden, wenn du so viele Herzen auszahlst!" | ||
withdrawConfirmmsg: "&8&oVerwende <underlined><click:SUGGEST_COMMAND:/withdrawheart %amount% confirm>/withdrawheart %amount% confirm</click></underlined>, wenn du wirklich Herzen auszahlen möchtest." | ||
maxHeartLimitReached: "&cDu hast bereits das Limit von %limit% Herzen erreicht!" | ||
closeBtn: "&cSchließen" | ||
backBtn: "&cZurück" | ||
nextBtn: "&cNächste Seite" | ||
reviveTitle: "&8Spieler wiederbeleben" | ||
revivePlayerDesc: "&7Klicke hier, um diesen Spieler wiederzubeleben" | ||
viewheartsYou: "&7Du hast derzeit &c%amount% &7Herzen!" | ||
viewheartsOther: "&c%player% &7hat derzeit &c%amount% &7Herzen!" | ||
heartconsume: "&7Du hast &c%amount% &7Herzen erhalten!" | ||
heartconsumeCooldown: "&cDu musst warten, bevor du ein weiteres Herz benutzen kannst!" | ||
recipeNotCraftable: "&cDieser Gegenstand kann nicht hergestellt werden!" | ||
altKill: "&cBitte töte keine Alts! Dieser Versuch wurde protokolliert!" | ||
withdrawMin: "&cDu kannst nicht weniger als 1 Herz auszahlen!" | ||
giveItem: "&7Du hast %amount%x &c%item%&7 erhalten!" |
Oops, something went wrong.