mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 16:37:38 +01:00
Delete EventGroup.java, make InstanceEvent an interface
This commit is contained in:
parent
0b6c7b0b0e
commit
096e1de9b5
@ -1,27 +0,0 @@
|
||||
package net.minestom.server.event;
|
||||
|
||||
import net.minestom.server.event.handler.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EventGroup implements ListenerAttach {
|
||||
|
||||
private final EventListener<?>[] listeners;
|
||||
|
||||
protected EventGroup(@NotNull EventListener<?>... listeners) {
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachTo(@NotNull EventHandler handler) {
|
||||
for (EventListener<?> listener : listeners) {
|
||||
listener.attachTo(handler);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachFrom(@NotNull EventHandler handler) {
|
||||
for (EventListener<?> listener : listeners) {
|
||||
listener.detachFrom(handler);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package net.minestom.server.event;
|
||||
|
||||
import net.minestom.server.instance.Instance;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InstanceEvent implements Event {
|
||||
|
||||
protected final Instance instance;
|
||||
|
||||
public InstanceEvent(@NotNull Instance instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the instance.
|
||||
*
|
||||
* @return instance
|
||||
*/
|
||||
@NotNull
|
||||
public Instance getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
@ -2,7 +2,8 @@ package net.minestom.server.event.instance;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.event.CancellableEvent;
|
||||
import net.minestom.server.event.InstanceEvent;
|
||||
import net.minestom.server.event.trait.EntityEvent;
|
||||
import net.minestom.server.event.trait.InstanceEvent;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -10,17 +11,23 @@ import org.jetbrains.annotations.NotNull;
|
||||
* Called by an Instance when an entity is added to it.
|
||||
* Can be used attach data.
|
||||
*/
|
||||
public class AddEntityToInstanceEvent extends InstanceEvent implements CancellableEvent {
|
||||
public class AddEntityToInstanceEvent implements InstanceEvent, EntityEvent, CancellableEvent {
|
||||
|
||||
private final Instance instance;
|
||||
private final Entity entity;
|
||||
|
||||
private boolean cancelled;
|
||||
|
||||
public AddEntityToInstanceEvent(@NotNull Instance instance, @NotNull Entity entity) {
|
||||
super(instance);
|
||||
this.instance = instance;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Instance getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity being added.
|
||||
*
|
||||
|
@ -1,22 +1,28 @@
|
||||
package net.minestom.server.event.instance;
|
||||
|
||||
import net.minestom.server.event.InstanceEvent;
|
||||
import net.minestom.server.event.trait.InstanceEvent;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a chunk in an instance is loaded.
|
||||
*/
|
||||
public class InstanceChunkLoadEvent extends InstanceEvent {
|
||||
public class InstanceChunkLoadEvent implements InstanceEvent {
|
||||
|
||||
private final Instance instance;
|
||||
private final int chunkX, chunkZ;
|
||||
|
||||
public InstanceChunkLoadEvent(@NotNull Instance instance, int chunkX, int chunkZ) {
|
||||
super(instance);
|
||||
this.instance = instance;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Instance getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chunk X.
|
||||
*
|
||||
|
@ -1,22 +1,28 @@
|
||||
package net.minestom.server.event.instance;
|
||||
|
||||
import net.minestom.server.event.InstanceEvent;
|
||||
import net.minestom.server.event.trait.InstanceEvent;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a chunk in an instance is unloaded.
|
||||
*/
|
||||
public class InstanceChunkUnloadEvent extends InstanceEvent {
|
||||
public class InstanceChunkUnloadEvent implements InstanceEvent {
|
||||
|
||||
private final Instance instance;
|
||||
private final int chunkX, chunkZ;
|
||||
|
||||
public InstanceChunkUnloadEvent(@NotNull Instance instance, int chunkX, int chunkZ) {
|
||||
super(instance);
|
||||
this.instance = instance;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Instance getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chunk X.
|
||||
*
|
||||
@ -34,5 +40,4 @@ public class InstanceChunkUnloadEvent extends InstanceEvent {
|
||||
public int getChunkZ() {
|
||||
return chunkZ;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,27 @@
|
||||
package net.minestom.server.event.instance;
|
||||
|
||||
import net.minestom.server.event.InstanceEvent;
|
||||
import net.minestom.server.event.trait.InstanceEvent;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when an instance processes a tick.
|
||||
*/
|
||||
public class InstanceTickEvent extends InstanceEvent {
|
||||
public class InstanceTickEvent implements InstanceEvent {
|
||||
|
||||
private final Instance instance;
|
||||
private final int duration;
|
||||
|
||||
public InstanceTickEvent(@NotNull Instance instance, long time, long lastTickAge) {
|
||||
super(instance);
|
||||
this.instance = instance;
|
||||
this.duration = (int) (time - lastTickAge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Instance getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the duration of the tick in ms.
|
||||
*
|
||||
|
@ -2,24 +2,31 @@ package net.minestom.server.event.instance;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.event.CancellableEvent;
|
||||
import net.minestom.server.event.InstanceEvent;
|
||||
import net.minestom.server.event.trait.EntityEvent;
|
||||
import net.minestom.server.event.trait.InstanceEvent;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called by an Instance when an entity is removed from it.
|
||||
*/
|
||||
public class RemoveEntityFromInstanceEvent extends InstanceEvent implements CancellableEvent {
|
||||
public class RemoveEntityFromInstanceEvent implements InstanceEvent, EntityEvent, CancellableEvent {
|
||||
|
||||
private final Instance instance;
|
||||
private final Entity entity;
|
||||
|
||||
private boolean cancelled;
|
||||
|
||||
public RemoveEntityFromInstanceEvent(@NotNull Instance instance, @NotNull Entity entity) {
|
||||
super(instance);
|
||||
this.instance = instance;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Instance getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entity being removed.
|
||||
*
|
||||
|
@ -0,0 +1,15 @@
|
||||
package net.minestom.server.event.trait;
|
||||
|
||||
import net.minestom.server.event.Event;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface InstanceEvent extends Event {
|
||||
|
||||
/**
|
||||
* Gets the instance.
|
||||
*
|
||||
* @return instance
|
||||
*/
|
||||
@NotNull Instance getInstance();
|
||||
}
|
Loading…
Reference in New Issue
Block a user