diff --git a/src/main/java/net/minestom/server/event/instance/InstanceTickEvent.java b/src/main/java/net/minestom/server/event/instance/InstanceTickEvent.java index 3d32146c5..0fb1377d5 100644 --- a/src/main/java/net/minestom/server/event/instance/InstanceTickEvent.java +++ b/src/main/java/net/minestom/server/event/instance/InstanceTickEvent.java @@ -5,25 +5,38 @@ 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 int duration; + private final InstanceContainer instance; - public InstanceTickEvent(@NotNull long time, @Nullable long lastTickAge) { + 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 instance + * @return the duration */ @NotNull public int getDuration() { return duration; } + + /** + * Gets the instance of the event + * + * @return the instance + */ + @NotNull + public InstanceContainer getInstance() { + return instance; + } } \ No newline at end of file diff --git a/src/main/java/net/minestom/server/instance/InstanceContainer.java b/src/main/java/net/minestom/server/instance/InstanceContainer.java index 7d58ae802..a9ce2b61e 100644 --- a/src/main/java/net/minestom/server/instance/InstanceContainer.java +++ b/src/main/java/net/minestom/server/instance/InstanceContainer.java @@ -65,6 +65,9 @@ public class InstanceContainer extends Instance { private final ReadWriteLock changingBlockLock = new ReentrantReadWriteLock(); private final Map 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 private IChunkLoader chunkLoader; @@ -78,9 +81,6 @@ public class InstanceContainer extends Instance { // Fields for instance copy protected InstanceContainer srcInstance; // only present if this instance has been created using a copy private long lastBlockChangeTime; // Time at which the last block change happened (#setBlock) - - // Fields for tick events - private long lastTickAge; /** * Creates an {@link InstanceContainer}. @@ -794,7 +794,7 @@ public class InstanceContainer extends Instance { super.tick(time); // Process tick events - InstanceTickEvent chunkTickEvent = new InstanceTickEvent(time, lastTickAge); + InstanceTickEvent chunkTickEvent = new InstanceTickEvent(time, lastTickAge, this); callEvent(InstanceTickEvent.class, chunkTickEvent); Lock wrlock = changingBlockLock.writeLock();