Skip to content

Commit

Permalink
add spam packet debug command
Browse files Browse the repository at this point in the history
  • Loading branch information
vectrixdevelops committed Oct 13, 2024
1 parent 40ae1b6 commit 9f629cb
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bukkit-example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
plugins {
id("apollo.base-conventions")
id("apollo.shadow-conventions")
}

dependencies {
compileOnly(libs.bukkit.api)

// Used for Proto Implementation
api(libs.protobuf)

// Used for Proto & Json Implementation
api(libs.bundles.adventure) {
exclude("org.checkerframework")
exclude("net.kyori", "adventure-api")
exclude("net.kyori", "adventure-bom")
}

// Used for API Implementation
compileOnly(project(":extra:apollo-extra-adventure4"))
compileOnly(project(path = ":apollo-api", configuration = "bukkit"))
compileOnly(project(path = ":apollo-common", configuration = "shadow"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import com.lunarclient.apollo.example.commands.TransferCommand;
import com.lunarclient.apollo.example.commands.VignetteCommand;
import com.lunarclient.apollo.example.commands.WaypointCommand;
import com.lunarclient.apollo.example.commands.debug.SpamPacketDebugCommand;
import com.lunarclient.apollo.example.debug.SpamPacketDebug;
import com.lunarclient.apollo.example.listeners.PlayerListener;
import com.lunarclient.apollo.example.modules.BeamExample;
import com.lunarclient.apollo.example.modules.BorderExample;
Expand Down Expand Up @@ -110,6 +112,8 @@ public class ApolloExamplePlugin extends JavaPlugin {
private VignetteExample vignetteExample;
private WaypointExample waypointExample;

private SpamPacketDebug spamPacketDebug;

@Override
public void onEnable() {
plugin = this;
Expand Down Expand Up @@ -150,6 +154,8 @@ private void registerModuleExamples() {
this.transferExample = new TransferExample();
this.vignetteExample = new VignetteExample();
this.waypointExample = new WaypointExample();

this.spamPacketDebug = new SpamPacketDebug();
}

private void registerCommands() {
Expand Down Expand Up @@ -178,6 +184,8 @@ private void registerCommands() {
this.getCommand("transfer").setExecutor(new TransferCommand());
this.getCommand("vignette").setExecutor(new VignetteCommand());
this.getCommand("waypoint").setExecutor(new WaypointCommand());

this.getCommand("spampacketdebug").setExecutor(new SpamPacketDebugCommand());
}

private void registerListeners() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2023 Moonsworth
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.lunarclient.apollo.example.commands.debug;

import com.lunarclient.apollo.example.ApolloExamplePlugin;
import com.lunarclient.apollo.example.debug.SpamPacketDebug;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class SpamPacketDebugCommand implements CommandExecutor {

private final SpamPacketDebug spamPacketDebug = ApolloExamplePlugin.getPlugin().getSpamPacketDebug();

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Player only!");
return true;
}

Player player = (Player) sender;

if (args.length != 1) {
player.sendMessage("Usage: /spampacketdebug <start|pause|stop>");
return true;
}

switch (args[0].toLowerCase()) {
case "start": {
this.spamPacketDebug.start(player);
player.sendMessage("Debug started.");
break;
}

case "pause": {
this.spamPacketDebug.pause(player);
player.sendMessage("Debug paused.");
break;
}

case "stop": {
this.spamPacketDebug.stop();
player.sendMessage("Debug stopped.");
break;
}

default: {
player.sendMessage("Usage: /spampacketdebug <start|pause|stop>");
break;
}
}

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2023 Moonsworth
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.lunarclient.apollo.example.debug;

import com.google.common.collect.Sets;
import com.lunarclient.apollo.Apollo;
import com.lunarclient.apollo.example.ApolloExamplePlugin;
import com.lunarclient.apollo.network.NetworkOptions;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;

public class SpamPacketDebug implements Listener {

private final Set<UUID> players = Sets.newConcurrentHashSet();

private final SpamPacketTask debug;

public SpamPacketDebug() {
this.debug = new SpamPacketTask();

Bukkit.getPluginManager().registerEvents(this, ApolloExamplePlugin.getPlugin());
}

@EventHandler
private void onPlayerQuit(PlayerQuitEvent event) {
this.pause(event.getPlayer());
}

public void start(Player player) {
this.players.add(player.getUniqueId());

if(!this.debug.running) {
this.debug.start();
}
}

public void pause(Player player) {
this.players.remove(player.getUniqueId());
}

public void stop() {
this.players.clear();
}

public class SpamPacketTask implements Runnable {
private boolean running;

public void start() {
this.running = true;

Thread debugThread = new Thread(this);
debugThread.setDaemon(true);
debugThread.start();
}

@Override
public void run() {
while (this.running) {
Set<UUID> players = SpamPacketDebug.this.players;
if (players.isEmpty()) {
this.running = false;
}

for (UUID uuid : players) {
Apollo.getPlayerManager().getPlayer(uuid)
.ifPresent(apolloPlayer -> NetworkOptions.sendOptions(Apollo.getModuleManager().getModules(), true, apolloPlayer));
}

try {
Thread.sleep(10); // Runs every 10 milliseconds
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
}
}
}
2 changes: 2 additions & 0 deletions bukkit-example/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ commands:
description: "Vignette!"
waypoint:
description: "Waypoints!"
spampacketdebug:
description: "Spam Packet Debug!"

0 comments on commit 9f629cb

Please sign in to comment.