Skip to content

Commit

Permalink
Implement Basic Multiversion Support
Browse files Browse the repository at this point in the history
  • Loading branch information
bundabrg committed Aug 16, 2020
1 parent c3c993d commit d8f7553
Show file tree
Hide file tree
Showing 18 changed files with 709 additions and 114 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ jobs:
mvn -B versions:set -DnewVersion=${MAVEN_VERSION}
# Set Plugin Version
sed -i "/version = .*/ s/version = \"[^\"]*\"/version = \"${MAVEN_VERSION}\"/" src/main/java/au/com/grieve/edusupport/EduSupport.java
sed -i "/version = .*/ s/version = \"[^\"]*\"/version = \"${MAVEN_VERSION}\"/" geyser-reversion/src/main/java/au/com/grieve/geyser/reversion/GeyserReversionPlugin.java
- name: Update Version for Developmental Build
if: "!startsWith(github.ref,'refs/tags/v')"
run: |
sed -i "/version = .*/ s/-dev/-b${GITHUB_RUN_NUMBER}/" src/main/java/au/com/grieve/edusupport/EduSupport.java
sed -i "/version = .*/ s/-dev/-b${GITHUB_RUN_NUMBER}/" geyser-reversion/src/main/java/au/com/grieve/geyser/reversion/GeyserReversionPlugin.java
- name: Build with Maven
run: |
mkdir -p build/output
mvn -B package --file pom.xml && \
cp target/EduSupport-*.jar build/output/
cp target/GeyserReversion-*.jar build/output/
- name: Publish to Maven Repo
if: (github.ref == 'refs/heads/master' || startsWith(github.ref,'refs/tags/v'))
Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:
for asset in ./build/binary/*.jar; do
assets+=("-a" "$asset")
done
assets+=("-a" "build/docs/pdf/documentation.pdf#EduSupport-Documentation.pdf")
assets+=("-a" "build/docs/pdf/documentation.pdf#GeyserReversion-Documentation.pdf")
tag_name="${GITHUB_REF##*/}"
hub release create \
Expand All @@ -143,7 +143,7 @@ jobs:
"$tag_name" << EOF
Release $tag_name
[Online Documentation](https://bundabrg.github.io/EduSupport)
[Online Documentation](https://bundabrg.github.io/GeyserReversion)
Since Last Release:
$(git log $(git describe --tags --abbrev=0 HEAD^ 2> /dev/null || git rev-list --max-parents=0 HEAD)..HEAD --graph --pretty=format:'%h %d %s [%an]' --abbrev-commit)
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
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
2 changes: 1 addition & 1 deletion .idea/copyright/GLP3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
![Logo](https://bundabrg.github.io/EduSupport/img/title.png)
![Logo](https://bundabrg.github.io/GeyserReversion/img/title.png)

[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)
[![GitHub release](https://img.shields.io/github/release/Bundabrg/EduSupport)](https://GitHub.com/Bundabrg/EduSupport/releases/)
[![GitHub commits](https://img.shields.io/github/commits-since/Bundabrg/EduSupport/latest)](https://GitHub.com/Bundabrg/EduSupport/commit/)
[![Github all releases](https://img.shields.io/github/downloads/Bundabrg/EduSupport/total.svg)](https://GitHub.com/Bundabrg/EduSupport/releases/)
![HitCount](http://hits.dwyl.com/bundabrg/EduSupport.svg)

![Workflow](https://github.com/bundabrg/EduSupport/workflows/build/badge.svg)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Bundabrg/EduSupport/graphs/commit-activity)
[![GitHub contributors](https://img.shields.io/github/contributors/Bundabrg/EduSupport)](https://GitHub.com/Bundabrg/EduSupport/graphs/contributors/)
[![GitHub issues](https://img.shields.io/github/issues/Bundabrg/EduSupport)](https://GitHub.com/Bundabrg/EduSupport/issues/)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/Bundabrg/EduSupport.svg)](http://isitmaintained.com/project/Bundabrg/EduSupport "Average time to resolve an issue")
[![GitHub pull-requests](https://img.shields.io/github/issues-pr/Bundabrg/EduSupport)](https://GitHub.com/Bundabrg/EduSupport/pull/)
[![GitHub release](https://img.shields.io/github/release/Bundabrg/GeyserReversion)](https://GitHub.com/Bundabrg/GeyserReversion/releases/)
[![GitHub commits](https://img.shields.io/github/commits-since/Bundabrg/GeyserReversion/latest)](https://GitHub.com/Bundabrg/GeyserReversion/commit/)
[![Github all releases](https://img.shields.io/github/downloads/Bundabrg/GeyserReversion/total.svg)](https://GitHub.com/Bundabrg/GeyserReversion/releases/)
![HitCount](http://hits.dwyl.com/bundabrg/GeyserReversion.svg)

![Workflow](https://github.com/bundabrg/GeyserReversion/workflows/build/badge.svg)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Bundabrg/GeyserReversion/graphs/commit-activity)
[![GitHub contributors](https://img.shields.io/github/contributors/Bundabrg/GeyserReversion)](https://GitHub.com/Bundabrg/GeyserReversion/graphs/contributors/)
[![GitHub issues](https://img.shields.io/github/issues/Bundabrg/GeyserReversion)](https://GitHub.com/Bundabrg/GeyserReversion/issues/)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/Bundabrg/GeyserReversion.svg)](http://isitmaintained.com/project/Bundabrg/GeyserReversion "Average time to resolve an issue")
[![GitHub pull-requests](https://img.shields.io/github/issues-pr/Bundabrg/GeyserReversion)](https://GitHub.com/Bundabrg/GeyserReversion/pull/)


---

[**Documentation**](https://bundabrg.github.io/EduSupport/)
[**Documentation**](https://bundabrg.github.io/GeyserReversion/)

[**Source Code**](https://github.com/bundabrg/EduSupport/)
[**Source Code**](https://github.com/bundabrg/GeyserReversion/)

---

EduSupport is a Geyser Plugin that provides protocol support for Minecraft Educational Edition.
GeyserReversion is a Geyser Plugin that provides multiversion support for Geyser.

## Features

Expand Down
101 changes: 101 additions & 0 deletions geyser-reversion/pom.xml
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>
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();
}
}
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);
}
Loading

0 comments on commit d8f7553

Please sign in to comment.