froobynooby / ViewDistanceTweaks

Paper plugin that allows for dynamic simulation and view distances.
https://ci.froobworld.com/job/ViewDistanceTweaks/
MIT License
89 stars 17 forks source link

Add option for adjusting view distance in reactive mode #53

Open froobynooby opened 9 months ago

froobynooby commented 9 months ago

Adds options as below to make the reactive (and mixed) adjustment mode affect the view distance rather than just the simulation distance. In deciding when to increase or decrease the view distance and simulation distance in reactive mode, the plugin will attempt to maintain a fixed ratio between the view distance and simulation distance. This defaults to 2.0 (i.e. try to have view distance at least 2x that of the simulation distance).

  # These settings concern how view distance should be handled by reactive mode.
  reactive-view-distance:
    # Should we adjust the view distance in reactive mode?
    #  * Note: If set to false, view distance will be adjusted as though proactive mode is active.
    use-reactive-view-distance: true

    # What ratio should we try to maintain between the view distance and simulation distance?
    #  * This prevents the simulation distance and view distance bunching up.
    #  * As an example, setting this to 2 would target a view distance which is at least 2x the simulation distance.
    target-view-distance-ratio: 2.0

People upgrading the plugin from previous versions will need to switch the use-reactive-view-distance option to true to use this feature - upgraded configs default to false to maintain plugin behaviour between versions.

Plugin jar for those who want to test ViewDistanceTweaks-1.5.7-reactive-vd.zip.

Fixes #49, #52

jojommeke commented 4 months ago

i tested the plugin, the config updated to:

# Configuration for View Distance Tweaks.
# Plugin page: https://www.spigotmc.org/resources/75164/
# Github: https://github.com/froobynooby/ViewDistanceTweaks

# Please don't change this!
version: 9

# Set this to true to enable the plugin. The plugin is initially disabled so that you can make changes to the config
# appropriate to your server.
enabled: true

# How should we determine whether the simulation distance needs adjusting? Accepts three values:
#  * proactive : Adjust the simulation distance so that the player-loaded chunk count is always below a set threshold.
#  * reactive  : Adjust the simulation distance in response to changes in the server's MSPT.
#  * mixed     : Be both proactive and reactive; prioritising decreasing the simulation distance over increasing.
adjustment-mode: mixed

# These settings are for the proactive adjustment mode.
proactive-mode-settings:
  # Set this to the maximum ticking chunk count your server can handle. The simulation distance of each world will be
  # adjusted such that the total number of player-loaded chunks is sitting as close to this value as possible.
  #  * If you know your server can handle up to p many players with a simulation distance of d, a reasonable choice is
  #    to set this to (2d + 1)^2 * p.
  #  * As an example, 5780 is the number of player-loaded ticking chunks for 20 players with a simulation distance of 8.
  global-ticking-chunk-count-target: 578

  # Set this to the maximum number of non-ticking chunks you want to be loaded by the view distance.
  #  * Note: this only counts chunks that are outside of the simulation distance of a player, but within the view
  #    view distance of a player.
  #  * If you know your server can handle up to p many players with a view distance of v and a simulation distance of s,
  #    a reasonable choice is to set this to ((2v + 1)^2 - (2s + 1)^2) * p.
  #  * As an example, 6720 is the number of non-ticking chunks loaded by the view distance for 20 players with a view
  #    distance of 12 and a simulation distance of 8.
  global-non-ticking-chunk-count-target: 2464

# These settings are for the reactive adjustment mode.
#  * MSPT stands for "milliseconds per tick", and tells you how long your server takes to tick on average. A server
#    whose MSPT is above 50 will notice things slowing down, as the TPS drops.
reactive-mode-settings:
  # Below what MSPT should we consider increasing the simulation distance?
  increase-mspt-threshold: 40.0

  # Above what MSPT should we consider decreasing the simulation distance?
  decrease-mspt-threshold: 47.0

  # These settings concern how view distance should be handled by reactive mode.
  reactive-view-distance:
    # Should we adjust the view distance in reactive mode?
    #  * Note: If set to false, view distance will be adjusted as though proactive mode is active.
    use-reactive-view-distance: true

    # What ratio should we try to maintain between the view distance and simulation distance?
    #  * This prevents the simulation distance and view distance bunching up.
    #  * As an example, setting this to 2 would target a view distance which is at least 2x the simulation distance.
    target-view-distance-ratio: 2.5

  # These settings concern how we determine the server's MSPT.
  #  * Only touch these settings if you know what you're doing.
  mspt-tracker-settings:
    # Over how many ticks should we collect tick durations for calculating the MSPT?
    #  * Setting this too high will make the MSPT very slow to react to changes.
    #  * Setting this too low will make the MSPT volatile.
    collection-period: 1200

  # We keep a history of MSPT vs. player-loaded chunk count in order to better predict what the MSPT will settle to
  # after increasing the simulation distance.
  mspt-prediction:
    # Should we use MSPT prediction when we are considering increasing the simulation distance?
    #  * For example, we may be at 38 MSPT with a simulation distance of 6, meaning we would consider increasing the
    #    simulation distance to 7. However, if we saw that 10 minutes ago with a simulation distance of 7 we had
    #    48 MSPT, we would hold off on increasing.
    #  * Disabling this can lead to a back-and-forth game of increasing and decreasing the simulation distance every few
    #    minutes - not ideal.
    enabled: true

    # For how long (in minutes) should we keep a MSPT / chunk count history?
    history-length: 30

# Every how many ticks should we check whether the simulation distance needs to be updated?
ticks-per-check: 600

# How long in ticks should we wait before starting the checking tasks following the plugin's start up?
#  * This is useful when using the 'mixed' or 'reactive' adjustment modes where it is desirable to ignore the server's
#    performance in the first few minutes following a restart.
start-up-delay: 2400

# How many checks in a row that say to increase the simulation or view distance should be required before an increase
# actually occurs?
#  * This is useful as it guards against the following kind of case: A player leaves and the view distance is
#    increased, but the player returns three minutes later and the view distance is lowered to its previous value.
#  * Since increasing the view distance can cause lag-spikes for players with poorer connections, it is
#    recommended to keep this value relatively high.
passed-checks-for-increase: 10

# How many checks in a row that say to decrease the simulation or view distance should be required before a decrease
# actually occurs?
passed-checks-for-decrease: 1

# Should we send a message to the console when we change the simulation or view distance?
log-changes: true

# These settings can be specified per world. If a world is not specified or if a setting is missing, it will use the
# settings listed under the default section.
world-settings:
  default:
    # These settings concern the simulation distance of this world.
    simulation-distance:
      # Should we not manage the simulation distance in this world?
      #  * Note: Even if excluded, the world's chunks will be counted for the purpose of adjusting the simulation distance
      #    of other worlds. If you do not want this, also be sure to set the chunk-weight to 0.
      exclude: false

      # What should the absolute minimum simulation distance be in this world?
      minimum-simulation-distance: 4

      # What should the absolute maximum simulation distance be in this world?
      maximum-simulation-distance: 8

    # These settings concern the view distance of this world.
    view-distance:
      # Should we not manage the view distance in this world?
      #  * Note: Even if excluded, the world's chunks will be counted for the purpose of adjusting the view distances
      #    of other worlds.
      exclude: false

      # What should the absolute minimum view distance be in this world?
      minimum-view-distance: 5

      # What should the absolute maximum view distance be in this world?
      maximum-view-distance: 32

    # Relative to the other worlds, how 'heavy' is a chunk on performance?
    #  * For example: In the End dimension, about half of the chunks you encounter are void and so have very little
    #    impact on performance. For this reason, you may want to set the chunk-weight of the End to 0.5.
    chunk-weight: 1

    # These settings concern how we count the number of chunks in this world.
    chunk-counter-settings:
      # When two players are near each other, the chunks they load can overlap. Should we not double count the chunks
      # that are overlapping?
      exclude-overlap: true

  world_the_end:
    simulation-distance:
      minimum-simulation-distance: 4
      maximum-simulation-distance: 8
    chunk-weight: 0.5

  world_nether:
    chunk-weight: 1.5

  season2new_the_end:
    simulation-distance:
      minimum-simulation-distance: 4
      maximum-simulation-distance: 8
    chunk-weight: 0.5

season2new_nether:
    chunk-weight: 1.5 

but if i do /vdt reload or /viewdistancetweaks reload(in console so without slash) or other subcommands, it gives this error:

! [wo 15:01:17 WARN  DiscordSRV] Task #4130 for DiscordSRV v1.26.2 generated an exception
org.bukkit.command.CommandException: Cannot execute command 'viewdistancetweaks' in plugin ViewDistanceTweaks v1.5.7 - plugin is disabled.
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:37)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155)
    at org.bukkit.craftbukkit.v1_20_R1.CraftServer.dispatchCommand(CraftServer.java:987)
    at DiscordSRV-Build-1.26.2.jar//github.scarsz.discordsrv.listeners.DiscordConsoleListener.lambda$onGuildMessageReceived$0(DiscordConsoleListener.java:95)
    at org.bukkit.craftbukkit.v1_20_R1.scheduler.CraftTask.run(CraftTask.java:101)
    at org.bukkit.craftbukkit.v1_20_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:480)
    at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1479)
    at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:446)
    at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1393)
    at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1170)
    at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317)
    at java.base/java.lang.Thread.run(Thread.java:840)
jojommeke commented 4 months ago

(i downgraded my plugin for now)

jojommeke commented 4 months ago

do i have to delete config when replacing old plugin with new?

jojommeke commented 4 months ago

do i have to delete config when replacing old plugin with new?

still does not work