Skip to content

Commit 2774f83

Browse files
committed
Add payload & handshake checks
1 parent 50e28c1 commit 2774f83

File tree

5 files changed

+100
-7
lines changed

5 files changed

+100
-7
lines changed

bukkit-example/src/main/java/com/lunarclient/apollo/example/ApolloExamplePlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ public class ApolloExamplePlugin extends JavaPlugin {
197197
private VignetteExample vignetteExample;
198198
private WaypointExample waypointExample;
199199

200-
private DebugManager debugManager;
201200
private SpamPacketDebug spamPacketDebug;
202201

203202
@Override
@@ -358,12 +357,12 @@ private void registerModuleExamples() {
358357
}
359358

360359
private void registerListeners() {
361-
this.debugManager = new DebugManager();
362360
this.spamPacketDebug = new SpamPacketDebug();
363361

364362
switch (TYPE) {
365363
case API: {
366364
this.playerApiListener = new ApolloPlayerApiListener(this);
365+
new DebugManager();
367366
break;
368367
}
369368

bukkit-example/src/main/java/com/lunarclient/apollo/example/common/commands/debug/ApolloDebugCommand.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
package com.lunarclient.apollo.example.common.commands.debug;
2525

2626
import com.lunarclient.apollo.common.ApolloComponent;
27+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
28+
import com.lunarclient.apollo.example.common.modules.ApolloExampleType;
2729
import net.kyori.adventure.text.Component;
2830
import net.kyori.adventure.text.format.NamedTextColor;
2931
import net.kyori.adventure.text.format.TextDecoration;
@@ -42,6 +44,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
4244
return true;
4345
}
4446

47+
if (ApolloExamplePlugin.TYPE != ApolloExampleType.API) {
48+
sender.sendMessage("Debug is only available with the API example type!");
49+
sender.sendMessage("Run '/switch API' for more info");
50+
return true;
51+
}
52+
4553
Player player = (Player) sender;
4654

4755
if (args.length < 1) {

bukkit-example/src/main/java/com/lunarclient/apollo/example/common/commands/debug/BordersCommand.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
package com.lunarclient.apollo.example.common.commands.debug;
2525

2626
import com.lunarclient.apollo.common.ApolloComponent;
27-
import com.lunarclient.apollo.example.ApolloExamplePlugin;
2827
import com.lunarclient.apollo.example.debug.DebugManager;
2928
import com.lunarclient.apollo.example.debug.impl.BorderCollisionTest;
3029
import net.kyori.adventure.text.Component;
@@ -38,8 +37,6 @@
3837

3938
public class BordersCommand implements CommandExecutor {
4039

41-
private final DebugManager debugManager = ApolloExamplePlugin.getPlugin().getDebugManager();
42-
4340
@Override
4441
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
4542
if (!(sender instanceof Player)) {
@@ -48,6 +45,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
4845
}
4946

5047
Player player = (Player) sender;
48+
DebugManager debugManager = DebugManager.getInstance();
5149

5250
if (args.length < 2) {
5351
this.sendUsage(player);
@@ -56,12 +54,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
5654

5755
switch (args[1].toLowerCase()) {
5856
case "start": {
59-
this.debugManager.start(player, new BorderCollisionTest(player));
57+
debugManager.start(player, new BorderCollisionTest(player));
6058
break;
6159
}
6260

6361
case "stop": {
64-
this.debugManager.stop(player);
62+
debugManager.stop(player);
6563
break;
6664
}
6765

bukkit-example/src/main/java/com/lunarclient/apollo/example/debug/DebugManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package com.lunarclient.apollo.example.debug;
2525

2626
import com.lunarclient.apollo.example.ApolloExamplePlugin;
27+
import com.lunarclient.apollo.example.debug.payload.PayloadListener;
2728
import java.util.HashMap;
2829
import java.util.Map;
2930
import java.util.UUID;
@@ -43,6 +44,9 @@ public DebugManager() {
4344
instance = this;
4445

4546
this.players = new HashMap<>();
47+
48+
new PayloadListener();
49+
4650
Bukkit.getPluginManager().registerEvents(this, ApolloExamplePlugin.getPlugin());
4751
}
4852

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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.example.debug.payload;
25+
26+
import com.lunarclient.apollo.Apollo;
27+
import com.lunarclient.apollo.event.ApolloListener;
28+
import com.lunarclient.apollo.event.EventBus;
29+
import com.lunarclient.apollo.event.Listen;
30+
import com.lunarclient.apollo.event.player.ApolloPlayerHandshakeEvent;
31+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
32+
import java.util.HashSet;
33+
import java.util.Set;
34+
import java.util.UUID;
35+
import org.bukkit.Bukkit;
36+
import org.bukkit.ChatColor;
37+
import org.bukkit.entity.Player;
38+
import org.bukkit.event.EventHandler;
39+
import org.bukkit.event.Listener;
40+
import org.bukkit.event.player.PlayerJoinEvent;
41+
import org.bukkit.event.player.PlayerQuitEvent;
42+
43+
public class PayloadListener implements Listener, ApolloListener {
44+
45+
private final Set<UUID> handshakeUuids;
46+
47+
public PayloadListener() {
48+
this.handshakeUuids = new HashSet<>();
49+
50+
EventBus.getBus().register(this);
51+
Bukkit.getPluginManager().registerEvents(this, ApolloExamplePlugin.getPlugin());
52+
}
53+
54+
private void checkReceivedPackets(Player player) {
55+
Bukkit.getScheduler().runTaskLater(ApolloExamplePlugin.getPlugin(), () -> {
56+
UUID uuid = player.getUniqueId();
57+
58+
boolean register = Apollo.getPlayerManager().hasSupport(uuid);
59+
boolean handshake = this.handshakeUuids.contains(uuid);
60+
61+
if (register && !handshake) {
62+
player.sendMessage(ChatColor.RED + "Received Apollo register but not the handshake!");
63+
} else if (!register && !handshake) {
64+
player.sendMessage(ChatColor.RED + "Failed to receive Apollo register and handshake!");
65+
}
66+
}, 20 * 3);
67+
}
68+
69+
@EventHandler
70+
private void onPlayerJoin(PlayerJoinEvent event) {
71+
this.checkReceivedPackets(event.getPlayer());
72+
}
73+
74+
@EventHandler
75+
private void onPlayerQuit(PlayerQuitEvent event) {
76+
this.handshakeUuids.remove(event.getPlayer().getUniqueId());
77+
}
78+
79+
@Listen
80+
private void onApolloPlayerHandshake(ApolloPlayerHandshakeEvent event) {
81+
this.handshakeUuids.add(event.getPlayer().getUniqueId());
82+
}
83+
84+
}

0 commit comments

Comments
 (0)