Skip to content

Commit a3570f0

Browse files
AlexanderTrysMinemd5sha256
authored andcommitted
Show rental time left in list command
1 parent 5ca428b commit a3570f0

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

realty-paper/src/main/java/io/github/md5sha256/realty/command/ListCommand.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package io.github.md5sha256.realty.command;
22

3+
import io.github.md5sha256.realty.api.DurationFormatter;
34
import io.github.md5sha256.realty.api.RealtyApi;
45
import io.github.md5sha256.realty.command.util.NamedAuthority;
56
import io.github.md5sha256.realty.command.util.NamedAuthorityParser;
7+
import io.github.md5sha256.realty.database.entity.LeaseholdContractEntity;
68
import io.github.md5sha256.realty.database.entity.RealtyRegionEntity;
79
import io.github.md5sha256.realty.localisation.MessageContainer;
810
import io.github.md5sha256.realty.localisation.MessageKeys;
@@ -141,7 +143,7 @@ private void listAll(@NotNull CommandSender sender, @NotNull UUID targetId,
141143
builder.append(parseMiniMessage(MessageKeys.LIST_HEADER, "<player>", targetName));
142144
appendCategory(builder, "Owned", result.owned());
143145
appendCategory(builder, "Landlord", result.landlord());
144-
appendCategory(builder, "Rented", result.rented());
146+
appendRentedCategory(builder, "Rented", result.rented());
145147
appendFooter(builder, targetName, null, page, totalPages);
146148
sender.sendMessage(builder.build());
147149
}
@@ -169,7 +171,11 @@ private void listCategory(@NotNull CommandSender sender, @NotNull UUID targetId,
169171
String label = "owned".equals(category) ? "Owned" : "Rented";
170172
TextComponent.Builder builder = Component.text();
171173
builder.append(parseMiniMessage(MessageKeys.LIST_HEADER, "<player>", targetName));
172-
appendCategory(builder, label, result.regions());
174+
if ("owned".equals(category)) {
175+
appendCategory(builder, label, result.regions());
176+
} else {
177+
appendRentedCategory(builder, label, result.regions());
178+
}
173179
appendFooter(builder, targetName, category, page, totalPages);
174180
sender.sendMessage(builder.build());
175181
}
@@ -189,6 +195,25 @@ private void appendCategory(@NotNull TextComponent.Builder builder, @NotNull Str
189195
}
190196
}
191197

198+
private void appendRentedCategory(@NotNull TextComponent.Builder builder, @NotNull String label,
199+
@NotNull List<RealtyRegionEntity> regions) {
200+
if (regions.isEmpty()) {
201+
return;
202+
}
203+
builder.appendNewline()
204+
.append(parseMiniMessage(MessageKeys.LIST_CATEGORY, "<label>", label));
205+
for (RealtyRegionEntity region : regions) {
206+
LeaseholdContractEntity leasehold = logic.getLeaseholdContract(region.worldGuardRegionId(), region.worldId());
207+
String timeLeft = DurationFormatter.formatTimeLeft(leasehold != null ? leasehold.endDate() : null);
208+
builder.appendNewline()
209+
.append(parseMiniMessage(
210+
MessageKeys.LIST_RENTED_ENTRY,
211+
"<region>", region.worldGuardRegionId(),
212+
"<time_left>", timeLeft
213+
));
214+
}
215+
}
216+
192217
private void appendFooter(@NotNull TextComponent.Builder builder, @NotNull String targetName,
193218
@Nullable String category, int page, int totalPages) {
194219
Component previousComponent = page > 1

realty-paper/src/main/java/io/github/md5sha256/realty/localisation/MessageKeys.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ private MessageKeys() {}
180180
public static final String LIST_HEADER = "list.header";
181181
public static final String LIST_CATEGORY = "list.category";
182182
public static final String LIST_ENTRY = "list.entry";
183+
public static final String LIST_RENTED_ENTRY = "list.rented-entry";
183184
public static final String LIST_FOOTER = "list.footer";
184185
public static final String LIST_PREVIOUS = "list.previous";
185186
public static final String LIST_NEXT = "list.next";

realty-paper/src/main/resources/messages.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ list:
171171
header: "--- Regions for <player> ---"
172172
category: "<label>:"
173173
entry: " - <region>"
174+
rented-entry: " - <region> <gray>(<time_left>)</gray>"
174175
footer: "Page <page> of <total> <previous><next>"
175176
previous: "<click:run_command:<command>><yellow>< Previous</yellow></click> "
176177
next: " <click:run_command:<command>><yellow>Next ></yellow></click>"

0 commit comments

Comments
 (0)