Skip to content

Commit

Permalink
Add Events to allow overriding core functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
bundabrg committed Jul 6, 2020
1 parent 1a7a76e commit 4cb1217
Show file tree
Hide file tree
Showing 22 changed files with 353 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.event.EventManager;
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.event.events.BedrockCodecRegistryEvent;
import org.geysermc.connector.metrics.Metrics;
import org.geysermc.connector.network.ConnectorServerEventHandler;
import org.geysermc.connector.network.remote.RemoteServer;
Expand Down Expand Up @@ -77,7 +78,7 @@ public class GeyserConnector {

public static final ObjectMapper JSON_MAPPER = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);

public static final BedrockPacketCodec BEDROCK_PACKET_CODEC = Bedrock_v407.V407_CODEC;
public static BedrockPacketCodec BEDROCK_PACKET_CODEC;

public static final String NAME = "Geyser";
public static final String VERSION = "DEV"; // A fallback for running in IDEs
Expand Down Expand Up @@ -129,7 +130,9 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {

this.eventManager = new EventManager(this);
this.pluginManager = new PluginManager(this, bootstrap.getConfigFolder().resolve("plugins").toFile());
System.exit(1);

// Set Codec
BEDROCK_PACKET_CODEC = eventManager.triggerEvent(new BedrockCodecRegistryEvent(Bedrock_v407.V407_CODEC)).getEvent().getCodec();

PacketTranslatorRegistry.init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@

@SuppressWarnings("unused")
@Getter
@AllArgsConstructor
public class EventManager {
@Getter
private static EventManager instance;
private final Map<Class<? extends GeyserEvent>, PriorityQueue<EventHandler<? extends GeyserEvent>>> eventHandlers = new HashMap<>();
private final Map<Object, ArrayList<EventHandler<?>>> classEventHandlers = new HashMap<>();

private final GeyserConnector connector;

public EventManager(GeyserConnector connector) {
instance = this;
this.connector = connector;
}

/**
* Trigger a new event.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*
*/

package org.geysermc.connector.event.events;

import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@Data
public class BedrockCodecRegistryEvent extends GeyserEvent {
private BedrockPacketCodec codec;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*
*/

package org.geysermc.connector.event.events;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

import java.util.Set;

/**
* Triggered when registering Packet Translators
*/
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@Data
public class BlockEntityRegistryEvent extends GeyserEvent {
private Set<Class<?>> registeredTranslators;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@

package org.geysermc.connector.event.events;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Getter
@ToString
@EqualsAndHashCode(callSuper = true)
@Data
public abstract class CancellableGeyserEvent extends GeyserEvent {
@Setter
private boolean cancelled = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import com.github.steveice10.packetlib.packet.Packet;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.geysermc.connector.network.session.GeyserSession;
Expand All @@ -38,11 +40,10 @@
* If cancelled then regular processes of the packet will not proceed
*/

@Getter
@ToString
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@Data
public class DownstreamPacketReceiveEvent<T extends Packet> extends CancellableGeyserEvent {

private final GeyserSession session;
private final T packet;
private GeyserSession session;
private T packet;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import com.github.steveice10.packetlib.packet.Packet;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.geysermc.connector.network.session.GeyserSession;
Expand All @@ -38,11 +40,10 @@
* If cancelled then regular processes of the packet will not proceed
*/

@Getter
@ToString
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@Data
public class DownstreamPacketSendEvent<T extends Packet> extends CancellableGeyserEvent {

private final GeyserSession session;
private final T packet;
private GeyserSession session;
private T packet;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@

package org.geysermc.connector.event.events;

import lombok.Data;

@Data
public abstract class GeyserEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*
*/

package org.geysermc.connector.event.events;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

import java.util.Set;

/**
* Triggered when registering Item Remapper Translators
*/
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@Data
public class ItemRemapperRegistryEvent extends GeyserEvent {
private Set<Class<?>> registeredTranslators;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*
*/

package org.geysermc.connector.event.events;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Set;

/**
* Triggered when registering Packet Translators
*/
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@Data
public class PacketTranslatorRegistryEvent extends GeyserEvent {
private Set<Class<?>> registeredTranslators;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
package org.geysermc.connector.event.events;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.geysermc.connector.plugin.GeyserPlugin;

@Getter
@ToString
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@Data
public class PluginDisableEvent extends GeyserEvent {
private final GeyserPlugin plugin;
private GeyserPlugin plugin;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
package org.geysermc.connector.event.events;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.geysermc.connector.plugin.GeyserPlugin;

@Getter
@ToString
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@Data
public class PluginEnableEvent extends CancellableGeyserEvent {
private final GeyserPlugin plugin;
private GeyserPlugin plugin;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
package org.geysermc.connector.event.events;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.geysermc.connector.network.session.GeyserSession;

@Getter
@ToString
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@Data
public class PluginMessageEvent extends CancellableGeyserEvent {
private final GeyserSession session;
private final String channel;
private final byte[] data;
private GeyserSession session;
private String channel;
private byte[] data;
}
Loading

0 comments on commit 4cb1217

Please sign in to comment.