mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-19 09:05:26 +01:00
Implemented velocity command adapter
This commit is contained in:
parent
a76932c256
commit
f85fff7f93
@ -32,7 +32,7 @@ public class SpongeCMDSender implements CMDSender {
|
||||
|
||||
@Override
|
||||
public MessageBuilder buildMessage() {
|
||||
return null;
|
||||
return null;/*TODO*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,8 +16,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.commands.PlanProxyCommand;
|
||||
import com.djrapitops.plan.commands.use.Subcommand;
|
||||
import com.djrapitops.plan.commands.use.VelocityCommand;
|
||||
import com.djrapitops.plan.exceptions.EnableException;
|
||||
import com.djrapitops.plan.settings.locale.Locale;
|
||||
import com.djrapitops.plan.settings.locale.lang.PluginLang;
|
||||
@ -93,9 +93,8 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
||||
logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||
onDisable();
|
||||
}
|
||||
PlanProxyCommand command = component.planCommand();
|
||||
command.registerCommands();
|
||||
registerCommand("planvelocity", command);
|
||||
|
||||
registerCommand(component.planCommand().build());
|
||||
if (system != null) {
|
||||
system.getProcessing().submitNonCritical(() -> system.getListenerSystem().callEnableEvent(this));
|
||||
}
|
||||
@ -114,8 +113,15 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommand(Subcommand subcommand) {
|
||||
throw new UnsupportedOperationException();
|
||||
public void registerCommand(Subcommand command) {
|
||||
if (command == null) {
|
||||
logger.warn("Attempted to register a null command!");
|
||||
return;
|
||||
}
|
||||
getProxy().getCommandManager().register(
|
||||
new VelocityCommand(runnableFactory, command),
|
||||
command.getAliases().toArray(new String[0])
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.commands.PlanProxyCommand;
|
||||
import com.djrapitops.plan.commands.PlanCommand;
|
||||
import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
||||
@ -49,7 +49,7 @@ import javax.inject.Singleton;
|
||||
})
|
||||
public interface PlanVelocityComponent {
|
||||
|
||||
PlanProxyCommand planCommand();
|
||||
PlanCommand planCommand();
|
||||
|
||||
PlanSystem system();
|
||||
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.commands.use;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import net.kyori.text.TextComponent;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VelocityCMDSender implements CMDSender {
|
||||
|
||||
final CommandSource commandSource;
|
||||
|
||||
public VelocityCMDSender(CommandSource commandSource) {
|
||||
this.commandSource = commandSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder buildMessage() {
|
||||
return null; /*TODO*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getPlayerName() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return commandSource.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UUID> getUUID() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(String message) {
|
||||
commandSource.sendMessage(TextComponent.of(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatFormatter getFormatter() {
|
||||
return new ConsoleChatFormatter();
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.commands.use;
|
||||
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.velocitypowered.api.command.Command;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VelocityCommand implements Command {
|
||||
|
||||
private final RunnableFactory runnableFactory;
|
||||
private final Subcommand command;
|
||||
|
||||
public VelocityCommand(RunnableFactory runnableFactory, Subcommand command) {
|
||||
this.runnableFactory = runnableFactory;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource source, String[] args) {
|
||||
runnableFactory.create("", new AbsRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
command.getExecutor().accept(getSender(source), new Arguments(args));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private CMDSender getSender(CommandSource source) {
|
||||
if (source instanceof Player) {
|
||||
return new VelocityPlayerCMDSender((Player) source);
|
||||
} else {
|
||||
return new VelocityCMDSender(source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandSource source, String[] currentArgs) {
|
||||
return command.getArgumentResolver().apply(getSender(source), new Arguments(currentArgs));
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.commands.use;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VelocityPlayerCMDSender extends VelocityCMDSender {
|
||||
|
||||
private final Player player;
|
||||
|
||||
public VelocityPlayerCMDSender(Player player) {
|
||||
super(player);
|
||||
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getPlayerName() {
|
||||
return Optional.of(player.getUsername());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UUID> getUUID() {
|
||||
return Optional.of(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatFormatter getFormatter() {
|
||||
return new PlayerChatFormatter();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user