Translation support

This commit is contained in:
dfsek
2020-10-07 02:46:44 -07:00
parent c107f98550
commit 68863241da
41 changed files with 272 additions and 109 deletions

View File

@@ -5,6 +5,7 @@ import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.genconfig.OreConfig;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
@@ -23,17 +24,16 @@ public class OreCommand extends WorldCommand {
if(args.length > 0) {
OreConfig ore = TerraWorld.getWorld(w).getConfig().getOre(args[0]);
if(ore == null) {
sender.sendMessage("Unable to find Ore");
LangUtil.send("command.ore.invalid-ore", sender, args[0]);
return true;
}
if(bl == null) {
sender.sendMessage("Block out of range");
LangUtil.send("command.ore.out-of-range", sender);
return true;
}
ore.doVein(bl.getLocation(), new Random());
} else {
sender.sendMessage("---------------Terra/ore---------------");
sender.sendMessage("Generates a vein of ore at the block you are looking at.");
LangUtil.send("command.ore.main-menu", sender);
}
return true;
}

View File

@@ -3,6 +3,7 @@ package com.dfsek.terra.command;
import com.dfsek.terra.Terra;
import com.dfsek.terra.command.type.Command;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@@ -23,7 +24,7 @@ public class ReloadCommand extends Command {
@Override
public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
ConfigUtil.loadConfig(Terra.getInstance());
sender.sendMessage("Reloaded Terra config.");
LangUtil.send("command.reload", sender);
return true;
}

View File

@@ -1,6 +1,8 @@
package com.dfsek.terra.command;
import com.dfsek.terra.command.type.Command;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
@@ -10,16 +12,16 @@ import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class SaveDataCommand extends Command {
public class SaveDataCommand extends WorldCommand {
@Override
public String getName() {
return "save-data";
}
@Override
public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
public boolean execute(@NotNull Player sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
TerraChunkGenerator.saveAll();
sender.sendMessage("Saved population data.");
LangUtil.send("debug.data-save", sender, w.getName());
return true;
}

View File

@@ -6,6 +6,7 @@ import com.dfsek.terra.command.image.ImageCommand;
import com.dfsek.terra.command.profile.ProfileCommand;
import com.dfsek.terra.command.structure.StructureCommand;
import com.dfsek.terra.command.type.Command;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@@ -35,13 +36,7 @@ public class TerraCommand extends Command {
@Override
public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
sender.sendMessage("--------------------Terra--------------------");
sender.sendMessage("reload - Reload configuration data");
sender.sendMessage("biome - Get current biome");
sender.sendMessage("ore - Generate an ore vein at the location you are facing (For debugging)");
sender.sendMessage("save-data - Save population data");
sender.sendMessage("structure - Load and export structures");
sender.sendMessage("profile - Profiler options");
LangUtil.send("command.main-menu", sender);
return true;
}

View File

@@ -4,6 +4,7 @@ import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -20,7 +21,7 @@ public class BiomeCommand extends WorldCommand {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
TerraBiomeGrid grid = TerraWorld.getWorld(sender.getWorld()).getGrid();
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(sender.getLocation(), GenerationPhase.POPULATE);
sender.sendMessage("You are in " + TerraWorld.getWorld(w).getConfig().getBiome(biome).getID());
LangUtil.send("command.biome.in", sender, TerraWorld.getWorld(w).getConfig().getBiome(biome).getID());
return true;
}

View File

@@ -5,6 +5,7 @@ import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.async.AsyncBiomeFinder;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bukkit.Bukkit;
import org.bukkit.World;
@@ -30,14 +31,14 @@ public class BiomeLocateCommand extends WorldCommand {
try {
maxRadius = Integer.parseInt(args[1]);
} catch(NumberFormatException e) {
sender.sendMessage("Invalid radius: " + args[1]);
LangUtil.send("command.biome.invalid-radius", sender, args[1]);
return true;
}
UserDefinedBiome b;
try {
b = TerraWorld.getWorld(world).getConfig().getBiome(id).getBiome();
} catch(IllegalArgumentException | NullPointerException e) {
sender.sendMessage("Invalid biome ID: " + id);
LangUtil.send("command.biome.invalid", sender, id);
return true;
}
Bukkit.getScheduler().runTaskAsynchronously(Terra.getInstance(), new AsyncBiomeFinder(TerraWorld.getWorld(world).getGrid(), b, sender, 0, maxRadius, tp));

View File

@@ -1,6 +1,7 @@
package com.dfsek.terra.command.geometry;
import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.procgen.voxel.DeformedSphere;
import com.dfsek.terra.procgen.voxel.Sphere;
import org.bukkit.Material;
@@ -21,14 +22,14 @@ public class DeformedSphereCommand extends PlayerCommand {
try {
radius = Integer.parseInt(args[0]);
} catch(NumberFormatException e) {
sender.sendMessage("Invalid radius: " + args[0]);
LangUtil.send("command.geometry.deform.invalid-radius", sender, args[0]);
return true;
}
double deform;
try {
deform = Double.parseDouble(args[1]);
} catch(NumberFormatException e) {
sender.sendMessage("Invalid deform: " + args[1]);
LangUtil.send("command.geometry.deform.invalid-deform", sender, args[1]);
return true;
}
@@ -36,7 +37,7 @@ public class DeformedSphereCommand extends PlayerCommand {
try {
freq = Float.parseFloat(args[2]);
} catch(NumberFormatException e) {
sender.sendMessage("Invalid frequency: " + args[2]);
LangUtil.send("command.geometry.deform.invalid-frequency", sender, args[2]);
return true;
}
FastNoise n = new FastNoise((int) sender.getWorld().getSeed());

View File

@@ -1,6 +1,7 @@
package com.dfsek.terra.command.geometry;
import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -13,11 +14,7 @@ import java.util.List;
public class GeometryCommand extends PlayerCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
sender.sendMessage("---------------Terra/geometry----------------");
sender.sendMessage("Various voxel geometry debugging commands");
sender.sendMessage("sphere - Generate a sphere");
sender.sendMessage("deformsphere - Generate a deformed sphere");
sender.sendMessage("tube - Generate a tube");
LangUtil.send("command.geometry.main-menu", sender);
return true;
}

View File

@@ -1,6 +1,7 @@
package com.dfsek.terra.command.geometry;
import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.procgen.voxel.Sphere;
import org.bukkit.Material;
import org.bukkit.command.Command;
@@ -19,7 +20,7 @@ public class SphereCommand extends PlayerCommand {
try {
radius = Integer.parseInt(args[0]);
} catch(NumberFormatException e) {
sender.sendMessage("Invalid radius: " + args[0]);
LangUtil.send("command.geometry.sphere.invalid-radius", sender, args[0]);
return true;
}
Sphere sphere = new Sphere(sender.getLocation().toVector(), radius);

View File

@@ -1,5 +1,6 @@
package com.dfsek.terra.command.geometry;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.util.structure.WorldEditUtil;
import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.procgen.voxel.Tube;
@@ -23,7 +24,7 @@ public class TubeCommand extends PlayerCommand {
try {
radius = Integer.parseInt(args[0]);
} catch(NumberFormatException e) {
sender.sendMessage("Invalid radius: " + args[0]);
LangUtil.send("command.geometry.tube.invalid-radius", sender, args[0]);
return true;
}
Tube tube = new Tube(l[0].toVector(), l[1].toVector(), radius);

View File

@@ -2,6 +2,7 @@ package com.dfsek.terra.command.image;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.command.image.gui.GUICommand;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -15,9 +16,7 @@ import java.util.List;
public class ImageCommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
sender.sendMessage("---------------Terra/image---------------");
sender.sendMessage("render - Render an image with a given width and height, that can later be imported as a world.");
sender.sendMessage("gui - Open debug GUI (Must be enabled in config)");
LangUtil.send("command.image.main-menu", sender);
return true;
}

View File

@@ -2,6 +2,7 @@ package com.dfsek.terra.command.image;
import com.dfsek.terra.Terra;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.image.WorldImageGenerator;
import org.bukkit.World;
import org.bukkit.command.Command;
@@ -23,11 +24,11 @@ public class RenderCommand extends WorldCommand {
file.mkdirs();
file.createNewFile();
g.save(file);
sender.sendMessage("Saved image to " + file.getPath());
LangUtil.send("command.image.render.save", sender, file.getAbsolutePath());
return true;
} catch(Exception e) {
e.printStackTrace();
sender.sendMessage("An error occurred while generating the image!");
LangUtil.send("command.image.render.error", sender);
return true;
}
}

View File

@@ -1,6 +1,7 @@
package com.dfsek.terra.command.image.gui;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -14,9 +15,7 @@ import java.util.List;
public class GUICommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
sender.sendMessage("-------------Terra/image/gui-------------");
sender.sendMessage("raw - Open GUI with raw Biome data");
sender.sendMessage("step - Re-render data to show borders more clearly");
LangUtil.send("command.image.gui.main-menu", sender);
return true;
}

View File

@@ -4,6 +4,7 @@ import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.image.ImageLoader;
import org.bukkit.World;
import org.bukkit.command.Command;
@@ -18,7 +19,7 @@ public class RawGUICommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
if(! ConfigUtil.debug) {
sender.sendMessage("Debug mode must be enabled to use the debug GUI! The debug GUI is NOT PRODUCTION SAFE!");
LangUtil.send("command.image.gui.debug", sender);
return true;
}
ImageLoader loader = TerraWorld.getWorld(world).getWorldConfig().imageLoader;

View File

@@ -4,6 +4,7 @@ import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.image.ImageLoader;
import org.bukkit.World;
import org.bukkit.command.Command;
@@ -18,7 +19,7 @@ public class StepGUICommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
if(! ConfigUtil.debug) {
sender.sendMessage("Debug mode must be enabled to use the debug GUI! The debug GUI is NOT PRODUCTION SAFE!");
LangUtil.send("command.image.gui.debug", sender);
return true;
}
ImageLoader loader = TerraWorld.getWorld(world).getWorldConfig().imageLoader;

View File

@@ -1,6 +1,7 @@
package com.dfsek.terra.command.profile;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -14,11 +15,7 @@ import java.util.List;
public class ProfileCommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
sender.sendMessage("---------------Terra/profile---------------");
sender.sendMessage("start - Starts the profiler");
sender.sendMessage("stop - Stops the profiler");
sender.sendMessage("query - Fetches profiler data");
sender.sendMessage("reset - Resets profiler data");
LangUtil.send("command.profile.main-menu", sender);
return true;
}

View File

@@ -2,6 +2,7 @@ package com.dfsek.terra.command.profile;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -17,7 +18,7 @@ public class ResetCommand extends WorldCommand {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = TerraProfiler.fromWorld(world);
profile.reset();
sender.sendMessage("Profiler has been reset.");
LangUtil.send("command.profile.reset", sender);
return true;
}

View File

@@ -2,6 +2,7 @@ package com.dfsek.terra.command.profile;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -17,7 +18,7 @@ public class StartCommand extends WorldCommand {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = TerraProfiler.fromWorld(world);
profile.setProfiling(true);
sender.sendMessage("Profiler has started.");
LangUtil.send("command.profile.start", sender);
return true;
}

View File

@@ -2,6 +2,7 @@ package com.dfsek.terra.command.profile;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -17,7 +18,7 @@ public class StopCommand extends WorldCommand {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = TerraProfiler.fromWorld(world);
profile.setProfiling(false);
sender.sendMessage("Profiler has stopped.");
LangUtil.send("command.profile.stop", sender);
return true;
}

View File

@@ -1,6 +1,7 @@
package com.dfsek.terra.command.structure;
import com.dfsek.terra.Terra;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.util.structure.WorldEditUtil;
import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.structure.GaeaStructure;
@@ -35,7 +36,7 @@ public class ExportCommand extends PlayerCommand {
file.getParentFile().mkdirs();
file.createNewFile();
structure.save(file);
sender.sendMessage("Saved structure with ID " + structure.getId() + ", UUID: " + structure.getUuid().toString() + " to " + file.getPath());
LangUtil.send("command.structure.export", sender, file.getAbsolutePath());
} catch(IOException e) {
e.printStackTrace();
}

View File

@@ -2,6 +2,7 @@ package com.dfsek.terra.command.structure;
import com.dfsek.terra.Terra;
import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.structure.GaeaStructure;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -23,7 +24,7 @@ public class LoadCommand extends PlayerCommand {
else struc.paste(sender.getLocation(), sender.getLocation().getChunk(), r);
} catch(IOException e) {
e.printStackTrace();
sender.sendMessage("Structure not found.");
LangUtil.send("command.structure.invalid", sender, args[0]);
}
return true;
}

View File

@@ -6,6 +6,7 @@ import com.dfsek.terra.async.AsyncStructureFinder;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.genconfig.StructureConfig;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.generation.TerraChunkGenerator;
import com.dfsek.terra.procgen.GridSpawn;
import org.bukkit.Bukkit;
@@ -35,14 +36,14 @@ public class LocateCommand extends WorldCommand {
try {
maxRadius = Integer.parseInt(args[1]);
} catch(NumberFormatException e) {
sender.sendMessage("Invalid radius: " + args[1]);
LangUtil.send("command.structure.invalid-radius", sender, args[1]);
return true;
}
StructureConfig s;
try {
s = Objects.requireNonNull(TerraWorld.getWorld(world).getConfig().getStructure(id));
} catch(IllegalArgumentException | NullPointerException e) {
sender.sendMessage("Invalid biome ID: " + id);
LangUtil.send("command.structure.invalid", sender, id);
return true;
}
Bukkit.getScheduler().runTaskAsynchronously(Terra.getInstance(), new AsyncStructureFinder(TerraWorld.getWorld(world).getGrid(), s, sender, 0, maxRadius, tp));

View File

@@ -1,6 +1,7 @@
package com.dfsek.terra.command.structure;
import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -13,9 +14,7 @@ import java.util.List;
public class StructureCommand extends PlayerCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
sender.sendMessage("---------------Terra/structure---------------");
sender.sendMessage("export - Export your current WorldEdit selection as a Terra structure.");
sender.sendMessage("load - Load a Terra structure");
LangUtil.send("command.structure.main-menu", sender);
return true;
}

View File

@@ -1,6 +1,7 @@
package com.dfsek.terra.command.type;
import com.dfsek.terra.Debug;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
@@ -67,7 +68,7 @@ public abstract class Command implements CommandExecutor, TabCompleter {
if(c.getName().equals(args[0])) return c.onCommand(sender, command, label, Arrays.stream(args, 1, args.length).toArray(String[]::new));
}
if(args.length != arguments()) {
sender.sendMessage("Invalid command. (Expected " + arguments() + " arguments, found " + args.length + ").");
LangUtil.send("command.invalid", sender, String.valueOf(arguments()), String.valueOf(args.length));
return true;
}
return execute(sender, command, label, args);

View File

@@ -1,5 +1,6 @@
package com.dfsek.terra.command.type;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -23,7 +24,7 @@ public abstract class PlayerCommand extends Command {
@Override
public final boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
if(!(sender instanceof Player)) {
sender.sendMessage("Command is for players only.");
LangUtil.send("command.players-only", sender);
return true;
}
Player p = (Player) sender;

View File

@@ -1,5 +1,6 @@
package com.dfsek.terra.command.type;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bukkit.World;
import org.bukkit.command.Command;
@@ -27,7 +28,7 @@ public abstract class WorldCommand extends PlayerCommand {
if(sender.getWorld().getGenerator() instanceof TerraChunkGenerator) {
return execute(sender, command, label, args, sender.getWorld());
} else {
sender.sendMessage("This world is not a Terra world!");
LangUtil.send("command.world", sender);
}
return true;
}