-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40ae1b6
commit 9f629cb
Showing
5 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...e/src/main/java/com/lunarclient/apollo/example/commands/debug/SpamPacketDebugCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
bukkit-example/src/main/java/com/lunarclient/apollo/example/debug/SpamPacketDebug.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters