2020-04-11 02:19:18 +02:00
|
|
|
package com.plotsquared.bukkit;
|
2016-02-23 05:11:28 +01:00
|
|
|
|
2020-04-11 02:19:18 +02:00
|
|
|
import com.plotsquared.bukkit.commands.DebugUUID;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
|
|
import com.plotsquared.commands.MainCommand;
|
|
|
|
import com.plotsquared.player.ConsolePlayer;
|
|
|
|
import com.plotsquared.player.PlotPlayer;
|
2019-11-04 18:44:23 +01:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
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;
|
|
|
|
import org.bukkit.command.TabCompleter;
|
2016-02-23 05:11:28 +01:00
|
|
|
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() {
|
2016-03-24 10:57:59 +01:00
|
|
|
new DebugUUID();
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-10 17:01:10 +02:00
|
|
|
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel,
|
|
|
|
String[] args) {
|
2016-02-23 05:11:28 +01:00
|
|
|
if (commandSender instanceof Player) {
|
2016-03-24 10:57:59 +01:00
|
|
|
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), args);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
if (commandSender instanceof ConsoleCommandSender
|
|
|
|
|| commandSender instanceof ProxiedCommandSender
|
|
|
|
|| commandSender instanceof RemoteConsoleCommandSender) {
|
2016-03-24 10:57:59 +01:00
|
|
|
return MainCommand.onCommand(ConsolePlayer.getConsole(), args);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-04-02 01:14:46 +02:00
|
|
|
return false;
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-10 17:01:10 +02:00
|
|
|
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);
|
2016-03-24 10:57:59 +01:00
|
|
|
if (args.length == 0) {
|
|
|
|
return Collections.singletonList("plots");
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2020-04-11 02:19:18 +02:00
|
|
|
Collection<com.plotsquared.commands.Command> objects = MainCommand.getInstance().tab(player, args, s.endsWith(" "));
|
2016-03-24 10:57:59 +01:00
|
|
|
if (objects == null) {
|
2016-02-23 05:11:28 +01:00
|
|
|
return null;
|
|
|
|
}
|
2016-03-24 10:57:59 +01:00
|
|
|
List<String> result = new ArrayList<>();
|
2020-04-11 02:19:18 +02:00
|
|
|
for (com.plotsquared.commands.Command o : objects) {
|
2016-03-24 10:57:59 +01:00
|
|
|
result.add(o.toString());
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-04-02 07:30:26 +02:00
|
|
|
return result.isEmpty() ? null : result;
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
}
|