This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
generated from LabyMod/1.16.5-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial release of the core functionality
- Loading branch information
Showing
27 changed files
with
938 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ run/** | |
# .idea/compiler.xml | ||
.idea/modules.xml | ||
.idea/*.iml | ||
.idea | ||
# .idea/modules | ||
# *.iml | ||
# *.ipr | ||
|
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,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. |
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,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 |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
rootProject.name = 'addon-example' | ||
rootProject.name = 'viaversion-addon' | ||
|
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/main/java/com/example/addon/ExampleAddonTransformer.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
src/main/java/de/rexlmanu/viaversionaddon/ViaVersionAddon.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,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) { | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/de/rexlmanu/viaversionaddon/ViaVersionAddonTransformer.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,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"); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/de/rexlmanu/viaversionaddon/handler/CommonTransformer.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,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(); | ||
} | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/de/rexlmanu/viaversionaddon/handler/PipelineReorderEvent.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,4 @@ | ||
package de.rexlmanu.viaversionaddon.handler; | ||
|
||
public class PipelineReorderEvent { | ||
} |
Oops, something went wrong.