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;
|
2016-03-24 10:57:59 +01: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
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.command.TabCompleter;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
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
|
2016-03-26 20:47:34 +01:00
|
|
|
public boolean onCommand(final CommandSender commandSender, org.bukkit.command.Command command, final 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
|
|
|
}
|
|
|
|
if (commandSender == null || commandSender.getClass() == Bukkit.getConsoleSender().getClass()) {
|
2016-03-24 10:57:59 +01:00
|
|
|
return MainCommand.onCommand(ConsolePlayer.getConsole(), args);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
ConsolePlayer sender = new ConsolePlayer() {
|
|
|
|
@Override
|
|
|
|
public void sendMessage(String message) {
|
|
|
|
commandSender.sendMessage(commandLabel);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public boolean hasPermission(String permission) {
|
2016-02-23 05:11:28 +01:00
|
|
|
return commandSender.hasPermission(commandLabel);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
if (commandSender.getName().equals("CONSOLE")) {
|
|
|
|
return "*";
|
|
|
|
}
|
|
|
|
return commandSender.getName();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
sender.teleport(ConsolePlayer.getConsole().getLocationFull());
|
2016-03-24 10:57:59 +01:00
|
|
|
boolean result = MainCommand.onCommand(sender, args);
|
2016-02-23 05:11:28 +01:00
|
|
|
ConsolePlayer.getConsole().teleport(sender.getLocationFull());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-24 10:57:59 +01:00
|
|
|
public List<String> onTabComplete(CommandSender commandSender, org.bukkit.command.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
|
|
|
}
|
2016-03-24 10:57:59 +01:00
|
|
|
Collection objects = MainCommand.getInstance().tab(player, args, s.endsWith(" "));
|
|
|
|
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<>();
|
|
|
|
for (Object o : objects) {
|
|
|
|
result.add(o.toString());
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-24 10:57:59 +01:00
|
|
|
return result;
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
}
|