2020-03-17 16:43:09 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2020-03-17 16:43:09 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
package org.geysermc.geyser.platform.spigot.command;
|
2020-03-17 16:43:09 +00:00
|
|
|
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.command.TabExecutor;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.GeyserImpl;
|
|
|
|
import org.geysermc.geyser.command.CommandExecutor;
|
|
|
|
import org.geysermc.geyser.command.GeyserCommand;
|
|
|
|
import org.geysermc.geyser.network.session.GeyserSession;
|
|
|
|
import org.geysermc.geyser.utils.LanguageUtils;
|
2020-03-17 16:43:09 +00:00
|
|
|
|
|
|
|
import java.util.Arrays;
|
2021-10-31 01:57:54 +00:00
|
|
|
import java.util.Collections;
|
2020-03-17 16:43:09 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2021-01-17 03:18:13 +00:00
|
|
|
public class GeyserSpigotCommandExecutor extends CommandExecutor implements TabExecutor {
|
2020-03-17 16:43:09 +00:00
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
public GeyserSpigotCommandExecutor(GeyserImpl geyser) {
|
|
|
|
super(geyser);
|
2021-01-17 03:18:13 +00:00
|
|
|
}
|
2020-03-17 16:43:09 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2021-10-31 05:22:41 +00:00
|
|
|
SpigotCommandSender commandSender = new SpigotCommandSender(sender);
|
|
|
|
GeyserSession session = getGeyserSession(commandSender);
|
|
|
|
|
2020-03-17 16:43:09 +00:00
|
|
|
if (args.length > 0) {
|
2021-01-17 03:18:13 +00:00
|
|
|
GeyserCommand geyserCommand = getCommand(args[0]);
|
|
|
|
if (geyserCommand != null) {
|
|
|
|
if (!sender.hasPermission(geyserCommand.getPermission())) {
|
|
|
|
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());
|
2020-07-05 23:35:51 +00:00
|
|
|
|
2020-10-29 22:30:52 +00:00
|
|
|
commandSender.sendMessage(ChatColor.RED + message);
|
2020-03-17 16:43:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-10-31 05:22:41 +00:00
|
|
|
if (geyserCommand.isBedrockOnly() && session == null) {
|
|
|
|
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.getLocale()));
|
|
|
|
return true;
|
2021-01-17 03:18:13 +00:00
|
|
|
}
|
|
|
|
geyserCommand.execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
|
2020-03-17 16:43:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
2021-10-31 05:22:41 +00:00
|
|
|
getCommand("help").execute(session, commandSender, new String[0]);
|
2020-03-17 16:43:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
if (args.length == 1) {
|
2021-10-31 01:57:54 +00:00
|
|
|
return tabComplete(new SpigotCommandSender(sender));
|
2020-03-17 16:43:09 +00:00
|
|
|
}
|
2021-10-31 01:57:54 +00:00
|
|
|
return Collections.emptyList();
|
2020-03-17 16:43:09 +00:00
|
|
|
}
|
|
|
|
}
|