Improvements to /plot list command (#3585)

* refactor: list command shows owner better
added check for:
- unknown owners (UUID not cached/invalid)
- server plots
- plots owner by everyone

* fix: show correct color in list command if plot is owned by everyone

* refactor: improved List command for server plots

(cherry picked from commit fed700f0d8)

* refactor: removed duplicate code

* refactor: renamed placeholders to reflect their use

Co-authored-by: Alexander Brandes <mc.cache@web.de>
This commit is contained in:
Bernhard 2022-05-10 09:50:27 +02:00 committed by GitHub
parent 13d7357c85
commit 7d6e515ba8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 30 deletions

View File

@ -32,6 +32,7 @@ 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.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.database.DBFunc;
import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
@ -39,6 +40,7 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.expiration.ExpireManager; import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.flag.implementations.PriceFlag; import com.plotsquared.core.plot.flag.implementations.PriceFlag;
import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag;
import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.MathMan;
@ -418,7 +420,7 @@ public class ListCmd extends SubCommand {
Caption color; Caption color;
if (plot.getOwner() == null) { if (plot.getOwner() == null) {
color = TranslatableCaption.of("info.plot_list_no_owner"); color = TranslatableCaption.of("info.plot_list_no_owner");
} else if (plot.isOwner(player.getUUID())) { } else if (plot.isOwner(player.getUUID()) || plot.getOwner().equals(DBFunc.EVERYONE)) {
color = TranslatableCaption.of("info.plot_list_owned_by"); color = TranslatableCaption.of("info.plot_list_owned_by");
} else if (plot.isAdded(player.getUUID())) { } else if (plot.isAdded(player.getUUID())) {
color = TranslatableCaption.of("info.plot_list_added_to"); color = TranslatableCaption.of("info.plot_list_added_to");
@ -456,7 +458,17 @@ public class ListCmd extends SubCommand {
String prefix = ""; String prefix = "";
String online = TranslatableCaption.of("info.plot_list_player_online").getComponent(player); String online = TranslatableCaption.of("info.plot_list_player_online").getComponent(player);
String offline = TranslatableCaption.of("info.plot_list_player_offline").getComponent(player); String offline = TranslatableCaption.of("info.plot_list_player_offline").getComponent(player);
String unknown = TranslatableCaption.of("info.plot_list_player_unknown").getComponent(player);
String server = TranslatableCaption.of("info.plot_list_player_server").getComponent(player);
String everyone = TranslatableCaption.of("info.plot_list_player_everyone").getComponent(player);
TextComponent.Builder builder = Component.text(); TextComponent.Builder builder = Component.text();
if (plot.getFlag(ServerPlotFlag.class)) {
Template serverTemplate = Template.of(
"info.server",
TranslatableCaption.of("info.server").getComponent(player)
);
builder.append(MINI_MESSAGE.parse(server, serverTemplate));
} else {
try { try {
final List<UUIDMapping> names = PlotSquared.get().getImpromptuUUIDPipeline().getNames(plot.getOwners()) final List<UUIDMapping> names = PlotSquared.get().getImpromptuUUIDPipeline().getNames(plot.getOwners())
.get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS); .get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS);
@ -466,6 +478,18 @@ public class ListCmd extends SubCommand {
Template playerTemplate = Template.of("player", uuidMapping.getUsername()); Template playerTemplate = Template.of("player", uuidMapping.getUsername());
if (pp != null) { if (pp != null) {
builder.append(MINI_MESSAGE.parse(online, prefixTemplate, playerTemplate)); builder.append(MINI_MESSAGE.parse(online, prefixTemplate, playerTemplate));
} else if (uuidMapping.getUsername().equalsIgnoreCase("unknown")) {
Template unknownTemplate = Template.of(
"info.unknown",
TranslatableCaption.of("info.unknown").getComponent(player)
);
builder.append(MINI_MESSAGE.parse(unknown, unknownTemplate));
} else if (uuidMapping.getUuid().equals(DBFunc.EVERYONE)) {
Template everyoneTemplate = Template.of(
"info.everyone",
TranslatableCaption.of("info.everyone").getComponent(player)
);
builder.append(MINI_MESSAGE.parse(everyone, everyoneTemplate));
} else { } else {
builder.append(MINI_MESSAGE.parse(offline, prefixTemplate, playerTemplate)); builder.append(MINI_MESSAGE.parse(offline, prefixTemplate, playerTemplate));
} }
@ -488,6 +512,7 @@ public class ListCmd extends SubCommand {
} catch (TimeoutException e) { } catch (TimeoutException e) {
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout")); player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
} }
}
Template players = Template.of("players", builder.asComponent()); Template players = Template.of("players", builder.asComponent());
caption.set(TranslatableCaption.of("info.plot_list_item")); caption.set(TranslatableCaption.of("info.plot_list_item"));
caption.setTemplates(command_tp, command_info, hover_info, numberTemplate, plotTemplate, players); caption.setTemplates(command_tp, command_info, hover_info, numberTemplate, plotTemplate, players);

View File

@ -381,6 +381,9 @@
"info.plot_list_default": "<gold><plot></gold>", "info.plot_list_default": "<gold><plot></gold>",
"info.plot_list_player_online": "<dark_aqua><prefix></dark_aqua><hover:show_text:\"<dark_aqua>Online</dark_aqua>\"><gold><player></gold></hover>", "info.plot_list_player_online": "<dark_aqua><prefix></dark_aqua><hover:show_text:\"<dark_aqua>Online</dark_aqua>\"><gold><player></gold></hover>",
"info.plot_list_player_offline": "<dark_aqua><prefix></dark_aqua><hover:show_text:\"<dark_gray>Offline</dark_gray>\"><gold><player></gold></hover>", "info.plot_list_player_offline": "<dark_aqua><prefix></dark_aqua><hover:show_text:\"<dark_gray>Offline</dark_gray>\"><gold><player></gold></hover>",
"info.plot_list_player_unknown": "<hover:show_text:\"<red>The owner of this plot is unknown</red>\"><white><info.unknown></white></hover>",
"info.plot_list_player_server": "<hover:show_text:\"<red>The plot is owned by the server</red>\"><white><info.server></white></hover>",
"info.plot_list_player_everyone": "<hover:show_text:\"<blue>The plot is owned by everyone</blue>\"><white><info.everyone></white></hover>",
"info.area_info_format": "<header>\n<reset><gold>Name: </gold><gray><name></gray>\n<gold>Type: </gold><gray><type></gray>\n<gold>Terrain: </gold><gray><terrain></gray>\n<gold>Usage: </gold><gray><usage>%</gray>\n<gold>Claimed: </gold><gray><claimed></gray>\n<gold>Clusters: </gold><gray><clusters></gray>\n<gold>Region: </gold><gray><region></gray>\n<gold>Generator: </gold><gray><generator></gray>\n<footer>", "info.area_info_format": "<header>\n<reset><gold>Name: </gold><gray><name></gray>\n<gold>Type: </gold><gray><type></gray>\n<gold>Terrain: </gold><gray><terrain></gray>\n<gold>Usage: </gold><gray><usage>%</gray>\n<gold>Claimed: </gold><gray><claimed></gray>\n<gold>Clusters: </gold><gray><clusters></gray>\n<gold>Region: </gold><gray><region></gray>\n<gold>Generator: </gold><gray><generator></gray>\n<footer>",
"info.area_list_tooltip": "<gold>Claimed=</gold><gray><claimed></gray>\n<gold>Usage=</gold><gray><usage></gray>\n<gold>Clusters=</gold><gray><clusters></gray>\n<gold>Region=</gold><gray><region></gray>\n<gold>Generator=</gold><gray><generator></gray>", "info.area_list_tooltip": "<gold>Claimed=</gold><gray><claimed></gray>\n<gold>Usage=</gold><gray><usage></gray>\n<gold>Clusters=</gold><gray><clusters></gray>\n<gold>Region=</gold><gray><region></gray>\n<gold>Generator=</gold><gray><generator></gray>",
"info.area_list_item": "<click:run_command:<command_tp>><hover:show_text:\"<command_tp>\"><dark_gray>[</dark_gray><gold><number></gold><dark_gray>]</dark_gray></hover></click> <click:run_command:<command_info>><hover:show_text:\"<hover_info>\"><gold><area_name></gold></hover></click><gray> - </gray><gray><area_type>:<area_terrain></gray>", "info.area_list_item": "<click:run_command:<command_tp>><hover:show_text:\"<command_tp>\"><dark_gray>[</dark_gray><gold><number></gold><dark_gray>]</dark_gray></hover></click> <click:run_command:<command_info>><hover:show_text:\"<hover_info>\"><gold><area_name></gold></hover></click><gray> - </gray><gray><area_type>:<area_terrain></gray>",