Skip to content

Commit

Permalink
Added a command to send or broadcast the rules. (#110)
Browse files Browse the repository at this point in the history
* NEW: added a `/uh rules [receiver]` command to broadcast or send the rules on-demand.
  • Loading branch information
AmauryCarrade committed Jan 12, 2016
1 parent 1946d15 commit 9cf1dec
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import eu.carrade.amaury.UHCReloaded.commands.commands.uh.UHInfosCommand;
import eu.carrade.amaury.UHCReloaded.commands.commands.uh.UHKillCommand;
import eu.carrade.amaury.UHCReloaded.commands.commands.uh.UHResurrectCommand;
import eu.carrade.amaury.UHCReloaded.commands.commands.uh.UHRulesCommand;
import eu.carrade.amaury.UHCReloaded.commands.commands.uh.UHShiftCommand;
import eu.carrade.amaury.UHCReloaded.commands.commands.uh.UHSpawnsCommand;
import eu.carrade.amaury.UHCReloaded.commands.commands.uh.UHSpectatorsCommand;
Expand Down Expand Up @@ -99,6 +100,7 @@ public UHRootCommand(UHCReloaded plugin)
registerSubCommand(new UHTimersCommand(p));
registerSubCommand(new UHTPCommand(p));
registerSubCommand(new UHInfosCommand(p));
registerSubCommand(new UHRulesCommand(p));
registerSubCommand(new UHAboutCommand(p));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright or © or Copr. Amaury Carrade (2014 - 2016)
*
* http://amaury.carrade.eu
*
* This software is governed by the CeCILL-B license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-B
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-B license and that you accept its terms.
*/
package eu.carrade.amaury.UHCReloaded.commands.commands.uh;

import eu.carrade.amaury.UHCReloaded.UHCReloaded;
import eu.carrade.amaury.UHCReloaded.commands.commands.categories.Category;
import eu.carrade.amaury.UHCReloaded.commands.core.AbstractCommand;
import eu.carrade.amaury.UHCReloaded.commands.core.annotations.Command;
import eu.carrade.amaury.UHCReloaded.commands.core.exceptions.CannotExecuteCommandException;
import eu.carrade.amaury.UHCReloaded.i18n.I18n;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Collections;
import java.util.List;


@Command (name = "rules")
public class UHRulesCommand extends AbstractCommand
{
private UHCReloaded p;
private I18n i;

public UHRulesCommand(UHCReloaded plugin)
{
p = plugin;
i = p.getI18n();
}


@Override
public void run(CommandSender sender, String[] args) throws CannotExecuteCommandException
{
if (!p.getRulesManager().isEnabled())
{
sender.sendMessage(i.t("rules.command.unset"));
return;
}

if (args.length >= 1)
{
Player player = Bukkit.getPlayer(args[0]);
if (player != null)
{
p.getRulesManager().displayRulesTo(player);

if (!sender.equals(player))
sender.sendMessage(i.t("rules.command.sent", player.getName()));
}
else
{
sender.sendMessage(i.t("rules.command.offline", args[0]));
}
}
else
{
p.getRulesManager().broadcastRules();
}
}

@Override
public List<String> tabComplete(CommandSender sender, String[] args)
{
return null;
}

@Override
public List<String> help(CommandSender sender)
{
return null;
}

@Override
public List<String> onListHelp(CommandSender sender)
{
return Collections.singletonList(i.t("cmd.helpRules"));
}

@Override
public String getCategory()
{
return Category.MISC.getTitle();
}
}
6 changes: 6 additions & 0 deletions src/main/resources/i18n/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ keys:
helpTP: "{cc}/uh tp {ci}: teleports the spectators or an entire team. See /uh tp for details."
helpTimers: "{cc}/uh timers {ci}: manages the timers. See /uh timers for details."
helpInfos: "{cc}/uh infos {ci}: prints some infos about the current game."
helpRules: "{cc}/uh rules [player] {ci}: sends the server rules to the server or the given player."
helpAbout: "{cc}/uh about {ci}: informations about the plugin and the translation."

startHelpTitle: "{aqua}------ Beginning of the game ------"
Expand Down Expand Up @@ -575,3 +576,8 @@ keys:
rules:
header: "{red}{bold}Rules and informations"
bullet: "{darkgray}- {reset}{0}"

command:
offline: "{ce}Cannot display the rules to {0} because he (or she) is offline."
unset: "{ce}No rules are set in the config file."
sent: "{cs}Rules sent to {0}."
6 changes: 6 additions & 0 deletions src/main/resources/i18n/fr_FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ keys:
helpTP: "{cc}/uh tp {ci}: téléporte les spectateurs ou une équipe. Consultez /uh tp pour plus de détails."
helpTimers: "{cc}/uh timers {ci}: gère les comptes à rebours. Consultez /uh timers pour plus de détails."
helpInfos: "{cc}/uh infos {ci}: affiche des informations à propos du jeu en cours."
helpRules: "{cc}/uh rules [joueur] {ci}: envoie les règles du jeu au serveur ou au joueur spécifié."
helpAbout: "{cc}/uh about {ci}: informations à propos du plugin et des traductions."

startHelpTitle: "{aqua}------ Démarrage du jeu ------"
Expand Down Expand Up @@ -575,3 +576,8 @@ keys:
rules:
header: "{red}{bold}Règles et informations"
bullet: "{darkgray}- {reset}{0}"

command:
offline: "{ce}Impossible d'afficher les règles à {0} car il ou elle est hors-ligne."
unset: "{ce}Aucune règle n'est enregistrée dans le fichier de configuration."
sent: "{cs}Les règles ont été envoyées à {0}."
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ permissions:
uh.spec: true
uh.finish: true
uh.infos: true
uh.rules: true
uh.timers: true
uh.tp: true
uh.team.spy: true
Expand Down Expand Up @@ -138,6 +139,9 @@ permissions:
uh.infos:
description: Allows an user to get infos about the current game with /uh infos
default: true
uh.rules:
description: Allows an user to broadcast or send the rules on-demand
default: op
uh.about:
description: Prints some informations about the plugin and the translation.
default: true
Expand Down

0 comments on commit 9cf1dec

Please sign in to comment.