Skip to content

Commit

Permalink
Added language-file support
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDutchMC committed Oct 7, 2020
1 parent fcbf43e commit c847230
Show file tree
Hide file tree
Showing 16 changed files with 243 additions and 57 deletions.
15 changes: 4 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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')

}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pluginVersion = 2.1.1
pluginVersion = 2.1.2
pluginGroup = nl.thedutchmc.harotorch
pluginName = HaroTorch
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/nl/thedutchmc/harotorch/HaroTorch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,17 +26,20 @@ 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);

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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Torchy> torchys = nl.thedutchmc.haro_torch.plugin.torch.TorchHandler.getTorches();

Expand All @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,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 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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Location> nearbyTorches = TorchHandler.getTorchLocationsNearPlayer((Player) sender, HaroTorch.getConfigHandler().torchHighlightRange);
final List<TorchParticleObject> torchParticles = new ArrayList<>();
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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);

Expand All @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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"));
}
}
}
Loading

0 comments on commit c847230

Please sign in to comment.