2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
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.util.BukkitUtil;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.command.MainCommand;
|
2021-10-04 17:10:36 +02:00
|
|
|
import com.plotsquared.core.configuration.Settings;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.player.ConsolePlayer;
|
|
|
|
import com.plotsquared.core.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;
|
2021-10-04 17:10:36 +02:00
|
|
|
import java.util.Locale;
|
2016-03-28 19:28:21 +02:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|
|
|
|
|
|
|
@Override
|
2021-01-09 22:28:41 +01:00
|
|
|
public boolean onCommand(
|
|
|
|
CommandSender commandSender, Command command, String commandLabel,
|
|
|
|
String[] args
|
|
|
|
) {
|
2016-02-23 05:11:28 +01:00
|
|
|
if (commandSender instanceof Player) {
|
2020-07-17 22:58:10 +02:00
|
|
|
return MainCommand.onCommand(BukkitUtil.adapt((Player) commandSender), args);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
if (commandSender instanceof ConsoleCommandSender
|
2021-01-09 22:28:41 +01:00
|
|
|
|| 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
|
2021-01-09 22:28:41 +01:00
|
|
|
public List<String> onTabComplete(
|
2021-10-04 17:10:36 +02:00
|
|
|
CommandSender commandSender, Command command, String label,
|
2021-01-09 22:28:41 +01:00
|
|
|
String[] args
|
|
|
|
) {
|
2016-02-23 05:11:28 +01:00
|
|
|
if (!(commandSender instanceof Player)) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-05-01 18:33:02 +02:00
|
|
|
PlotPlayer<?> player = BukkitUtil.adapt((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
|
|
|
}
|
2021-10-04 17:10:36 +02:00
|
|
|
if (!Settings.Enabled_Components.TAB_COMPLETED_ALIASES.contains(label.toLowerCase(Locale.ENGLISH))) {
|
|
|
|
return List.of();
|
|
|
|
}
|
2020-04-30 12:01:52 +02:00
|
|
|
Collection<com.plotsquared.core.command.Command> objects =
|
2021-10-04 17:10:36 +02:00
|
|
|
MainCommand.getInstance().tab(player, args, label.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-15 21:26:54 +02:00
|
|
|
for (com.plotsquared.core.command.Command o : objects) {
|
2016-03-24 10:57:59 +01:00
|
|
|
result.add(o.toString());
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2020-06-05 14:06:43 +02:00
|
|
|
return result;
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|