Clearing the Arena without Lag (//set 0)

ardacarofficial

New member
Jun 27, 2024
2
0
1
I have a PVP server and there is an area where people can break blocks and put blocks.

When there are too many transactions in this area, I wrote a Script code to turn this area back to the old one.

Field size: ( 100 x 100 )

The script code is as follows:

command /cleararena:
trigger:
# Hava
make player execute command "//pos1 67,6,-479"
wait 1 tick
make player execute command "//pos2 -80,101,-332"
wait 1 tick
make player execute command "//set 0"

# Yeşil Bölge
make player execute command "//pos1 67,1,-479"
wait 1 tick
make player execute command "//pos2 -6,5,-406"
wait 1 tick
make player execute command "//set 80%%lime_terracotta,20%%green_terracotta"

# Kırmızı Bölge
make player execute command "//pos1 -7,5,-406"
wait 1 tick
make player execute command "//pos2 -80,1,-479"
wait 1 tick
make player execute command "//set 80%%red_terracotta,20%%black_terracotta"

# Mavi Bölge
make player execute command "//pos1 -7,5,-405"
wait 1 tick
make player execute command "//pos2 -80,1,-332"
wait 1 tick
make player execute command "//set 80%%light_blue_concrete,20%%blue_concrete"

# Beyaz Bölge
make player execute command "//pos1 -6,5,-405"
wait 1 tick
make player execute command "//pos2 67,1,-332"
wait 1 tick
make player execute command "//set 80%%light_gray_concrete,20%%white_concrete"

But this causes the server to lag too much instantly (TPS drops to 15, instant pings go up to 500)

Other servers have arenas and there is no lag when players clear the arena while playing in the game instantly.

How do they achieve that?

Note: my server is not any VDS problem with 20 gb ram and 18 cpu.
 

Me4502

Paper Maintainer
Staff member
Dec 17, 2021
1
1
3
madelinemiller.dev
The best way to solve this is to just do it via the API. That way you can do all of those edits as a single operation, as well as disable history tracking as it's unnecessary in this situation. And then also edit side effects to disable anything you don't need such as neighbour updates and block updates.

Otherwise if you absolutely must do it via commands (which you generally should never do for scripting), you can disable side effects via the //perf command. Disabling everything you don't need will speed things up. However you will never be able to get it as fast as if it was done via the API by scripting it like this.

for some java-like pseudocode, you'd want to do something like this using the API:

Java:
try (EditSession editSession = WorldEdit.getInstance().newEditSession(world)) {
  editSession.setTrackingHistory(false);
  editSession.setSideEffectApplier(SideEffectSet.defaults().with(SideEffect.UPDATE, SideEffect.State.OFF).with(SideEffect.NEIGHBORS, SideEffect.State.OFF));
  editSession.setBlocks(new CuboidRegion(BlockVector3.at(67,7,-479), BlockVector3.at(-80, 101, -332)), BlockTypes.AIR.getDefaultState());
  RandomPattern green = new RandomPattern();
  green.add(BlockTypes.LIME_TERRACOTTA.getDefaultState(), 0.8);
  green.add(BlockTypes.GREEN_TERRACOTTA.getDefaultState(), 0.2);
  editSession.setBlocks(new CuboidRegion(BlockVector3.at(67,1,-479), BlockVector3.at(-6,5,-406)), green);
  // ... repeated for each region & pattern
}
 
Last edited:
  • Love
Reactions: ardacarofficial