mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-14 03:11:25 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
0de69ae2ad
@ -0,0 +1,42 @@
|
|||||||
|
package net.minestom.server.event.instance;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import net.minestom.server.event.Event;
|
||||||
|
import net.minestom.server.instance.InstanceContainer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when an instance processes a tick
|
||||||
|
*/
|
||||||
|
public class InstanceTickEvent extends Event {
|
||||||
|
|
||||||
|
private final int duration;
|
||||||
|
private final InstanceContainer instance;
|
||||||
|
|
||||||
|
public InstanceTickEvent(@NotNull long time, @Nullable long lastTickAge, InstanceContainer someInstance) {
|
||||||
|
this.duration = (int) (time - lastTickAge);
|
||||||
|
this.instance = someInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the duration of the tick in ms
|
||||||
|
*
|
||||||
|
* @return the duration
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public int getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the instance of the event
|
||||||
|
*
|
||||||
|
* @return the instance
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public InstanceContainer getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ import net.minestom.server.data.SerializableData;
|
|||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.event.instance.InstanceChunkLoadEvent;
|
import net.minestom.server.event.instance.InstanceChunkLoadEvent;
|
||||||
import net.minestom.server.event.instance.InstanceChunkUnloadEvent;
|
import net.minestom.server.event.instance.InstanceChunkUnloadEvent;
|
||||||
|
import net.minestom.server.event.instance.InstanceTickEvent;
|
||||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
||||||
import net.minestom.server.instance.batch.BlockBatch;
|
import net.minestom.server.instance.batch.BlockBatch;
|
||||||
import net.minestom.server.instance.batch.ChunkBatch;
|
import net.minestom.server.instance.batch.ChunkBatch;
|
||||||
@ -65,6 +66,9 @@ public class InstanceContainer extends Instance {
|
|||||||
private final ReadWriteLock changingBlockLock = new ReentrantReadWriteLock();
|
private final ReadWriteLock changingBlockLock = new ReentrantReadWriteLock();
|
||||||
private final Map<BlockPosition, Block> currentlyChangingBlocks = new HashMap<>();
|
private final Map<BlockPosition, Block> currentlyChangingBlocks = new HashMap<>();
|
||||||
|
|
||||||
|
// Fields for tick events
|
||||||
|
private long lastTickAge = System.currentTimeMillis();
|
||||||
|
|
||||||
// the chunk loader, used when trying to load/save a chunk from another source
|
// the chunk loader, used when trying to load/save a chunk from another source
|
||||||
private IChunkLoader chunkLoader;
|
private IChunkLoader chunkLoader;
|
||||||
|
|
||||||
@ -789,10 +793,17 @@ public class InstanceContainer extends Instance {
|
|||||||
// Time/world border
|
// Time/world border
|
||||||
super.tick(time);
|
super.tick(time);
|
||||||
|
|
||||||
|
// Process tick events
|
||||||
|
InstanceTickEvent chunkTickEvent = new InstanceTickEvent(time, lastTickAge, this);
|
||||||
|
callEvent(InstanceTickEvent.class, chunkTickEvent);
|
||||||
|
|
||||||
Lock wrlock = changingBlockLock.writeLock();
|
Lock wrlock = changingBlockLock.writeLock();
|
||||||
wrlock.lock();
|
wrlock.lock();
|
||||||
currentlyChangingBlocks.clear();
|
currentlyChangingBlocks.clear();
|
||||||
wrlock.unlock();
|
wrlock.unlock();
|
||||||
|
|
||||||
|
// Set last tick age
|
||||||
|
lastTickAge = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user