|
50 | 50 | import io.github.md5sha256.realty.command.util.SafeLocationFinder; |
51 | 51 | import io.github.md5sha256.realty.database.Database; |
52 | 52 | import io.github.md5sha256.realty.database.RealtyBackendImpl; |
| 53 | +import io.github.md5sha256.realty.database.SqlSessionWrapper; |
53 | 54 | import io.github.md5sha256.realty.database.maria.MariaDatabase; |
54 | 55 | import io.github.md5sha256.realty.listener.SignInteractionListener; |
55 | 56 | import io.github.md5sha256.realty.localisation.MessageContainer; |
|
104 | 105 | import java.time.Duration; |
105 | 106 | import java.util.HashMap; |
106 | 107 | import java.util.List; |
| 108 | +import java.util.Set; |
107 | 109 | import java.util.Map; |
108 | 110 | import java.util.Objects; |
109 | 111 | import java.util.concurrent.ExecutorService; |
@@ -259,6 +261,7 @@ public void onEnable() { |
259 | 261 | .register(RealtyBackend.class, this.logic, this, ServicePriority.Normal); |
260 | 262 | getServer().getServicesManager() |
261 | 263 | .register(RealtyPaperApi.class, this.paperApi, this, ServicePriority.Normal); |
| 264 | + warnOrphanedTags(); |
262 | 265 | getLogger().info("Plugin enabled successfully"); |
263 | 266 | } |
264 | 267 |
|
@@ -421,6 +424,25 @@ private void registerTagPermissions(@NotNull RealtyTags realtyTags) { |
421 | 424 | } |
422 | 425 | } |
423 | 426 |
|
| 427 | + private void warnOrphanedTags() { |
| 428 | + executorState.dbExec().execute(() -> { |
| 429 | + try (SqlSessionWrapper session = database.openSession(true)) { |
| 430 | + List<String> dbTagIds = session.regionTagMapper().selectDistinctTagIds(); |
| 431 | + Set<String> configTagIds = realtyTags.get().tagIds(); |
| 432 | + List<String> orphaned = dbTagIds.stream() |
| 433 | + .filter(tagId -> !configTagIds.contains(tagId)) |
| 434 | + .toList(); |
| 435 | + if (!orphaned.isEmpty()) { |
| 436 | + getLogger().warning("Found orphaned tags in the database that are not in region-tags.yml: " |
| 437 | + + String.join(", ", orphaned) |
| 438 | + + ". Run /realty cleanup tags to remove them."); |
| 439 | + } |
| 440 | + } catch (Exception ex) { |
| 441 | + getLogger().warning("Failed to check for orphaned tags: " + ex.getMessage()); |
| 442 | + } |
| 443 | + }); |
| 444 | + } |
| 445 | + |
424 | 446 | private void reloadMessages() throws IOException { |
425 | 447 | ConfigurationNode node = copyDefaultsYaml("messages"); |
426 | 448 | this.messageContainer.load(node); |
@@ -470,6 +492,7 @@ private void performReload() throws IOException { |
470 | 492 | configureRegionFlagService(this.regionFlagSettings.get()); |
471 | 493 | this.profileApplicator.applyAll(this.settings.get().profileReapplyPerTick()); |
472 | 494 | reloadMessages(); |
| 495 | + warnOrphanedTags(); |
473 | 496 | } |
474 | 497 |
|
475 | 498 | private void registerCommands( |
|
0 commit comments