78 lines
2.1 KiB
Java
78 lines
2.1 KiB
Java
package eu.univento.core.commands;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import eu.univento.core.Core;
|
|
import eu.univento.core.api.AutoCommand;
|
|
import eu.univento.core.api.Messages;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import eu.univento.core.api.player.Perms.Ranks;
|
|
|
|
/**
|
|
* lets other player run commands
|
|
* @author joethei
|
|
* @version 1.0
|
|
*/
|
|
public class RunAs extends AutoCommand<Core>{
|
|
|
|
/**
|
|
* @param plugin main class
|
|
* @param command command to execute
|
|
* @param description describes the command
|
|
* @param aliases aliases of command
|
|
*/
|
|
public RunAs(Core plugin, String command, String description, String[] aliases) {
|
|
super(plugin, command, description, aliases);
|
|
}
|
|
|
|
|
|
@Override
|
|
public boolean execute(CommandSender sender, String label, String[] args) {
|
|
if(sender instanceof Player) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
|
if(p.isAllowed(Ranks.Admin)) {
|
|
if(args.length >= 2) {
|
|
CustomPlayer t = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
|
|
if(t != null) {
|
|
String msg = "";
|
|
for(int i = 1; i < args.length; i++) {
|
|
msg = msg + args[i] + " ";
|
|
}
|
|
t.chat(msg);
|
|
p.sendMessage("§2Erfolgreich ausgeführt");
|
|
return true;
|
|
}else {
|
|
String msg = Messages.readString("Messages.Player.NotOnline");
|
|
msg = msg.replace("$player", args[0]);
|
|
p.sendMessage(msg);
|
|
}
|
|
}else {
|
|
p.sendMessage("§cDu musst §6/RunAs <Spieler> <Command/Nachricht> §causführen");
|
|
}
|
|
}else {
|
|
p.sendMessage(Messages.NO_PERMS);
|
|
}
|
|
}else {
|
|
sender.sendMessage(Messages.NOT_A_PLAYER);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
|
List<String> list = new ArrayList<String>();
|
|
|
|
for(Player players : Bukkit.getOnlinePlayers()) {
|
|
list.add(players.getDisplayName());
|
|
}
|
|
return list;
|
|
}
|
|
|
|
|
|
}
|