MWCommandCompletions.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * This file is part of MissileWars (https://github.com/Butzlabben/missilewars).
  3. * Copyright (c) 2018-2021 Daniel Nägele.
  4. *
  5. * MissileWars is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * MissileWars is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with MissileWars. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. package de.butzlabben.missilewars.commands;
  19. import co.aikar.commands.BukkitCommandCompletionContext;
  20. import co.aikar.commands.CommandCompletions;
  21. import co.aikar.commands.PaperCommandManager;
  22. import com.google.common.collect.ImmutableList;
  23. import de.butzlabben.missilewars.configuration.Config;
  24. import de.butzlabben.missilewars.game.Game;
  25. import de.butzlabben.missilewars.game.GameManager;
  26. import org.bukkit.command.CommandSender;
  27. import org.bukkit.entity.Player;
  28. public class MWCommandCompletions {
  29. private final CommandCompletions<BukkitCommandCompletionContext> commandCompletions;
  30. public MWCommandCompletions(PaperCommandManager commandManager) {
  31. this.commandCompletions = commandManager.getCommandCompletions();
  32. registerGamesResult();
  33. registerMissilesResult();
  34. registerMissileFlagsResult();
  35. registerArenasResult();
  36. registerTeamsResult();
  37. registerGamePlayerResult();
  38. }
  39. private void registerGamesResult() {
  40. commandCompletions.registerCompletion("games", c -> GameManager.getInstance().getGames().keySet());
  41. }
  42. private void registerMissilesResult() {
  43. commandCompletions.registerCompletion("missiles", c -> {
  44. CommandSender sender = c.getSender();
  45. if (!(sender instanceof Player)) return null;
  46. Player player = (Player) sender;
  47. Game game = GameManager.getInstance().getGame(player.getLocation());
  48. if (game == null) return null;
  49. return game.getArenaConfig().getMissileConfig().getSchematicNames();
  50. });
  51. }
  52. private void registerMissileFlagsResult() {
  53. commandCompletions.registerCompletion("missile-flags", c -> {
  54. CommandSender sender = c.getSender();
  55. if (!(sender instanceof Player)) return null;
  56. Player player = (Player) sender;
  57. Game game = GameManager.getInstance().getGame(player.getLocation());
  58. if (game == null) return null;
  59. return ImmutableList.of("-tempblock:" + Config.isTempBlockEnabled(),
  60. "-tempblock_material:" + Config.getTempBlockMaterial(),
  61. "-tempblock_delay:" + Config.getUpdateDelay(),
  62. "-tempblock_radius:" + Config.getUpdateRadius());
  63. });
  64. }
  65. private void registerArenasResult() {
  66. commandCompletions.registerCompletion("arenas", c -> {
  67. CommandSender sender = c.getSender();
  68. if (!(sender instanceof Player)) return null;
  69. Player player = (Player) sender;
  70. Game game = GameManager.getInstance().getGame(player.getLocation());
  71. if (game == null) return null;
  72. return game.getGameConfig().getPossibleArenas();
  73. });
  74. }
  75. private void registerTeamsResult() {
  76. commandCompletions.registerCompletion("teams", c -> {
  77. CommandSender sender = c.getSender();
  78. if (!(sender instanceof Player)) return null;
  79. Player player = (Player) sender;
  80. Game game = GameManager.getInstance().getGame(player.getLocation());
  81. if (game == null) return null;
  82. return ImmutableList.of("1", "2", "spec");
  83. });
  84. }
  85. private void registerGamePlayerResult() {
  86. commandCompletions.registerCompletion("game-players", c -> {
  87. CommandSender sender = c.getSender();
  88. if (!(sender instanceof Player)) return null;
  89. Player player = (Player) sender;
  90. Game game = GameManager.getInstance().getGame(player.getLocation());
  91. if (game == null) return null;
  92. return game.getPlayerList();
  93. });
  94. }
  95. }