translatable StatsCommand
This commit is contained in:
		
					parent
					
						
							
								2bc7a3979e
							
						
					
				
			
			
				commit
				
					
						583f8a1257
					
				
			
		
					 8 changed files with 144 additions and 20 deletions
				
			
		|  | @ -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; | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -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; | ||||
|     } | ||||
| } | ||||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| package de.lunarakai.minecleaner.utils; | ||||
| 
 | ||||
| import de.iani.cubesideutils.StringUtil; | ||||
| import java.net.URL; | ||||
| 
 | ||||
| public class MinecleanerStringUtil { | ||||
|     private MinecleanerStringUtil() { | ||||
|  | @ -51,5 +51,15 @@ public class MinecleanerStringUtil { | |||
|         percent = percent * 100; | ||||
|         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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue