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

Commit 0b93cb0

Browse files
Merged velocity support.
2 parents 0a63704 + 0e5bd55 commit 0b93cb0

6 files changed

Lines changed: 133 additions & 5 deletions

File tree

.github/ISSUE_TEMPLATE/bug-or-plugin-incompatibility.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ assignees: Sportkanone123
88
---
99

1010
**General Information**
11-
Server version: ... (e.g.: 1.17.1)
12-
Server software: ... (e.g.: Paper/Spigot/Bukkit)
13-
Client version: ... (e.g.: 1.17.1)
14-
Client software: ... (e.g.: Vanilla/Lunar/Badlion/Forge)
15-
Plugin version: ... (e.g.: 2.2.5)
11+
Server version: (e.g.: Paper/Spigot 1.19.2)
12+
Client version: (e.g.: Vanilla/Fabric/Forge/Badlion/Lunar 1.19.2)
13+
Plugin version: (e.g.: 2.5.3)
1614

1715

1816
**Describe the bug**

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ ClientDetector uses the PacketEvents API. Check it out here: https://github.com/
4343

4444
### Forge Mods
4545
* All Forge Mods from 1.8 - 1.17.1 (with some limitations)
46+
47+
### Contributors
48+
<a href="https://github.com/Sportkanone123/ClientDetector/graphs/contributors">
49+
<img src="https://contrib.rocks/image?repo=Sportkanone123/ClientDetector" />

pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
<source>8</source>
2424
<target>8</target>
2525
<compilerArgument>-XDignore.symbol.file</compilerArgument>
26+
<annotationProcessorPaths>
27+
<path>
28+
<groupId>com.velocitypowered</groupId>
29+
<artifactId>velocity-api</artifactId>
30+
<version>3.0.1</version>
31+
</path>
32+
</annotationProcessorPaths>
2633
</configuration>
2734
</plugin>
2835
<plugin>
@@ -86,6 +93,11 @@
8693
<id>dmulloy2-repo</id>
8794
<url>https://repo.dmulloy2.net/repository/public/</url>
8895
</repository>
96+
97+
<repository>
98+
<id>papermc</id>
99+
<url>https://repo.papermc.io/repository/maven-public/</url>
100+
</repository>
89101
</repositories>
90102

91103
<dependencies>
@@ -124,5 +136,12 @@
124136
<scope>provided</scope>
125137
</dependency>
126138

139+
<dependency>
140+
<groupId>com.velocitypowered</groupId>
141+
<artifactId>velocity-api</artifactId>
142+
<version>3.0.1</version>
143+
<scope>provided</scope>
144+
</dependency>
145+
127146
</dependencies>
128147
</project>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package de.sportkanone123.clientdetector.velocity;
2+
3+
import com.google.inject.Inject;
4+
import com.velocitypowered.api.event.Subscribe;
5+
import com.velocitypowered.api.event.connection.DisconnectEvent;
6+
import com.velocitypowered.api.event.connection.PluginMessageEvent;
7+
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
8+
import com.velocitypowered.api.plugin.annotation.DataDirectory;
9+
import com.velocitypowered.api.proxy.ProxyServer;
10+
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
11+
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
12+
import com.velocitypowered.api.proxy.server.RegisteredServer;
13+
14+
import java.nio.charset.StandardCharsets;
15+
import java.nio.file.Path;
16+
import java.util.ArrayList;
17+
import java.util.HashMap;
18+
import java.util.List;
19+
import java.util.Map;
20+
import java.util.concurrent.TimeUnit;
21+
import java.util.logging.Logger;
22+
23+
@com.velocitypowered.api.plugin.Plugin(
24+
id = "clientdetector",
25+
name = "ClientDetector",
26+
version = "2.5.2",
27+
description = "A simple plugin to detect and manage a player's client/mods",
28+
authors = {"Sportkanone123"}
29+
)
30+
public class ClientDetectorVelocity {
31+
32+
public static final LegacyChannelIdentifier LEGACY_BUNGEE_CHANNEL = new LegacyChannelIdentifier("cd:bungee");
33+
public static final MinecraftChannelIdentifier MODERN_BUNGEE_CHANNEL = MinecraftChannelIdentifier.create("cd", "bungee");
34+
public static final MinecraftChannelIdentifier MODERN_SPIGOT_CHANNEL = MinecraftChannelIdentifier.create("cd", "spigot");
35+
36+
private ProxyServer server;
37+
private Logger logger;
38+
private Path dataDirectory;
39+
private Map<RegisteredServer, List<byte[]>> queue = new HashMap<>();
40+
41+
@Inject
42+
public ClientDetectorVelocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
43+
this.server = server;
44+
this.logger = logger;
45+
this.dataDirectory = dataDirectory;
46+
}
47+
48+
@Subscribe
49+
public void onProxyInitialization(ProxyInitializeEvent event) {
50+
//this.server.getEventManager().register(this, this); (Velocity already auto registered the main class)
51+
this.server.getChannelRegistrar().register(LEGACY_BUNGEE_CHANNEL, MODERN_BUNGEE_CHANNEL);
52+
53+
runQueue();
54+
}
55+
56+
public void runQueue() {
57+
this.server.getScheduler().buildTask(this, new Runnable() {
58+
@Override
59+
public void run() {
60+
for(RegisteredServer registeredServer : queue.keySet()){
61+
if(!registeredServer.getPlayersConnected().isEmpty() && queue.get(registeredServer) != null){
62+
List<byte[]> toRemove = new ArrayList<>();
63+
for(byte[] data : queue.get(registeredServer)){
64+
toRemove.add(data);
65+
registeredServer.sendPluginMessage(MODERN_SPIGOT_CHANNEL, data);
66+
}
67+
queue.get(registeredServer).removeAll(toRemove);
68+
}
69+
}
70+
}
71+
}).repeat(1, TimeUnit.SECONDS);
72+
}
73+
74+
@Subscribe
75+
public void onPluginMessage(PluginMessageEvent event) {
76+
System.out.println(event.getIdentifier() + " // " + new java.lang.String(event.getData()));
77+
if (event.getIdentifier().getId().equalsIgnoreCase("cd:bungee")) {
78+
sync(event.getData());
79+
}
80+
}
81+
82+
private void sync(String string){
83+
sync(string.getBytes(StandardCharsets.UTF_8));
84+
}
85+
86+
private void sync(byte[] data){
87+
for(RegisteredServer server : this.server.getAllServers()){
88+
if(server.getPlayersConnected().isEmpty()){
89+
if(queue.get(server) == null) queue.put(server, new ArrayList<>());
90+
91+
if(!new String(data, StandardCharsets.UTF_8).contains("CROSS_SERVER_MESSAGE"))
92+
queue.get(server).add(data);
93+
}else{
94+
server.sendPluginMessage(MODERN_SPIGOT_CHANNEL, data);
95+
}
96+
}
97+
}
98+
99+
@Subscribe
100+
public void onDisconnect(DisconnectEvent e) {
101+
String placeholder = "@@";
102+
sync("PLAYER_LEFT" + placeholder + e.getPlayer().getUsername());
103+
}
104+
105+
}

src/main/resources/bungee.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ name: ClientDetector
22
version: 2.5.4
33
author: Sportkanone123
44
main: de.sportkanone123.clientdetector.bungeecord.ClientDetectorBungee
5+
description: A simple plugin to detect and manage a player's client/mods

src/main/resources/plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: ClientDetector
22
version: 2.5.4
33
author: Sportkanone123
44
main: de.sportkanone123.clientdetector.spigot.ClientDetector
5+
description: A simple plugin to detect and manage a player's client/mods
56
load: POSTWORLD
67
api-version: 1.13
78

0 commit comments

Comments
 (0)