diff --git a/build.gradle b/build.gradle index b77f189..d1ad6bc 100644 --- a/build.gradle +++ b/build.gradle @@ -24,17 +24,7 @@ allprojects { maven { url 'https://jitpack.io' } } - - print(pluginVersion) - - //processResources { - // from(sourceSets.main.resources.srcDirs) { - // filesMatching('plugin.yml') { - // filter ReplaceTokens, tokens: [version: "2.1.1"] - // } - // } - //} - + processResources { from (sourceSets.main.resources) { include 'plugin.yml' @@ -50,6 +40,9 @@ dependencies { //We depend on the old HaroTorch so we can convert Torches to the v2 format implementation 'com.github.TheDutchMC:HaroTorch:jmil-SNAPSHOT' + //Apache Commons IO + compile group: 'commons-io', name: 'commons-io', version: '2.6' + compile project('Spigot_1_16_R2') } diff --git a/gradle.properties b/gradle.properties index 37c0488..952c6a0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -pluginVersion = 2.1.1 +pluginVersion = 2.1.2 pluginGroup = nl.thedutchmc.harotorch pluginName = HaroTorch \ No newline at end of file diff --git a/src/main/java/nl/thedutchmc/harotorch/ConfigurationHandler.java b/src/main/java/nl/thedutchmc/harotorch/ConfigurationHandler.java index 85fb25d..9681b90 100644 --- a/src/main/java/nl/thedutchmc/harotorch/ConfigurationHandler.java +++ b/src/main/java/nl/thedutchmc/harotorch/ConfigurationHandler.java @@ -14,7 +14,7 @@ public class ConfigurationHandler { private HaroTorch plugin; - public String torchBlock, messageTorchBrokenOwnerMismatch, messageTorchBrokenSuccess, messageTorchPlacedSucccess; + public String torchBlock, activeLang; public boolean enableTorchParticles; public int torchRange, torchHighlightRange, torchHighlightTime, torchAoeParticleHeight; @@ -54,9 +54,7 @@ public void loadConfig() { public void readConfig() { torchBlock = this.getConfig().getString("torchBlock"); - messageTorchBrokenOwnerMismatch = this.getConfig().getString("messageTorchBrokenOwnerMismatch"); - messageTorchBrokenSuccess = this.getConfig().getString("messageTorchBrokenSuccess"); - messageTorchPlacedSucccess = this.getConfig().getString("messageTorchPlacedSucccess"); + activeLang = this.getConfig().getString("activeLang"); enableTorchParticles = this.getConfig().getBoolean("enableTorchParticles"); diff --git a/src/main/java/nl/thedutchmc/harotorch/HaroTorch.java b/src/main/java/nl/thedutchmc/harotorch/HaroTorch.java index 4265909..4c308e2 100644 --- a/src/main/java/nl/thedutchmc/harotorch/HaroTorch.java +++ b/src/main/java/nl/thedutchmc/harotorch/HaroTorch.java @@ -17,6 +17,7 @@ import nl.thedutchmc.harotorch.events.BlockPlaceEventListener; import nl.thedutchmc.harotorch.events.CreatureSpawnEventListener; import nl.thedutchmc.harotorch.events.EntityExplodeEventListener; +import nl.thedutchmc.harotorch.lang.LangHandler; import nl.thedutchmc.harotorch.torch.Recipe; import nl.thedutchmc.harotorch.torch.TorchHandler; @@ -25,10 +26,8 @@ public class HaroTorch extends JavaPlugin { private static ConfigurationHandler CONFIG; public static double RANGE; - public static final String NMS_VERSION = Bukkit.getServer().getClass().getPackage().getName().substring(23); - @Override public void onEnable() { logInfo("You are using NMS version " + NMS_VERSION); @@ -36,6 +35,11 @@ public void onEnable() { CONFIG = new ConfigurationHandler(this); CONFIG.loadConfig(); + LangHandler langHandler = new LangHandler(this); + langHandler.load(); + + logInfo(LangHandler.activeLang.getLangMessages().get("welcome")); + RANGE = Math.pow(CONFIG.torchRange, 2); //TorchHandler @@ -81,6 +85,11 @@ public void run() { } } + @Override + public void onDisable() { + logInfo(LangHandler.activeLang.getLangMessages().get("goodbye")); + } + public void logInfo(String log) { this.getLogger().info(log); } diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/TorchCommandExecutor.java b/src/main/java/nl/thedutchmc/harotorch/commands/TorchCommandExecutor.java index 6e23dc3..46f2b57 100644 --- a/src/main/java/nl/thedutchmc/harotorch/commands/TorchCommandExecutor.java +++ b/src/main/java/nl/thedutchmc/harotorch/commands/TorchCommandExecutor.java @@ -11,6 +11,7 @@ import nl.thedutchmc.harotorch.commands.torchSubCmds.HighlightAreaOfEffectExecutor; import nl.thedutchmc.harotorch.commands.torchSubCmds.HighlightExecutor; import nl.thedutchmc.harotorch.commands.torchSubCmds.VersionExecutor; +import nl.thedutchmc.harotorch.lang.LangHandler; public class TorchCommandExecutor implements CommandExecutor { @@ -24,13 +25,14 @@ public TorchCommandExecutor(HaroTorch plugin) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(args.length < 1) { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "Missing arguments! Use " + ChatColor.RED + "/torch help" + ChatColor.GOLD + " for help!"); + String msg = LangHandler.activeLang.getLangMessages().get("missingArguments").replaceAll("%HELP_COMMAND%", ChatColor.RED + "/torch help" + ChatColor.GOLD); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + msg); return true; } if(args[0].equalsIgnoreCase("help")) { if(!sender.hasPermission("harotorch.help")) { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + "You do not have permission to use this command!"); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission")); return true; } @@ -39,7 +41,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St else if(args[0].equalsIgnoreCase("version")) { if(!sender.hasPermission("harotorch.version")) { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + "You do not have permission to use this command!"); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission")); return true; } @@ -48,7 +50,7 @@ else if(args[0].equalsIgnoreCase("version")) { else if(args[0].equalsIgnoreCase("convert")) { if(!sender.hasPermission("harotorch.convert")) { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + "You do not have permission to use this command!"); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission")); return true; } @@ -57,7 +59,7 @@ else if(args[0].equalsIgnoreCase("convert")) { else if(args[0].equalsIgnoreCase("give")) { if(!sender.hasPermission("harotorch.give")) { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + "You do not have permission to use this command!"); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission")); return true; } @@ -66,7 +68,7 @@ else if(args[0].equalsIgnoreCase("give")) { else if(args[0].equalsIgnoreCase("highlight")) { if(!sender.hasPermission("harotorch.highlight")) { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + "You do not have permission to use this command!"); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission")); return true; } @@ -75,7 +77,7 @@ else if(args[0].equalsIgnoreCase("highlight")) { else if(args[0].equalsIgnoreCase("aoe")) { if(!sender.hasPermission("harotorch.aoe")) { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + "You do not have permission to use this command!"); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission")); return true; } diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/ConvertExecutor.java b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/ConvertExecutor.java index f978008..c44f56e 100644 --- a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/ConvertExecutor.java +++ b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/ConvertExecutor.java @@ -11,6 +11,7 @@ import net.md_5.bungee.api.ChatColor; import nl.thedutchmc.haro_torch.plugin.torch.Torchy; import nl.thedutchmc.harotorch.HaroTorch; +import nl.thedutchmc.harotorch.lang.LangHandler; import nl.thedutchmc.harotorch.torch.Torch; import nl.thedutchmc.harotorch.torch.TorchHandler; @@ -19,11 +20,11 @@ public class ConvertExecutor { public static boolean convert(CommandSender sender) { if(Bukkit.getPluginManager().getPlugin("HaroTorch") == null) { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "HaroTorch v1 is not installed. Aborting."); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("v1NotInstalledMessage")); return true; } - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "Converting HaroTorch v1 Torches to v2..."); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("convertingToV2Start")); List torchys = nl.thedutchmc.haro_torch.plugin.torch.TorchHandler.getTorches(); @@ -41,7 +42,7 @@ public static boolean convert(CommandSender sender) { TorchHandler.addTorch(new Torch(owner, loc)); } - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "Conversion complete. Disabling HaroTorch v1!"); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("convertingToV2Complete")); Plugin haroTorchV1 = Bukkit.getPluginManager().getPlugin("HaroTorch"); diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/GiveExecutor.java b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/GiveExecutor.java index 0bd4b4b..4ae48eb 100644 --- a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/GiveExecutor.java +++ b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/GiveExecutor.java @@ -5,6 +5,7 @@ import net.md_5.bungee.api.ChatColor; import nl.thedutchmc.harotorch.HaroTorch; +import nl.thedutchmc.harotorch.lang.LangHandler; import nl.thedutchmc.harotorch.torch.TorchHandler; public class GiveExecutor { @@ -12,7 +13,7 @@ public class GiveExecutor { public static boolean give(CommandSender sender, String[] args) { if(!(sender instanceof Player)) { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + "This command can only be used by Players!"); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("commandOnlyForPlayers")); return true; } @@ -27,13 +28,13 @@ public static boolean give(CommandSender sender, String[] args) { count = Integer.valueOf(args[1]); } else { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "The given quantity is not a number!"); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("quantityNaN")); return true; } } if(count <= 0) { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "Quantity may not be 0 or negative!"); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("quantityNegOrZero")); return true; } diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HelpExecutor.java b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HelpExecutor.java index ee8fd35..837f1db 100644 --- a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HelpExecutor.java +++ b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HelpExecutor.java @@ -4,19 +4,20 @@ import org.bukkit.command.CommandSender; import nl.thedutchmc.harotorch.HaroTorch; +import nl.thedutchmc.harotorch.lang.LangHandler; public class HelpExecutor { public static boolean help(CommandSender sender) { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "HaroTorch help menu"); - sender.sendMessage("- " + ChatColor.GOLD + "/torch help " + ChatColor.WHITE + "Shows you this page."); - sender.sendMessage("- " + ChatColor.GOLD + "/torch highlight " + ChatColor.WHITE + "Highlight all nearby torches."); - sender.sendMessage("- " + ChatColor.GOLD + "/torch give " + ChatColor.WHITE + "Give yourself a HaroTorch."); - sender.sendMessage("- " + ChatColor.GOLD + "/torch convert " + ChatColor.WHITE + "Convert v1 torches to v2 torches."); - sender.sendMessage("- " + ChatColor.GOLD + "/torch version " + ChatColor.WHITE + "Get the HaroTorch and NMS version number."); - + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("helpMenuTitle")); + sender.sendMessage("- " + ChatColor.GOLD + "/torch help " + ChatColor.WHITE + LangHandler.activeLang.getLangMessages().get("helpHelp")); + sender.sendMessage("- " + ChatColor.GOLD + "/torch highlight " + ChatColor.WHITE + LangHandler.activeLang.getLangMessages().get("helpHighlight")); + sender.sendMessage("- " + ChatColor.GOLD + "/torch give " + ChatColor.WHITE + LangHandler.activeLang.getLangMessages().get("helpGive")); + sender.sendMessage("- " + ChatColor.GOLD + "/torch convert " + ChatColor.WHITE + LangHandler.activeLang.getLangMessages().get("helpConvert")); + sender.sendMessage("- " + ChatColor.GOLD + "/torch version " + ChatColor.WHITE + LangHandler.activeLang.getLangMessages().get("helpVersion")); + sender.sendMessage("- " + ChatColor.GOLD + "/torch aoe " + ChatColor.WHITE + LangHandler.activeLang.getLangMessages().get("helpAoe")); + return true; } - } diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightAreaOfEffectExecutor.java b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightAreaOfEffectExecutor.java index 0e9f206..b5e7c16 100644 --- a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightAreaOfEffectExecutor.java +++ b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightAreaOfEffectExecutor.java @@ -14,13 +14,15 @@ import net.md_5.bungee.api.ChatColor; import nl.thedutchmc.harotorch.HaroTorch; +import nl.thedutchmc.harotorch.lang.LangHandler; import nl.thedutchmc.harotorch.torch.TorchHandler; public class HighlightAreaOfEffectExecutor { public static boolean aoe(CommandSender sender, HaroTorch plugin) { - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "Showing the area of effect for " + ChatColor.RED + HaroTorch.getConfigHandler().torchHighlightTime + ChatColor.GOLD + " seconds!"); + String msg = LangHandler.activeLang.getLangMessages().get("startingAoe").replaceAll("%SECONDS%", ChatColor.RED + String.valueOf(HaroTorch.getConfigHandler().torchHighlightTime) + ChatColor.GOLD); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + msg); List nearbyTorches = TorchHandler.getTorchLocationsNearPlayer((Player) sender, HaroTorch.getConfigHandler().torchHighlightRange); final List torchParticles = new ArrayList<>(); @@ -80,7 +82,7 @@ public void run() { @Override public void run() { particle.cancel(); - sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "Highlighting has ended!"); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("endingAoe")); } }.runTaskLater(plugin, 30L * 20L); diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightExecutor.java b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightExecutor.java index 03dc490..eed9db9 100644 --- a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightExecutor.java +++ b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightExecutor.java @@ -9,6 +9,7 @@ import net.md_5.bungee.api.ChatColor; import nl.thedutchmc.harotorch.HaroTorch; +import nl.thedutchmc.harotorch.lang.LangHandler; import nl.thedutchmc.harotorch.torch.TorchHandler; public class HighlightExecutor { @@ -23,11 +24,13 @@ public static boolean highlight(CommandSender sender, String[] args, HaroTorch p switch(HaroTorch.NMS_VERSION) { case "v1_16_R2": returnedIds = Highlight_1_16_r2.spawnHighlight(p, nearbyTorches); break; default: - p.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "The highlight feature is not supported on this version of Minecraft! (" + HaroTorch.NMS_VERSION + ")"); + String msg = LangHandler.activeLang.getLangMessages().get("highlightVersionNotSupported").replaceAll("%NMS_VERSION%", HaroTorch.NMS_VERSION); + p.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + msg); return true; } - p.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "Highlighting all Torches for " + ChatColor.RED + HaroTorch.getConfigHandler().torchHighlightTime + ChatColor.GOLD + " seconds!"); + String msg = LangHandler.activeLang.getLangMessages().get("startingHiglight").replaceAll("%SECONDS%", ChatColor.RED + String.valueOf(HaroTorch.getConfigHandler().torchHighlightTime) + ChatColor.GOLD); + p.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + msg); new BukkitRunnable() { @@ -39,7 +42,7 @@ public void run() { } - p.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "Highlighting has ended!"); + p.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("endingHighlight")); } }.runTaskLater(plugin, HaroTorch.getConfigHandler().torchHighlightTime * 20); diff --git a/src/main/java/nl/thedutchmc/harotorch/events/BlockBreakEventListener.java b/src/main/java/nl/thedutchmc/harotorch/events/BlockBreakEventListener.java index b1f2e23..17f4e43 100644 --- a/src/main/java/nl/thedutchmc/harotorch/events/BlockBreakEventListener.java +++ b/src/main/java/nl/thedutchmc/harotorch/events/BlockBreakEventListener.java @@ -10,6 +10,7 @@ import net.md_5.bungee.api.ChatColor; import nl.thedutchmc.harotorch.HaroTorch; +import nl.thedutchmc.harotorch.lang.LangHandler; import nl.thedutchmc.harotorch.torch.Torch; import nl.thedutchmc.harotorch.torch.TorchHandler; @@ -23,7 +24,7 @@ public void onBlockBreakEvent(BlockBreakEvent event) { if(TorchHandler.isTorch(loc_y_plus_1)) { - event.getPlayer().sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "You may not break this block. A HaroTorch stands ontop!"); + event.getPlayer().sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("blockBreakNotAllowedTorchOntop")); event.setCancelled(true); return; @@ -36,7 +37,7 @@ public void onBlockBreakEvent(BlockBreakEvent event) { UUID torchOwner = TorchHandler.getTorchOwner(loc); if(!event.getPlayer().getUniqueId().equals(torchOwner)) { - event.getPlayer().sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + HaroTorch.getConfigHandler().messageTorchBrokenOwnerMismatch); + event.getPlayer().sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("blockBreakNotAllowedOwnerMismatch")); event.setCancelled(true); @@ -52,6 +53,6 @@ public void onBlockBreakEvent(BlockBreakEvent event) { event.getBlock().getWorld().dropItemNaturally(loc, torchStack); - event.getPlayer().sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + HaroTorch.getConfigHandler().messageTorchBrokenSuccess); + event.getPlayer().sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("torchBroken")); } } diff --git a/src/main/java/nl/thedutchmc/harotorch/events/BlockPlaceEventListener.java b/src/main/java/nl/thedutchmc/harotorch/events/BlockPlaceEventListener.java index f0e3b4c..cf5ce76 100644 --- a/src/main/java/nl/thedutchmc/harotorch/events/BlockPlaceEventListener.java +++ b/src/main/java/nl/thedutchmc/harotorch/events/BlockPlaceEventListener.java @@ -8,6 +8,7 @@ import net.md_5.bungee.api.ChatColor; import nl.thedutchmc.harotorch.HaroTorch; +import nl.thedutchmc.harotorch.lang.LangHandler; import nl.thedutchmc.harotorch.torch.Torch; import nl.thedutchmc.harotorch.torch.TorchHandler; @@ -26,7 +27,7 @@ public void onBlockPlaceEvent(BlockPlaceEvent event) { Location l = event.getBlock().getLocation(); TorchHandler.addTorch(new Torch(event.getPlayer().getUniqueId(), l)); - event.getPlayer().sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + HaroTorch.getConfigHandler().messageTorchPlacedSucccess); + event.getPlayer().sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("torchPlaced")); } } } diff --git a/src/main/java/nl/thedutchmc/harotorch/lang/LangHandler.java b/src/main/java/nl/thedutchmc/harotorch/lang/LangHandler.java new file mode 100644 index 0000000..d1154a1 --- /dev/null +++ b/src/main/java/nl/thedutchmc/harotorch/lang/LangHandler.java @@ -0,0 +1,119 @@ +package nl.thedutchmc.harotorch.lang; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.apache.commons.io.FileUtils; + +import nl.thedutchmc.harotorch.HaroTorch; + +public class LangHandler { + + public static Language activeLang; + + private String basePath; + private HaroTorch plugin; + + public LangHandler(HaroTorch plugin) { + this.plugin = plugin; + + basePath = plugin.getDataFolder() + File.separator + "Lang"; + } + + private File configFile; + private Properties props; + + public void load() { + + String activeLangPath = ""; + for(String langFile : discover()) { + if(langFile.endsWith(HaroTorch.getConfigHandler().activeLang + ".properties")) activeLangPath = langFile; + } + + if(activeLangPath.equals("")) { + plugin.logWarn("Active language file " + HaroTorch.getConfigHandler().activeLang + ".properties not found! Please check your Lang directory and your config file. Defaulting to English"); + configFile = new File(basePath, "en.properties"); + HaroTorch.getConfigHandler().activeLang = "en"; + } else { + configFile = new File(activeLangPath); + } + + if(!configFile.exists()) { + configFile.getParentFile().mkdirs(); + plugin.saveResource("en.properties", false); + + //FileUtil.copy(plugin.getResource("en.properties"), configFile); + try { + FileUtils.copyToFile(plugin.getResource("en.properties"), configFile); + } catch (IOException e) { + plugin.logWarn("Something went wrong whilst trying to create " + configFile.getAbsolutePath()); + e.printStackTrace(); + } + } + + try { + props = new Properties(); + props.load(new FileInputStream(configFile)); + + readLang(HaroTorch.getConfigHandler().activeLang); + } catch(FileNotFoundException e) { + plugin.logWarn("Language file not found!"); + } catch(IOException e) { + e.printStackTrace(); + } + } + + private void readLang(String lang) { + + HashMap langMap = new HashMap<>(); + + for(String key : props.stringPropertyNames()) { + String value = props.getProperty(key).toString(); + + langMap.put(key, value); + } + + activeLang= new Language(lang, langMap); + } + + private List discover() { + + File storageFolder = new File(basePath); + + if(!storageFolder.exists()) { + try { + Files.createDirectories(Paths.get(storageFolder.getAbsolutePath())); + } catch (IOException | SecurityException e) { + plugin.logWarn("Failed to create Lang storage directory! Please check your file permissions!"); + + return null; + } + } + + try { + Stream walk = Files.walk(Paths.get(storageFolder.getAbsolutePath())); + + List result = walk.map(x -> x.toString()).filter(f -> f.endsWith(".properties")).collect(Collectors.toList()); + + walk.close(); + + return result; + } catch(IOException e) { + plugin.logWarn("A IOException was thrown whilst discovering Lang files!"); + + e.printStackTrace(); + + return null; + } + } +} diff --git a/src/main/java/nl/thedutchmc/harotorch/lang/Language.java b/src/main/java/nl/thedutchmc/harotorch/lang/Language.java new file mode 100644 index 0000000..c297166 --- /dev/null +++ b/src/main/java/nl/thedutchmc/harotorch/lang/Language.java @@ -0,0 +1,22 @@ +package nl.thedutchmc.harotorch.lang; + +import java.util.HashMap; + +public class Language { + + private String lang; + private HashMap langMessages; + + public Language(String lang, HashMap langMessages) { + this.lang = lang; + this.langMessages = langMessages; + } + + public String getLang() { + return this.lang; + } + + public HashMap getLangMessages() { + return this.langMessages; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c00025b..430233f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -8,15 +8,6 @@ enableTorchParticles: true #What should the range of the Torch be. Default: 64 torchRange: 64 -#What should we tell the Player when they try to break a Torch which is not theirs -messageTorchBrokenOwnerMismatch: "You are not allowed to break this Torch since you do not own it!" - -#What should we tell the Player when they successfully break a torch -messageTorchBrokenSuccess: "Torch broken successfully!" - -#What should we tell the Player when they successfully place a torch -messageTorchPlacedSucccess: "Torch placed successfully!" - #What radius should we use to highlight Torches. Default: 64 torchHighlightRange: 64 diff --git a/src/main/resources/en.properties b/src/main/resources/en.properties new file mode 100644 index 0000000..c76903f --- /dev/null +++ b/src/main/resources/en.properties @@ -0,0 +1,42 @@ +welcome=Welcome to HaroTorch +goodbye=Thank you for using HaroTorch! + +#Commands +commandOnlyForPlayers=This command can only be used by Players! +noPermission=You do not have permission to use this command! +missingArguments=Missing arguments! Use %HELP_COMMAND% for help! + +#GiveExecutor +quantityNaN=The given quantity is not a number! +quantityNegOrZero=Quantity may not be 0 or negative! + +#HighlightAreaOfEffectExecutor +startingAoe=Showing the area of effect for %SECONDS% seconds! +endingAoe=Highlighting has ended! + +#HighlightExecutor +highlightVersionNotSupported=The highlight feature is not supported on this version of Minecraft! (%NMS_VERSION%) +startingHiglight=Highlighting all Torches for %SECONDS% seconds! +endingHighlight=Highlighting has ended! + +#ConvertExecutor +v1NotInstalledMessage=HaroTorch v1 is not installed. Aborting. +convertingToV2Start=Converting HaroTorch v1 Torches to v2... +convertingToV2Complete=Conversion complete. Disabling HaroTorch v1! + +#BreakEvent +blockBreakNotAllowedTorchOntop=You may not break this block. A HaroTorch stands on top! +blockBreakNotAllowedOwnerMismatch=You are not allowed to break this Torch since you do not own it! +torchBroken=Torch broken successfully! + +#PlaceEvent +torchPlaced=Torch placed successfully! + +#HelpExecutor +helpMenuTitle=HaroTorch Help Menu +helpHelp=Shows you this page. +helpHighlight=Highlight all nearby torches. +helpGive=Highlight all nearby torches. +helpConvert=Convert v1 torches to v2 torches. +helpVersion=Get the HaroTorch and NMS version number. +helpAoe=Show the Area of Effect of all nearby torches using particles \ No newline at end of file