Merge pull request #142 from cabaletta/direct-invocation
direct invocation
This commit is contained in:
commit
dfd2ef055e
@ -49,7 +49,6 @@ import org.lwjgl.input.Keyboard;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
@ -61,12 +60,20 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onTick(TickEvent event) {
|
public final void onTick(TickEvent event) {
|
||||||
dispatch(listener -> listener.onTick(event));
|
for (IGameEventListener l : listeners) {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onTick(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onPlayerUpdate(PlayerUpdateEvent event) {
|
public final void onPlayerUpdate(PlayerUpdateEvent event) {
|
||||||
dispatch(listener -> listener.onPlayerUpdate(event));
|
for (IGameEventListener l : listeners) {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onPlayerUpdate(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -86,12 +93,20 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(IGameEventListener::onProcessKeyBinds);
|
for (IGameEventListener l : listeners) {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onProcessKeyBinds();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onSendChatMessage(ChatEvent event) {
|
public final void onSendChatMessage(ChatEvent event) {
|
||||||
dispatch(listener -> listener.onSendChatMessage(event));
|
for (IGameEventListener l : listeners) {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onSendChatMessage(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -117,18 +132,20 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dispatch(listener -> listener.onChunkEvent(event));
|
for (IGameEventListener l : listeners) {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onChunkEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onRenderPass(RenderEvent event) {
|
public final void onRenderPass(RenderEvent event) {
|
||||||
/*
|
for (IGameEventListener l : listeners) {
|
||||||
WorldProvider.INSTANCE.ifWorldLoaded(world -> world.forEachRegion(region -> region.forEachChunk(chunk -> {
|
if (canDispatch(l)) {
|
||||||
drawChunkLine(region.getX() * 512 + chunk.getX() * 16, region.getZ() * 512 + chunk.getZ() * 16, event.getPartialTicks());
|
l.onRenderPass(event);
|
||||||
})));
|
}
|
||||||
*/
|
}
|
||||||
|
|
||||||
dispatch(listener -> listener.onRenderPass(event));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -148,47 +165,71 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(listener -> listener.onWorldEvent(event));
|
for (IGameEventListener l : listeners) {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onWorldEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onSendPacket(PacketEvent event) {
|
public final void onSendPacket(PacketEvent event) {
|
||||||
dispatch(listener -> listener.onSendPacket(event));
|
for (IGameEventListener l : listeners) {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onSendPacket(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onReceivePacket(PacketEvent event) {
|
public final void onReceivePacket(PacketEvent event) {
|
||||||
dispatch(listener -> listener.onReceivePacket(event));
|
for (IGameEventListener l : listeners) {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onReceivePacket(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerRelativeMove(RelativeMoveEvent event) {
|
public void onPlayerRelativeMove(RelativeMoveEvent event) {
|
||||||
dispatch(listener -> listener.onPlayerRelativeMove(event));
|
for (IGameEventListener l : listeners) {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onPlayerRelativeMove(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockInteract(BlockInteractEvent event) {
|
public void onBlockInteract(BlockInteractEvent event) {
|
||||||
dispatch(listener -> listener.onBlockInteract(event));
|
for (IGameEventListener l : listeners) {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onBlockInteract(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerDeath() {
|
public void onPlayerDeath() {
|
||||||
dispatch(IGameEventListener::onPlayerDeath);
|
for (IGameEventListener l : listeners) {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onPlayerDeath();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPathEvent(PathEvent event) {
|
public void onPathEvent(PathEvent event) {
|
||||||
dispatch(listener -> listener.onPathEvent(event));
|
for (IGameEventListener l : listeners) {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onPathEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void registerEventListener(IGameEventListener listener) {
|
public final void registerEventListener(IGameEventListener listener) {
|
||||||
this.listeners.add(listener);
|
this.listeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dispatch(Consumer<IGameEventListener> dispatchFunction) {
|
|
||||||
this.listeners.stream().filter(this::canDispatch).forEach(dispatchFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canDispatch(IGameEventListener listener) {
|
private boolean canDispatch(IGameEventListener listener) {
|
||||||
return !(listener instanceof Toggleable) || ((Toggleable) listener).isEnabled();
|
return !(listener instanceof Toggleable) || ((Toggleable) listener).isEnabled();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user