Skip to content

Commit d3f1020

Browse files
committed
feat: 1.17+ support, gradle token replacement
1 parent 629e844 commit d3f1020

File tree

16 files changed

+253
-75
lines changed

16 files changed

+253
-75
lines changed

base/src/main/java/by/milansky/protocol/base/packet/handler/annotation/AnnotationBasedHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public static PacketHandler create(final Object... handlers) {
6363

6464
try {
6565
return (PacketHandleResult) declaredMethod.invoke(handler, channel, packet);
66-
} catch (final InvocationTargetException | IllegalAccessException e) {
67-
log.catching(e);
66+
} catch (final InvocationTargetException | IllegalAccessException throwable) {
67+
log.catching(throwable);
6868
} finally {
6969
declaredMethod.setAccessible(false);
7070
}

build.gradle

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import org.apache.tools.ant.filters.ReplaceTokens
2+
13
plugins {
24
id 'com.gradleup.shadow' version '9.0.0-beta4' apply false
35
}
46

57
allprojects {
68
group = 'by.milansky.protocol'
7-
version = '1.0.1'
9+
version = '1.1.0'
810
}
911

1012
configure(subprojects - project(':examples')) {
@@ -27,6 +29,7 @@ configure(subprojects - project(':examples')) {
2729
testCompileOnly libs.lombok
2830
testAnnotationProcessor libs.lombok
2931

32+
compileOnly libs.fastutil
3033
compileOnly libs.netty.all
3134
compileOnly libs.log4j.core
3235
compileOnly libs.jetbrains.annotations
@@ -76,6 +79,23 @@ configure(subprojects - project(':examples')) {
7679
}
7780
}
7881

82+
tasks {
83+
register('processSource', Copy) {
84+
from(sourceSets.main.java)
85+
into("$buildDir/src")
86+
87+
inputs.property 'version', version
88+
filter(ReplaceTokens, tokens: [version: version], beginToken: '${', endToken: '}')
89+
}
90+
91+
compileJava {
92+
sourceCompatibility = JavaVersion.VERSION_17
93+
targetCompatibility = JavaVersion.VERSION_17
94+
95+
source = processSource.outputs
96+
}
97+
}
98+
7999
test {
80100
useJUnitPlatform()
81101
}

bukkit/src/main/java/by/milansky/protocol/bukkit/ProtocolBukkit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @author milansky
2020
*/
2121
@Log4j2
22-
@Plugin(name = "Protocol", version = "1.0.1-BETA")
22+
@Plugin(name = "Protocol", version = "${version}")
2323
public class ProtocolBukkit extends JavaPlugin {
2424
private Injector injector;
2525

examples/bukkit-disguise/src/main/java/by/milansky/protocol/example/DisguisePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@Commands({
1717
@Command(name = "disguise")
1818
})
19-
@Plugin(name = "Disguise", version = "1.0.0-TEST")
19+
@Plugin(name = "Disguise", version = "${version}")
2020
@Description("An example plugin that shows how to use minecraft protocol library")
2121
public final class DisguisePlugin extends JavaPlugin {
2222
@Override

examples/bukkit-disguise/src/main/java/by/milansky/protocol/example/command/DisguiseCommand.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import org.bukkit.entity.Player;
1212
import org.jetbrains.annotations.NotNull;
1313

14-
import java.util.Optional;
15-
1614
/**
1715
* @author milansky
1816
*/

examples/bukkit-disguise/src/main/java/by/milansky/protocol/example/player/DisguisePlayerStorage.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import java.util.HashMap;
1010
import java.util.Map;
11-
import java.util.concurrent.ConcurrentHashMap;
1211

1312
/**
1413
* @author milansky

examples/bukkit-nametags/src/main/java/by/milansky/protocol/example/NametagPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* @author milansky
1010
*/
11-
@Plugin(name = "Nametags", version = "1.0.0-TEST")
11+
@Plugin(name = "Nametags", version = "${version}")
1212
@Description("An example plugin that shows how to use minecraft protocol library")
1313
public final class NametagPlugin extends JavaPlugin {
1414
@Override

examples/bukkit-nametags/src/main/java/by/milansky/protocol/example/listener/NametagListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public void onPlayerCreate(final ProtocolPlayerCreateEvent event) {
3333
Component.text(" JOB", NamedTextColor.GREEN, TextDecoration.BOLD),
3434
ClientboundTeam.NameTagVisibility.ALWAYS,
3535
ClientboundTeam.CollisionRule.NEVER,
36-
0, (byte) 0, new String[]{protocolPlayer.nativePlayer().getName()}
36+
NamedTextColor.WHITE,
37+
(byte) 0, new String[]{protocolPlayer.nativePlayer().getName()}
3738
));
3839
}
3940
}

readme.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22
<img src=".assets/illustration.png" width="500"/>
33
<br>
44
<img src="https://img.shields.io/badge/language-java-gold?style=flat" />
5-
<img src="https://img.shields.io/badge/beta-v1.0.1-gold?style=flat" />
5+
<img src="https://img.shields.io/badge/v1.1.0-gold?style=flat" />
66
<img src="https://img.shields.io/github/stars/rmilansky/minecraft-protocol-java?style=flat" />
77
</div>
88

99
# Introduction
1010

11-
Minecraft Protocol is a project I developed because all existing libraries for packet handling are either outdated or insufficiently lightweight for use in my projects (also due to a complete rewrite of the [Abelix](https://abelix.team) codebase).
11+
Minecraft Protocol is a project I developed because all existing libraries for packet handling are either outdated or
12+
insufficiently lightweight for use in my projects (also due to a complete rewrite of the [Abelix](https://abelix.team)
13+
codebase).
1214

13-
The project was written in a single attempt by one person, so there might be bugs or less-than-perfect code. I would greatly appreciate any pull requests or issues.
15+
The project was written in a single attempt by one person, so there might be bugs or less-than-perfect code. I would
16+
greatly appreciate any pull requests or issues.
1417

1518
<img src=".assets/time.jpg" width="500"/>
1619

1720
# Project Overview
1821

1922
## Purpose
2023

21-
This project is designed for the most convenient and integrable development of systems that require the use of Minecraft protocol packets (e.g., fake entities, nametags for servers, proxy systems).
24+
This project is designed for the most convenient and integrable development of systems that require the use of Minecraft
25+
protocol packets (e.g., fake entities, nametags for servers, proxy systems).
2226

2327
## Key Objectives
2428

@@ -33,7 +37,8 @@ This project is designed for the most convenient and integrable development of s
3337

3438
1. Add a repository:
3539

36-
Maven:
40+
Maven:
41+
3742
```xml
3843
<repositories>
3944
<repository>
@@ -42,7 +47,9 @@ Maven:
4247
</repository>
4348
</repositories>
4449
```
50+
4551
Gradle:
52+
4653
```groovy
4754
repositories {
4855
maven {
@@ -54,9 +61,10 @@ repositories {
5461
2. Add dependencies
5562

5663
Maven:
64+
5765
```xml
5866
<properties>
59-
<protocol.version>1.0.1</protocol.version>
67+
<protocol.version>1.1.0</protocol.version>
6068
</properties>
6169

6270
<dependencies>
@@ -85,11 +93,12 @@ Maven:
8593
</dependencies>
8694
```
8795

88-
Gradle:
96+
Gradle:
97+
8998
```groovy
9099
dependencies {
91100
// It's better to use gradle's dependencyResolutionManagement
92-
def protocolVersion = '1.0.1'
101+
def protocolVersion = '1.1.0'
93102
94103
compileOnly "by.milansky.protocol:api:${protocolVersion}"
95104
compileOnly "by.milansky.protocol:base:${protocolVersion}"
@@ -102,7 +111,8 @@ dependencies {
102111

103112
## Java API usage
104113

105-
More detailed usage examples can be found in the [examples](examples) directory. However, to briefly explain, here's how you can listen to all `ClientboundTeam` packets:
114+
More detailed usage examples can be found in the [examples](examples) directory. However, to briefly explain, here's how
115+
you can listen to all `ClientboundTeam` packets:
106116

107117
1. Create a handler to process packets:
108118

@@ -144,5 +154,6 @@ public final class NametagListener implements Listener {
144154

145155
Special thanks for ideas and inspiration to these projects:
146156

147-
* [Velocity](https://github.com/PaperMC/Velocity), [BungeeCord](https://github.com/SpigotMC/BungeeCord) - for some ideas and packet structures.
157+
* [Velocity](https://github.com/PaperMC/Velocity), [BungeeCord](https://github.com/SpigotMC/BungeeCord) - for some ideas
158+
and packet structures.
148159
* [BridgeNet](https://github.com/MikhailSterkhov/bridgenet) - for the idea of this beautiful readme
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package by.milansky.protocol.vanilla.channel;
2+
3+
import io.netty.channel.ChannelDuplexHandler;
4+
import io.netty.channel.ChannelHandlerContext;
5+
import io.netty.channel.ChannelPromise;
6+
import lombok.AccessLevel;
7+
import lombok.RequiredArgsConstructor;
8+
import lombok.experimental.FieldDefaults;
9+
import lombok.extern.log4j.Log4j2;
10+
import org.jetbrains.annotations.NotNull;
11+
12+
/**
13+
* @author milansky
14+
*/
15+
@Log4j2
16+
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
17+
@RequiredArgsConstructor(staticName = "create", access = AccessLevel.PACKAGE)
18+
final class ProxiedInboundChannelHandler extends ChannelDuplexHandler {
19+
ChannelDuplexHandler parent;
20+
Runnable afterWrite;
21+
22+
@Override
23+
public void write(
24+
final @NotNull ChannelHandlerContext ctx,
25+
final @NotNull Object msg,
26+
final @NotNull ChannelPromise promise
27+
) throws Exception {
28+
parent.write(ctx, msg, promise);
29+
afterWrite.run();
30+
}
31+
32+
@Override
33+
public void channelRead(
34+
final @NotNull ChannelHandlerContext ctx,
35+
final @NotNull Object msg
36+
) throws Exception {
37+
parent.channelRead(ctx, msg);
38+
}
39+
}

0 commit comments

Comments
 (0)