Last active
August 29, 2015 14:17
-
-
Save Romain-P/fb28d1565b7a0a0ed7d4 to your computer and use it in GitHub Desktop.
jaja
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.heat.world.commands.impl.actions; | |
| import com.google.inject.Inject; | |
| import org.heat.world.commands.*; | |
| import java.util.Arrays; | |
| import java.util.Map; | |
| import java.util.stream.Collectors; | |
| /** | |
| * Managed by romain on 08/03/2015. | |
| */ | |
| public class HelpAction implements CommandAction { | |
| @Inject Map<String, CommandTree> commands; | |
| @Inject Map<Class, CommandCond> conditions; | |
| @Override | |
| public void execute(CommandSender sender, String... args) { | |
| boolean spot = args.length > 0; | |
| String text; | |
| if(spot) { | |
| String name = args[0]; | |
| CommandTree command = commands.get(name); | |
| //works with/without prefix | |
| if(command != null || (command = commands.get(name.substring(1))) != null) | |
| text = "Syntaxe de votre commande: \n"+ | |
| command.getCommand().getSyntax(); | |
| else | |
| text = "Commande non trouvée."; | |
| } else { | |
| text = "Liste des commandes disponibles: \n" + commands.values() | |
| .stream() | |
| .map((x) -> { | |
| Command command = x.getCommand(); | |
| Class[] classes = command.getConditions(); | |
| boolean b = Arrays.stream(classes) | |
| .filter((c) -> conditions.get(c).isEligible(sender)) | |
| .count() == classes.length; | |
| return b ? command.getSyntax() : ""; | |
| }) | |
| .collect(Collectors.joining()); | |
| } | |
| sender.reply(text); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment