mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 21:17:53 +01:00
Merge branch 'Minestom:master' into master
This commit is contained in:
commit
74abe0439b
@ -16,7 +16,7 @@ import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.metadata.EntityMeta;
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.ListenerHandle;
|
||||
import net.minestom.server.event.GlobalHandles;
|
||||
import net.minestom.server.event.entity.*;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.instance.Instance;
|
||||
@ -65,8 +65,6 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||
private static final Map<UUID, Entity> ENTITY_BY_UUID = new ConcurrentHashMap<>();
|
||||
private static final AtomicInteger LAST_ENTITY_ID = new AtomicInteger();
|
||||
|
||||
private static final ListenerHandle<EntityTickEvent> ENTITY_TICK_HANDLER = EventDispatcher.getHandle(EntityTickEvent.class);
|
||||
|
||||
protected Instance instance;
|
||||
protected Chunk currentChunk;
|
||||
protected Pos position;
|
||||
@ -448,7 +446,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||
update(time);
|
||||
|
||||
ticks++;
|
||||
EventDispatcher.call(new EntityTickEvent(this), ENTITY_TICK_HANDLER);
|
||||
EventDispatcher.call(new EntityTickEvent(this), GlobalHandles.ENTITY_TICK);
|
||||
|
||||
// remove expired effects
|
||||
effectTick(time);
|
||||
|
@ -32,7 +32,7 @@ import net.minestom.server.entity.fakeplayer.FakePlayer;
|
||||
import net.minestom.server.entity.metadata.PlayerMeta;
|
||||
import net.minestom.server.entity.vehicle.PlayerVehicleInformation;
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.ListenerHandle;
|
||||
import net.minestom.server.event.GlobalHandles;
|
||||
import net.minestom.server.event.inventory.InventoryOpenEvent;
|
||||
import net.minestom.server.event.item.ItemDropEvent;
|
||||
import net.minestom.server.event.item.ItemUpdateStateEvent;
|
||||
@ -99,8 +99,6 @@ import java.util.function.UnaryOperator;
|
||||
*/
|
||||
public class Player extends LivingEntity implements CommandSender, Localizable, HoverEventSource<ShowEntity>, Identified, NamedAndIdentified {
|
||||
|
||||
private static final ListenerHandle<PlayerTickEvent> PLAYER_TICK_HANDLER = EventDispatcher.getHandle(PlayerTickEvent.class);
|
||||
|
||||
private long lastKeepAlive;
|
||||
private boolean answerKeepAlive;
|
||||
|
||||
@ -353,7 +351,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
}
|
||||
|
||||
// Tick event
|
||||
EventDispatcher.call(new PlayerTickEvent(this), PLAYER_TICK_HANDLER);
|
||||
EventDispatcher.call(new PlayerTickEvent(this), GlobalHandles.PLAYER_TICK);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
26
src/main/java/net/minestom/server/event/GlobalHandles.java
Normal file
26
src/main/java/net/minestom/server/event/GlobalHandles.java
Normal file
@ -0,0 +1,26 @@
|
||||
package net.minestom.server.event;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.event.entity.EntityTickEvent;
|
||||
import net.minestom.server.event.instance.InstanceChunkLoadEvent;
|
||||
import net.minestom.server.event.instance.InstanceTickEvent;
|
||||
import net.minestom.server.event.player.PlayerChunkLoadEvent;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.event.player.PlayerPacketEvent;
|
||||
import net.minestom.server.event.player.PlayerTickEvent;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Contains handles to the main node {@link MinecraftServer#getGlobalEventHandler()}
|
||||
* (compatible with {@link EventDispatcher}).
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public final class GlobalHandles {
|
||||
public static final ListenerHandle<PlayerTickEvent> PLAYER_TICK = EventDispatcher.getHandle(PlayerTickEvent.class);
|
||||
public static final ListenerHandle<PlayerPacketEvent> PLAYER_PACKET = EventDispatcher.getHandle(PlayerPacketEvent.class);
|
||||
public static final ListenerHandle<PlayerMoveEvent> PLAYER_MOVE = EventDispatcher.getHandle(PlayerMoveEvent.class);
|
||||
public static final ListenerHandle<EntityTickEvent> ENTITY_TICK = EventDispatcher.getHandle(EntityTickEvent.class);
|
||||
public static final ListenerHandle<InstanceTickEvent> INSTANCE_TICK = EventDispatcher.getHandle(InstanceTickEvent.class);
|
||||
public static final ListenerHandle<PlayerChunkLoadEvent> PLAYER_CHUNK_LOAD = EventDispatcher.getHandle(PlayerChunkLoadEvent.class);
|
||||
public static final ListenerHandle<InstanceChunkLoadEvent> INSTANCE_CHUNK_LOAD = EventDispatcher.getHandle(InstanceChunkLoadEvent.class);
|
||||
}
|
@ -2,6 +2,12 @@ package net.minestom.server.event;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Represents a key to access an {@link EventNode} listeners.
|
||||
* Useful to avoid map lookups.
|
||||
*
|
||||
* @param <E> the event type
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public interface ListenerHandle<E extends Event> {
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.pathfinding.PFColumnarSpace;
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.GlobalHandles;
|
||||
import net.minestom.server.event.player.PlayerChunkLoadEvent;
|
||||
import net.minestom.server.event.player.PlayerChunkUnloadEvent;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
@ -279,7 +280,7 @@ public abstract class Chunk implements BlockGetter, BlockSetter, Viewable, Ticka
|
||||
|
||||
if (result) {
|
||||
PlayerChunkLoadEvent playerChunkLoadEvent = new PlayerChunkLoadEvent(player, chunkX, chunkZ);
|
||||
EventDispatcher.call(playerChunkLoadEvent);
|
||||
EventDispatcher.call(playerChunkLoadEvent, GlobalHandles.PLAYER_CHUNK_LOAD);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -17,7 +17,7 @@ import net.minestom.server.entity.ExperienceOrb;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.pathfinding.PFInstanceSpace;
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.ListenerHandle;
|
||||
import net.minestom.server.event.GlobalHandles;
|
||||
import net.minestom.server.event.instance.AddEntityToInstanceEvent;
|
||||
import net.minestom.server.event.instance.InstanceTickEvent;
|
||||
import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent;
|
||||
@ -62,8 +62,6 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
protected static final BlockManager BLOCK_MANAGER = MinecraftServer.getBlockManager();
|
||||
protected static final UpdateManager UPDATE_MANAGER = MinecraftServer.getUpdateManager();
|
||||
|
||||
private static final ListenerHandle<InstanceTickEvent> INSTANCE_TICK_HANDLER = EventDispatcher.getHandle(InstanceTickEvent.class);
|
||||
|
||||
private boolean registered;
|
||||
|
||||
private final DimensionType dimensionType;
|
||||
@ -708,7 +706,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
// Tick event
|
||||
{
|
||||
// Process tick events
|
||||
EventDispatcher.call(new InstanceTickEvent(this, time, lastTickAge), INSTANCE_TICK_HANDLER);
|
||||
EventDispatcher.call(new InstanceTickEvent(this, time, lastTickAge), GlobalHandles.INSTANCE_TICK);
|
||||
// Set last tick age
|
||||
this.lastTickAge = time;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.GlobalHandles;
|
||||
import net.minestom.server.event.instance.InstanceChunkLoadEvent;
|
||||
import net.minestom.server.event.instance.InstanceChunkUnloadEvent;
|
||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
||||
@ -273,7 +274,7 @@ public class InstanceContainer extends Instance {
|
||||
// cache the retrieved chunk (in the next instance tick for thread-safety)
|
||||
.whenComplete((chunk, throwable) -> scheduleNextTick(instance -> {
|
||||
cacheChunk(chunk);
|
||||
EventDispatcher.call(new InstanceChunkLoadEvent(this, chunkX, chunkZ));
|
||||
EventDispatcher.call(new InstanceChunkLoadEvent(this, chunkX, chunkZ), GlobalHandles.INSTANCE_CHUNK_LOAD);
|
||||
synchronized (loadingChunks) {
|
||||
this.loadingChunks.remove(ChunkUtils.getChunkIndex(chunk));
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package net.minestom.server.listener;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.ListenerHandle;
|
||||
import net.minestom.server.event.GlobalHandles;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.network.packet.client.play.*;
|
||||
@ -12,8 +12,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlayerPositionListener {
|
||||
|
||||
private static final ListenerHandle<PlayerMoveEvent> PLAYER_MOVE_HANDLER = EventDispatcher.getHandle(PlayerMoveEvent.class);
|
||||
|
||||
public static void playerPacketListener(ClientPlayerPacket packet, Player player) {
|
||||
player.refreshOnGround(packet.onGround);
|
||||
}
|
||||
@ -56,7 +54,7 @@ public class PlayerPositionListener {
|
||||
}
|
||||
|
||||
PlayerMoveEvent playerMoveEvent = new PlayerMoveEvent(player, newPosition);
|
||||
EventDispatcher.call(playerMoveEvent, PLAYER_MOVE_HANDLER);
|
||||
EventDispatcher.call(playerMoveEvent, GlobalHandles.PLAYER_MOVE);
|
||||
// True if the event call changed the player position (possibly a teleport)
|
||||
if (!playerMoveEvent.isCancelled() && currentPosition.equals(player.getPosition())) {
|
||||
// Move the player
|
||||
|
@ -3,7 +3,7 @@ package net.minestom.server.listener.manager;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.ListenerHandle;
|
||||
import net.minestom.server.event.GlobalHandles;
|
||||
import net.minestom.server.event.player.PlayerPacketEvent;
|
||||
import net.minestom.server.listener.*;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
@ -24,8 +24,6 @@ public final class PacketListenerManager {
|
||||
public final static Logger LOGGER = LoggerFactory.getLogger(PacketListenerManager.class);
|
||||
private static final ConnectionManager CONNECTION_MANAGER = MinecraftServer.getConnectionManager();
|
||||
|
||||
private static final ListenerHandle<PlayerPacketEvent> PLAYER_PACKET_HANDLER = EventDispatcher.getHandle(PlayerPacketEvent.class);
|
||||
|
||||
private final Map<Class<? extends ClientPlayPacket>, PacketListenerConsumer> listeners = new ConcurrentHashMap<>();
|
||||
|
||||
public PacketListenerManager() {
|
||||
@ -92,7 +90,7 @@ public final class PacketListenerManager {
|
||||
|
||||
// Event
|
||||
PlayerPacketEvent playerPacketEvent = new PlayerPacketEvent(player, packet);
|
||||
EventDispatcher.call(playerPacketEvent, PLAYER_PACKET_HANDLER);
|
||||
EventDispatcher.call(playerPacketEvent, GlobalHandles.PLAYER_PACKET);
|
||||
if (playerPacketEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user