Skip to content

Commit 3686727

Browse files
committed
Velocity & Folia impl
1 parent 65e08cd commit 3686727

File tree

16 files changed

+635
-72
lines changed

16 files changed

+635
-72
lines changed

api/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ setupPlatforms()
77

88
setupPlatformDependency("bukkit", "bukkitJar")
99
setupPlatformDependency("bungee", "bungeeJar")
10-
setupPlatformDependency("velocity", "velocityJar")
10+
setupPlatformDependency("velocity", "velocityJar", 17)
1111
setupPlatformDependency("folia", "foliaJar", 21)
1212

1313
val main by sourceSets

build-logic/src/main/kotlin/apollo.base-conventions.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import com.diffplug.gradle.spotless.FormatExtension
2+
import org.gradle.jvm.toolchain.JavaLanguageVersion
3+
import org.gradle.jvm.toolchain.JavaToolchainService
24
import java.nio.charset.StandardCharsets
35
import java.nio.file.Files
46
import java.util.regex.Pattern
@@ -83,6 +85,11 @@ checkstyle {
8385

8486
tasks {
8587
javadoc {
88+
val javaToolchains = project.extensions.getByType(JavaToolchainService::class.java)
89+
javadocTool.set(javaToolchains.javadocToolFor {
90+
languageVersion.set(JavaLanguageVersion.of(21))
91+
})
92+
8693
val minimalOptions: MinimalJavadocOptions = options
8794
options.encoding("UTF-8")
8895

bukkit/src/main/java/com/lunarclient/apollo/listener/ApolloMetadataListener.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.lunarclient.apollo.metadata.BukkitMetadataManager;
2828
import java.nio.charset.StandardCharsets;
2929
import java.util.Map;
30-
import java.util.logging.Level;
3130
import org.bukkit.Bukkit;
3231
import org.bukkit.event.EventHandler;
3332
import org.bukkit.event.Listener;
@@ -54,14 +53,8 @@ public final class ApolloMetadataListener implements Listener {
5453
public ApolloMetadataListener(JavaPlugin plugin) {
5554
this.plugin = plugin;
5655

56+
this.registerBrandListener();
5757
Bukkit.getPluginManager().registerEvents(this, plugin);
58-
59-
this.registerIncomingPluginChannel("MC|Brand", "minecraft:brand", (channel, player, bytes) -> {
60-
String brand = new String(bytes, StandardCharsets.UTF_8);
61-
this.plugin.getLogger().log(Level.WARNING, player.getName() + " is using client brand: " + brand);
62-
BukkitMetadataManager manager = (BukkitMetadataManager) ApolloManager.getMetadataManager();
63-
manager.getClientBrands().add(brand);
64-
});
6558
}
6659

6760
@EventHandler
@@ -71,21 +64,24 @@ private void onResourcePackStatus(PlayerResourcePackStatusEvent event) {
7164
Map<String, Integer> statuses = manager.getResourcePackStatuses();
7265

7366
statuses.put(status, statuses.getOrDefault(status, 0) + 1);
74-
75-
statuses.forEach((key, value) -> {
76-
this.plugin.getLogger().log(Level.INFO, "Resource Pack Status: " + key + " - Count: " + value);
77-
});
7867
}
7968

80-
private void registerIncomingPluginChannel(String legacyChannel, String modernChannel, PluginMessageListener listener) {
69+
private void registerBrandListener() {
70+
PluginMessageListener listener = (channel, player, bytes) -> {
71+
String brand = new String(bytes, StandardCharsets.UTF_8);
72+
73+
BukkitMetadataManager manager = (BukkitMetadataManager) ApolloManager.getMetadataManager();
74+
manager.getClientBrands().add(brand);
75+
};
76+
8177
Messenger messenger = this.plugin.getServer().getMessenger();
8278

8379
try {
84-
messenger.registerIncomingPluginChannel(this.plugin, legacyChannel, listener);
80+
messenger.registerIncomingPluginChannel(this.plugin, "MC|Brand", listener);
8581
} catch (IllegalArgumentException ignored) {
8682
}
8783

88-
messenger.registerIncomingPluginChannel(this.plugin, modernChannel, listener);
84+
messenger.registerIncomingPluginChannel(this.plugin, "minecraft:brand", listener);
8985
}
9086

9187
}

bukkit/src/main/java/com/lunarclient/apollo/metadata/BukkitMetadataManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ public void clear() {
5555
this.clientBrands.clear();
5656
this.resourcePackStatuses.clear();
5757
}
58+
5859
}

bungee/src/main/java/com/lunarclient/apollo/listener/ApolloMetadataListener.java

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@
2525

2626
import com.google.common.io.ByteArrayDataInput;
2727
import com.google.common.io.ByteStreams;
28-
import com.lunarclient.apollo.ApolloBungeePlatform;
2928
import com.lunarclient.apollo.ApolloManager;
3029
import com.lunarclient.apollo.metadata.BungeeMetadataManager;
3130
import com.lunarclient.apollo.util.ByteBufUtil;
3231
import java.net.InetSocketAddress;
3332
import java.nio.charset.StandardCharsets;
34-
import java.util.logging.Level;
3533
import net.md_5.bungee.api.ProxyServer;
36-
import net.md_5.bungee.api.connection.Connection;
3734
import net.md_5.bungee.api.connection.PendingConnection;
3835
import net.md_5.bungee.api.connection.ProxiedPlayer;
3936
import net.md_5.bungee.api.event.PluginMessageEvent;
@@ -74,20 +71,18 @@ public ApolloMetadataListener(Plugin plugin) {
7471
@EventHandler
7572
public void onPluginMessage(PluginMessageEvent event) {
7673
if (!(event.getSender() instanceof ProxiedPlayer)) {
77-
System.out.println("Not a player Brand");
7874
return;
7975
}
8076

81-
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
8277
String tag = event.getTag();
8378

8479
if (tag.equals("minecraft:brand") || tag.equals("MC|Brand")) {
85-
this.handleBrand(event.getData(), player);
80+
this.handleBrand(event.getData());
8681
return;
8782
}
8883

8984
if (tag.equals("fml:handshake") || tag.equals("FML|HS")) {
90-
this.handleFml(event.getData(), player);
85+
this.handleFml(event.getData());
9186
}
9287
}
9388

@@ -107,7 +102,6 @@ public void onPreLogin(PreLoginEvent event) {
107102
}
108103

109104
String hostString;
110-
111105
if (host.getAddress() != null) {
112106
hostString = host.getAddress().getHostAddress();
113107
} else {
@@ -116,36 +110,34 @@ public void onPreLogin(PreLoginEvent event) {
116110

117111
BungeeMetadataManager manager = (BungeeMetadataManager) ApolloManager.getMetadataManager();
118112
manager.getServerAddress().add(hostString + ":" + host.getPort());
119-
ApolloBungeePlatform.getInstance().getPlatformLogger().log(Level.WARNING, hostString + ":" + host.getPort());
120113
}
121114

122-
private void handleBrand(byte[] data, Connection sender) {
115+
private void handleBrand(byte[] data) {
123116
String brand = new String(data, StandardCharsets.UTF_8);
124-
ApolloBungeePlatform.getInstance().getPlatformLogger().log(Level.WARNING, ((ProxiedPlayer) sender).getName() + " is using client brand: " + brand);
125-
126117
BungeeMetadataManager manager = (BungeeMetadataManager) ApolloManager.getMetadataManager();
127118
manager.getClientBrands().add(brand);
128119
}
129120

130-
private void handleFml(byte[] data, Connection sender) {
131-
ProxiedPlayer player = (ProxiedPlayer) sender;
132-
121+
private void handleFml(byte[] data) {
133122
ByteArrayDataInput in = ByteStreams.newDataInput(data);
134-
byte discriminator = in.readByte();
135123

136-
if (discriminator != 2) {
137-
return;
138-
}
124+
try {
125+
byte discriminator = in.readByte();
126+
127+
if (discriminator != 2) {
128+
return;
129+
}
139130

140-
int count = ByteBufUtil.readVarInt(in);
131+
int count = ByteBufUtil.readVarInt(in);
141132

142-
for (int i = 0; i < count; i++) {
143-
String modId = ByteBufUtil.readString(in);
144-
String version = ByteBufUtil.readString(in);
133+
for (int i = 0; i < count; i++) {
134+
String modId = ByteBufUtil.readString(in);
135+
String version = ByteBufUtil.readString(in);
145136

146-
ApolloBungeePlatform.getInstance().getPlatformLogger().log(Level.WARNING, player.getName() + " is using mod: " + modId + " with version: " + version);
147-
BungeeMetadataManager manager = (BungeeMetadataManager) ApolloManager.getMetadataManager();
148-
manager.getMods().put(modId, version);
137+
BungeeMetadataManager manager = (BungeeMetadataManager) ApolloManager.getMetadataManager();
138+
manager.getMods().put(modId, version);
139+
}
140+
} catch (Exception ignored) {
149141
}
150142
}
151143

folia/src/main/java/com/lunarclient/apollo/ApolloFoliaPlatform.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525

2626
import com.lunarclient.apollo.command.impl.ApolloCommand;
2727
import com.lunarclient.apollo.command.impl.LunarClientCommand;
28+
import com.lunarclient.apollo.listener.ApolloMetadataListener;
2829
import com.lunarclient.apollo.listener.ApolloPlayerListener;
2930
import com.lunarclient.apollo.listener.ApolloWorldListener;
31+
import com.lunarclient.apollo.metadata.FoliaMetadataManager;
3032
import com.lunarclient.apollo.module.ApolloModuleManagerImpl;
3133
import com.lunarclient.apollo.module.autotexthotkey.AutoTextHotkeyModule;
3234
import com.lunarclient.apollo.module.beam.BeamModule;
@@ -109,7 +111,9 @@ public void onEnable() {
109111
this.stats = new FoliaApolloStats();
110112

111113
ApolloManager.bootstrap(this);
114+
ApolloManager.setMetadataManager(new FoliaMetadataManager());
112115

116+
new ApolloMetadataListener(this);
113117
new ApolloPlayerListener(this);
114118
new ApolloWorldListener(this);
115119

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.listener;
25+
26+
import com.lunarclient.apollo.ApolloManager;
27+
import com.lunarclient.apollo.metadata.FoliaMetadataManager;
28+
import java.util.Map;
29+
import org.bukkit.Bukkit;
30+
import org.bukkit.entity.Player;
31+
import org.bukkit.event.EventHandler;
32+
import org.bukkit.event.Listener;
33+
import org.bukkit.event.player.PlayerJoinEvent;
34+
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
35+
import org.bukkit.plugin.java.JavaPlugin;
36+
37+
/**
38+
* Handles Apollo metadata listeners.
39+
*
40+
* @since 1.1.9
41+
*/
42+
public final class ApolloMetadataListener implements Listener {
43+
44+
private final JavaPlugin plugin;
45+
46+
/**
47+
* Constructs the {@link ApolloMetadataListener}.
48+
*
49+
* @param plugin the plugin
50+
* @since 1.1.9
51+
*/
52+
public ApolloMetadataListener(JavaPlugin plugin) {
53+
this.plugin = plugin;
54+
55+
Bukkit.getPluginManager().registerEvents(this, plugin);
56+
}
57+
58+
@EventHandler
59+
private void onPlayerJoin(PlayerJoinEvent event) {
60+
Player player = event.getPlayer();
61+
62+
Bukkit.getGlobalRegionScheduler().runDelayed(this.plugin, t -> {
63+
if (!player.isOnline()) {
64+
return;
65+
}
66+
67+
String brand = player.getClientBrandName();
68+
if (brand == null) {
69+
return;
70+
}
71+
72+
FoliaMetadataManager manager = (FoliaMetadataManager) ApolloManager.getMetadataManager();
73+
manager.getClientBrands().add(brand);
74+
}, 20L * 3);
75+
}
76+
77+
@EventHandler
78+
private void onResourcePackStatus(PlayerResourcePackStatusEvent event) {
79+
String status = event.getStatus().name();
80+
FoliaMetadataManager manager = (FoliaMetadataManager) ApolloManager.getMetadataManager();
81+
Map<String, Integer> statuses = manager.getResourcePackStatuses();
82+
83+
statuses.put(status, statuses.getOrDefault(status, 0) + 1);
84+
}
85+
86+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.metadata;
25+
26+
import com.lunarclient.apollo.stats.metadata.PlatformMetadata;
27+
import java.util.Map;
28+
import java.util.Set;
29+
import lombok.Builder;
30+
import lombok.ToString;
31+
32+
/**
33+
* Represents the folia metadata implementation.
34+
*
35+
* @since 1.1.9
36+
*/
37+
@ToString
38+
@Builder(toBuilder = true)
39+
public class FoliaMetadata extends PlatformMetadata {
40+
41+
/**
42+
* Tracks client brands sent by the players.
43+
*
44+
* <p>A {@link Set} of {@link String} client brands.</p>
45+
*
46+
* @since 1.1.9
47+
*/
48+
private final Set<String> clientBrands;
49+
50+
/**
51+
* Tracks the total number of resource pack status events received.
52+
*
53+
* <p>Represents a {@link Map} of {@link String} status enum name as a key
54+
* and {@link Integer} count of how many times that status has been reported.</p>
55+
*
56+
* @since 1.1.9
57+
*/
58+
private final Map<String, Integer> resourcePackStatuses;
59+
60+
}

0 commit comments

Comments
 (0)