Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import java.util.*;
  2. import org.bukkit.command.*;
  3.  
  4. public final class DelegatingCommand implements CommandExecutor {
  5.  
  6. private final Map<String, ? extends CommandExecutor> children;
  7. private final CommandExecutor defaultCase;
  8.  
  9. public DelegatingCommand(Map<String, ? extends CommandExecutor> children) {
  10. this(($1, $2, $3, $4) -> false, children);
  11. }
  12.  
  13. public DelegatingCommand(CommandExecutor defaultCase, Map<String, ? extends CommandExecutor> children) {
  14. this.children = new HashMap<>(children);
  15. this.defaultCase = defaultCase;
  16. }
  17.  
  18. @Override
  19. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  20. if (args.length > 0) {
  21. String childLabel = args[0];
  22. if (children.containsKey(childLabel)) {
  23. return children.get(childLabel).onCommand(sender, command, childLabel, Arrays.copyOfRange(args, 1, args.length));
  24. }
  25. }
  26. return defaultCase.onCommand(sender, command, label, args);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement