PlotSquared/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java

59 lines
2.1 KiB
Java
Raw Normal View History

2016-02-23 05:11:28 +01:00
package com.plotsquared.bukkit.util;
import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.bukkit.commands.DebugUUID;
import org.bukkit.command.Command;
2016-02-23 05:11:28 +01:00
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.ProxiedCommandSender;
import org.bukkit.command.RemoteConsoleCommandSender;
2016-02-23 05:11:28 +01:00
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
2016-03-28 19:28:21 +02:00
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
2016-02-23 05:11:28 +01:00
public class BukkitCommand implements CommandExecutor, TabCompleter {
public BukkitCommand() {
new DebugUUID();
2016-02-23 05:11:28 +01:00
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel, String[] args) {
2016-02-23 05:11:28 +01:00
if (commandSender instanceof Player) {
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), args);
2016-02-23 05:11:28 +01:00
}
if (commandSender instanceof ConsoleCommandSender || commandSender instanceof ProxiedCommandSender
|| commandSender instanceof RemoteConsoleCommandSender) {
return MainCommand.onCommand(ConsolePlayer.getConsole(), args);
2016-02-23 05:11:28 +01:00
}
return false;
2016-02-23 05:11:28 +01:00
}
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
2016-02-23 05:11:28 +01:00
if (!(commandSender instanceof Player)) {
return null;
}
2016-03-23 02:41:37 +01:00
PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
if (args.length == 0) {
return Collections.singletonList("plots");
2016-02-23 05:11:28 +01:00
}
Collection objects = MainCommand.getInstance().tab(player, args, s.endsWith(" "));
if (objects == null) {
2016-02-23 05:11:28 +01:00
return null;
}
List<String> result = new ArrayList<>();
for (Object o : objects) {
result.add(o.toString());
2016-02-23 05:11:28 +01:00
}
return result.size() == 0 ? null : result;
2016-02-23 05:11:28 +01:00
}
}