Ajout de la commande /muco

This commit is contained in:
Marc Baloup 2015-02-16 21:48:02 -05:00
parent c0db2ed949
commit 0b6b288c8d
5 changed files with 319 additions and 3 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jardesc>
<jar path="PandacraftUtils/jar_export/PandacraftUtils-3.10.jar"/>
<jar path="PandacraftUtils/jar_export/PandacraftUtils-3.11.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/PandacraftUtils/make_jar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>

View File

@ -1,6 +1,6 @@
name: PandacraftUtils
main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils
version: 3.10
version: 3.11
@ -78,6 +78,10 @@ commands:
usage: /coeur
permission: pandacraft.coeur
aliases: [heart, love]
muco:
description: Succession automatique de commandes
usage: /muco <NomListe> [paramètres ...]
permission: pandacraft.muco
@ -166,9 +170,21 @@ permissions:
#### à ajouter
pandacraft.coeur:
description: Utiliser la commande animal pour tout les animaux
description: Utiliser la commande coeur
default: true
#### à ajouter
pandacraft.muco:
description: Utiliser la commande muco
default: op
# pandacraft.muco.sitemembre donne accès à la liste de commande nommé "sitemembre"
#### à ajouter
pandacraft.muco.*:
description: Utiliser toutes les listes de commandes muco
default: op
pandacraft.antispam.exempt:
description: Ignoré par le système anti-spam

View File

@ -130,6 +130,7 @@ public class ConfigManager {
initCommandAlias();
initAutomessages();
initWorldBorder();
initMultiCommand();
}
@ -446,6 +447,118 @@ public class ConfigManager {
/*
* Multicommand
*/
public Map<String, List<String>> MultiCommand_config;
private void initMultiCommand() {
/*
* Format d'un String dans l'ArrayList :
* T C A /CMD ...
* - T : temps en tick, depuis l'exécution de la commande /muco
* - C : "C" si doit être exécuté en tant que la console, autre chose sinon
* - A : "A" si la commande peut être exécuté en mode asynchrone, autre chose, sinon
* (T, C et A ne peuvent pas contenir d'espace)
* /CMD ... correspond à la commande, avec le / devant. Peut contenir $1, $2, ... comme des paramètres
*/
MultiCommand_config = new HashMap<String, List<String>>();
List<String> list = new ArrayList<String>();
list.add("0 - - /pex user $1 remove $2");
list.add("1 - - /pex user $1 add $3");
list.add("1 - - /m $1 La mise à jour de votre grade est terminé :) !");
MultiCommand_config.put("gradejoueur", list);
list = new ArrayList<String>();
list.add("0 - - /region select arenespleef_niv1");
list.add("1 - - //replace 0 87");
list.add("2 - - /region select arenespleef_niv2");
list.add("3 - - //replace 0 87");
list.add("4 - - /region select arenespleef_niv3");
list.add("5 - - //replace 0 87");
list.add("6 - - /region select arenespleef_niv4");
list.add("7 - - //replace 0 87");
list.add("8 - - /region select arenespleef_niv5");
list.add("9 - - //replace 0 87");
list.add("10 - - /region select arenespleef_niv6");
list.add("11 - - //replace 0 87");
list.add("12 - - /region select arenespleef_niv7");
list.add("13 - - //replace 0 87");
list.add("14 - - /region select arenespleef_niv8");
list.add("15 - - //replace 0 87");
MultiCommand_config.put("arenespleef_reparer", list);
list = new ArrayList<String>();
list.add("0 - - /pex user $1 group add premium");
list.add("0 - - /m $1 Vous venez de passer Premium :)");
MultiCommand_config.put("addpremium", list);
list = new ArrayList<String>();
list.add("0 - - /pex user $1 group remove premium");
MultiCommand_config.put("delpremium", list);
list = new ArrayList<String>();
list.add("0 - - /pex user $1 group add ultimate");
list.add("0 - - /m $1 Vous venez de recevoir le grade Ultimate, félicitation :)");
MultiCommand_config.put("addultimate", list);
list = new ArrayList<String>();
list.add("0 - - /pex user $1 group remove ultimate");
list.add("0 - - /mail send $1 Vous venez de perdre votre grade Ultimate et tous ses avantages car la durée est écoulée.");
list.add("1 - - /mail send $1 Si vous voulez encore en profiter, rendez vous sur http://mc-pandacraft.net/?p=ultimate");
MultiCommand_config.put("delultimate", list);
list = new ArrayList<String>();
list.add("0 - - /region select arenepvp_solarene");
list.add("1 - - //replace 11 20");
MultiCommand_config.put("arenepvp_proteger_lave", list);
list = new ArrayList<String>();
list.add("0 - - /region select arenepvp_solarene");
list.add("1 - - //replace 20 11");
MultiCommand_config.put("arenepvp_remettre_lave", list);
list = new ArrayList<String>();
list.add("0 - - /region select arenepvp_toit");
list.add("1 - - //replace 20 98");
MultiCommand_config.put("arenepvp_fermer_fenetre", list);
list = new ArrayList<String>();
list.add("0 - - /region select arenepvp_toit");
list.add("1 - - //replace 98 20");
MultiCommand_config.put("arenepvp_ouvrir_fenetre", list);
list = new ArrayList<String>();
list.add("0 C - /broadcast &7Site Web :&a https://www.mc-pandacraft.net/");
MultiCommand_config.put("site", list);
list = new ArrayList<String>();
list.add("0 C - /broadcast &7Devenir &f[&bMembre&f]&7 :&a http://mc-pandacraft.net/?id=12");
MultiCommand_config.put("sitemembre", list);
list = new ArrayList<String>();
list.add("0 C - /broadcast Grade &f[&eUltimate&f]&7 :&a http://mc-pandacraft.net/?p=ultimate");
MultiCommand_config.put("siteultimate", list);
list = new ArrayList<String>();
list.add("0 - - /mv regen Survival_the_end");
list.add("1 - - /mvconfirm");
MultiCommand_config.put("new_ender", list);
list = new ArrayList<String>();
list.add("0 - - /mv regen Survival_nether");
list.add("1 - - /mvconfirm");
list.add("600 - - /mv regen Faction_nether");
list.add("601 - - /mvconfirm");
MultiCommand_config.put("new_nether", list);
}

View File

@ -0,0 +1,186 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;
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;
import org.bukkit.scheduler.BukkitScheduler;
public class CommandMuco extends AbstractCommandExecutor {
public CommandMuco() {
super("muco");
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label,
String[] args) {
if (args.length == 0) {
sendMucoLists(sender);
return true;
}
Map<String, List<String>> lists = ConfigManager.getInstance().MultiCommand_config;
String list_name = args[0].toLowerCase();
if (!lists.containsKey(list_name)) {
sender.sendMessage(ChatColor.RED+"La sous commande '"+list_name+"' n'existe pas");
return true;
}
if ((sender instanceof Player) && !OnlinePlayerManager.get((Player)sender).hasPermission("pandacraft.muco."+list_name)) {
sender.sendMessage(ChatColor.RED+"Vous n'avez pas la permission pour la sous commande '"+list_name+"'");
return true;
}
List<String> params = new ArrayList<String>();
for (int i=1; i<args.length; i++) {
params.add(args[i]);
}
List<String> list = lists.get(list_name);
for (String line : list) {
executeListedCommand(sender, line, params);
}
return true;
}
private void sendMucoLists(CommandSender sender) {
List<String> list_names = getMucoLists((sender instanceof Player)?OnlinePlayerManager.get((Player) sender):null);
sender.sendMessage(ChatColor.GOLD+"----- Liste des commandes /muco -----");
for (String name : list_names) {
sender.sendMessage(" - "+ChatColor.GRAY+name);
}
sender.sendMessage(ChatColor.GOLD+"-----------------------------------");
}
private List<String> getMucoLists(OnlinePlayer permittedPlayer) {
Set<String> list_names = ConfigManager.getInstance().MultiCommand_config.keySet();
List<String> retList = new ArrayList<String>();
for (String name : list_names) {
if (permittedPlayer == null || permittedPlayer.hasPermission("pandacraft.muco."+name))
retList.add(name);
}
return retList;
}
private void executeListedCommand(CommandSender sender, String line, List<String> params) {
String[] args = line.split(" ", 4);
if (args.length != 4) {
plugin.getLogger().warning("/muco : bad format for "+ChatColor.ITALIC+line);
return;
}
long time;
try {
time = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
plugin.getLogger().warning("/muco : bad format for "+ChatColor.ITALIC+line);
return;
}
boolean console = args[1].equalsIgnoreCase("c");
boolean async = args[2].equalsIgnoreCase("a");
if (!args[3].startsWith("/")) {
plugin.getLogger().warning("/muco : bad format for "+ChatColor.ITALIC+line);
return;
}
String cmd = args[3].substring(1);
for (int i=0; i<params.size(); i++) {
cmd = cmd.replaceAll("\\$"+(i+1), params.get(i));
}
sender = console ? plugin.getServer().getConsoleSender() : sender;
BukkitScheduler scheduler = plugin.getServer().getScheduler();
Runnable executor = new Runnable() {
CommandSender sender; String cmd;
public Runnable init(CommandSender s, String c) {
sender = s; cmd = c;
return this;
}
@Override
public void run() {
plugin.getServer().dispatchCommand(sender, cmd);
}
}.init(sender, cmd);
if (async)
scheduler.runTaskLaterAsynchronously(plugin, executor, time);
else
scheduler.runTaskLater(plugin, executor, time);
}
}

View File

@ -54,6 +54,7 @@ public class PandacraftUtilsCommandsManager {
add(new CommandSystem());
add(new CommandAnimal());
add(new CommandCoeur());
add(new CommandMuco());
}