Переход на свой EventBus
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package mc.core;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.eventbus.EventBus;
|
||||
import mc.core.eventbus.Subscriber;
|
||||
import mc.core.eventbus.events.CS_PlayerMoveEvent;
|
||||
import mc.core.eventbus.events.SC_ChunkLoadEvent;
|
||||
import mc.core.eventbus.events.SC_ChunkUnloadEvent;
|
||||
@@ -14,12 +16,11 @@ import java.util.Iterator;
|
||||
public class CoreEventListener {
|
||||
@PostConstruct
|
||||
public void registerEventHandlers() {
|
||||
// EventBusGetter.getInstance().register(this);
|
||||
EventBus.getInstance().registerSubscribes(this);
|
||||
}
|
||||
|
||||
@Subscriber
|
||||
public void handlerPlayerMoveEvent(CS_PlayerMoveEvent event) {
|
||||
log.trace("(GameLoop) playerMoveEventHandler()");
|
||||
|
||||
Chunk chunk;
|
||||
chunk = event.getPlayer().getWorld().getChunk(event.getOldLocation().toBlockLocation()); // Old chunk
|
||||
int ccX = chunk.getX();
|
||||
@@ -47,7 +48,7 @@ public class CoreEventListener {
|
||||
}
|
||||
|
||||
if (!eventChunkUnload.getNeedUnloadChunks().isEmpty()) {
|
||||
// EventBusGetter.getInstance().post(eventChunkUnload);
|
||||
EventBus.getInstance().post(eventChunkUnload);
|
||||
}
|
||||
|
||||
SC_ChunkLoadEvent eventChunkLoad = new SC_ChunkLoadEvent(event.getPlayer());
|
||||
@@ -64,7 +65,7 @@ public class CoreEventListener {
|
||||
}
|
||||
|
||||
if (!eventChunkLoad.getNeedLoadChunks().isEmpty()) {
|
||||
// EventBusGetter.getInstance().post(eventChunkLoad);
|
||||
EventBus.getInstance().post(eventChunkLoad);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ package mc.core;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.eventbus.EventBus;
|
||||
import mc.core.player.PlayerManager;
|
||||
import mc.core.time.TimeProcessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -47,6 +48,8 @@ public class GameLoop extends Thread {
|
||||
|
||||
/* --- --- --- */
|
||||
|
||||
EventBus.getInstance().process();
|
||||
|
||||
/* TODO нужно перенести этот функционал на Network */
|
||||
playerManager.getBroadcastChannel().sendTimeUpdate(
|
||||
gameTimer.getGameTime(),
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.stream.Stream;
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class EventBus {
|
||||
@Getter
|
||||
private static final EventBus insnance = new EventBus();
|
||||
private static final EventBus instance = new EventBus();
|
||||
|
||||
private Queue<Event> eventQueue = new ConcurrentLinkedQueue<>();
|
||||
private Map<Class<? extends Event>, List<Pair<Object, Method>>> subscribes = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user