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

Commit 0650e24

Browse files
committed
Initial release of the core functionality
1 parent a77b4e5 commit 0650e24

27 files changed

+938
-76
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ run/**
6767
# .idea/compiler.xml
6868
.idea/modules.xml
6969
.idea/*.iml
70+
.idea
7071
# .idea/modules
7172
# *.iml
7273
# *.ipr

LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2021 Emmanuel Lampe
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
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.

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ViaVersion Addon
2+
3+
ViaVersion implemented as labymod addon for 1.16 with a easily switch between protocol versions.
4+
5+
## Credits
6+
7+
Thanks to the repos
8+
9+
- https://github.com/ViaVersion/ViaVersion
10+
- https://github.com/ViaVersion/ViaFabric
11+
- https://github.com/FlorianMichael/ViaForge
12+
13+
I learned really much about the viaversion api and I really like it.
14+
I even started to implemented viaversion to my own server software.
15+
16+
## License
17+
18+
The repository is licensed under MIT

build.gradle

+27-5
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,22 @@ apply plugin: 'eclipse'
2424
apply plugin: 'maven-publish'
2525
apply plugin: 'org.spongepowered.mixin'
2626

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

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

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

35+
configurations {
36+
shade
37+
compile.extendsFrom shade
38+
}
39+
3540
mixin {
3641
defaultObfuscationEnv searge
37-
add sourceSets.main, "example.refmap.json"
42+
add sourceSets.main, "network.refmap.json"
3843
}
3944

4045
minecraft {
@@ -74,15 +79,27 @@ repositories {
7479
name = 'impactdevelopment-repo'
7580
url = 'https://impactdevelopment.github.io/maven/'
7681
}
82+
maven { url = "https://repo.viaversion.com/" }
7783
mavenLocal()
7884
}
7985

8086

8187
dependencies {
8288
annotationProcessor("org.spongepowered:mixin:0.8.2:processor")
89+
annotationProcessor 'org.projectlombok:lombok:1.18.20'
8390

8491
minecraft 'com.github.ImpactDevelopment:Vanilla:1.16.5'
85-
compile(files('libs/lm_api_mc1.16.5.jar'))
92+
93+
shade("org.yaml:snakeyaml:1.28")
94+
shade("com.viaversion:viaversion:4.0.0-1.17-pre2-SNAPSHOT") { transitive = false }
95+
shade("com.viaversion:viabackwards:4.0.0-1.17-pre2-SNAPSHOT") { transitive = false }
96+
shade("com.viaversion:viarewind-core:2.0.0-SNAPSHOT") { transitive = false }
97+
98+
compile(files(
99+
'libs/lm_api_mc1.16.5.jar',
100+
))
101+
102+
compileOnly 'org.projectlombok:lombok:1.18.20'
86103

87104
compile("org.ow2.asm:asm-analysis:6.2") { transitive = false }
88105
compile("org.ow2.asm:asm-util:6.2") { transitive = false }
@@ -94,6 +111,11 @@ dependencies {
94111
jar {
95112
// Excludes the start file
96113
exclude("**/launch")
114+
configurations.shade.each { dep ->
115+
from(project.zipTree(dep)) {
116+
exclude 'META-INF', 'META-INF/**'
117+
}
118+
}
97119
}
98120

99121
task downloadAPI(type: Download) {

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
rootProject.name = 'addon-example'
1+
rootProject.name = 'viaversion-addon'
22

src/main/java/com/example/addon/ExampleAddon.java

-25
This file was deleted.

src/main/java/com/example/addon/ExampleAddonTransformer.java

-12
This file was deleted.

src/main/java/com/example/addon/mixin/ExampleMixin.java

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package de.rexlmanu.viaversionaddon;
2+
3+
import com.google.common.util.concurrent.ThreadFactoryBuilder;
4+
import com.viaversion.viaversion.ViaManagerImpl;
5+
import com.viaversion.viaversion.api.Via;
6+
import com.viaversion.viaversion.api.data.MappingDataLoader;
7+
import de.rexlmanu.viaversionaddon.loader.AddonBackwardsLoader;
8+
import de.rexlmanu.viaversionaddon.loader.AddonViaProviderLoader;
9+
import de.rexlmanu.viaversionaddon.menu.ProtocolScreen;
10+
import de.rexlmanu.viaversionaddon.platform.AddonInjector;
11+
import de.rexlmanu.viaversionaddon.platform.AddonPlatform;
12+
import io.netty.channel.DefaultEventLoop;
13+
import io.netty.channel.EventLoop;
14+
import lombok.Getter;
15+
import lombok.Setter;
16+
import net.labymod.api.LabyModAddon;
17+
import net.labymod.gui.elements.Tabs;
18+
import net.labymod.settings.elements.SettingsElement;
19+
20+
import java.io.File;
21+
import java.util.List;
22+
import java.util.concurrent.CompletableFuture;
23+
import java.util.concurrent.ExecutorService;
24+
import java.util.concurrent.Executors;
25+
import java.util.concurrent.ThreadFactory;
26+
27+
@Getter
28+
public class ViaVersionAddon extends LabyModAddon {
29+
30+
public static final String NAME = "ViaVersionAddon";
31+
32+
public static final int SHARED_VERSION = 754;
33+
34+
@Getter
35+
private static ViaVersionAddon instance;
36+
37+
private final CompletableFuture<Void> initFuture = new CompletableFuture<>();
38+
39+
private ExecutorService executorService;
40+
private EventLoop eventLoop;
41+
42+
private File dataFolder;
43+
44+
@Getter
45+
@Setter
46+
private int version;
47+
48+
public ViaVersionAddon() {
49+
ViaVersionAddon.instance = this;
50+
51+
ThreadFactory factory = new ThreadFactoryBuilder()
52+
.setDaemon(true)
53+
.setNameFormat("ViaVersionAddon-%d")
54+
.build();
55+
this.executorService = Executors.newFixedThreadPool(
56+
8,
57+
factory
58+
59+
);
60+
61+
this.eventLoop = new DefaultEventLoop(factory).next();
62+
this.eventLoop.submit(initFuture::join);
63+
64+
this.dataFolder = new File(NAME.toLowerCase());
65+
66+
this.version = SHARED_VERSION;
67+
68+
this.dataFolder.mkdir();
69+
}
70+
71+
@Override
72+
public void onEnable() {
73+
Via.init(
74+
ViaManagerImpl.builder()
75+
.injector(new AddonInjector())
76+
.platform(new AddonPlatform(this.dataFolder))
77+
.loader(new AddonViaProviderLoader())
78+
.build()
79+
);
80+
81+
MappingDataLoader.enableMappingsCache();
82+
((ViaManagerImpl) Via.getManager()).init();
83+
84+
85+
new AddonBackwardsLoader(new File(this.dataFolder, "backwards"));
86+
87+
this.initFuture.complete(null);
88+
89+
Tabs.registerTab("Protocol", ProtocolScreen.class);
90+
}
91+
92+
@Override
93+
public void loadConfig() {
94+
95+
}
96+
97+
@Override
98+
protected void fillSettings(List<SettingsElement> list) {
99+
}
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package de.rexlmanu.viaversionaddon;
2+
3+
import net.labymod.addon.AddonTransformer;
4+
import net.labymod.api.TransformerType;
5+
6+
public class ViaVersionAddonTransformer extends AddonTransformer {
7+
8+
@Override
9+
public void registerTransformers() {
10+
this.registerTransformer(TransformerType.VANILLA, "network.mixin.json");
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package de.rexlmanu.viaversionaddon.handler;
2+
3+
import com.viaversion.viaversion.util.PipelineUtil;
4+
import io.netty.buffer.ByteBuf;
5+
import io.netty.channel.ChannelHandler;
6+
import io.netty.channel.ChannelHandlerContext;
7+
import io.netty.handler.codec.ByteToMessageDecoder;
8+
import io.netty.handler.codec.MessageToByteEncoder;
9+
import io.netty.handler.codec.MessageToMessageDecoder;
10+
11+
import java.lang.reflect.InvocationTargetException;
12+
13+
public class CommonTransformer {
14+
15+
public static final String HANDLER_DECODER_NAME = "via-decoder";
16+
public static final String HANDLER_ENCODER_NAME = "via-encoder";
17+
18+
public static void decompress(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
19+
ChannelHandler handler = ctx.pipeline().get("decompress");
20+
ByteBuf decompressed = handler instanceof MessageToMessageDecoder
21+
? (ByteBuf) PipelineUtil.callDecode((MessageToMessageDecoder<?>) handler, ctx, buf).get(0)
22+
: (ByteBuf) PipelineUtil.callDecode((ByteToMessageDecoder) handler, ctx, buf).get(0);
23+
try {
24+
buf.clear().writeBytes(decompressed);
25+
} finally {
26+
decompressed.release();
27+
}
28+
}
29+
30+
public static void compress(ChannelHandlerContext ctx, ByteBuf buf) throws Exception {
31+
ByteBuf compressed = ctx.alloc().buffer();
32+
try {
33+
PipelineUtil.callEncode((MessageToByteEncoder<?>) ctx.pipeline().get("compress"), ctx, buf, compressed);
34+
buf.clear().writeBytes(compressed);
35+
} finally {
36+
compressed.release();
37+
}
38+
}
39+
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package de.rexlmanu.viaversionaddon.handler;
2+
3+
public class PipelineReorderEvent {
4+
}

0 commit comments

Comments
 (0)