use of net.kyori.adventure.text.Component in project Prism-Bukkit by prism.
the class ActionMessage method getMainMessage.
private TextComponent getMainMessage(ActionType action, String format1) {
final TextColor highlight = NamedTextColor.DARK_AQUA;
TextComponent out = Component.text().content(format1).build();
Component result = out.replaceFirstText(Pattern.compile("<prefix>"), builder -> getPosNegPrefix()).replaceFirstText(Pattern.compile("<index>"), builder -> builder.content("[" + index + "] ").color(NamedTextColor.GRAY)).replaceFirstText(Pattern.compile("<target>"), builder -> Component.text().content(handler.getSourceName()).color(highlight)).replaceFirstText(Pattern.compile("<description>"), builder -> Component.text().content(getDescription((ActionTypeImpl) action)).color(NamedTextColor.WHITE)).replaceFirstText(Pattern.compile("<actorNice>"), builder -> getActor((ActionTypeImpl) action, highlight)).replaceFirstText(Pattern.compile("<actor>"), builder -> Component.text().content(action.getName())).replaceFirstText(Pattern.compile("<extendedInfo>"), builder -> Component.text().append(getExtendedInfo())).replaceFirstText(Pattern.compile("<timeDiff>"), builder -> Component.text().append(getTimeDiff())).replaceFirstText(Pattern.compile("<count>"), builder -> Component.text().append(getCount())).replaceFirstText(Pattern.compile("<actionType>"), builder -> Component.text().content("(a:" + action.getShortName() + ")").color(NamedTextColor.GRAY)).replaceFirstText(Pattern.compile("<handlerId>"), builder -> Component.text(handler.getId()).toBuilder().color(NamedTextColor.GRAY));
return Component.text().content("").append(result).hoverEvent(HoverEvent.showText(Component.text("Click to teleport").color(NamedTextColor.DARK_AQUA))).clickEvent(ClickEvent.runCommand("/pr tp " + index)).build();
}
use of net.kyori.adventure.text.Component in project Prism-Bukkit by prism.
the class ActionMessage method getMessage.
/**
* Get the message.
*
* @return String[]
*/
public TextComponent getMessage() {
String format1 = "<prefix> <index> <target> <description> <actorNice> <extendedInfo><count> <timeDiff> <actionType>";
String format2 = "-<handlerId>- <dateTime> - <location>";
ActionType action = handler.getActionType();
TextComponent out = getMainMessage(action, format1);
if (showExtended) {
out = out.append(Component.newline());
Component line2 = Component.text().content(format2).build().replaceFirstText(Pattern.compile("<handlerId>"), builder -> Component.text(handler.getId()).toBuilder().color(NamedTextColor.GRAY)).replaceFirstText(Pattern.compile("<dateTime>"), builder -> Component.text().content(handler.getDisplayDate() + " " + handler.getDisplayTime())).replaceFirstText(Pattern.compile("<location>"), builder -> Component.text().content(getFormattedLocation()));
out = out.append(line2);
}
return out;
}
use of net.kyori.adventure.text.Component in project Prism-Bukkit by prism.
the class DrainCommand method handle.
@Override
public void handle(CallInfo call) {
String drainType = "";
int radius = plugin.getConfig().getInt("prism.drain.default-radius");
if (call.getArgs().length == 3) {
if (call.getArg(1).equalsIgnoreCase("water") || call.getArg(1).equalsIgnoreCase("lava")) {
drainType = call.getArg(1);
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Invalid drain type. Must be lava, water, or left out."));
return;
}
// Validate radius
radius = validateRadius(call, call.getArg(2));
} else if (call.getArgs().length == 2) {
if (TypeUtils.isNumeric(call.getArg(1))) {
radius = validateRadius(call, call.getArg(1));
} else {
if (call.getArg(1).equalsIgnoreCase("water") || call.getArg(1).equalsIgnoreCase("lava")) {
drainType = call.getArg(1);
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Invalid drain type. Must be lava, water, or left out."));
return;
}
}
}
if (radius == 0) {
return;
}
TextComponent.Builder builder = Component.text().append(Il8nHelper.formatMessage("command-drain-lookup", drainType, radius));
String key = "command-drain-lookup-water";
if (drainType.equals("lava")) {
key = "command-drain-lookup-lava";
}
builder.append(Component.text(" ")).append(Il8nHelper.getMessage(key).color(NamedTextColor.GRAY));
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(builder.build()));
ArrayList<BlockStateChange> blockStateChanges = null;
if (drainType.isEmpty()) {
blockStateChanges = Utilities.drain(call.getPlayer().getLocation(), radius);
} else if (drainType.equals("water")) {
blockStateChanges = Utilities.drainWater(call.getPlayer().getLocation(), radius);
} else if (drainType.equals("lava")) {
blockStateChanges = Utilities.drainLava(call.getPlayer().getLocation(), radius);
}
if (blockStateChanges != null && !blockStateChanges.isEmpty()) {
// @todo remove the extra space in msg
Component out = Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("command-drain-lookup-result", blockStateChanges.size(), drainType)).append(Component.newline()).append(Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("command-drain-result-undo")));
Prism.messenger.sendMessage(call.getSender(), out);
// Trigger the event
final PrismDrainEvent event = EventHelper.createDrainEvent(blockStateChanges, call.getPlayer(), radius);
plugin.getServer().getPluginManager().callEvent(event);
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("command-drain-result-empty")));
}
}
use of net.kyori.adventure.text.Component in project Prism-Bukkit by prism.
the class LookupCommand method handle.
/**
* Handle the command.
*/
@Override
public void handle(final CallInfo call) {
// Process and validate all of the arguments
final QueryParameters parameters = PreprocessArgs.process(plugin, call.getSender(), call.getArgs(), PrismProcessType.LOOKUP, 1, !plugin.getConfig().getBoolean("prism.queries.never-use-defaults"));
if (parameters == null) {
return;
}
// Run the lookup itself in an async task so the lookup query isn't done on the main thread
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
// determine if defaults were used
final List<String> defaultsUsed = parameters.getDefaultsUsed();
StringBuilder defaultsReminder = new StringBuilder();
if (!defaultsUsed.isEmpty()) {
defaultsReminder.append(Il8nHelper.getRawMessage("queryparameter.defaults.prefix"));
for (final String d : defaultsUsed) {
defaultsReminder.append(" ").append(d);
}
}
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(parameters, call.getSender());
final StringBuilder sharingWithPlayers = new StringBuilder();
for (final CommandSender shareWith : parameters.getSharedPlayers()) {
sharingWithPlayers.append(shareWith.getName()).append(", ");
}
if (sharingWithPlayers.length() > 0) {
sharingWithPlayers.delete(sharingWithPlayers.lastIndexOf(","), sharingWithPlayers.length());
}
final String playersList = sharingWithPlayers.toString();
// Add current sender
parameters.addSharedPlayer(call.getSender());
for (final CommandSender player : parameters.getSharedPlayers()) {
final boolean isSender = player.getName().equals(call.getSender().getName());
if (!isSender) {
Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("lookup-share-message").color(NamedTextColor.GOLD).replaceText(Pattern.compile("<sender>"), builder -> Component.text().content(call.getSender().getName()).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, TextDecoration.State.TRUE), 1)));
} else if (sharingWithPlayers.length() > 0) {
Component component = Il8nHelper.getMessage("lookup-share-to-message").color(NamedTextColor.GOLD).replaceText(Pattern.compile("<players>"), builder -> Component.text().content(playersList).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, TextDecoration.State.TRUE), 1);
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerHeaderMsg(component));
}
if (!results.getActionResults().isEmpty()) {
Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("lookup-header-message", results.getTotalResults(), 1, results.getTotalPages())));
if ((defaultsReminder.length() > 0) && isSender) {
Prism.messenger.sendMessage(player, Prism.messenger.playerSubduedHeaderMsg(Component.text(defaultsReminder.toString())));
}
final List<Handler> paginated = results.getPaginatedActionResults();
if (paginated != null) {
int resultCount = results.getIndexOfFirstResult();
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();
}
am.setResultIndex(resultCount);
MiscUtils.sendClickableTpRecord(am, player);
resultCount++;
}
MiscUtils.sendPageButtons(results, player);
} else {
Prism.messenger.sendMessage(player, Prism.messenger.playerError(Il8nHelper.getMessage("no-pagination-found")));
}
if (parameters.hasFlag(Flag.PASTE)) {
StringBuilder paste = new StringBuilder();
for (final Handler a : results.getActionResults()) {
paste.append(new ActionMessage(a).getRawMessage()).append("\r\n");
}
MiscUtils.paste_results(player, paste.toString());
}
} else {
if (defaultsReminder.length() > 0) {
if (isSender) {
Prism.messenger.sendMessage(player, Prism.messenger.playerSubduedHeaderMsg(Component.text(defaultsReminder.toString())));
}
}
if (isSender) {
Prism.messenger.sendMessage(player, Prism.messenger.playerError("Nothing found." + ChatColor.GRAY + " Either you're missing something, or we are."));
}
}
}
// Flush timed data
plugin.eventTimer.printTimeRecord();
});
}
use of net.kyori.adventure.text.Component in project Denizen-For-Bukkit by DenizenScript.
the class PaperAdvancedTextImpl method getSignLines.
@Override
public String[] getSignLines(Sign sign) {
String[] output = new String[4];
int i = 0;
for (Component component : sign.lines()) {
output[i++] = PaperModule.stringifyComponent(component, ChatColor.BLACK);
}
return output;
}
Aggregations