Skip to content

Commit

Permalink
Added /uh about command to display infos about the plugin & the trans…
Browse files Browse the repository at this point in the history
…lation.

Also, reorganized commands in the help.
  • Loading branch information
AmauryCarrade committed Aug 20, 2014
1 parent bd1f4e0 commit 9d0273e
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 5 deletions.
43 changes: 42 additions & 1 deletion src/main/java/me/azenet/UHPlugin/UHPluginCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import me.azenet.UHPlugin.i18n.I18n;

Expand Down Expand Up @@ -33,6 +34,7 @@ public UHPluginCommand(UHPlugin p) {
this.p = p;
this.i = p.getI18n();

commands.add("about");
commands.add("start");
commands.add("shift");
commands.add("team");
Expand Down Expand Up @@ -158,7 +160,6 @@ private void help(CommandSender sender, boolean error) {
sender.sendMessage(i.t("cmd.helpAddspawn"));
sender.sendMessage(i.t("cmd.helpAddspawnXZ"));
sender.sendMessage(i.t("cmd.helpSpec"));
sender.sendMessage(i.t("cmd.helpFreeze"));
sender.sendMessage(i.t("cmd.helpWall"));
sender.sendMessage(i.t("cmd.helpBorder"));

Expand All @@ -167,6 +168,10 @@ private void help(CommandSender sender, boolean error) {
sender.sendMessage(i.t("cmd.helpHealall"));
sender.sendMessage(i.t("cmd.helpResurrect"));
sender.sendMessage(i.t("cmd.helpTpback"));

sender.sendMessage(i.t("cmd.titleMiscCmd"));
sender.sendMessage(i.t("cmd.helpFreeze"));
sender.sendMessage(i.t("cmd.helpAbout"));
}

/**
Expand Down Expand Up @@ -202,6 +207,42 @@ private void unauthorized(CommandSender sender, Command command) {
sender.sendMessage(i.t("cmd.errorUnauthorized"));
}


/**
* This command prints some informations about the plugin and the translation.
* Usage: /uh about
*
* @param sender
* @param command
* @param label
* @param args
*/
@SuppressWarnings("unused")
private void doAbout(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) sender.sendMessage("");
sender.sendMessage(i.t("cmd.titleHelp", p.getDescription().getDescription(), p.getDescription().getVersion()));

String authors = "";
List<String> listAuthors = p.getDescription().getAuthors();
for(String author : listAuthors) {
if(author == listAuthors.get(0)) {
// Nothing
}
else if(author == listAuthors.get(listAuthors.size() - 1)) {
authors += " " + i.t("about.and") + " ";
}
else {
authors += ", ";
}
authors += author;
}
sender.sendMessage(i.t("about.authors", authors));

sender.sendMessage(i.t("about.i18n.title"));
sender.sendMessage(i.t("about.i18n.selected", i.getSelectedLanguage(), i.getTranslator(i.getSelectedLanguage())));
sender.sendMessage(i.t("about.i18n.fallback", i.getDefaultLanguage(), i.getTranslator(i.getDefaultLanguage())));
}

/**
* This command starts the game.
* Usage: /uh start [slow]
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/me/azenet/UHPlugin/i18n/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,37 @@ public I18n(Plugin plugin) {
this(plugin, Locale.getDefault().toString());
}

/**
* Returns the translator of the given language.
*
* @param lang The language.
* @return The translator, or null if not defined.
*/
public String getTranslator(String lang) {
if(this.languageSource.get(lang) == null) {
return null;
}
return this.languageSource.get(lang).getString("author");
}

/**
* Returns the selected language.
*
* @return The code of the language (ex. en_US).
*/
public String getSelectedLanguage() {
return this.selectedLanguage;
}

/**
* Returns the default (fallback) language.
*
* @return The code of the language (ex. en_US).
*/
public String getDefaultLanguage() {
return this.defaultLanguage;
}

/**
* Returns the translated value associated to a key.
*
Expand Down
17 changes: 14 additions & 3 deletions src/main/resources/i18n/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ keys:
helpAddspawn: "{cc}/uh addspawn {ci}: adds a spawn point for a team or a player, at the current location of the sender."
helpAddspawnXZ: "{cc}/uh addspawn <x> <z> {ci}: adds a spawn point for a team or a player, at the provided coordinates."
helpSpec: "{cc}/uh spec {ci}: manages the spectators. Execute /uh spec for details."
helpFreeze: "{cc}/uh freeze {ci}: (un)freezes the entire game, or a player. See /uh freeze for details."
helpWall: "{cc}/uh generatewalls {ci}: generates the walls according to the configuration."
helpBorder: "{cc}/uh border {ci}: manages borders. Execute /uh border for details."

Expand All @@ -45,13 +44,17 @@ keys:
helpResurrect: "{cc}/uh resurrect <player> {ci}: resurrects a player."
helpTpback: "{cc}/uh tpback <player> [force] {ci}: safely teleports back a player to his death location."

titleMiscCmd: "{aqua}------ Miscellaneous commands ------"
helpFreeze: "{cc}/uh freeze {ci}: (un)freezes the entire game, or a player. See /uh freeze for details."
helpAbout: "{cc}/uh about {ci}: informations about the plugin and the translation"

teamHelpAvailable: "{ci}Available options are listed below."
teamHelpAdd: "{cc}/uh team add <color> {ci}: adds a team with the provided color."
teamHelpAddName: "{cc}/uh team add <color> <name ...> {ci}: adds a named team with the provided name and color."
teamHelpRemove: "{cc}/uh team remove <name ...> {ci}: removes a team"
teamHelpAddplayer: "{cc}/uh team addplayer <player> <teamName ...>{ci}: adds a player inside the given team. The name of the team is it color, or the explicit name given."
teamHelpRemoveplayer: "{cc}/uh team removeplayer <player> {ci}: removes a player from his team."
teamHelpList: "{cc}/uh team list {ci}: list the teams and their players."
teamHelpList: "{cc}/uh team list {ci}: lists the teams and their players."
teamHelpReset: "{cc}/uh team reset {ci}: removes all teams."

specHelpAvailable: "{ci}Available options are listed below."
Expand All @@ -67,11 +70,19 @@ keys:

borderHelpAvailable: "{ci}Available options are listed below."
borderHelpCurrent: "{cc}/uh border current{ci}: returns the current size of the map."
borderHelpSet: "{cc}/uh border set <diameter> [force]{ci}: change the size of the map. If force is not given, the operation will be canceled if there is a player outside the border."
borderHelpSet: "{cc}/uh border set <diameter> [force]{ci}: changes the size of the map. If force is not given, the operation will be canceled if there is a player outside the border."
borderHelpWarning: "{cc}/uh border warning <futureDiameter> [minutesBeforeReduction]{ci}: warns all players outside the given future diameter. It's just a notice, nothing else."
borderHelpWarningCancel: "{cc}/uh border warning cancel{ci}: cancels a previously-set warning."
borderHelpCheck: "{cc}/uh border check <diameter>{ci}: returns a list of the players outside the given border size."

about:
authors: "Plugin made with love by {0}."
and: "and"

i18n:
title: "{aqua}------ Translations ------"
selected: "Current language: {0} (translated by {1})"
fallback: "Fallback language: {0} (translated by {1})"

start:
already: "{ce}The game is already started! Reload or restart the server to restart the game."
Expand Down
14 changes: 13 additions & 1 deletion src/main/resources/i18n/fr_FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ keys:
helpAddspawn: "{cc}/uh addspawn {ci}: ajoute un point de démarrage pour une équipe ou un joueur, à la position de l'exécutant."
helpAddspawnXZ: "{cc}/uh addspawn <x> <z> {ci}: ajoute un point de démarrage pour une équipe ou un joueur, aux coordonnées données."
helpSpec: "{cc}/uh spec {ci}: gère les spectateurs. Exécutez /uh spec pour plus de détails."
helpFreeze: "{cc}/uh freeze {ci}: (dés)immobilise l'ensemble du jeu, ou un joueur. Consultez /uh freeze pour plus de détails."
helpWall: "{cc}/uh generatewalls {ci}: génère les murs suivant la configuration."
helpBorder: "{cc}/uh border {ci}: gère la bordure. Exécutez /uh border pour plus de détails."

Expand All @@ -45,6 +44,10 @@ keys:
helpResurrect: "{cc}/uh resurrect <joueur> {ci}: fait revivre un joueur."
helpTpback: "{cc}/uh tpback <joueur> [force] {ci}: téléporte un joueur au lieu de sa mort en toute sécurité."

titleMiscCmd: "{aqua}------ Commandes diverses ------"
helpFreeze: "{cc}/uh freeze {ci}: (dés)immobilise l'ensemble du jeu, ou un joueur. Consultez /uh freeze pour plus de détails."
helpAbout: "{cc}/uh about {ci}: informations à propos du plugin et des traductions"

teamHelpAvailable: "{ci}Les options disponibles sont listées ci-dessous."
teamHelpAdd: "{cc}/uh team add <couleur> {ci}: ajoute une équipe de la couleur donnée."
teamHelpAddName: "{cc}/uh team add <couleur> <nom ...> {ci}: ajoute une équipe avec le nom et la couleur donnés."
Expand Down Expand Up @@ -72,6 +75,15 @@ keys:
borderHelpWarningCancel: "{cc}/uh border warning cancel{ci}: annule un précédent avertissement."
borderHelpCheck: "{cc}/uh border check <diamètre>{ci}: retourne la liste des joueurs hors de la bordure."

about:
authors: "Plugin réalisé avec amour par {0}."
and: "et"

i18n:
title: "{aqua}------ Traductions ------"
selected: "Langue courante : {0} (traduit par {1})"
fallback: "Langue par défaut : {0} (traduit par {1})"

start:
already: "{ce}Le jeu est déjà démarré ! Rechargez ou redémarrez le serveur pour redémarrer."
syntax: "{ce}Erreur de syntaxe. Utilisation : /uh start [slow] ou /uh start slow go."
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ permissions:
description: Gives access to all Ultra Hardcore commands.
children:
uh.build: true
uh.about: true
uh.start: true
uh.shift: true
uh.team: true
uh.addspawn: true
uh.generatewalls: true
uh.freeze: true
uh.border: true
uh.heal: true
uh.healall: true
uh.tpback: true
Expand All @@ -36,6 +39,9 @@ permissions:
uh.build:
description: Allows an user to build before the beginning of the game
default: op
uh.about:
description: Prints some informations about the plugin and the translation.
default: true
uh.start:
description: Allows an user to start the game with /uh start
default: op
Expand All @@ -51,6 +57,9 @@ permissions:
uh.generatewalls:
description: Allows an user to generate the walls around the map
default: op
uh.freeze:
description: Allows an user to freeze the players
default: op
uh.border:
description: Allows an user to manage the border using /uh border *
default: op
Expand Down

0 comments on commit 9d0273e

Please sign in to comment.