RankCommandAsyncTask.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package com.gmail.nossr50.runnables.commands;
  2. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  3. import com.gmail.nossr50.mcMMO;
  4. import org.apache.commons.lang.Validate;
  5. import org.bukkit.command.CommandSender;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.scheduler.BukkitRunnable;
  8. import java.util.Map;
  9. public class RankCommandAsyncTask extends BukkitRunnable {
  10. private final mcMMO pluginRef;
  11. private final String playerName;
  12. private final CommandSender sender;
  13. private final boolean useBoard, useChat;
  14. public RankCommandAsyncTask(mcMMO pluginRef, String playerName, CommandSender sender, boolean useBoard, boolean useChat) {
  15. this.pluginRef = pluginRef;
  16. Validate.isTrue(useBoard || useChat, "Attempted to start a rank retrieval with both board and chat off");
  17. Validate.notNull(sender, "Attempted to start a rank retrieval with no recipient");
  18. if (useBoard) {
  19. Validate.isTrue(sender instanceof Player, "Attempted to start a rank retrieval displaying scoreboard to a non-player");
  20. }
  21. this.playerName = playerName;
  22. this.sender = sender;
  23. this.useBoard = useBoard;
  24. this.useChat = useChat;
  25. }
  26. @Override
  27. public void run() {
  28. Map<PrimarySkillType, Integer> skills = pluginRef.getDatabaseManager().readRank(playerName);
  29. new RankCommandDisplayTask(pluginRef, skills, sender, playerName, useBoard, useChat).runTaskLater(pluginRef, 1);
  30. }
  31. }