use of com.velocitypowered.api.command.CommandSource in project Floodgate by GeyserMC.
the class VelocityPlatformModule method configure.
@Override
protected void configure() {
VelocityCommandUtil commandUtil = new VelocityCommandUtil();
requestInjection(commandUtil);
bind(CommandUtil.class).to(VelocityCommandUtil.class);
bind(VelocityCommandUtil.class).toInstance(commandUtil);
Injector child = guice.createChildInjector(new CloudInjectionModule<>(UserAudience.class, CommandExecutionCoordinator.simpleCoordinator(), commandUtil::getAudience, audience -> (CommandSource) audience.source()));
CommandManager<UserAudience> commandManager = child.getInstance(new Key<VelocityCommandManager<UserAudience>>() {
});
bind(new Key<CommandManager<UserAudience>>() {
}).toInstance(commandManager);
commandManager.registerCommandPreProcessor(new FloodgateCommandPreprocessor<>(commandUtil));
}
use of com.velocitypowered.api.command.CommandSource in project Floodgate by GeyserMC.
the class VelocityCommandUtil method getAudience.
@Override
@NonNull
public UserAudience getAudience(@NonNull Object sourceObj) {
if (!(sourceObj instanceof CommandSource)) {
throw new IllegalArgumentException("Can only work with CommandSource!");
}
CommandSource source = (CommandSource) sourceObj;
if (!(source instanceof Player)) {
if (console != null) {
return console;
}
return console = new VelocityConsoleAudience(source, this);
}
Player player = (Player) source;
UUID uuid = player.getUniqueId();
String username = player.getUsername();
String locale = Utils.getLocale(player.getPlayerSettings().getLocale());
return AUDIENCE_CACHE.computeIfAbsent(uuid, $ -> new VelocityPlayerAudience(uuid, username, locale, source, true, this));
}
use of com.velocitypowered.api.command.CommandSource in project ConnectorPlugin by Phoenix616.
the class TeleportToPlayerCommand method run.
@Override
public boolean run(CommandSource sender, String alias, String[] args) {
String playerName;
String targetName;
if (args.length == 1 && sender instanceof Player) {
playerName = ((Player) sender).getUsername();
targetName = args[0];
} else if (args.length == 2) {
playerName = args[0];
targetName = args[1];
} else {
return false;
}
Player player = plugin.getProxy().getPlayer(playerName).orElse(null);
if (player == null) {
sender.sendMessage(Component.text("No player with the name " + playerName + " found!").color(NamedTextColor.RED));
return true;
}
Player target = plugin.getProxy().getPlayer(targetName).orElse(null);
if (target == null) {
sender.sendMessage(Component.text("No player with the name " + targetName + " found!").color(NamedTextColor.RED));
return true;
}
plugin.getBridge().teleport(player.getUsername(), target.getUsername(), m -> sender.sendMessage(LegacyComponentSerializer.legacySection().deserialize(m))).thenAccept(success -> {
if (!success) {
sender.sendMessage(Component.text("Error while teleporting...").color(NamedTextColor.RED));
}
});
return true;
}
use of com.velocitypowered.api.command.CommandSource in project message by OskarsMC-Plugins.
the class MessageHandler method handleMessageEvent.
/**
* Handle the message event once it's been fired.
* @param event The Message Event instance.
*/
public void handleMessageEvent(@NotNull MessageEvent event) {
if (messageSettings.selfMessageSending() && event.sender() == event.recipient()) {
event.sender().sendMessage(Component.translatable("oskarsmc.message.command.common.self-sending-error", NamedTextColor.RED));
return;
}
if (event.getResult().isAllowed()) {
Component senderName = event.sender() instanceof Player ? Component.text(((Player) event.sender()).getUsername()) : Component.text("UNKNOWN");
Component receiverName = Component.text(event.recipient().getUsername());
List<Template> templates = new ArrayList<>(List.of(Template.template("sender", senderName), Template.template("receiver", receiverName), Template.template("message", Component.text(event.message()))));
if (messageSettings.luckpermsIntegration()) {
LuckPerms luckPerms = LuckPermsProvider.get();
PlayerAdapter<Player> playerAdapter = luckPerms.getPlayerAdapter(Player.class);
CachedMetaData senderMetaData = null;
if (event.sender() instanceof Player) {
senderMetaData = playerAdapter.getUser(((Player) event.sender())).getCachedData().getMetaData();
}
CachedMetaData recipientMetaData = playerAdapter.getUser(event.recipient()).getCachedData().getMetaData();
templates.addAll(craftLuckpermsTemplates("sender", senderMetaData));
templates.addAll(craftLuckpermsTemplates("receiver", recipientMetaData));
}
for (Map.Entry<String, Component> entry : event.extraPlaceholders().entrySet()) {
templates.add(Template.template(entry.getKey(), entry.getValue()));
}
Component senderMessage = miniMessage.deserialize(messageSettings.messageSentMiniMessage(), TemplateResolver.templates(templates));
Component receiverMessage = miniMessage.deserialize(messageSettings.messageReceivedMiniMessage(), TemplateResolver.templates(templates));
event.sender().sendMessage(senderMessage);
event.recipient().sendMessage(receiverMessage);
if (event.sender() instanceof Player) {
conversations.remove(event.recipient());
conversations.put(event.recipient(), ((Player) event.sender()));
}
Component socialSpyComponent = miniMessage.deserialize(messageSettings.messageSocialSpyMiniMessage(), TemplateResolver.templates(templates));
for (CommandSource watcher : conversationWatchers) {
watcher.sendMessage(socialSpyComponent);
}
}
}
use of com.velocitypowered.api.command.CommandSource in project LimboAuth by Elytrium.
the class ChangePasswordCommand 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 (this.needOldPass ? args.length == 2 : args.length == 1) {
if (this.needOldPass) {
RegisteredPlayer player = AuthSessionHandler.fetchInfo(this.playerDao, ((Player) source).getUsername());
if (player == null) {
source.sendMessage(this.notRegistered);
return;
} else if (player.getHash().isEmpty()) {
source.sendMessage(this.crackedCommand);
} else if (!AuthSessionHandler.checkPassword(args[0], player, this.playerDao)) {
source.sendMessage(this.wrongPassword);
return;
}
}
try {
UpdateBuilder<RegisteredPlayer, String> updateBuilder = this.playerDao.updateBuilder();
updateBuilder.where().eq("NICKNAME", ((Player) source).getUsername());
updateBuilder.updateColumnValue("HASH", AuthSessionHandler.genHash(this.needOldPass ? args[1] : args[0]));
updateBuilder.update();
source.sendMessage(this.successful);
} catch (SQLException e) {
source.sendMessage(this.errorOccurred);
e.printStackTrace();
}
return;
}
source.sendMessage(this.usage);
}
Aggregations