Advertisement
lLuffy

Untitled

Jul 19th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. /**
  2. * Copyright (C) 2016 Chikachi
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License as
  6. * published by the Free Software Foundation, either version 3 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Affero General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public License
  15. * along with this program. If not, see http://www.gnu.org/licenses.
  16. */
  17.  
  18. package chikachi.discord.command.discord;
  19.  
  20. import chikachi.discord.DiscordClient;
  21. import com.google.common.base.Joiner;
  22. import net.dv8tion.jda.entities.User;
  23. import net.minecraft.server.MinecraftServer;
  24.  
  25. import java.util.ArrayList;
  26. import java.util.List;
  27.  
  28. public class OnlineCommandConfig extends CommandConfig {
  29. public OnlineCommandConfig() {
  30. super("online");
  31. }
  32.  
  33. @Override
  34. public void execute(User user, List<String> args) {
  35. List<String> playerNames = new ArrayList<>();
  36.  
  37. String[] players = MinecraftServer.getServer().getConfigurationManager().getAllUsernames();
  38.  
  39. for (String player : players) {
  40. if (player.startsWith("@")) {
  41. continue;
  42. }
  43. playerNames.add(player);
  44. }
  45.  
  46. int playersOnline = playerNames.size();
  47. if (playersOnline == 0) {
  48. DiscordClient.getInstance().sendMessage("No players online");
  49. return;
  50. }
  51.  
  52. if (playersOnline == 1) {
  53. DiscordClient.getInstance().sendMessage(
  54. String.format(
  55. "Currently 1 player online: `%s`",
  56. Joiner.on(", ").join(playerNames)
  57. )
  58. );
  59. return;
  60. }
  61.  
  62. DiscordClient.getInstance().sendMessage(
  63. String.format(
  64. "Currently %d players online:\n`%s`",
  65. playersOnline,
  66. Joiner.on("`, `").join(playerNames)
  67. )
  68. );
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement