translatable StatsCommand

This commit is contained in:
LunarAkai 2024-05-15 18:55:12 +02:00
commit 583f8a1257
8 changed files with 144 additions and 20 deletions

View file

@ -43,10 +43,10 @@ public class InfoCommand extends SubCommand{
ArgsParser args) throws DisallowsCommandBlockException, RequiresPlayerException,
NoPermissionException, IllegalSyntaxException, InternalCommandException {
sender.sendMessage(NamedChatColor.GREEN + "--- " + ChatColor.AQUA + plugin.getName() + ChatColor.GREEN + " ---");
sender.sendMessage(createLangComponent("minecleaner.info.version", NamedTextColor.AQUA) + ": " + ChatColor.GREEN + plugin.getPluginMeta().getVersion());
sender.sendMessage(createLangComponent("minecleaner.info.developer", NamedTextColor.AQUA) + ": " + ChatColor.GREEN + plugin.getPluginMeta().getAuthors().get(0));
sender.sendMessage(createLangComponent("minecleaner.info.website", NamedTextColor.AQUA) + ": " + ChatColor.GREEN + plugin.getPluginMeta().getWebsite());
sender.sendMessage(createLangComponent("minecleaner.info.license", NamedTextColor.AQUA) + ": " + ChatColor.GREEN + "GPL-3.0");
sender.sendMessage(createLangComponent("minecleaner.info.version", ": ", plugin.getPluginMeta().getVersion(), NamedTextColor.AQUA, NamedTextColor.GREEN));
sender.sendMessage(createLangComponent("minecleaner.info.developer", ": ", plugin.getPluginMeta().getAuthors().get(0), NamedTextColor.AQUA, NamedTextColor.GREEN));
sender.sendMessage(createLangComponent("minecleaner.info.website", ": ", plugin.getPluginMeta().getWebsite(), NamedTextColor.AQUA, NamedTextColor.GREEN));
sender.sendMessage(createLangComponent("minecleaner.info.license", ": ", "GPL-3.0", NamedTextColor.AQUA, NamedTextColor.GREEN));
return true;
}
}

View file

@ -0,0 +1,37 @@
package de.lunarakai.minecleaner.commands;
import de.iani.cubesideutils.bukkit.commands.SubCommand;
import de.iani.cubesideutils.bukkit.commands.exceptions.*;
import de.iani.cubesideutils.commands.ArgsParser;
import de.lunarakai.minecleaner.MinecleanerPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class InviteCommand extends SubCommand {
/*
TODO:
- Invite other Players to play in Duo Mode
- Add Functionality to support multiple Players in the same game
- use settings of player that invited the other player
*/
@Override
public String getUsage() {
return "<Player>";
}
@Override
public boolean requiresPlayer() {
return true;
}
@Override
public String getRequiredPermission() {
return MinecleanerPlugin.PERMISSION_PLAY;
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String s1, ArgsParser argsParser) throws DisallowsCommandBlockException, RequiresPlayerException, NoPermissionException, IllegalSyntaxException, InternalCommandException {
return false;
}
}

View file

@ -8,7 +8,6 @@ import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import de.iani.cubesideutils.StringUtil;
import de.iani.cubesideutils.bukkit.commands.SubCommand;
import de.iani.cubesideutils.bukkit.commands.exceptions.DisallowsCommandBlockException;
import de.iani.cubesideutils.bukkit.commands.exceptions.IllegalSyntaxException;
@ -19,7 +18,6 @@ import de.iani.cubesideutils.commands.ArgsParser;
import de.lunarakai.minecleaner.MinecleanerPlugin;
import de.lunarakai.minecleaner.PlayerStatisticsData;
import de.lunarakai.minecleaner.utils.MinecleanerStringUtil;
import net.md_5.bungee.api.ChatColor;
import static de.lunarakai.minecleaner.utils.MinecleanerComponentUtils.createLangComponent;
@ -61,8 +59,22 @@ public class StatsCommand extends SubCommand {
} else {
sender.sendMessage(createLangComponent("data.player.other", plugin.getDisplayedPluginName(), data.getPlayerName(), NamedTextColor.AQUA).append(Component.text(":")));
}
sender.sendMessage(ChatColor.BLUE + " Punkte erspielt: " + ChatColor.GREEN + data.getPointsAcquiredTotal() + " (Dieser Monat: " + data.getPointsAquiredMonth() + ")");
sender.sendMessage(ChatColor.BLUE + " Runden gewonnen: " + ChatColor.GREEN + data.getWonGamesPlayed() + " (Dieser Monat: " + data.getWonGamesPlayedThisMonth() + ")");
sender.sendMessage(createLangComponent("data.player.pointsscored", NamedTextColor.BLUE)
.append(Component.text(": ", NamedTextColor.BLUE))
.append(Component.text(String.valueOf(data.getPointsAcquiredTotal()), NamedTextColor.GREEN))
.append(Component.text(" (", NamedTextColor.GREEN))
.append(createLangComponent("data.player.thismonth", NamedTextColor.GREEN))
.append(Component.text(": " + String.valueOf(data.getPointsAquiredMonth()) + ")", NamedTextColor.GREEN)));
sender.sendMessage(createLangComponent("data.player.roundswon", NamedTextColor.BLUE)
.append(Component.text(": ", NamedTextColor.BLUE))
.append(Component.text(String.valueOf(data.getWonGamesPlayed()), NamedTextColor.GREEN))
.append(Component.text(" (", NamedTextColor.GREEN))
.append(createLangComponent("data.player.thismonth", NamedTextColor.GREEN))
.append(Component.text(": " + String.valueOf(data.getWonGamesPlayedThisMonth()) + ")", NamedTextColor.GREEN)));
for(Entry<Integer, String> e : plugin.getManager().getSizes().entrySet()) {
int totalWonSize = data.getGamesPlayedSize(e.getKey());
int totalWonMonth = data.getGamesPlayedSizeThisMonth(e.getKey());
@ -70,14 +82,35 @@ public class StatsCommand extends SubCommand {
int totalSizeMonth = data.getTotalGamesPlayedSizeThisMonth(e.getKey());
if(totalSize > 0) {
String sizeName = StringUtil.capitalizeFirstLetter(e.getValue(), false);
sender.sendMessage(ChatColor.AQUA + " " + sizeName + ":");
sender.sendMessage(ChatColor.BLUE + " Runden gewonnen: " + ChatColor.GREEN + totalWonSize + " von " + totalSize + " (" + MinecleanerStringUtil.percentageString(totalWonSize, totalSize)+ ") ");
sender.sendMessage(ChatColor.BLUE + " Dieser Monat: " + ChatColor.GREEN + totalWonMonth + " von " + totalSizeMonth + " (" + MinecleanerStringUtil.percentageString(totalWonMonth, totalSizeMonth)+ ")");
String sizeName = e.getValue();
if(sizeName.equals("groß")) {
sizeName = "gross";
}
sender.sendMessage(createLangComponent("arena.width." + sizeName, NamedTextColor.AQUA).append(Component.text(":", NamedTextColor.AQUA)));
sender.sendMessage(Component.text(" ")
.append(createLangComponent("data.player.roundswon", NamedTextColor.BLUE))
.append(Component.text(" "))
.append(Component.text(String.valueOf(totalWonSize), NamedTextColor.GREEN))
.append(Component.text(" "))
.append(createLangComponent("data.player.outof", NamedTextColor.GREEN))
.append(Component.text(" " + totalSize + " (" + MinecleanerStringUtil.percentageString(totalWonSize, totalSize) + ")", NamedTextColor.GREEN)));
sender.sendMessage(Component.text(" ")
.append(createLangComponent("data.player.thismonth", NamedTextColor.BLUE))
.append(Component.text(" "))
.append(Component.text(String.valueOf(totalWonMonth), NamedTextColor.GREEN))
.append(Component.text(" "))
.append(createLangComponent("data.player.outof", NamedTextColor.GREEN))
.append(Component.text(" " + totalSize + " (" + MinecleanerStringUtil.percentageString(totalWonMonth, totalSizeMonth) + ")", NamedTextColor.GREEN)));
Integer time = data.getBestTime(e.getKey());
Integer timeThisMonth = data.getBestTimeThisMonth(e.getKey());
sender.sendMessage(ChatColor.BLUE + " Bestzeit: " + ChatColor.GREEN + (time == null ? "-" : MinecleanerStringUtil.timeToString(time, false)));
sender.sendMessage(ChatColor.BLUE + " Dieser Monat: " + ChatColor.GREEN + (timeThisMonth == null ? "-" : MinecleanerStringUtil.timeToString(timeThisMonth, false)));
sender.sendMessage(Component.text(" ")
.append(createLangComponent("data.player.besttime",": ", (time == null ? "-" : MinecleanerStringUtil.timeToString(time, false)), NamedTextColor.BLUE, NamedTextColor.GREEN)));
sender.sendMessage(Component.text(" ")
.append(createLangComponent("data.player.thismonth", ": ", (timeThisMonth == null ? "-" : MinecleanerStringUtil.timeToString(timeThisMonth, false)), NamedTextColor.BLUE, NamedTextColor.GREEN)));
}
}
}
@ -86,7 +119,7 @@ public class StatsCommand extends SubCommand {
if(sender instanceof Player) {
plugin.getManager().getStatisticsForPlayer((Player) sender, callback);
} else {
sender.sendMessage(ChatColor.GREEN + "Für die Konsole existieren keine Daten.");
sender.sendMessage(createLangComponent("data.console.nodata", NamedTextColor.GREEN));
}
} else {
plugin.getManager().getStatisticsForPlayerIfExists(playerName, callback);

View file

@ -2,6 +2,7 @@ package de.lunarakai.minecleaner.utils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
public class MinecleanerComponentUtils {
@ -27,4 +28,25 @@ public class MinecleanerComponentUtils {
.build();
}
public static TextComponent createLangComponent(String langKey, String filler, String arg1, NamedTextColor namedColor, NamedTextColor namedColorArg1) {
if(MinecleanerStringUtil.isValidURL(arg1)) {
TextComponent urlMessage = Component.text(arg1);
urlMessage = urlMessage.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, arg1));
urlMessage = urlMessage.color(namedColorArg1);
return Component.text()
.color(namedColor)
.append(Component.translatable(langKey))
.append(Component.text(filler))
.append(urlMessage)
.build();
} else {
return Component.text()
.color(namedColor)
.append(Component.translatable(langKey))
.append(Component.text(filler))
.append(Component.text(arg1, namedColorArg1))
.build();
}
}
}

View file

@ -1,6 +1,6 @@
package de.lunarakai.minecleaner.utils;
import de.iani.cubesideutils.StringUtil;
import java.net.URL;
public class MinecleanerStringUtil {
private MinecleanerStringUtil() {
@ -52,4 +52,14 @@ public class MinecleanerStringUtil {
String percentageString = String.format("%.1f", percent);
return percentageString + "%";
}
public static boolean isValidURL(String urlString) {
try {
URL url = new URL(urlString);
url.toURI();
return true;
} catch (Exception e) {
return false;
}
}
}

View file

@ -5,6 +5,10 @@ minecleaner.info.license=Lizenz
arena.name.invalid=Ungueltiger Arenaname. Erlaubt sind Buchstaben, Zahlen und der Unterstrich
arena.name.exists=Eine Arena mit diesem Namen existiert bereits
arena.width.klein=Klein
arena.width.mittel=Mittel
arena.width.gross=Gross
arena.width.experte=Experte
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
@ -19,6 +23,13 @@ arena.list.none=(keine)
data.player.noData=Fuer Spieler "{0}" existieren keine Daten.
data.player.self=Deine {0} Statistik
data.player.other={0}-Statistik von {1}
data.player.roundswon=Runden gewonnen
data.player.pointsscored=Punkte erspielt
data.player.from=von
data.player.besttime=Bestzeit
data.player.thismonth=Dieser Monat
data.delete.playerNotFound=Ein Spieler mit dem Namen "{0}" konnte nicht gefunden werden.
data.delete.deleted=Alle {0}-Statistiken von Spieler "{1}" wurden geloescht.
data.console.nodata=Fuer die Konsole existieren keine Daten.

View file

@ -5,6 +5,10 @@ minecleaner.info.license=License
arena.name.invalid=Invalid arena name. Allowed are letters, numbers and the underscore
arena.name.exists=An arena with this name already exists
arena.width.klein=Small
arena.width.mittel=Medium
arena.width.gross=Large
arena.width.experte=Expert
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
@ -19,6 +23,13 @@ arena.list.none=(none)
data.player.noData=No data exists for player "{0}".
data.player.self=Your {0} statistics
data.player.other={0} statistics from {1}
data.player.roundswon=Rounds won
data.player.pointsscored=Points scored
data.player.outof=out of
data.player.besttime=Best time
data.player.thismonth=This month
data.delete.playerNotFound=A player with the name "{0}" could not be found.
data.delete.deleted=All {0} stats of player "{1}" have been deleted.
data.console.nodata=No data exists for the console.

View file

@ -1,7 +1,7 @@
name: Minecleaner
version: '${project.version}-${git.commit.id.abbrev}'
author: LunarAkai
website: https://github.com/LunarAkai/Minecleaner
website: https://git.lunarakai.de/LunarAkai/NewMinecleaner
main: de.lunarakai.minecleaner.MinecleanerPlugin
api-version: '1.20'
depend: