started work on translatable Strings (CreateCommand)
This commit is contained in:
parent
e2c84ec436
commit
94d796e09b
6 changed files with 80 additions and 12 deletions
|
|
@ -1,6 +1,10 @@
|
|||
package de.lunarakai.minecleaner;
|
||||
|
||||
import de.lunarakai.minecleaner.commands.SettingsCommand;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.translation.GlobalTranslator;
|
||||
import net.kyori.adventure.translation.TranslationRegistry;
|
||||
import net.kyori.adventure.util.UTF8ResourceBundleControl;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import de.iani.cubesidestats.api.CubesideStatisticsAPI;
|
||||
import de.iani.cubesideutils.bukkit.commands.CommandRouter;
|
||||
|
|
@ -12,6 +16,8 @@ import de.lunarakai.minecleaner.commands.InfoCommand;
|
|||
import de.lunarakai.minecleaner.commands.ListCommand;
|
||||
import de.lunarakai.minecleaner.commands.StatsCommand;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public final class MinecleanerPlugin extends JavaPlugin {
|
||||
|
|
@ -26,6 +32,18 @@ public final class MinecleanerPlugin extends JavaPlugin {
|
|||
@Override
|
||||
public void onEnable() {
|
||||
this.saveDefaultConfig();
|
||||
|
||||
TranslationRegistry registry = TranslationRegistry.create(Key.key("minecleaner:lang"));
|
||||
|
||||
ResourceBundle bundle_en_US = ResourceBundle.getBundle("lang.en_US", Locale.US, UTF8ResourceBundleControl.get());
|
||||
registry.registerAll(Locale.US, bundle_en_US, true);
|
||||
GlobalTranslator.translator().addSource(registry);
|
||||
|
||||
ResourceBundle bundle_de_DE = ResourceBundle.getBundle("lang.de_DE", Locale.GERMAN, UTF8ResourceBundleControl.get());
|
||||
registry.registerAll(Locale.GERMAN, bundle_de_DE, true);
|
||||
|
||||
GlobalTranslator.translator().addSource(registry);
|
||||
|
||||
getServer().getScheduler().runTask(this, this::onLateEnable);
|
||||
}
|
||||
|
||||
|
|
@ -42,6 +60,10 @@ public final class MinecleanerPlugin extends JavaPlugin {
|
|||
this.getLogger().log(Level.WARNING, "Cubeside Statistics not found. No Statistics will be available");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
arenaList = new ArenaList(this);
|
||||
arenaList.load();
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.command.Command;
|
||||
|
|
@ -22,6 +24,8 @@ import de.lunarakai.minecleaner.MinecleanerArena;
|
|||
import de.lunarakai.minecleaner.MinecleanerPlugin;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import static de.lunarakai.minecleaner.utils.MinecleanerComponentUtils.createLangComponent;
|
||||
|
||||
public class CreateCommand extends SubCommand {
|
||||
private static final Pattern VALID_ARENA_NAME = Pattern.compile("^[a-z0-9_]+$");
|
||||
|
||||
|
|
@ -55,11 +59,11 @@ public class CreateCommand extends SubCommand {
|
|||
}
|
||||
String name = args.getNext().toLowerCase().trim();
|
||||
if(!VALID_ARENA_NAME.matcher(name).matches()) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Ungültiger Arenaname. Erlaubt sind Buchstaben, Zahlen und der Unterstrich");
|
||||
sender.sendMessage(createLangComponent("arena.name.invalid", NamedTextColor.DARK_RED));
|
||||
return true;
|
||||
}
|
||||
if(plugin.getArenaList().getArena(name) != null) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Eine Arena mit diesem Namen existiert bereits");
|
||||
sender.sendMessage(createLangComponent( "arena.name.exists", NamedTextColor.DARK_RED));
|
||||
return true;
|
||||
}
|
||||
boolean noblocks = false;
|
||||
|
|
@ -73,13 +77,13 @@ public class CreateCommand extends SubCommand {
|
|||
try {
|
||||
widthindex = Integer.parseInt(arg);
|
||||
} catch(NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Kein Valider Arena WidthIndex!");
|
||||
sender.sendMessage(ChatColor.DARK_RED + "0 (oder weglassen) = 9*9, 1 = 12*12, 2 = 12*18, 3 = 12*33");
|
||||
sender.sendMessage(createLangComponent("arena.widthindex.invalid", NamedTextColor.DARK_RED));
|
||||
sender.sendMessage(createLangComponent("arena.widthindex.validOptions", NamedTextColor.DARK_RED));
|
||||
return true;
|
||||
}
|
||||
if(widthindex > 3) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Arena WidthIndex darf nicht größer als 3 sein");
|
||||
sender.sendMessage(ChatColor.DARK_RED + "0 (oder weglassen) = 9*9, 1 = 12*12, 2 = 12*18, 3 = 12*33");
|
||||
sender.sendMessage(createLangComponent( "arena.widthindex.toolarge", NamedTextColor.DARK_RED));
|
||||
sender.sendMessage(createLangComponent("arena.widthindex.validOptions", NamedTextColor.DARK_RED));
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -94,12 +98,14 @@ public class CreateCommand extends SubCommand {
|
|||
@Nullable
|
||||
RayTraceResult target = player.rayTraceBlocks(6);
|
||||
if(target == null || target.getHitBlock() == null) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Bitte gucke den Block an, der im Zentrum des " + plugin.getDisplayedPluginName() + "-Spielfelds sein soll.");
|
||||
//sender.sendMessage(ChatColor.DARK_RED + "Bitte gucke den Block an, der im Zentrum des " + plugin.getDisplayedPluginName() + "-Spielfelds sein soll.");
|
||||
sender.sendMessage(createLangComponent( "arena.create.lookAtCenter", plugin.getDisplayedPluginName(), NamedTextColor.DARK_RED));
|
||||
return true;
|
||||
}
|
||||
BlockFace face = target.getHitBlockFace();
|
||||
if(face != BlockFace.NORTH && face != BlockFace.WEST && face != BlockFace.EAST && face != BlockFace.SOUTH) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Bitte gucke die Seite des Blockes an, wo das " + plugin.getDisplayedPluginName() + "-Spielfeld erstellt werden soll.");
|
||||
//sender.sendMessage(ChatColor.DARK_RED + "Bitte gucke die Seite des Blockes an, wo das " + plugin.getDisplayedPluginName() + "-Spielfeld erstellt werden soll.");
|
||||
sender.sendMessage(createLangComponent("arena.create.lookAtSide", plugin.getDisplayedPluginName(), NamedTextColor.DARK_RED));
|
||||
return true;
|
||||
}
|
||||
location = target.getHitBlock().getLocation();
|
||||
|
|
@ -107,7 +113,7 @@ public class CreateCommand extends SubCommand {
|
|||
|
||||
MinecleanerArena newArena = new MinecleanerArena(plugin, name, location, widthindex, orientation);
|
||||
if(plugin.getArenaList().collidesWithArena(newArena)) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "An dieser Stelle befindet sich bereits eine Arena.");
|
||||
sender.sendMessage(createLangComponent("arena.create.otherArena", NamedTextColor.DARK_RED));
|
||||
return true;
|
||||
}
|
||||
newArena.generateBlockDisplays();
|
||||
|
|
@ -115,7 +121,7 @@ public class CreateCommand extends SubCommand {
|
|||
newArena.generateBackgroundBlocks();
|
||||
}
|
||||
plugin.getArenaList().addArena(newArena);
|
||||
sender.sendMessage(ChatColor.GREEN + "Die Arena wurde erfolgreich angelegt.");
|
||||
sender.sendMessage(createLangComponent("arena.create.success", NamedTextColor.GREEN));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -151,5 +157,4 @@ public class CreateCommand extends SubCommand {
|
|||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package de.lunarakai.minecleaner.utils;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
public class MinecleanerComponentUtils {
|
||||
|
||||
public static TextComponent createLangComponent(String langKey, NamedTextColor namedColor) {
|
||||
return Component.text()
|
||||
.color(namedColor)
|
||||
.append(Component.translatable(langKey))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static TextComponent createLangComponent(String langKey, String arg0, NamedTextColor namedColor) {
|
||||
return Component.text()
|
||||
.color(namedColor)
|
||||
.append(Component.translatable(langKey, Component.text(arg0)))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
9
src/main/resources/lang/de_DE.properties
Normal file
9
src/main/resources/lang/de_DE.properties
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
arena.name.invalid=Ungueltiger Arenaname. Erlaubt sind Buchstaben, Zahlen und der Unterstrich
|
||||
arena.name.exists=Eine Arena mit diesem Namen existiert bereits
|
||||
arena.widthindex.invalid=Kein Valider Arena WidthIndex!
|
||||
arena.widthindex.validOptions=0 (oder weglassen) = 9*9, 1 = 12*12, 2 = 12*18, 3 = 12*33
|
||||
arena.widthindex.toolarge=Arena WidthIndex darf nicht groesser als 3 sein
|
||||
arena.create.lookAtCenter=Bitte gucke den Block an, der im Zentrum des {0}-Spielfelds sein soll.
|
||||
arena.create.lookAtSide=Bitte gucke die Seite des Blockes an, wo das {0}-Spielfeld erstellt werden soll.
|
||||
arena.create.otherArena=An dieser Stelle befindet sich bereits eine Arena.
|
||||
arena.create.success=Die Arena wurde erfolgreich angelegt.
|
||||
9
src/main/resources/lang/en_US.properties
Normal file
9
src/main/resources/lang/en_US.properties
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
arena.name.invalid=Invalid arena name. Allowed are letters, numbers and the underscore
|
||||
arena.name.exists=An arena with this name already exists
|
||||
arena.widthindex.invalid=Not a valid Arena WidthIndex
|
||||
arena.widthindex.validOptions=0 (or leave empty) = 9*9, 1 = 12*12, 2 = 12*18, 3 = 12*33
|
||||
arena.widthindex.toolarge=Arena WidthIndex must not be greater than 3
|
||||
arena.create.lookAtCenter=Please look at the block that should be in the center of the {0} field.
|
||||
arena.create.lookAtSide=Please look at the side of the block where the {0} field is to be created.
|
||||
arena.create.otherArena=There is already an arena at this location.
|
||||
arena.create.success=The arena has been created successfully.
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
name: Minecleaner
|
||||
version: '${project.version}-${git.commit.id.abbrev}'
|
||||
version: '${project.version}-dev-${git.commit.id.abbrev}'
|
||||
author: LunarAkai
|
||||
website: https://github.com/LunarAkai/Minecleaner
|
||||
main: de.lunarakai.minecleaner.MinecleanerPlugin
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue