Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-14 Implement packetevents #14

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions newbieprotection-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ dependencies {
implementation("net.megavex:scoreboard-library-api:$scoreboardLibraryVersion")
runtimeOnly("net.megavex:scoreboard-library-implementation:$scoreboardLibraryVersion")
runtimeOnly("net.megavex:scoreboard-library-packetevents:$scoreboardLibraryVersion")
compileOnly("com.github.retrooper:packetevents-spigot:2.5.0")

implementation("com.github.retrooper:packetevents-spigot:2.5.0")

// bStats system
implementation("org.bstats:bstats-bukkit:3.0.2")
Expand Down Expand Up @@ -86,7 +87,6 @@ bukkit {
name = "ptrlNewbieProtection"
author = "Piotrulla"
apiVersion = "1.13"
softDepend = listOf("PacketEvents")
}

tasks {
Expand All @@ -109,6 +109,8 @@ tasks.withType<ShadowJar> {
val prefix = "dev.piotrulla.newbieprotection.shared"

listOf(
"com.github.retrooper",
"io.github.retrooper",
"com.eternalcode",
"dev.rollczi",
"eu.okaeri",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.eternalcode.commons.adventure.AdventureLegacyColorPreProcessor;
import com.eternalcode.commons.adventure.AdventureUrlPostProcessor;
import com.eternalcode.multification.shared.Formatter;
import com.github.retrooper.packetevents.PacketEvents;
import dev.piotrulla.newbieprotection.configuration.ConfigService;
import dev.piotrulla.newbieprotection.configuration.implementation.CommandConfiguration;
import dev.piotrulla.newbieprotection.configuration.implementation.MessagesConfiguration;
Expand All @@ -18,6 +19,7 @@
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
import dev.rollczi.litecommands.meta.Meta;
import dev.rollczi.litecommands.schematic.Schematic;
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
import net.kyori.adventure.platform.AudienceProvider;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand All @@ -42,6 +44,15 @@ public class NewbieProtectionPlugin extends JavaPlugin {

private LiteCommands<CommandSender> liteCommands;

@Override
public void onLoad() {
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
PacketEvents.getAPI().getSettings().reEncodeByDefault(false)
.checkForUpdates(false)
.bStats(false);
PacketEvents.getAPI().load();
}

@Override
public void onEnable() {
ConfigService configService = new ConfigService();
Expand All @@ -68,7 +79,7 @@ public void onEnable() {
if (configuration.nameTag.enabled) {
try {
this.scoreboardLibrary = ScoreboardLibrary.loadScoreboardLibrary(this);
System.out.println("Scoreboard library loaded");
this.getLogger().info("Scoreboard library loaded");
}
catch (NoPacketAdapterAvailableException ignored) {
this.scoreboardLibrary = new NoopScoreboardLibrary();
Expand Down Expand Up @@ -161,6 +172,7 @@ public void onEnable() {

@Override
public void onDisable() {
PacketEvents.getAPI().terminate();
this.scoreboardLibrary.close();
this.audienceProvider.close();
this.liteCommands.unregister();
Expand Down