forked from GeyserMC/Geyser
First Event!
This commit is contained in:
parent
58819ea9ce
commit
f0551727ca
12 changed files with 232 additions and 14 deletions
|
@ -30,6 +30,7 @@ import com.nukkitx.protocol.bedrock.BedrockPong;
|
|||
import com.nukkitx.protocol.bedrock.BedrockServerEventHandler;
|
||||
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||
import com.nukkitx.protocol.bedrock.v361.Bedrock_v361;
|
||||
import org.geysermc.api.events.player.PingEvent;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.configuration.GeyserConfiguration;
|
||||
import org.geysermc.connector.console.GeyserLogger;
|
||||
|
@ -54,15 +55,14 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
|||
|
||||
@Override
|
||||
public BedrockPong onQuery(InetSocketAddress inetSocketAddress) {
|
||||
PingEvent pong = new PingEvent(inetSocketAddress);
|
||||
GeyserLogger.DEFAULT.debug(inetSocketAddress + " has pinged you!");
|
||||
GeyserConfiguration config = connector.getConfig();
|
||||
BedrockPong pong = new BedrockPong();
|
||||
pong.setEdition("MCPE");
|
||||
pong.setGameType("Default");
|
||||
pong.setNintendoLimited(false);
|
||||
pong.setProtocolVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion());
|
||||
pong.setVersion("1.12.0");
|
||||
pong.setIpv4Port(19132);
|
||||
|
||||
if (connector.getConfig().isPingPassthrough()) {
|
||||
ServerStatusInfo serverInfo = connector.getPassthroughThread().getInfo();
|
||||
|
@ -79,7 +79,22 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
|||
pong.setMotd(config.getBedrock().getMotd1());
|
||||
pong.setSubMotd(config.getBedrock().getMotd2());
|
||||
}
|
||||
return pong;
|
||||
|
||||
BedrockPong c = new BedrockPong();
|
||||
|
||||
c.setEdition(pong.getEdition());
|
||||
c.setGameType(pong.getGameType());
|
||||
c.setNintendoLimited(pong.isNintendoLimited());
|
||||
c.setProtocolVersion(pong.getProtocolVersion());
|
||||
c.setVersion(pong.getVersion());
|
||||
|
||||
c.setMotd(pong.getMotd());
|
||||
c.setSubMotd(pong.getSubMotd());
|
||||
c.setPlayerCount(pong.getPlayerCount());
|
||||
c.setMaximumPlayerCount(pong.getMaximumPlayerCount());
|
||||
|
||||
return c;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,9 +38,11 @@ import com.nukkitx.protocol.PlayerSession;
|
|||
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.api.session.AuthData;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.network.remote.RemoteJavaServer;
|
||||
import org.geysermc.connector.network.translators.Registry;
|
||||
import sun.security.krb5.internal.AuthorizationData;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -128,10 +130,10 @@ public class GeyserSession implements PlayerSession {
|
|||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class AuthenticationData {
|
||||
public class AuthenticationData implements AuthData {
|
||||
|
||||
private String name;
|
||||
private UUID uuid;
|
||||
private String xboxUUID;
|
||||
private UUID UUID;
|
||||
private String XUID;
|
||||
}
|
||||
}
|
|
@ -32,6 +32,7 @@ import org.geysermc.api.Connector;
|
|||
import org.geysermc.api.plugin.Plugin;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
|
@ -51,7 +52,7 @@ public class GeyserPluginLoader extends ClassLoader {
|
|||
}
|
||||
|
||||
for (File f : dir.listFiles()) {
|
||||
if (!f.getName().endsWith(".jar"))
|
||||
if (!f.getName().toLowerCase().endsWith(".jar"))
|
||||
continue;
|
||||
|
||||
try {
|
||||
|
@ -83,6 +84,19 @@ public class GeyserPluginLoader extends ClassLoader {
|
|||
PluginYML yml = mapper.readValue(is, PluginYML.class);
|
||||
is.close();
|
||||
Plugin plugin = (Plugin) Class.forName(yml.main, true, this).newInstance();
|
||||
|
||||
Class cl = Plugin.class;
|
||||
|
||||
Field name = cl.getDeclaredField("name");
|
||||
name.setAccessible(true);
|
||||
|
||||
Field version = cl.getDeclaredField("version");
|
||||
version.setAccessible(true);
|
||||
|
||||
name.set(plugin, yml.name);
|
||||
|
||||
version.set(plugin, yml.version);
|
||||
|
||||
connector.getLogger().info("Loading plugin " + yml.name + " version " + yml.version);
|
||||
connector.getPluginManager().loadPlugin(plugin);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -26,19 +26,23 @@
|
|||
package org.geysermc.connector.plugin;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.geysermc.api.events.EventHandler;
|
||||
import org.geysermc.api.events.Listener;
|
||||
import org.geysermc.api.plugin.Plugin;
|
||||
import org.geysermc.api.plugin.PluginManager;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.awt.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class GeyserPluginManager implements PluginManager {
|
||||
private final List<PluginListener> EVENTS = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private GeyserPluginLoader loader;
|
||||
|
||||
@Getter
|
||||
private Set<Plugin> plugins = new HashSet<Plugin>();
|
||||
private Map<String, Plugin> plugins = new HashMap<>();
|
||||
|
||||
public GeyserPluginManager(GeyserPluginLoader loader) {
|
||||
this.loader = loader;
|
||||
|
@ -46,7 +50,7 @@ public class GeyserPluginManager implements PluginManager {
|
|||
|
||||
public void loadPlugin(Plugin plugin) {
|
||||
loader.loadPlugin(plugin);
|
||||
plugins.add(plugin);
|
||||
plugins.put(plugin.getName(), plugin);
|
||||
}
|
||||
|
||||
public void unloadPlugin(Plugin plugin) {
|
||||
|
@ -62,6 +66,42 @@ public class GeyserPluginManager implements PluginManager {
|
|||
}
|
||||
|
||||
public Set<Plugin> getPlugins() {
|
||||
return plugins;
|
||||
return new HashSet<>(plugins.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerEventListener(Plugin p, Listener l) {
|
||||
try {
|
||||
Class<? extends Listener> clazz = l.getClass();
|
||||
|
||||
for(Method m : clazz.getMethods()) {
|
||||
if(m.getAnnotation(EventHandler.class) != null) {
|
||||
PluginListener listener = new PluginListener();
|
||||
|
||||
listener.plugin = p;
|
||||
listener.listener = l;
|
||||
listener.clazz = m.getParameterTypes()[0];
|
||||
listener.priority = m.getAnnotation(EventHandler.class).value();
|
||||
listener.run = m;
|
||||
EVENTS.add(listener);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runEvent(Object o) {
|
||||
for(EventHandler.EventPriority p : EventHandler.EventPriority.values()) {
|
||||
for (PluginListener listener : EVENTS) {
|
||||
listener.runIfNeeded(p, o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin getPluginByName(String name) {
|
||||
return plugins.get(name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.geysermc.connector.plugin;
|
||||
|
||||
import org.geysermc.api.events.EventHandler;
|
||||
import org.geysermc.api.events.Listener;
|
||||
import org.geysermc.api.plugin.Plugin;
|
||||
import org.geysermc.connector.console.GeyserLogger;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class PluginListener {
|
||||
Method run;
|
||||
Plugin plugin;
|
||||
Listener listener;
|
||||
Class clazz;
|
||||
EventHandler.EventPriority priority;
|
||||
|
||||
void runIfNeeded(EventHandler.EventPriority p, Object o) {
|
||||
if(p.equals(priority) && clazz.isInstance(o)) {
|
||||
try {
|
||||
run.invoke(listener, o);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
GeyserLogger.DEFAULT.severe("Exception while trying to run event! Contact the maintainer of " + plugin.getName());
|
||||
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -649,5 +649,14 @@ public class GeyserUtils {
|
|||
|
||||
}
|
||||
|
||||
public static <T> boolean instanceOf(Class<T> clazz, Object o) {
|
||||
try {
|
||||
T t = (T) o;
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue