Ajout d'une commande pour voir les messages automatiques, manuellement

This commit is contained in:
Marc Baloup 2015-01-24 23:11:06 -05:00
parent b917f40f6d
commit f95a459bde
3 changed files with 66 additions and 1 deletions

View File

@ -60,6 +60,11 @@ commands:
usage: /broadcastperm <permission> <message> usage: /broadcastperm <permission> <message>
permission: pandacraft.broadcast permission: pandacraft.broadcast
aliases: [bcperm, bcastperm, shoutperm] 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: pandacraft.broadcast:
description: Utiliser la commande broadcast et broadcastperm description: Utiliser la commande broadcast et broadcastperm
default: op default: op
# à ajouter ######################
pandacraft.automessager:
description: Utiliser la commande automessager
default: op
pandacraft.antispam.exempt: pandacraft.antispam.exempt:

View File

@ -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<AutoMessage> 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;
}
}

View File

@ -22,7 +22,7 @@ public class AutoMessagesManager extends BukkitRunnable {
public AutoMessagesManager() 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(); int id = op.getAutomessage_last_message_id();
boolean atLeastOnePermitted = true; boolean atLeastOnePermitted = true;
int c = 0; int c = 0;
// on cherche le prochain message à afficher
do { do {
id++; id++;
c++; c++;