2019-02-27 02:50:18 +01:00
|
|
|
package com.songoda.ultimatemoderation.command.commands;
|
|
|
|
|
|
|
|
import com.songoda.ultimatemoderation.UltimateModeration;
|
|
|
|
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
|
|
|
import com.songoda.ultimatemoderation.utils.Methods;
|
|
|
|
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 {
|
|
|
|
|
|
|
|
public CommandRandomPlayer() {
|
2019-03-03 22:33:44 +01:00
|
|
|
super(true, false, "RandomPlayer");
|
2019-02-27 02:50:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
|
|
|
List<Player> players = new ArrayList<>(Bukkit.getOnlinePlayers());
|
|
|
|
Collections.shuffle(players);
|
|
|
|
players.remove(sender);
|
|
|
|
|
|
|
|
if (players.size() == 0) {
|
2019-07-25 18:15:42 +02:00
|
|
|
instance.getLocale().newMessage("&c You 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
|
|
|
|
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|