-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Basic Multiversion Support
- Loading branch information
Showing
18 changed files
with
709 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "src/main/resources/mappings"] | ||
path = src/main/resources/mappings | ||
url = https://github.com/bundabrg/mappings-education.git |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ EduSupport - Minecraft Protocol Support for MultiVersion in Geyser | ||
~ Copyright (C) 2020 GeyserReversion Developers | ||
~ | ||
~ This program is free software: you can redistribute it and/or modify | ||
~ it under the terms of the GNU General Public License as published by | ||
~ the Free Software Foundation, either version 3 of the License, or | ||
~ (at your option) any later version. | ||
~ | ||
~ This program is distributed in the hope that it will be useful, | ||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
~ GNU General Public License for more details. | ||
~ | ||
~ You should have received a copy of the GNU General Public License | ||
~ along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
|
||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>parent</artifactId> | ||
<groupId>au.com.grieve.geyser.reversion</groupId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>geyser-reversion</artifactId> | ||
|
||
<dependencies> | ||
<!-- Geyser --> | ||
<dependency> | ||
<groupId>org.geysermc</groupId> | ||
<artifactId>connector</artifactId> | ||
<version>1.2.0-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- Translators --> | ||
<dependency> | ||
<groupId>au.com.grieve.reversion</groupId> | ||
<artifactId>translator-v390ee_to_v408be</artifactId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>au.com.grieve.reversion</groupId> | ||
<artifactId>common</artifactId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>au.com.grieve.reversion</groupId> | ||
<artifactId>edition-education</artifactId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>au.com.grieve.reversion</groupId> | ||
<artifactId>edition-bedrock</artifactId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<directory>../target</directory> | ||
<finalName>GeyserReversion-${project.parent.version}</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.3</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<!-- <relocations>--> | ||
<!-- <relocation>--> | ||
<!-- <pattern>com.nukkitx.protocol.bedrock.v363</pattern>--> | ||
<!-- <shadedPattern>${project.groupId}.${project.artifactId}.v363</shadedPattern>--> | ||
<!-- </relocation>--> | ||
<!-- </relocations>--> | ||
<artifactSet> | ||
<excludes> | ||
<exclude>it.unimi.dsi.fastutil:*</exclude> | ||
</excludes> | ||
</artifactSet> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
169 changes: 169 additions & 0 deletions
169
geyser-reversion/src/main/java/au/com/grieve/geyser/reversion/GeyserReversionPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* | ||
* EduSupport - Minecraft Protocol Support for MultiVersion in Geyser | ||
* Copyright (C) 2020 GeyserReversion Developers | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package au.com.grieve.geyser.reversion; | ||
|
||
import au.com.grieve.geyser.reversion.api.Edition; | ||
import au.com.grieve.geyser.reversion.config.Configuration; | ||
import au.com.grieve.geyser.reversion.editions.bedrock.BedrockEdition; | ||
import au.com.grieve.geyser.reversion.editions.education.EducationEdition; | ||
import au.com.grieve.reversion.ReversionServer; | ||
import au.com.grieve.reversion.api.BaseTranslator; | ||
import au.com.grieve.reversion.api.TranslatorException; | ||
import au.com.grieve.reversion.translators.v390ee_to_v408be.Translator_v390ee_to_v408be; | ||
import lombok.Getter; | ||
import org.geysermc.connector.GeyserConnector; | ||
import org.geysermc.connector.event.annotations.GeyserEventHandler; | ||
import org.geysermc.connector.event.events.geyser.GeyserStartEvent; | ||
import org.geysermc.connector.event.handlers.EventHandler; | ||
import org.geysermc.connector.plugin.GeyserPlugin; | ||
import org.geysermc.connector.plugin.PluginClassLoader; | ||
import org.geysermc.connector.plugin.PluginManager; | ||
import org.geysermc.connector.plugin.annotations.Plugin; | ||
import org.geysermc.connector.utils.LanguageUtils; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.lang.reflect.Field; | ||
import java.net.InetSocketAddress; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Plugin( | ||
name = "GeyserReversion", | ||
version = "1.1.0-dev", | ||
authors = {"bundabrg"}, | ||
description = "Provides multiversion protocol support for Geyser" | ||
) | ||
@Getter | ||
public class GeyserReversionPlugin extends GeyserPlugin { | ||
@Getter | ||
private static GeyserReversionPlugin instance; | ||
|
||
private final Map<String, Edition> registeredEditions = new HashMap<>(); | ||
private final List<Class<? extends BaseTranslator>> registeredTranslators = new ArrayList<>(); | ||
|
||
private Configuration config; | ||
|
||
public GeyserReversionPlugin(PluginManager pluginManager, PluginClassLoader pluginClassLoader) { | ||
super(pluginManager, pluginClassLoader); | ||
instance = this; | ||
|
||
loadConfig(); | ||
registerEditions(); | ||
registerTranslators(); | ||
} | ||
|
||
/** | ||
* Register built-in editions | ||
*/ | ||
private void registerEditions() { | ||
registerEdition("bedrock", new BedrockEdition(this)); | ||
registerEdition("education", new EducationEdition(this)); | ||
} | ||
|
||
/** | ||
* Register built-in translators | ||
*/ | ||
private void registerTranslators() { | ||
registerTranslator(Translator_v390ee_to_v408be.class); | ||
} | ||
|
||
|
||
/** | ||
* Register an Edition | ||
*/ | ||
public void registerEdition(String name, Edition edition) { | ||
registeredEditions.put(name, edition); | ||
getLogger().debug("Registered Edition: " + name); | ||
} | ||
|
||
/** | ||
* Register a Translator | ||
*/ | ||
public void registerTranslator(Class<? extends BaseTranslator> translatorClass) { | ||
registeredTranslators.add(translatorClass); | ||
getLogger().debug("Registered Translator: " + translatorClass.getSimpleName()); | ||
} | ||
|
||
/** | ||
* Load our config, generating it if necessary | ||
*/ | ||
private void loadConfig() { | ||
File configFile = new File(getDataFolder(), "config.yml"); | ||
if (!configFile.exists()) { | ||
//noinspection ResultOfMethodCallIgnored | ||
configFile.getParentFile().mkdirs(); | ||
|
||
try (FileOutputStream fos = new FileOutputStream(configFile); | ||
InputStream fis = getResourceAsStream("config.yml")) { | ||
fis.transferTo(fos); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
config = Configuration.loadFromFile(configFile); | ||
} | ||
|
||
/** | ||
* Replace Geyser BedrockServer with one provided by an edition | ||
*/ | ||
@GeyserEventHandler(priority = EventHandler.PRIORITY.HIGH) | ||
public void onGeyserStart(GeyserStartEvent event) { | ||
Edition edition = registeredEditions.get(config.getEdition()); | ||
|
||
if (edition == null) { | ||
getLogger().error(String.format("Invalid Edition '%s'. Plugin disabled.", config.getEdition())); | ||
return; | ||
} | ||
|
||
InetSocketAddress address = GeyserConnector.getInstance().getBedrockServer().getBindAddress(); | ||
|
||
try { | ||
Field bedrockServer = GeyserConnector.class.getDeclaredField("bedrockServer"); | ||
bedrockServer.setAccessible(true); | ||
|
||
ReversionServer server = edition.createReversionServer(GeyserConnector.getInstance().getBedrockServer().getBindAddress()); | ||
for (Class<? extends BaseTranslator> translatorClass : getRegisteredTranslators()) { | ||
try { | ||
server.registerTranslator(translatorClass); | ||
getLogger().debug("Registered Translator: " + translatorClass.getSimpleName()); | ||
} catch (TranslatorException e) { | ||
getLogger().error(String.format("Unable to register Translator: %s", translatorClass.getName()), e); | ||
} | ||
} | ||
|
||
GeyserConnector.getInstance().getBedrockServer().close(); | ||
bedrockServer.set(GeyserConnector.getInstance(), server); | ||
|
||
} catch (NoSuchFieldException | IllegalAccessException e) { | ||
getLogger().error(String.format("Unable to set Edition '%s'. Plugin disabled.", config.getEdition()), e); | ||
} | ||
|
||
GeyserConnector.getInstance().getBedrockServer().bind().whenComplete((avoid, throwable) -> { | ||
if (throwable != null) { | ||
getLogger().severe(LanguageUtils.getLocaleStringLog("geyser.core.fail", address.getAddress().toString(), address.getPort())); | ||
throwable.printStackTrace(); | ||
} | ||
}).join(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
geyser-reversion/src/main/java/au/com/grieve/geyser/reversion/api/Edition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* EduSupport - Minecraft Protocol Support for MultiVersion in Geyser | ||
* Copyright (C) 2020 GeyserReversion Developers | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package au.com.grieve.geyser.reversion.api; | ||
|
||
import au.com.grieve.reversion.ReversionServer; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
public interface Edition { | ||
ReversionServer createReversionServer(InetSocketAddress address); | ||
} |
Oops, something went wrong.