From f95a459bdec0ece1bc0a0b77a38318c1f8806fbb Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 24 Jan 2015 23:11:06 -0500 Subject: [PATCH] Ajout d'une commande pour voir les messages automatiques, manuellement --- resources/plugin.yml | 10 ++++ .../commands/CommandAutomessager.java | 53 +++++++++++++++++++ .../modules/AutoMessagesManager.java | 4 +- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAutomessager.java diff --git a/resources/plugin.yml b/resources/plugin.yml index d5e7ea0..d17285a 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -60,6 +60,11 @@ commands: usage: /broadcastperm permission: pandacraft.broadcast aliases: [bcperm, bcastperm, shoutperm] + automessager: + description: Afficher un des messages automatique + usage: /automessager [id] + permission: pandacraft.automessager + aliases: [am] @@ -130,6 +135,11 @@ permissions: pandacraft.broadcast: description: Utiliser la commande broadcast et broadcastperm default: op + +# à ajouter ###################### + pandacraft.automessager: + description: Utiliser la commande automessager + default: op pandacraft.antispam.exempt: diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAutomessager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAutomessager.java new file mode 100644 index 0000000..a602713 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAutomessager.java @@ -0,0 +1,53 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; + +import java.util.List; + +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.AutoMessagesManager.AutoMessage; +import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandAutomessager extends AbstractCommandExecutor { + + public CommandAutomessager() { + super("automessager"); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String alias, + String[] args) { + + List messages = plugin.autoMessagesManager.getMessagesFromConfig(); + + if (args.length == 0 || !(sender instanceof Player)) { + sender.sendMessage(ChatColor.GOLD+"Il y a "+messages.size()+" messages (de 0 à "+(messages.size()-1)+")"); + return true; + } + + int id; + try { + id = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + sender.sendMessage("§cLa valeur indiquée doit être un chiffre"); + return false; + } + + if (id < 0 || id >= messages.size()) { + sender.sendMessage("§cLe message numéro "+id+" n'existe pas"); + return false; + } + + OnlinePlayerManager + .getInstance() + .get((Player)sender) + .sendMessageFromServer(messages.get(id).getMessage()); + + + + return true; + } + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/AutoMessagesManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/AutoMessagesManager.java index 93d44b7..7496b39 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/AutoMessagesManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/AutoMessagesManager.java @@ -22,7 +22,7 @@ public class AutoMessagesManager extends BukkitRunnable { public AutoMessagesManager() { - plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, this, 0L, 20L); + plugin.getServer().getScheduler().runTaskTimer(plugin, this, 0L, 20L); } @@ -54,6 +54,8 @@ public class AutoMessagesManager extends BukkitRunnable { int id = op.getAutomessage_last_message_id(); boolean atLeastOnePermitted = true; int c = 0; + + // on cherche le prochain message à afficher do { id++; c++;