UltimateModeration/src/main/java/com/songoda/ultimatemoderation/commands/CommandRandomPlayer.java

56 lines
1.5 KiB
Java
Raw Normal View History

2019-10-19 19:29:46 +02:00
package com.songoda.ultimatemoderation.commands;
2019-02-27 02:50:18 +01:00
import com.craftaro.core.commands.AbstractCommand;
2019-02-27 02:50:18 +01:00
import com.songoda.ultimatemoderation.UltimateModeration;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
2019-03-03 22:33:44 +01:00
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
2019-02-27 02:50:18 +01:00
public class CommandRandomPlayer extends AbstractCommand {
2020-09-08 22:51:25 +02:00
private final UltimateModeration plugin;
2019-10-19 19:29:46 +02:00
2020-09-08 22:51:25 +02:00
public CommandRandomPlayer(UltimateModeration plugin) {
2019-10-19 19:29:46 +02:00
super(CommandType.PLAYER_ONLY, "RandomPlayer");
2020-09-08 22:51:25 +02:00
this.plugin = plugin;
2019-02-27 02:50:18 +01:00
}
@Override
2019-10-19 19:29:46 +02:00
protected ReturnType runCommand(CommandSender sender, String... args) {
2019-02-27 02:50:18 +01:00
List<Player> players = new ArrayList<>(Bukkit.getOnlinePlayers());
Collections.shuffle(players);
players.remove(sender);
if (players.size() == 0) {
this.plugin.getLocale().newMessage("&cYou are the only one online!").sendPrefixedMessage(sender);
2019-02-27 02:50:18 +01:00
return ReturnType.FAILURE;
}
2019-03-03 22:33:44 +01:00
((Player) sender).teleport(players.get(0).getLocation());
2019-02-27 02:50:18 +01:00
return ReturnType.SUCCESS;
}
@Override
2019-10-19 19:29:46 +02:00
protected List<String> onTab(CommandSender sender, String... args) {
2019-02-27 02:50:18 +01:00
return null;
}
@Override
public String getPermissionNode() {
return "um.randomplayer";
}
@Override
public String getSyntax() {
return "/RandomPlayer";
}
@Override
public String getDescription() {
2019-02-27 22:45:39 +01:00
return "Allows you to randomly teleport to a player on the server.";
2019-02-27 02:50:18 +01:00
}
}