Skip to content

Commit 50e28c1

Browse files
committed
Add debug system & implement Border Collisions Test
1 parent 8f325e4 commit 50e28c1

File tree

9 files changed

+538
-5
lines changed

9 files changed

+538
-5
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
102102
import com.lunarclient.apollo.example.common.modules.impl.TransferExample;
103103
import com.lunarclient.apollo.example.common.modules.impl.VignetteExample;
104104
import com.lunarclient.apollo.example.common.modules.impl.WaypointExample;
105-
import com.lunarclient.apollo.example.debug.SpamPacketDebug;
105+
import com.lunarclient.apollo.example.debug.DebugManager;
106+
import com.lunarclient.apollo.example.debug.impl.SpamPacketDebug;
106107
import com.lunarclient.apollo.example.json.examples.BeamJsonExample;
107108
import com.lunarclient.apollo.example.json.examples.BorderJsonExample;
108109
import com.lunarclient.apollo.example.json.examples.ChatJsonExample;
@@ -196,6 +197,7 @@ public class ApolloExamplePlugin extends JavaPlugin {
196197
private VignetteExample vignetteExample;
197198
private WaypointExample waypointExample;
198199

200+
private DebugManager debugManager;
199201
private SpamPacketDebug spamPacketDebug;
200202

201203
@Override
@@ -265,8 +267,6 @@ public void changeImplementationType(ApolloExampleType type) {
265267
}
266268

267269
private void registerModuleExamples() {
268-
this.spamPacketDebug = new SpamPacketDebug();
269-
270270
switch (TYPE) {
271271
case API: {
272272
this.beamExample = new BeamApiExample();
@@ -358,6 +358,9 @@ private void registerModuleExamples() {
358358
}
359359

360360
private void registerListeners() {
361+
this.debugManager = new DebugManager();
362+
this.spamPacketDebug = new SpamPacketDebug();
363+
361364
switch (TYPE) {
362365
case API: {
363366
this.playerApiListener = new ApolloPlayerApiListener(this);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
5151
.append(Component.text("/apollodebug spampackets [start|stop|stopall] ", NamedTextColor.WHITE))
5252
.append(Component.text("# Spam modsetting update packets to the client.", NamedTextColor.GREEN))
5353
.appendNewline()
54+
.append(Component.text("/apollodebug borders [start|stop] ", NamedTextColor.WHITE))
55+
.appendNewline()
5456
.append(Component.text("-------------------------------------", NamedTextColor.GRAY, TextDecoration.STRIKETHROUGH))
5557
.build()
5658
));
5759
} else if(args[0].equalsIgnoreCase("spampackets")) {
5860
return new SpamPacketsCommand().onCommand(sender, command, label, args);
61+
} else if (args[0].equalsIgnoreCase("borders")) {
62+
return new BordersCommand().onCommand(sender, command, label, args);
5963
}
6064

6165
return true;
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.common.commands.debug;
25+
26+
import com.lunarclient.apollo.common.ApolloComponent;
27+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
28+
import com.lunarclient.apollo.example.debug.DebugManager;
29+
import com.lunarclient.apollo.example.debug.impl.BorderCollisionTest;
30+
import net.kyori.adventure.text.Component;
31+
import net.kyori.adventure.text.format.NamedTextColor;
32+
import net.kyori.adventure.text.format.TextDecoration;
33+
import org.bukkit.command.Command;
34+
import org.bukkit.command.CommandExecutor;
35+
import org.bukkit.command.CommandSender;
36+
import org.bukkit.entity.Player;
37+
import org.jetbrains.annotations.NotNull;
38+
39+
public class BordersCommand implements CommandExecutor {
40+
41+
private final DebugManager debugManager = ApolloExamplePlugin.getPlugin().getDebugManager();
42+
43+
@Override
44+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
45+
if (!(sender instanceof Player)) {
46+
sender.sendMessage("Player only!");
47+
return true;
48+
}
49+
50+
Player player = (Player) sender;
51+
52+
if (args.length < 2) {
53+
this.sendUsage(player);
54+
return true;
55+
}
56+
57+
switch (args[1].toLowerCase()) {
58+
case "start": {
59+
this.debugManager.start(player, new BorderCollisionTest(player));
60+
break;
61+
}
62+
63+
case "stop": {
64+
this.debugManager.stop(player);
65+
break;
66+
}
67+
68+
default: {
69+
this.sendUsage(player);
70+
break;
71+
}
72+
}
73+
74+
return true;
75+
}
76+
77+
// TODO
78+
private void sendUsage(Player player) {
79+
player.sendMessage(ApolloComponent.toLegacy(Component.text()
80+
.append(Component.text("-------------------------------------", NamedTextColor.GRAY, TextDecoration.STRIKETHROUGH))
81+
.appendNewline()
82+
.append(Component.text("/apollodebug borders start", NamedTextColor.WHITE))
83+
.append(Component.text("# Starts spamming modsetting update packets to the client, delay is in milliseconds.", NamedTextColor.GREEN))
84+
.appendNewline()
85+
.append(Component.text("/apollodebug borders stop ", NamedTextColor.WHITE))
86+
.append(Component.text("# Stop spamming modsetting update packets to the client.", NamedTextColor.GREEN))
87+
.appendNewline()
88+
.append(Component.text("-------------------------------------", NamedTextColor.GRAY, TextDecoration.STRIKETHROUGH))
89+
.build()
90+
));
91+
}
92+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import com.lunarclient.apollo.common.ApolloComponent;
2727
import com.lunarclient.apollo.example.ApolloExamplePlugin;
28-
import com.lunarclient.apollo.example.debug.SpamPacketDebug;
28+
import com.lunarclient.apollo.example.debug.impl.SpamPacketDebug;
2929
import net.kyori.adventure.text.Component;
3030
import net.kyori.adventure.text.format.NamedTextColor;
3131
import net.kyori.adventure.text.format.TextDecoration;
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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;
25+
26+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
27+
import java.util.List;
28+
import org.bukkit.Bukkit;
29+
import org.bukkit.ChatColor;
30+
import org.bukkit.Location;
31+
import org.bukkit.World;
32+
import org.bukkit.entity.Player;
33+
import org.bukkit.event.HandlerList;
34+
import org.bukkit.event.Listener;
35+
36+
public abstract class Debug implements Listener {
37+
38+
public static final World DEBUG_WORLD = Bukkit.getWorld("world");
39+
40+
protected final Player player;
41+
42+
private List<DebugTask> steps;
43+
private int phase;
44+
protected boolean failed;
45+
46+
public Debug(Player player) {
47+
this.player = player;
48+
this.steps = this.steps();
49+
this.phase = 1;
50+
51+
Bukkit.getPluginManager().registerEvents(this, ApolloExamplePlugin.getPlugin());
52+
}
53+
54+
public abstract List<DebugTask> steps();
55+
56+
public abstract Location startingLocation();
57+
58+
public abstract double allowedOffset();
59+
60+
public void start() {
61+
this.player.teleport(this.startingLocation());
62+
63+
Bukkit.getScheduler().runTaskLater(
64+
ApolloExamplePlugin.getPlugin(),
65+
() -> this.nextStepOrEnd(), 20L
66+
);
67+
}
68+
69+
public void nextStepOrEnd() {
70+
if (this.steps.isEmpty()) {
71+
this.end(false);
72+
return;
73+
}
74+
75+
DebugTask activeTask = this.steps.remove(0);
76+
if (activeTask == null) {
77+
this.end(false);
78+
return;
79+
}
80+
81+
this.player.sendMessage("Phase " + ++this.phase);
82+
activeTask.run(this.player);
83+
84+
Bukkit.getScheduler().runTaskLater(
85+
ApolloExamplePlugin.getPlugin(),
86+
() -> this.nextStepOrEnd(), activeTask.getDurationTicks()
87+
);
88+
}
89+
90+
public void fail() {
91+
this.failed = true;
92+
this.player.sendMessage(ChatColor.RED + "Failed testing at phase " + this.phase);
93+
}
94+
95+
public void end(boolean forced) {
96+
if (forced) {
97+
this.player.sendMessage(ChatColor.DARK_RED + "Stopped testing...");
98+
} else if (this.failed) {
99+
this.player.sendMessage(ChatColor.RED + "Failed testing...");
100+
} else {
101+
this.player.sendMessage(ChatColor.GREEN + "Passed testing...");
102+
}
103+
104+
HandlerList.unregisterAll(this);
105+
DebugManager.getInstance().remove(this.player);
106+
}
107+
108+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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;
25+
26+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
27+
import java.util.HashMap;
28+
import java.util.Map;
29+
import java.util.UUID;
30+
import lombok.Getter;
31+
import org.bukkit.Bukkit;
32+
import org.bukkit.entity.Player;
33+
import org.bukkit.event.Listener;
34+
35+
public class DebugManager implements Listener {
36+
37+
@Getter
38+
private static DebugManager instance;
39+
40+
private final Map<UUID, Debug> players;
41+
42+
public DebugManager() {
43+
instance = this;
44+
45+
this.players = new HashMap<>();
46+
Bukkit.getPluginManager().registerEvents(this, ApolloExamplePlugin.getPlugin());
47+
}
48+
49+
public void remove(Player player) {
50+
this.players.remove(player.getUniqueId());
51+
}
52+
53+
public void start(Player player, Debug debug) {
54+
if (this.players.containsKey(player.getUniqueId())) {
55+
player.sendMessage("Already debugging!");
56+
return;
57+
}
58+
59+
this.players.put(player.getUniqueId(), debug);
60+
debug.start();
61+
62+
player.sendMessage("Starting debug!");
63+
}
64+
65+
public void stop(Player player) {
66+
Debug debug = this.players.remove(player.getUniqueId());
67+
68+
if (debug == null) {
69+
player.sendMessage("Not debugging!");
70+
return;
71+
}
72+
73+
debug.end(true);
74+
}
75+
76+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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;
25+
26+
import com.lunarclient.apollo.Apollo;
27+
import com.lunarclient.apollo.player.ApolloPlayer;
28+
import java.util.function.BiConsumer;
29+
import lombok.Getter;
30+
import lombok.RequiredArgsConstructor;
31+
import org.bukkit.entity.Player;
32+
33+
@Getter
34+
@RequiredArgsConstructor
35+
public class DebugTask {
36+
37+
private final int durationTicks;
38+
private final BiConsumer<Player, ApolloPlayer> action;
39+
private final String message;
40+
41+
public void run(Player player) {
42+
Apollo.getPlayerManager().getPlayer(player.getUniqueId())
43+
.ifPresent(apolloPlayer -> {
44+
player.sendMessage(this.message);
45+
this.action.accept(player, apolloPlayer);
46+
});
47+
}
48+
49+
}

0 commit comments

Comments
 (0)