use of net.kyori.adventure.audience.Audience in project SpongeCommon by SpongePowered.
the class MapTest method setMapNether.
private CommandResult setMapNether(final CommandContext ctx) throws CommandException {
final Audience audience = ctx.cause().audience();
final Player player = this.requirePlayer(ctx);
final ItemStack map = player.itemInHand(HandTypes.MAIN_HAND);
if (map.type() != ItemTypes.FILLED_MAP.get()) {
throw new CommandException(Component.text("You must hold a map in your hand"));
}
final ResourceKey netherKey = ResourceKey.minecraft("the_nether");
final Optional<ServerWorld> nether = Sponge.server().worldManager().world(netherKey);
if (!nether.isPresent()) {
final CompletableFuture<ServerWorld> loadedNether = Sponge.server().worldManager().loadWorld(netherKey);
loadedNether.whenComplete((v, e) -> {
if (e != null) {
audience.sendMessage(Component.text("Failed to load nether world!", NamedTextColor.GREEN));
logger.error("Error loading nether world!", e);
} else {
audience.sendMessage(Component.text("Loaded nether world (dim-1)", NamedTextColor.GREEN));
}
});
throw new CommandException(Component.text("No nether loaded, trying to load now, please wait"));
}
map.require(Keys.MAP_INFO).offer(Keys.MAP_WORLD, nether.get().key());
return CommandResult.success();
}
use of net.kyori.adventure.audience.Audience in project Prism-Bukkit by prism.
the class HelpCommand method help.
/**
* Displays help.
*
* @param s CommandSender
*/
protected void help(CommandSender s) {
Audience sender = Prism.getAudiences().sender(s);
if (failed) {
sender.sendMessage(Identity.nil(), Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("prism-disabled-header").color(NamedTextColor.GOLD)).append(Component.newline()).append(Prism.messenger.playerMsg(Il8nHelper.getMessage("prism-disabled-content")).color(NamedTextColor.GOLD)).append(Component.newline()).append(Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("discord", ":").color(NamedTextColor.WHITE).append(Component.text(Il8nHelper.getRawMessage("discord-url"))))).append(Component.newline()).append(Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("wiki", ":").color(NamedTextColor.WHITE).append(Component.text(Il8nHelper.getRawMessage("wiki-url"))))));
return;
}
TextComponent component = Prism.messenger.playerHeaderMsg(Component.text("--- Basic Usage ---").color(NamedTextColor.GOLD)).append(Component.newline()).append(Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("help-extended-message"))).append(Component.newline());
Stream<SubCommand> stream = Prism.getInstance().getCommands().getSubCommands().values().stream().distinct();
for (SubCommand command : stream.collect(Collectors.toList())) {
if (command.getHelp().length > 1) {
int i = 0;
for (String message : command.getHelp()) {
if (i == 0) {
component = component.append(Prism.messenger.playerHelp(Arrays.toString(command.getAliases()), message).clickEvent(ClickEvent.openUrl(command.getWebLink()))).append(Component.newline());
} else {
component = component.append(Prism.messenger.playerHelp(" |- ", message).clickEvent(ClickEvent.openUrl(command.getWebLink()))).append(Component.newline());
}
i++;
}
} else {
component = component.append(Prism.messenger.playerHelp(Arrays.toString(command.getAliases()), command.getHelp()[0]).clickEvent(ClickEvent.openUrl(command.getWebLink()))).append(Component.newline());
}
}
sender.sendMessage(Identity.nil(), component);
}
use of net.kyori.adventure.audience.Audience in project Prism-Bukkit by prism.
the class UndoCommand method handle.
@Override
public void handle(CallInfo call) {
final Audience audience = Prism.getAudiences().player(call.getPlayer());
if (call.getArgs().length > 1) {
final ActionsQuery aq = new ActionsQuery(plugin);
long recordId = 0;
if (TypeUtils.isNumeric(call.getArg(1))) {
recordId = Long.parseLong(call.getArg(1));
if (recordId <= 0) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Record ID must be greater than zero."));
return;
}
} else {
if (call.getArg(1).equals("last")) {
recordId = aq.getUsersLastPrismProcessId(call.getPlayer().getName());
}
}
// Invalid id
if (recordId == 0) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Either you have no last process or an invalid ID."));
return;
}
final PrismProcessAction process = aq.getPrismProcessRecord(recordId);
if (process == null) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("A process does not exists with that value."));
return;
}
// We only support this for drains
if (!process.getProcessChildActionType().equals("prism-drain")) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("You can't currently undo anything other than a drain process."));
return;
}
// Pull the actual block change data for this undo event
final QueryParameters parameters = new QueryParameters();
parameters.setWorld(call.getPlayer().getWorld().getName());
parameters.addActionType(process.getProcessChildActionType());
parameters.addPlayerName(call.getPlayer().getName());
parameters.setParentId(recordId);
parameters.setProcessType(PrismProcessType.UNDO);
// make sure the distance isn't too far away
final QueryResult results = aq.lookup(parameters, call.getPlayer());
if (!results.getActionResults().isEmpty()) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("command-undo-complete")));
final Previewable rb = new Undo(plugin, call.getPlayer(), results.getActionResults(), parameters, new PrismApplierCallback());
rb.apply();
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Nothing found to undo. Must be a problem with Prism."));
}
} else {
// Show the list
// Process and validate all of the arguments
final QueryParameters parameters = new QueryParameters();
parameters.setAllowNoRadius(true);
parameters.addActionType("prism-process");
parameters.addPlayerName(call.getPlayer().getName());
// @todo config this, and move the logic
parameters.setLimit(5);
// to queryparams
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(parameters, call.getPlayer());
if (!results.getActionResults().isEmpty()) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("lookup-header-message", results.getTotalResults(), 1, results.getTotalPages())));
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("command-undo-help")));
final List<Handler> paginated = results.getPaginatedActionResults();
if (paginated != null) {
for (final Handler a : paginated) {
final ActionMessage am = new ActionMessage(a);
if (parameters.hasFlag(Flag.EXTENDED) || plugin.getConfig().getBoolean("prism.messenger.always-show-extended")) {
am.showExtended();
}
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerMsg(am.getMessage()));
}
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Pagination can't find anything. Do you have the right page number?"));
}
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Nothing found." + ChatColor.GRAY + " Either you're missing something, or we are."));
}
}
}
use of net.kyori.adventure.audience.Audience in project SpongeCommon by SpongePowered.
the class TimingsExport method start.
@Override
public synchronized void start() {
boolean containsRconSource = false;
for (Audience receiver : this.listeners.getChannel().audiences()) {
if (receiver instanceof RconConnection) {
containsRconSource = true;
break;
}
}
if (containsRconSource) {
this.listeners.send(Component.text("Warning: Timings report done over RCON will cause lag spikes.", NamedTextColor.RED));
this.listeners.send(Component.text("You should use ", NamedTextColor.RED).append(Component.text("/sponge timings report", NamedTextColor.YELLOW)).append(Component.text(" in game or console.", NamedTextColor.RED)));
this.run();
} else {
super.start();
}
}
use of net.kyori.adventure.audience.Audience in project SpongeCommon by SpongePowered.
the class EntityMixin_Tracker method bridge$markEntityRemovedFromLevel.
@Override
public void bridge$markEntityRemovedFromLevel() {
if (this.tracker$destructCause != null && ShouldFire.DESTRUCT_ENTITY_EVENT) {
final Audience originalChannel = Audience.empty();
SpongeCommon.post(SpongeEventFactory.createDestructEntityEvent(this.tracker$destructCause, originalChannel, Optional.of(originalChannel), Component.empty(), Component.empty(), (org.spongepowered.api.entity.Entity) this, false));
this.tracker$destructCause = null;
}
}
Aggregations