Skip to content

Commit

Permalink
feat: Optimize block/entity explosion chunks lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
NCT-skyouo committed Sep 24, 2022
1 parent f2a8eb4 commit 3fedb15
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>engineer.skyouo.plugins</groupId>
<artifactId>NatureRevive</artifactId>
<version>1.5.1-SNAPSHOT</version>
<version>1.5.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>NatureRevive</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public final class NatureRevive extends JavaPlugin {
public static Queue<Task> queue = new Queue<>();
public static final Queue<BlockStateWithPos> blockStateWithPosQueue = new Queue<>();
public static final Queue<BlockDataChangeWithPos> blockDataChangeWithPos = new Queue<>();
// reserved for synchronous CoreProtect logging
public static final Queue<Location> blockExplosionQueue = new Queue<>();

@Override
public void onEnable() {
Expand Down Expand Up @@ -207,6 +207,12 @@ public void onEnable() {
};
}, 20L, 2L);

getServer().getScheduler().runTaskTimer(this, () -> {
for (int i = 0; i < NatureRevive.readonlyConfig.blockExplosionProcessingAmountPerProcessing && blockExplosionQueue.hasNext(); i++) {
ChunkRelatedEventListener.flagChunk(blockExplosionQueue.pop());
}
}, 20L, NatureRevive.readonlyConfig.blockExplosionProcessingTick);

getServer().getScheduler().runTaskTimer(this, () -> {
try {
databaseConfig.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ReadonlyConfig {

private YamlConfiguration configuration;

public final int CONFIG_VERSION = 9;
public final int CONFIG_VERSION = 10;

public boolean debug;

Expand Down Expand Up @@ -49,6 +49,10 @@ public class ReadonlyConfig {

public int maxPlayersCountForRegeneration;

public int blockExplosionProcessingTick;

public int blockExplosionProcessingAmountPerProcessing;

public String coreProtectUserName;

public String reloadSuccessMessage;
Expand Down Expand Up @@ -221,6 +225,17 @@ public ReadonlyConfig() {
"When passive is chosen, the plugin will only regenrate chunk on player visited, this method will reduce performance cost but not all the expired chunks will be regenerated."
));

configuration.set("block-explosion-queue-process-per-n-tick", 10);
configuration.setComments("queue-process-per-n-tick",
Arrays.asList("每 n 個 tick 處理一次爆炸影響之區塊計算 (1 tick = 50ms)",
"Proceeding the block/entity explosions affected chunks calculation function every n tick(s).")
);

configuration.set("block-explosion-queue-process-per-time", 200);
configuration.setComments("task-process-per-tick", Arrays.asList("每次可以處理幾個被爆炸範圍影響的方塊.",
"How many block(s) to calculate per explosion process period.")
);

configuration.set("storage.method", "yaml");
configuration.setComments("storage.method", Arrays.asList(
"選擇儲存待更新區塊的資料庫類型, 可選擇 yaml (本地), sqlite (本地), mysql (遠端, 需配置 MySQL 伺服器)",
Expand Down Expand Up @@ -406,6 +421,17 @@ private void updateConfigurations(int version) {
"When average is chosen, the plugin will check all players' neighboring chunks whether or not is expired, if it is, the neighboring chunks will be queued to be regenerated.",
"When passive is chosen, the plugin will only regenrate chunk on player visited, this method will reduce performance cost but not all the expired chunks will be regenerated."
));
case 9:
configuration.set("block-explosion-queue-process-per-n-tick", 10);
configuration.setComments("queue-process-per-n-tick",
Arrays.asList("每 n 個 tick 處理一次爆炸影響之區塊計算 (1 tick = 50ms)",
"Proceeding the block/entity explosions affected chunks calculation function every n tick(s).")
);

configuration.set("block-explosion-queue-process-per-time", 200);
configuration.setComments("task-process-per-tick", Arrays.asList("每次可以處理幾個被爆炸範圍影響的方塊.",
"How many block(s) to calculate per explosion process period.")
);
default:
configuration.set("config-version", CONFIG_VERSION);
try {
Expand Down Expand Up @@ -435,6 +461,8 @@ public void reloadConfig() {
minTPSCountForRegeneration = configuration.getDouble("min-tps-for-regenerate-chunk", 16.0);
maxPlayersCountForRegeneration = configuration.getInt("max-players-for-regenerate-chunk", 40);
regenerationStrategy = configuration.getString("regeneration-strategy", "aggressive");
blockExplosionProcessingTick = configuration.getInt("block-explosion-queue-process-per-n-tick", 10);
blockExplosionProcessingAmountPerProcessing = configuration.getInt("block-explosion-queue-process-per-time", 200);

ttlDuration = parseDuration(configuration.getString("ttl-duration", "7d"));
coreProtectUserName = configuration.getString("coreprotect-log-username", "#資源再生");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ public void onBlockExplodeEvent(BlockExplodeEvent event) {
if (event.isCancelled())
return;


for (Block block : event.blockList()) {
/*
flagChunk(block.getLocation());
log(event, block.getLocation());
*/

NatureRevive.blockExplosionQueue.add(block.getLocation());
}
}

Expand All @@ -91,8 +96,12 @@ public void onEntityExplodeEvent(EntityExplodeEvent event) {
return;

for (Block block : event.blockList()) {
/*
log(event, block.getLocation());
flagChunk(block.getLocation());
*/

NatureRevive.blockExplosionQueue.add(block.getLocation());
}
}

Expand Down Expand Up @@ -125,7 +134,7 @@ public void onChunkLoadEvent(ChunkLoadEvent e) {
}
}

protected static void flagChunk(Location location) {
public static void flagChunk(Location location) {
if (NatureRevive.readonlyConfig.ignoredWorld.contains(location.getWorld().getName()))
return;

Expand Down

0 comments on commit 3fedb15

Please sign in to comment.