Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable or disable stacking based on MSPT hysteresis #290

Open
wants to merge 10 commits into
base: 5.10
Choose a base branch
from
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@
<id>sonatype-oss-snapshots1</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -174,7 +178,7 @@
<dependency>
<groupId>com.github.Zrips</groupId>
<artifactId>Jobs</artifactId>
<version>4.17.2</version>
<version>v5.2.2.3</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -202,6 +206,12 @@
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>me.lucko</groupId>
<artifactId>spark-api</artifactId>
<version>0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
16 changes: 16 additions & 0 deletions src/main/java/uk/antiperson/stackmob/StackMob.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
import uk.antiperson.stackmob.entity.traits.TraitManager;
import uk.antiperson.stackmob.hook.HookManager;
import uk.antiperson.stackmob.listeners.*;
import uk.antiperson.stackmob.mspt.DummyMsptProvider;
import uk.antiperson.stackmob.mspt.MsptProvider;
import uk.antiperson.stackmob.mspt.PaperMsptProvider;
import uk.antiperson.stackmob.mspt.SparkMsptProvider;
import uk.antiperson.stackmob.packets.PlayerManager;
import uk.antiperson.stackmob.scheduler.BukkitScheduler;
import uk.antiperson.stackmob.scheduler.FoliaScheduler;
Expand Down Expand Up @@ -47,6 +51,7 @@ public class StackMob extends JavaPlugin {
private PlayerManager playerManager;
private BukkitAudiences adventure;
private Scheduler scheduler;
private MsptProvider msptProvider;

private boolean stepDamageError;

Expand Down Expand Up @@ -123,6 +128,13 @@ public void onEnable() {
getLogger().warning("It has been detected that you are not using Paper (https://papermc.io).");
getLogger().warning("StackMob makes use of Paper's API, which means you're missing out on features.");
}
if (this.getServer().getPluginManager().getPlugin("Spark") != null){
this.msptProvider = new SparkMsptProvider();
} else if (Utilities.isPaper()) {
this.msptProvider = new PaperMsptProvider();
} else {
this.msptProvider = new DummyMsptProvider();
}
new Metrics(this, 522);
}

Expand Down Expand Up @@ -179,6 +191,10 @@ private void registerEvent(Class<? extends Listener> clazz) throws NoSuchMethodE
getServer().getPluginManager().registerEvents(listener, this);
}

public MsptProvider getMsptProvider() {
return msptProvider;
}

public EntityTranslation getEntityTranslation() {
return entityTranslation;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/uk/antiperson/stackmob/config/EntityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ public String getTagFormat() {
return getString("display-name.format");
}

public boolean isMsptReactiveEnabled() {
return getBoolean("mspt-reactive.enabled");
}

public double getMsptReactiveTriggerThreshold() {
return getDouble("mspt-reactive.trigger-mspt-threshold");
}

public double getMsptReactiveUntriggerThreshold() {
return getDouble("mspt-reactive.untrigger-mspt-threshold");
}

public int getTagThreshold() {
return getInt( "display-name.threshold");
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/uk/antiperson/stackmob/mspt/DummyMsptProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package uk.antiperson.stackmob.mspt;

public class DummyMsptProvider extends MsptProvider {

@Override
public double getMspt() {
return 0;
}

@Override
public void setUnderLoad(boolean underLoad) { }

@Override
public boolean isUnderLoad() {
return false;
}
}
15 changes: 15 additions & 0 deletions src/main/java/uk/antiperson/stackmob/mspt/MsptProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package uk.antiperson.stackmob.mspt;

public abstract class MsptProvider {

boolean underLoad;
quiquelhappy marked this conversation as resolved.
Show resolved Hide resolved

public abstract double getMspt();
public void setUnderLoad(boolean underLoad) {
this.underLoad = underLoad;
}
public boolean isUnderLoad() {
return this.underLoad;
}

}
11 changes: 11 additions & 0 deletions src/main/java/uk/antiperson/stackmob/mspt/PaperMsptProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package uk.antiperson.stackmob.mspt;

import org.bukkit.Bukkit;

public class PaperMsptProvider extends MsptProvider {

@Override
public double getMspt() {
return Bukkit.getAverageTickTime();
}
}
23 changes: 23 additions & 0 deletions src/main/java/uk/antiperson/stackmob/mspt/SparkMsptProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package uk.antiperson.stackmob.mspt;

import me.lucko.spark.api.Spark;
import me.lucko.spark.api.SparkProvider;
import me.lucko.spark.api.statistic.StatisticWindow;

public class SparkMsptProvider extends MsptProvider {

Spark spark;
quiquelhappy marked this conversation as resolved.
Show resolved Hide resolved
boolean underLoad;
quiquelhappy marked this conversation as resolved.
Show resolved Hide resolved

public SparkMsptProvider(){
this.spark = SparkProvider.get();
}

@Override
public double getMspt() {
if(this.spark.mspt() == null){
return 0;
}
return this.spark.mspt().poll(StatisticWindow.MillisPerTick.SECONDS_10).mean();
}
}
17 changes: 17 additions & 0 deletions src/main/java/uk/antiperson/stackmob/tasks/MergeTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ public MergeTask(StackMob sm) {
}

private void checkEntity(StackEntity original, boolean checkHasMoved, double checkHasMovedDistance) {
if(original.getEntityConfig().isMsptReactiveEnabled()){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it likely that this would need to be enabled/disabled on a per entity type basis? Because at the moment this is doing the check for each entity, when it could just be checked once at the beginning of the task.

if (sm.getMsptProvider().isUnderLoad()){
if (sm.getMsptProvider().getMspt()<=original.getEntityConfig().getMsptReactiveUntriggerThreshold()){
// mspt was under heavy load, but no longer is, reset its status and skip stacking
sm.getMsptProvider().setUnderLoad(false);
return;
}
} else {
if (sm.getMsptProvider().getMspt()>=original.getEntityConfig().getMsptReactiveTriggerThreshold()){
// mspt is considered to be under heavy load, set under load to keep hysteresis status
sm.getMsptProvider().setUnderLoad(true);
} else {
// mspt is lower than the trigger threshold, skip stacking
return;
}
}
}
if (original.isWaiting()) {
original.incrementWait();
return;
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ wait-to-stack:
- SPAWNER
reasons-whitelist-invert: false

# Enable the system based on MSPT. The MSPT will be updated as often as stack.interval
# you should use paper or install Spark for this feature to work!
mspt-reactive:
enabled: false
# Above what MSPT should the reactive mode be triggered?
trigger-mspt-threshold: 65.0
# Below what MSPT should the reactive mode be untriggered?
untrigger-mspt-threshold: 45.0


# Enable/disable integration with other plugins. (*)
hooks:
# Allows the custom 'entity-stacking' flag to be used in worldguard regions.
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: ${project.version}
api-version: 1.16
folia-supported: true
depend: [ProtocolLib]
softdepend: [WorldGuard, MythicMobs, ClearLag, MyPet, mcMMO, Jobs, Citizens]
softdepend: [WorldGuard, MythicMobs, ClearLag, MyPet, mcMMO, Jobs, Citizens, Spark]
author: antiPerson
website: https://www.spigotmc.org/resources/stackmob-enhance-your-servers-performance-without-the-sacrifice.29999/
description: A plugin that aims to improve performance by 'stacking' entities together, with attempts to preserve game mechanics.
Expand Down