use of com.velocitypowered.api.command.CommandSource in project LimboAuth by Elytrium.
the class UnregisterCommand method execute.
@Override
public void execute(SimpleCommand.Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
if (!(source instanceof Player)) {
source.sendMessage(this.notPlayer);
return;
}
if (args.length == 2) {
if (args[1].equalsIgnoreCase("confirm")) {
String username = ((Player) source).getUsername();
RegisteredPlayer player = AuthSessionHandler.fetchInfo(this.playerDao, username);
if (player == null) {
source.sendMessage(this.notRegistered);
} else if (player.getHash().isEmpty()) {
source.sendMessage(this.crackedCommand);
} else if (AuthSessionHandler.checkPassword(args[0], player, this.playerDao)) {
try {
this.plugin.getServer().getEventManager().fireAndForget(new AuthUnregisterEvent(username));
this.playerDao.deleteById(username.toLowerCase(Locale.ROOT));
this.plugin.removePlayerFromCache(username);
((Player) source).disconnect(this.successful);
} catch (SQLException e) {
source.sendMessage(this.errorOccurred);
e.printStackTrace();
}
} else {
source.sendMessage(this.wrongPassword);
}
return;
}
}
source.sendMessage(this.usage);
}
use of com.velocitypowered.api.command.CommandSource in project AntiVPN by funkemunky.
the class VelocityPlugin method onInit.
@Subscribe
public void onInit(ProxyInitializeEvent event) {
INSTANCE = this;
logger.info("Loading config...");
config = new Config();
// Loading plugin
logger.info("Starting AntiVPN services...");
AntiVPN.start(new VelocityConfig(), new VelocityListener(), new VelocityPlayerExecutor(), configDir.toFile());
if (AntiVPN.getInstance().getConfig().metrics()) {
logger.info("Starting metrics...");
Metrics metrics = metricsFactory.make(this, 12791);
}
logger.info("Registering commands...");
for (Command command : AntiVPN.getInstance().getCommands()) {
server.getCommandManager().register(server.getCommandManager().metaBuilder(command.name()).aliases(command.aliases()).build(), (SimpleCommand) invocation -> {
CommandSource sender = invocation.source();
if (!invocation.source().hasPermission("antivpn.command.*") && !invocation.source().hasPermission(command.permission())) {
invocation.source().sendMessage(Component.text("No permission").toBuilder().color(TextColor.color(255, 0, 0)).build());
return;
}
val children = command.children();
String[] args = invocation.arguments();
if (children.length > 0 && args.length > 0) {
for (Command child : children) {
if (child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases()).anyMatch(alias -> alias.equalsIgnoreCase(args[0]))) {
if (!sender.hasPermission("antivpn.command.*") && !sender.hasPermission(child.permission())) {
invocation.source().sendMessage(Component.text("No permission").toBuilder().color(TextColor.color(255, 0, 0)).build());
return;
}
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build().deserialize(child.execute(new VelocityCommandExecutor(sender), IntStream.range(0, args.length - 1).mapToObj(i -> args[i + 1]).toArray(String[]::new))));
return;
}
}
}
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build().deserialize(command.execute(new VelocityCommandExecutor(sender), args)));
});
}
}
use of com.velocitypowered.api.command.CommandSource in project 2FA by LielAmar.
the class DisabledEvents method onMessage.
@Subscribe
public void onMessage(CommandExecuteEvent event) {
CommandSource source = event.getCommandSource();
if (!(source instanceof Player))
return;
Player player = (Player) source;
if (this.plugin.getAuthHandler().needsToAuthenticate(player.getUniqueId())) {
String command = event.getCommand();
if (this.plugin.getConfigHandler().isDisableCommands()) {
if (!this.plugin.getConfigHandler().getWhitelistedCommands().contains(command) && !command.toLowerCase(Locale.ROOT).startsWith(Constants.mainCommand.getA().toLowerCase(Locale.ROOT))) {
event.setResult(CommandExecuteEvent.CommandResult.denied());
this.plugin.getMessageHandler().sendMessage(player, MessageHandler.TwoFAMessages.VALIDATE_ACCOUNT);
}
} else {
if (this.plugin.getConfigHandler().getBlacklistedCommands().contains(command)) {
event.setResult(CommandExecuteEvent.CommandResult.denied());
this.plugin.getMessageHandler().sendMessage(player, MessageHandler.TwoFAMessages.VALIDATE_ACCOUNT);
}
}
}
}
use of com.velocitypowered.api.command.CommandSource in project Chocolate by GiansCode.
the class ChocolateCommand method execute.
@Override
public void execute(Invocation invocation) {
CommandSource commandSource = invocation.source();
String[] args = invocation.arguments();
if (permission != null && !commandSource.hasPermission(permission)) {
sendMessage(commandSource, Lang.GENERIC$NO_PERMISSIONS.getString());
return;
}
this.perform(commandSource, args);
}
use of com.velocitypowered.api.command.CommandSource in project FastLogin by games647.
the class PluginMessageListener method readMessage.
private void readMessage(Player forPlayer, String channel, byte[] data) {
FastLoginCore<Player, CommandSource, FastLoginVelocity> core = plugin.getCore();
ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
if (successChannel.equals(channel)) {
onSuccessMessage(forPlayer);
} else if (changeChannel.equals(channel)) {
ChangePremiumMessage changeMessage = new ChangePremiumMessage();
changeMessage.readFrom(dataInput);
String playerName = changeMessage.getPlayerName();
boolean isSourceInvoker = changeMessage.isSourceInvoker();
if (changeMessage.shouldEnable()) {
if (playerName.equals(forPlayer.getUsername()) && plugin.getCore().getConfig().get("premium-warning", true) && !core.getPendingConfirms().contains(forPlayer.getUniqueId())) {
String message = core.getMessage("premium-warning");
forPlayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message));
core.getPendingConfirms().add(forPlayer.getUniqueId());
return;
}
core.getPendingConfirms().remove(forPlayer.getUniqueId());
Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, true, isSourceInvoker);
plugin.getScheduler().runAsync(task);
} else {
Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, false, isSourceInvoker);
plugin.getScheduler().runAsync(task);
}
}
}
Aggregations