From aa06235fcb732031900212b3c9128d6e953cfab9 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Wed, 3 Jan 2024 00:38:33 -0700 Subject: [PATCH] Config Option - Only Render Territories Upon Startup (#1768) ## Problem Rendering territories is causing a lot of lag for some servers. ## Solution This PR introduces a config option to prevent the rendering of territories after the initial startup of the server. This limits the lag spike to one instance per session. ## Testing This was used by a server owner in the community and their TPS improved from 15 to 18. This seems to ease the lag a bit. ## Related Issues closes #1767 --- .../kotlin/com/dansplugins/factionsystem/MedievalFactions.kt | 4 ++++ .../com/dansplugins/factionsystem/claim/MfClaimService.kt | 4 ++-- .../com/dansplugins/factionsystem/faction/MfFactionService.kt | 2 +- .../com/dansplugins/factionsystem/player/MfPlayerService.kt | 4 ++-- src/main/resources/config.yml | 1 + src/main/resources/lang/lang_de_DE.properties | 1 + src/main/resources/lang/lang_en_GB.properties | 1 + src/main/resources/lang/lang_en_US.properties | 1 + src/main/resources/lang/lang_fr_FR.properties | 1 + 9 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/dansplugins/factionsystem/MedievalFactions.kt b/src/main/kotlin/com/dansplugins/factionsystem/MedievalFactions.kt index 71bac2c9..a3c1c5dc 100644 --- a/src/main/kotlin/com/dansplugins/factionsystem/MedievalFactions.kt +++ b/src/main/kotlin/com/dansplugins/factionsystem/MedievalFactions.kt @@ -300,6 +300,10 @@ class MedievalFactions : JavaPlugin() { MedievalFactionsPlaceholderExpansion(this).register() } + if (config.getBoolean("dynmap.onlyRenderTerritoriesUponStartup")) { + logger.info(language["DynmapOnlyRenderTerritoriesUponStartupEnabled"]) + } + if (dynmapService != null) { factionService.factions.forEach { faction -> dynmapService.scheduleUpdateClaims(faction) diff --git a/src/main/kotlin/com/dansplugins/factionsystem/claim/MfClaimService.kt b/src/main/kotlin/com/dansplugins/factionsystem/claim/MfClaimService.kt index 7030bea1..97d3676e 100644 --- a/src/main/kotlin/com/dansplugins/factionsystem/claim/MfClaimService.kt +++ b/src/main/kotlin/com/dansplugins/factionsystem/claim/MfClaimService.kt @@ -116,7 +116,7 @@ class MfClaimService(private val plugin: MedievalFactions, private val repositor } ) val dynmapService = plugin.services.dynmapService - if (dynmapService != null) { + if (dynmapService != null && !plugin.config.getBoolean("dynmap.onlyRenderTerritoriesUponStartup")) { plugin.server.scheduler.runTask( plugin, Runnable { @@ -167,7 +167,7 @@ class MfClaimService(private val plugin: MedievalFactions, private val repositor if (dynmapService != null) { val factionService = plugin.services.factionService val faction = factionService.getFaction(claim.factionId) - if (faction != null) { + if (faction != null && !plugin.config.getBoolean("dynmap.onlyRenderTerritoriesUponStartup")) { plugin.server.scheduler.runTask( plugin, Runnable { diff --git a/src/main/kotlin/com/dansplugins/factionsystem/faction/MfFactionService.kt b/src/main/kotlin/com/dansplugins/factionsystem/faction/MfFactionService.kt index 9d5b912f..ae861acc 100644 --- a/src/main/kotlin/com/dansplugins/factionsystem/faction/MfFactionService.kt +++ b/src/main/kotlin/com/dansplugins/factionsystem/faction/MfFactionService.kt @@ -123,7 +123,7 @@ class MfFactionService(private val plugin: MedievalFactions, private val reposit val result = repository.upsert(factionToSave) factionsById[result.id] = result val dynmapService = plugin.services.dynmapService - if (dynmapService != null) { + if (dynmapService != null && !plugin.config.getBoolean("dynmap.onlyRenderTerritoriesUponStartup")) { plugin.server.scheduler.runTask( plugin, Runnable { diff --git a/src/main/kotlin/com/dansplugins/factionsystem/player/MfPlayerService.kt b/src/main/kotlin/com/dansplugins/factionsystem/player/MfPlayerService.kt index ef1ac707..1c429bc1 100644 --- a/src/main/kotlin/com/dansplugins/factionsystem/player/MfPlayerService.kt +++ b/src/main/kotlin/com/dansplugins/factionsystem/player/MfPlayerService.kt @@ -53,7 +53,7 @@ class MfPlayerService(private val plugin: MedievalFactions, private val playerRe if (dynmapService != null) { val factionService = plugin.services.factionService val faction = factionService.getFaction(result.id) - if (faction != null) { + if (faction != null && !plugin.config.getBoolean("dynmap.onlyRenderTerritoriesUponStartup")) { plugin.server.scheduler.runTask( plugin, Runnable { @@ -74,7 +74,7 @@ class MfPlayerService(private val plugin: MedievalFactions, private val playerRe playerRepository.decreaseOfflinePlayerPower(onlinePlayerIds) playersById.putAll(playerRepository.getPlayers().associateBy(MfPlayer::id)) val dynmapService = plugin.services.dynmapService - if (dynmapService != null) { + if (dynmapService != null && !plugin.config.getBoolean("dynmap.onlyRenderTerritoriesUponStartup")) { val factionService = plugin.services.factionService factionService.factions.forEach { faction -> plugin.server.scheduler.runTask( diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1d5b5742..f1ad58be 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -94,5 +94,6 @@ duels: notificationDistance: 64 dynmap: enableDynmapIntegration: true + onlyRenderTerritoriesUponStartup: false dev: enableDevCommands: false \ No newline at end of file diff --git a/src/main/resources/lang/lang_de_DE.properties b/src/main/resources/lang/lang_de_DE.properties index d638dec6..7a60c8bc 100644 --- a/src/main/resources/lang/lang_de_DE.properties +++ b/src/main/resources/lang/lang_de_DE.properties @@ -1074,3 +1074,4 @@ CommandFactionJoinFactionFull=Die Fraktion, der du beitreten m CommandFactionAddMemberTargetFactionFull=Die Fraktion, zu der du diesen Spieler hinzufügen möchtest, ist voll. PlayerInteractEntityFailedToSavePlayer=Der Spieler konnte nicht gespeichert werden. PlayerInteractEntityCannotTradeWithVillager=Du kannst nicht mit diesem Dorfbewohner handeln. +DynmapOnlyRenderTerritoriesUponStartupEnabled=Die Konfigurationsoption ?dynmap.onlyRenderTerritoriesUponStartup? ist aktiviert. Gebiete werden nur beim Start gerendert. \ No newline at end of file diff --git a/src/main/resources/lang/lang_en_GB.properties b/src/main/resources/lang/lang_en_GB.properties index 9fb4f48e..25b6fc99 100644 --- a/src/main/resources/lang/lang_en_GB.properties +++ b/src/main/resources/lang/lang_en_GB.properties @@ -1073,3 +1073,4 @@ CommandFactionJoinFactionFull=The faction you are trying to join is full. CommandFactionAddMemberTargetFactionFull=The faction you are trying to add a member to is full. PlayerInteractEntityFailedToSavePlayer=Failed to save player. PlayerInteractEntityCannotTradeWithVillager=You cannot trade with this villager. +DynmapOnlyRenderTerritoriesUponStartupEnabled=The `dynmap.onlyRenderTerritoriesUponStartup` config option is enabled. Territories will only be rendered upon startup. \ No newline at end of file diff --git a/src/main/resources/lang/lang_en_US.properties b/src/main/resources/lang/lang_en_US.properties index 11532971..04533b56 100644 --- a/src/main/resources/lang/lang_en_US.properties +++ b/src/main/resources/lang/lang_en_US.properties @@ -1073,3 +1073,4 @@ CommandFactionJoinFactionFull=The faction you are trying to join is full. CommandFactionAddMemberTargetFactionFull=The faction you are trying to add a member to is full. PlayerInteractEntityFailedToSavePlayer=Failed to save player. PlayerInteractEntityCannotTradeWithVillager=You cannot trade with this villager. +DynmapOnlyRenderTerritoriesUponStartupEnabled=The `dynmap.onlyRenderTerritoriesUponStartup` config option is enabled. Territories will only be rendered upon startup. \ No newline at end of file diff --git a/src/main/resources/lang/lang_fr_FR.properties b/src/main/resources/lang/lang_fr_FR.properties index 68847bac..adf10d3d 100644 --- a/src/main/resources/lang/lang_fr_FR.properties +++ b/src/main/resources/lang/lang_fr_FR.properties @@ -1076,3 +1076,4 @@ CommandFactionJoinFactionFull=La faction est pleine. CommandFactionAddMemberTargetFactionFull=La faction est pleine. PlayerInteractEntityFailedToSavePlayer=Impossible de sauvegarder le joueur. PlayerInteractEntityCannotTradeWithVillager=Vous ne pouvez pas commercer avec ce villageois. +DynmapOnlyRenderTerritoriesUponStartupEnabled=L'option de configuration `dynmap.onlyRenderTerritoriesUponStartup` est activée. Les territoires ne seront rendus qu'au démarrage. \ No newline at end of file