Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Initial release of the core functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
rexlManu committed Jun 1, 2021
1 parent a77b4e5 commit 0650e24
Show file tree
Hide file tree
Showing 27 changed files with 938 additions and 76 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ run/**
# .idea/compiler.xml
.idea/modules.xml
.idea/*.iml
.idea
# .idea/modules
# *.iml
# *.ipr
Expand Down
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2021 Emmanuel Lampe

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.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ViaVersion Addon

ViaVersion implemented as labymod addon for 1.16 with a easily switch between protocol versions.

## Credits

Thanks to the repos

- https://github.com/ViaVersion/ViaVersion
- https://github.com/ViaVersion/ViaFabric
- https://github.com/FlorianMichael/ViaForge

I learned really much about the viaversion api and I really like it.
I even started to implemented viaversion to my own server software.

## License

The repository is licensed under MIT
32 changes: 27 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,22 @@ apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'org.spongepowered.mixin'

version = '1.0.0'
group = 'com.example' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'Example Addon'
version = '1.0'
group = 'de.rexlmanu' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'viaversion-addon'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

def mcpVersion = [channel: 'snapshot', version: '20201028-1.16.3']

configurations {
shade
compile.extendsFrom shade
}

mixin {
defaultObfuscationEnv searge
add sourceSets.main, "example.refmap.json"
add sourceSets.main, "network.refmap.json"
}

minecraft {
Expand Down Expand Up @@ -74,15 +79,27 @@ repositories {
name = 'impactdevelopment-repo'
url = 'https://impactdevelopment.github.io/maven/'
}
maven { url = "https://repo.viaversion.com/" }
mavenLocal()
}


dependencies {
annotationProcessor("org.spongepowered:mixin:0.8.2:processor")
annotationProcessor 'org.projectlombok:lombok:1.18.20'

minecraft 'com.github.ImpactDevelopment:Vanilla:1.16.5'
compile(files('libs/lm_api_mc1.16.5.jar'))

shade("org.yaml:snakeyaml:1.28")
shade("com.viaversion:viaversion:4.0.0-1.17-pre2-SNAPSHOT") { transitive = false }
shade("com.viaversion:viabackwards:4.0.0-1.17-pre2-SNAPSHOT") { transitive = false }
shade("com.viaversion:viarewind-core:2.0.0-SNAPSHOT") { transitive = false }

compile(files(
'libs/lm_api_mc1.16.5.jar',
))

compileOnly 'org.projectlombok:lombok:1.18.20'

compile("org.ow2.asm:asm-analysis:6.2") { transitive = false }
compile("org.ow2.asm:asm-util:6.2") { transitive = false }
Expand All @@ -94,6 +111,11 @@ dependencies {
jar {
// Excludes the start file
exclude("**/launch")
configurations.shade.each { dep ->
from(project.zipTree(dep)) {
exclude 'META-INF', 'META-INF/**'
}
}
}

task downloadAPI(type: Download) {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'addon-example'
rootProject.name = 'viaversion-addon'

25 changes: 0 additions & 25 deletions src/main/java/com/example/addon/ExampleAddon.java

This file was deleted.

12 changes: 0 additions & 12 deletions src/main/java/com/example/addon/ExampleAddonTransformer.java

This file was deleted.

17 changes: 0 additions & 17 deletions src/main/java/com/example/addon/mixin/ExampleMixin.java

This file was deleted.

100 changes: 100 additions & 0 deletions src/main/java/de/rexlmanu/viaversionaddon/ViaVersionAddon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package de.rexlmanu.viaversionaddon;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.viaversion.viaversion.ViaManagerImpl;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.MappingDataLoader;
import de.rexlmanu.viaversionaddon.loader.AddonBackwardsLoader;
import de.rexlmanu.viaversionaddon.loader.AddonViaProviderLoader;
import de.rexlmanu.viaversionaddon.menu.ProtocolScreen;
import de.rexlmanu.viaversionaddon.platform.AddonInjector;
import de.rexlmanu.viaversionaddon.platform.AddonPlatform;
import io.netty.channel.DefaultEventLoop;
import io.netty.channel.EventLoop;
import lombok.Getter;
import lombok.Setter;
import net.labymod.api.LabyModAddon;
import net.labymod.gui.elements.Tabs;
import net.labymod.settings.elements.SettingsElement;

import java.io.File;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

@Getter
public class ViaVersionAddon extends LabyModAddon {

public static final String NAME = "ViaVersionAddon";

public static final int SHARED_VERSION = 754;

@Getter
private static ViaVersionAddon instance;

private final CompletableFuture<Void> initFuture = new CompletableFuture<>();

private ExecutorService executorService;
private EventLoop eventLoop;

private File dataFolder;

@Getter
@Setter
private int version;

public ViaVersionAddon() {
ViaVersionAddon.instance = this;

ThreadFactory factory = new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat("ViaVersionAddon-%d")
.build();
this.executorService = Executors.newFixedThreadPool(
8,
factory

);

this.eventLoop = new DefaultEventLoop(factory).next();
this.eventLoop.submit(initFuture::join);

this.dataFolder = new File(NAME.toLowerCase());

this.version = SHARED_VERSION;

this.dataFolder.mkdir();
}

@Override
public void onEnable() {
Via.init(
ViaManagerImpl.builder()
.injector(new AddonInjector())
.platform(new AddonPlatform(this.dataFolder))
.loader(new AddonViaProviderLoader())
.build()
);

MappingDataLoader.enableMappingsCache();
((ViaManagerImpl) Via.getManager()).init();


new AddonBackwardsLoader(new File(this.dataFolder, "backwards"));

this.initFuture.complete(null);

Tabs.registerTab("Protocol", ProtocolScreen.class);
}

@Override
public void loadConfig() {

}

@Override
protected void fillSettings(List<SettingsElement> list) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package de.rexlmanu.viaversionaddon;

import net.labymod.addon.AddonTransformer;
import net.labymod.api.TransformerType;

public class ViaVersionAddonTransformer extends AddonTransformer {

@Override
public void registerTransformers() {
this.registerTransformer(TransformerType.VANILLA, "network.mixin.json");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package de.rexlmanu.viaversionaddon.handler;

import com.viaversion.viaversion.util.PipelineUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.MessageToMessageDecoder;

import java.lang.reflect.InvocationTargetException;

public class CommonTransformer {

public static final String HANDLER_DECODER_NAME = "via-decoder";
public static final String HANDLER_ENCODER_NAME = "via-encoder";

public static void decompress(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
ChannelHandler handler = ctx.pipeline().get("decompress");
ByteBuf decompressed = handler instanceof MessageToMessageDecoder
? (ByteBuf) PipelineUtil.callDecode((MessageToMessageDecoder<?>) handler, ctx, buf).get(0)
: (ByteBuf) PipelineUtil.callDecode((ByteToMessageDecoder) handler, ctx, buf).get(0);
try {
buf.clear().writeBytes(decompressed);
} finally {
decompressed.release();
}
}

public static void compress(ChannelHandlerContext ctx, ByteBuf buf) throws Exception {
ByteBuf compressed = ctx.alloc().buffer();
try {
PipelineUtil.callEncode((MessageToByteEncoder<?>) ctx.pipeline().get("compress"), ctx, buf, compressed);
buf.clear().writeBytes(compressed);
} finally {
compressed.release();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package de.rexlmanu.viaversionaddon.handler;

public class PipelineReorderEvent {
}
Loading

0 comments on commit 0650e24

Please sign in to comment.