update plot list

This commit is contained in:
dordsor21 2020-08-06 13:36:15 +01:00
parent 4a960d9f2c
commit f68eb9c778
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
3 changed files with 72 additions and 62 deletions

View File

@ -29,7 +29,9 @@ import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.caption.CaptionHolder; import com.plotsquared.core.configuration.caption.CaptionHolder;
import com.plotsquared.core.configuration.caption.StaticCaption;
import com.plotsquared.core.configuration.caption.Templates; import com.plotsquared.core.configuration.caption.Templates;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
@ -361,68 +363,69 @@ public class ListCmd extends SubCommand {
public void displayPlots(final PlotPlayer<?> player, List<Plot> plots, int pageSize, int page, String[] args) { public void displayPlots(final PlotPlayer<?> player, List<Plot> plots, int pageSize, int page, String[] args) {
// Header // Header
plots.removeIf(plot -> !plot.isBasePlot()); plots.removeIf(plot -> !plot.isBasePlot());
this.paginate(player, plots, pageSize, page, this.paginate(player, plots, pageSize, page, new RunnableVal3<Integer, Plot, CaptionHolder>() {
new RunnableVal3<Integer, Plot, CaptionHolder>() { @Override public void run(Integer i, Plot plot, CaptionHolder caption) {
@Override public void run(Integer i, Plot plot, CaptionHolder caption) { Caption color;
String color; if (plot.getOwner() == null) {
if (plot.getOwner() == null) { color = TranslatableCaption.of("info.plot_list_no_owner");
color = "$3"; } else if (plot.isOwner(player.getUUID())) {
} else if (plot.isOwner(player.getUUID())) { color = TranslatableCaption.of("info.plot_list_owned_by");
color = "$1"; } else if (plot.isAdded(player.getUUID())) {
} else if (plot.isAdded(player.getUUID())) { color = TranslatableCaption.of("info.plot_list_added_to");
color = "$4"; } else if (plot.isDenied(player.getUUID())) {
} else if (plot.isDenied(player.getUUID())) { color = TranslatableCaption.of("info.plot_list_denied_on");
color = "$2"; } else {
} else { color = TranslatableCaption.of("info.plot_list_default");
color = "$1";
}
PlotMessage trusted = new PlotMessage().text(Captions.color(
Captions.PLOT_INFO_TRUSTED.getTranslated()
.replaceAll("%trusted%", PlayerManager.getPlayerList(plot.getTrusted()))))
.color("$1");
PlotMessage members = new PlotMessage().text(Captions.color(
Captions.PLOT_INFO_MEMBERS.getTranslated()
.replaceAll("%members%", PlayerManager.getPlayerList(plot.getMembers()))))
.color("$1");
message.text("[").color("$3").text(i + "")
.command("/plot visit " + plot.getArea() + ";" + plot.getId())
.tooltip("/plot visit " + plot.getArea() + ";" + plot.getId()).color("$1")
.text("]").color("$3").text(" " + plot.toString()).tooltip(trusted, members)
.command("/plot info " + plot.getArea() + ";" + plot.getId()).color(color)
.text(" - ").color("$2");
String prefix = "";
try {
final List<UUIDMapping> names = PlotSquared.get().getImpromptuUUIDPipeline()
.getNames(plot.getOwners()).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS);
for (final UUIDMapping uuidMapping : names) {
PlotPlayer<?> pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid());
if (pp != null) {
message = message.text(prefix).color("$4").text(uuidMapping.getUsername()).color("$1")
.tooltip(new PlotMessage("Online").color("$4"));
} else {
message = message.text(prefix).color("$4").text(uuidMapping.getUsername()).color("$1")
.tooltip(new PlotMessage("Offline").color("$3"));
}
prefix = ", ";
}
} catch (InterruptedException | ExecutionException e) {
final StringBuilder playerBuilder = new StringBuilder();
final Iterator<UUID> uuidIterator = plot.getOwners().iterator();
while (uuidIterator.hasNext()) {
final UUID uuid = uuidIterator.next();
playerBuilder.append(uuid);
if (uuidIterator.hasNext()) {
playerBuilder.append(", ");
}
}
player.sendMessage(TranslatableCaption.of("errors.invalid_player"),
Templates.of("value", playerBuilder.toString()));
} catch (TimeoutException e) {
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
}
} }
}, "/plot list " + args[0], TranslatableCaption.of("list.plot_list_header_paged")); String trusted = MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("info.plot_info_trusted").getComponent(player),
Template.of("trusted", PlayerManager.getPlayerList(plot.getTrusted()))));
String members = MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("info.plot_info_members").getComponent(player),
Template.of("members", PlayerManager.getPlayerList(plot.getMembers()))));
Template command_tp = Template.of("command_tp", "/plot visit " + plot.getArea() + ";" + plot.getId());
Template command_info = Template.of("command_info", "/plot info " + plot.getArea() + ";" + plot.getId());
Template hover_info = Template.of("hover_info", trusted + "\n" + members);
Template numberTemplate = Template.of("number", String.valueOf(i));
Template plotTemplate =
Template.of("plot", MINI_MESSAGE.serialize(MINI_MESSAGE.parse(color.getComponent(player), Template.of("plot", plot.toString()))));
String prefix = "";
String online = TranslatableCaption.of("info.plot_list_player_online").getComponent(player);
String offline = TranslatableCaption.of("info.plot_list_player_offline").getComponent(player);
StringBuilder builder = new StringBuilder();
try {
final List<UUIDMapping> names = PlotSquared.get().getImpromptuUUIDPipeline().getNames(plot.getOwners())
.get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS);
for (final UUIDMapping uuidMapping : names) {
PlotPlayer<?> pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid());
Template prefixTemplate = Template.of("prefix", prefix);
Template playerTemplate = Template.of("prefix", uuidMapping.getUsername());
if (pp != null) {
builder.append(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(online, prefixTemplate, playerTemplate)));
} else {
builder.append(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(offline, prefixTemplate, playerTemplate)));
}
prefix = ", ";
}
} catch (InterruptedException | ExecutionException e) {
final StringBuilder playerBuilder = new StringBuilder();
final Iterator<UUID> uuidIterator = plot.getOwners().iterator();
while (uuidIterator.hasNext()) {
final UUID uuid = uuidIterator.next();
playerBuilder.append(uuid);
if (uuidIterator.hasNext()) {
playerBuilder.append(", ");
}
}
player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Templates.of("value", playerBuilder.toString()));
} catch (TimeoutException e) {
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
}
Template players = Template.of("players", builder.toString());
caption.set(StaticCaption.of(MINI_MESSAGE.serialize(MINI_MESSAGE
.parse(TranslatableCaption.of("info.plot_list_item").getComponent(player), command_tp, command_info, hover_info, numberTemplate,
plotTemplate, players))));
}
}, "/plot list " + args[0], TranslatableCaption.of("list.plot_list_header_paged"));
} }
@Override public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) { @Override public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {

View File

@ -61,7 +61,6 @@ public class Merge extends SubCommand {
public static final String[] values = new String[] {"north", "east", "south", "west"}; public static final String[] values = new String[] {"north", "east", "south", "west"};
public static final String[] aliases = new String[] {"n", "e", "s", "w"}; public static final String[] aliases = new String[] {"n", "e", "s", "w"};
private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
private final EventDispatcher eventDispatcher; private final EventDispatcher eventDispatcher;
private final EconHandler econHandler; private final EconHandler econHandler;

View File

@ -376,6 +376,14 @@
"info.plot_no_description": "<prefix><gray>No description set.</gray>", "info.plot_no_description": "<prefix><gray>No description set.</gray>",
"info.plot_caps_header": "<dark_gray><strikethrough>--------- <reset><gold>CAPS </gold><dark_gray><strikethrough>---------<reset>", "info.plot_caps_header": "<dark_gray><strikethrough>--------- <reset><gold>CAPS </gold><dark_gray><strikethrough>---------<reset>",
"info.plot_caps_format": "<prefix><gray>- Cap Type: </gray><gold><cap> </gold><gray>| Status: </gray><gold><current></gold><gray>/</gray><gold><limit> </gold><gray>(</gray><gold><percentage>%</gold><gray>)</gray>", "info.plot_caps_format": "<prefix><gray>- Cap Type: </gray><gold><cap> </gold><gray>| Status: </gray><gold><current></gold><gray>/</gray><gold><limit> </gold><gray>(</gray><gold><percentage>%</gold><gray>)</gray>",
"info.plot_list_item": "<click:run_command:<command_tp>><hover:show_text:<command_tp>><dark_grey>[</dark_grey><gold><number></gold><dark_grey>]</dark_grey></hover></click><click:run_command:<command_info>><hover:show_text:<hover_info>><gold> <plot></gold></hover></click><grey> - </grey><players>",
"info.plot_list_no_owner": "<dark_grey><plot></dark_grey>",
"info.plot_list_owned_by": "<gold><plot></gold>",
"info.plot_list_added_to": "<cyan><plot></cyan>",
"info.plot_list_denied_on": "<grey><plot></grey>",
"info.plot_list_default": "<gold><plot></gold>",
"info.plot_list_player_online": "<cyan><prefix></cyan><hover:show_text:<cyan>Online</cyan>><gold><player></gold></hover>",
"info.plot_list_player_offline": "<cyan><prefix></cyan><hover:show_text:<dark_grey>Offline</dark_grey>><gold><player></gold></hover>",
"info.area_info_format": "<header>\n<reset><gold>NAME: </gold><grey><name></grey>\n<gold>Type: </gold><grey><type></grey>\n<gold>Terrain: </gold><grey><terrain></grey>\n<gold>Usage: </gold><grey><usage>%</grey>\n<gold>Claimed: </gold><grey><claimed></grey>\n<gold>Clusters: </gold><grey><clusters></grey>\n<gold>Region: </gold><grey><region></grey>\n<gold>Generator: </gold><grey><generator></grey>\n<footer>", "info.area_info_format": "<header>\n<reset><gold>NAME: </gold><grey><name></grey>\n<gold>Type: </gold><grey><type></grey>\n<gold>Terrain: </gold><grey><terrain></grey>\n<gold>Usage: </gold><grey><usage>%</grey>\n<gold>Claimed: </gold><grey><claimed></grey>\n<gold>Clusters: </gold><grey><clusters></grey>\n<gold>Region: </gold><grey><region></grey>\n<gold>Generator: </gold><grey><generator></grey>\n<footer>",
"info.area_list_tooltip": "<gold>Claimed=</gold><grey><claimed></grey>\n<gold>Usage=</gold><grey><usage></grey>\n<gold>Clusters=</gold><grey><clusters></grey>\n<gold>Region=</gold><grey><region></grey>\n<gold>Generator=</gold><grey><generator></grey>\n", "info.area_list_tooltip": "<gold>Claimed=</gold><grey><claimed></grey>\n<gold>Usage=</gold><grey><usage></grey>\n<gold>Clusters=</gold><grey><clusters></grey>\n<gold>Region=</gold><grey><region></grey>\n<gold>Generator=</gold><grey><generator></grey>\n",
"info.area_list_item": "<click:run_command:<command_tp>><hover:show_text:<command_tp>><dark_grey>[</dark_grey><gold><number></gold><dark_grey>]</dark_grey></hover></click><click:run_command:<command_info>><hover:show_text:<hover_info>><gold> <area_name></gold></hover></click><grey> - </grey><dark_grey><area_type>:<area_terrain></dark_grey>", "info.area_list_item": "<click:run_command:<command_tp>><hover:show_text:<command_tp>><dark_grey>[</dark_grey><gold><number></gold><dark_grey>]</dark_grey></hover></click><click:run_command:<command_info>><hover:show_text:<hover_info>><gold> <area_name></gold></hover></click><grey> - </grey><dark_grey><area_type>:<area_terrain></dark_grey>",