Skip to content

Commit beed7cd

Browse files
committed
Add subregion tag blacklisting
1 parent 1f1facb commit beed7cd

5 files changed

Lines changed: 49 additions & 2 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.jetbrains.annotations.NotNull;
3434

3535
import java.time.Duration;
36+
import java.util.Collection;
3637
import java.util.List;
3738
import java.util.Objects;
3839
import java.util.UUID;
@@ -106,6 +107,42 @@ private void executeQuickCreate(@NotNull CommandContext<Source> ctx) {
106107
return;
107108
}
108109

110+
Collection<String> blacklist = settings.get().subregionTagBlacklist();
111+
if (!blacklist.isEmpty()) {
112+
String parentId = parentRegion.region().getId();
113+
api.getTagIdsByRegion(parentId).thenAccept(tags -> {
114+
for (String tag : tags) {
115+
if (blacklist.contains(tag)) {
116+
player.sendMessage(messages.messageFor(
117+
MessageKeys.SUBREGION_TAG_BLACKLISTED,
118+
Placeholder.unparsed("region", parentId),
119+
Placeholder.unparsed("tag", tag)));
120+
return;
121+
}
122+
}
123+
continueQuickCreate(player, parentRegion, name, price, duration,
124+
canBypass, regionManager);
125+
}).exceptionally(ex -> {
126+
Throwable cause = ex.getCause() != null ? ex.getCause() : ex;
127+
cause.printStackTrace();
128+
player.sendMessage(messages.messageFor(MessageKeys.SUBREGION_CREATE_ERROR,
129+
Placeholder.unparsed("error", cause.getMessage())));
130+
return null;
131+
});
132+
return;
133+
}
134+
135+
continueQuickCreate(player, parentRegion, name, price, duration,
136+
canBypass, regionManager);
137+
}
138+
139+
private void continueQuickCreate(@NotNull Player player,
140+
@NotNull WorldGuardRegion parentRegion,
141+
@NotNull String name,
142+
double price,
143+
@NotNull Duration duration,
144+
boolean canBypass,
145+
@NotNull RegionManager regionManager) {
109146
SelectionResult result = validateSelection(player, parentRegion, regionManager,
110147
settings.get().subregionMinVolume());
111148
switch (result) {

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
@@ -376,6 +376,7 @@ private MessageKeys() {}
376376
public static final String SUBREGION_EXCEEDS_BOUNDS = "subregion.exceeds-bounds";
377377
public static final String SUBREGION_OVERLAPS_SIBLING = "subregion.overlaps-sibling";
378378
public static final String SUBREGION_TOO_SMALL = "subregion.too-small";
379+
public static final String SUBREGION_TAG_BLACKLISTED = "subregion.tag-blacklisted";
379380

380381
// teleport
381382
public static final String TP_SUCCESS = "tp.success";

realty-paper/src/main/java/io/github/md5sha256/realty/settings/Settings.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.spongepowered.configurate.objectmapping.meta.Setting;
99

1010
import java.text.SimpleDateFormat;
11+
import java.util.List;
1112
import java.util.Map;
1213
import java.util.UUID;
1314

@@ -19,7 +20,8 @@ public record Settings(
1920
@Setting("date-format") @Required @NotNull SimpleDateFormat dateFormat,
2021
@Setting("profile-reapply-per-tick") int profileReapplyPerTick,
2122
@Setting("subregion-min-volume") int subregionMinVolume,
22-
@Setting("offer-payment-duration-seconds") long offerPaymentDurationSeconds
23+
@Setting("offer-payment-duration-seconds") long offerPaymentDurationSeconds,
24+
@Setting("subregion-tag-blacklist") @NotNull List<String> subregionTagBlacklist
2325
) {
2426

2527
public Settings {
@@ -32,6 +34,9 @@ public record Settings(
3234
if (offerPaymentDurationSeconds <= 0) {
3335
offerPaymentDurationSeconds = 86400;
3436
}
37+
if (subregionTagBlacklist == null) {
38+
subregionTagBlacklist = List.of();
39+
}
3540
}
3641
}
3742

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ subregion:
466466
exceeds-bounds: "Your selection exceeds the bounds of region <region>."
467467
overlaps-sibling: "Your selection overlaps with existing subregion <sibling>."
468468
too-small: "Your selection is too small (<volume> blocks). Minimum volume is <min-volume> blocks."
469+
tag-blacklisted: "Region <region> has tag <tag> which prevents subregioning."
469470

470471
sign:
471472
place-success: "Sign registered for region <region>."

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ profile-reapply-per-tick: 10
99
# Minimum volume (in blocks) for subregion selections.
1010
subregion-min-volume: 20
1111
# Duration (in seconds) for an accepted offer payment deadline. Default: 86400 (24 hours).
12-
offer-payment-duration-seconds: 86400
12+
offer-payment-duration-seconds: 86400
13+
# Tag IDs that prevent a parent region from being subregioned.
14+
# If a region has any of these tags, it cannot be used as a parent for subregion creation.
15+
subregion-tag-blacklist: []

0 commit comments

Comments
 (0)