Skip to content

Commit

Permalink
Initital
Browse files Browse the repository at this point in the history
  • Loading branch information
KartoffelChipss committed May 8, 2024
1 parent 3de7fca commit 3082c7f
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 40 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/strassburger/lifestealz/LifeStealZ.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public final class LifeStealZ extends JavaPlugin {
private VersionChecker versionChecker;
private PlayerDataStorage playerDataStorage;
private WorldGuardManager worldGuardManager;
private LanguageManager languageManager;
private final boolean hasWorldGuard = Bukkit.getPluginManager().getPlugin("WorldGuard") != null;
private final boolean hasPlaceholderApi = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;

Expand All @@ -38,6 +39,8 @@ public void onEnable() {
getConfig().options().copyDefaults(true);
saveDefaultConfig();

languageManager = new LanguageManager();

CommandManager.registerCommands();

EventManager.registerListeners();
Expand Down Expand Up @@ -90,6 +93,10 @@ public boolean hasPlaceholderApi() {
return hasPlaceholderApi;
}

public LanguageManager getLanguageManager() {
return languageManager;
}

private PlayerDataStorage createPlayerDataStorage() {
String option = getConfig().getString("storage.type");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

LifeStealZ.getInstance().reloadConfig();
config = LifeStealZ.getInstance().getConfig();
LifeStealZ.getInstance().getLanguageManager().reload();
sender.sendMessage(MessageUtils.getAndFormatMsg(true, "messages.reloadMsg", "&7Successfully reloaded the plugin!"));
return true;
}
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ public static Component formatMsg(String msg, Replaceable... replaceables) {
* @return The formatted message
*/
public static Component getAndFormatMsg(boolean addPrefix, String path, String fallback, Replaceable... replaceables) {
if (path.startsWith("messages.")) path = path.substring("messages.".length());

MiniMessage mm = MiniMessage.miniMessage();
String msg = "<!i>" + (LifeStealZ.getInstance().getConfig().getString(path) != null ? LifeStealZ.getInstance().getConfig().getString(path) : fallback);
String prefix = LifeStealZ.getInstance().getConfig().getString("messages.prefix") != null ? LifeStealZ.getInstance().getConfig().getString("messages.prefix") : "&8[&cLifeStealZ&8]";
String msg = "<!i>" + LifeStealZ.getInstance().getLanguageManager().getString(path, fallback);
String prefix = LifeStealZ.getInstance().getLanguageManager().getString("prefix", "&8[&cLifeStealZ&8]");
if (addPrefix) {
msg = prefix + " " + msg;
}
Expand Down
41 changes: 3 additions & 38 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

checkForUpdates: true

lang: "en_US"

#A list of worlds, where the plugin should take effect
worlds:
- "world"
Expand Down Expand Up @@ -168,41 +170,4 @@ items:
volume: 1.0
pitch: 1.0

# You can add as many custom items as you want

#You can modify all messages here
messages:
prefix: "&8[&cLifeStealZ&8]"
newVersionAvailable: "&7A new version of LifeStealZ is available!\n&c<click:OPEN_URL:https://modrinth.com/plugin/lifestealz/versions>https://modrinth.com/plugin/lifestealz/versions</click>"
usageError: "&cUsage: %usage%"
noPermsError: "<red>You do not have permission to execute this command!"
playerNotFound: "&cPlayer not found!"
worldNotWhitelisted: "&cThis world is not whitelisted for LifeStealZ!"
specifyPlayerOrBePlayer: "&cYou need to either specify a player or be a player yourself!"
noPermissionError: "&cYou don't have permission to use this!"
noPlayerData: "&cThis player has not played on this server yet!"
eliminateSuccess: "&7You successfully eliminated &c%player%&7!"
reviveSuccess: "&7You successfully revived &c%player%!"
reviveMaxReached: "&cThis player has already been revived %amount% times!"
onlyReviveElimPlayers: "&cYou can only revive eliminated players!"
eliminatedJoin: "&cYou don't have any hearts left!"
eliminationAnnouncement: "&c%player% &7has been eliminated by &c%killer%&7!"
eliminateionAnnouncementNature: "&c%player% &7has been eliminated!"
setHeartsConfirm: "&7Successfully set &c%player%&7's hearts to &c%amount%"
getHearts: "&c%player% &7currently has &c%amount% &7hearts!"
reloadMsg: "&7Successfully reloaded the plugin!"
versionMsg: "&7You are using version <red>%version%"
noWithdraw: "&cYou would be eliminated, if you withdraw a heart!"
withdrawConfirmmsg: "&8&oUse <underlined><click:SUGGEST_COMMAND:/withdrawheart %amount% confirm>/withdrawheart %amount% confirm</click></underlined> if you really want to withdraw a heart"
maxHeartLimitReached: "&cYou already reached the limit of %limit% hearts!"
closeBtn: "&cClose"
reviveTitle: "&8Revive a player"
revivePlayerDesc: "&7Click to revive this player"
viewheartsYou: "&7You currently have &c%amount% &7hearts!"
viewheartsOther: "&c%player% &7currently has &c%amount% &7hearts!"
heartconsume: "&7You got &c%amount% &7hearts!"
heartconsumeCooldown: "&cYou have to wait before using another heart!"
recipeNotCraftable: "&cThis item is not craftable!"
altKill: "&cPlease don't kill alts! This attempt has been logged!"
withdrawMin: "&cYou can't withdraw less than 1 heart!"
giveItem: "&7You received %amount%x &c%item%&7!"
# You can add as many custom items as you want
34 changes: 34 additions & 0 deletions src/main/resources/lang/de_DE.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 ein Herz auszahlst!"
withdrawConfirmmsg: "&8&oVerwende <underlined><click:SUGGEST_COMMAND:/withdrawheart %amount% confirm>/withdrawheart %amount% confirm</click></underlined>, wenn du wirklich ein Herz auszahlen möchtest."
maxHeartLimitReached: "&cDu hast bereits das Limit von %limit% Herzen erreicht!"
closeBtn: "&cSchließen"
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!"
34 changes: 34 additions & 0 deletions src/main/resources/lang/en_US.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
prefix: "&8[&cLifeStealZ&8]"
newVersionAvailable: "&7A new version of LifeStealZ is available!\n&c<click:OPEN_URL:https://modrinth.com/plugin/lifestealz/versions>https://modrinth.com/plugin/lifestealz/versions</click>"
usageError: "&cUsage: %usage%"
noPermsError: "<red>You do not have permission to execute this command!"
playerNotFound: "&cPlayer not found!"
worldNotWhitelisted: "&cThis world is not whitelisted for LifeStealZ!"
specifyPlayerOrBePlayer: "&cYou need to either specify a player or be a player yourself!"
noPermissionError: "&cYou don't have permission to use this!"
noPlayerData: "&cThis player has not played on this server yet!"
eliminateSuccess: "&7You successfully eliminated &c%player%&7!"
reviveSuccess: "&7You successfully revived &c%player%!"
reviveMaxReached: "&cThis player has already been revived %amount% times!"
onlyReviveElimPlayers: "&cYou can only revive eliminated players!"
eliminatedJoin: "&cYou don't have any hearts left!"
eliminationAnnouncement: "&c%player% &7has been eliminated by &c%killer%&7!"
eliminateionAnnouncementNature: "&c%player% &7has been eliminated!"
setHeartsConfirm: "&7Successfully set &c%player%&7's hearts to &c%amount%"
getHearts: "&c%player% &7currently has &c%amount% &7hearts!"
reloadMsg: "&7Successfully reloaded the plugin!"
versionMsg: "&7You are using version <red>%version%"
noWithdraw: "&cYou would be eliminated, if you withdraw a heart!"
withdrawConfirmmsg: "&8&oUse <underlined><click:SUGGEST_COMMAND:/withdrawheart %amount% confirm>/withdrawheart %amount% confirm</click></underlined> if you really want to withdraw a heart"
maxHeartLimitReached: "&cYou already reached the limit of %limit% hearts!"
closeBtn: "&cClose"
reviveTitle: "&8Revive a player"
revivePlayerDesc: "&7Click to revive this player"
viewheartsYou: "&7You currently have &c%amount% &7hearts!"
viewheartsOther: "&c%player% &7currently has &c%amount% &7hearts!"
heartconsume: "&7You got &c%amount% &7hearts!"
heartconsumeCooldown: "&cYou have to wait before using another heart!"
recipeNotCraftable: "&cThis item is not craftable!"
altKill: "&cPlease don't kill alts! This attempt has been logged!"
withdrawMin: "&cYou can't withdraw less than 1 heart!"
giveItem: "&7You received %amount%x &c%item%&7!"

0 comments on commit 3082c7f

Please sign in to comment.