Skip to content

Commit 0024743

Browse files
committed
Updated: PacketEvents to replace ProtocolLib
This makes the packet handling code easier to maintain. This also fixes an issue where inventory items would be invisible, which was caused by WINDOW_ITEMS setting null or continuing when it should have set the unmodified item stack back to the slot. This whole system is mostly kept for compatibility with old configs.
1 parent e949306 commit 0024743

File tree

13 files changed

+94
-1646
lines changed

13 files changed

+94
-1646
lines changed

modules/RoyalCommands/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@
256256
<scope>test</scope>
257257
</dependency>
258258
<dependency>
259-
<groupId>net.dmulloy2</groupId>
260-
<artifactId>ProtocolLib</artifactId>
261-
<version>5.4.0</version>
259+
<groupId>com.github.retrooper</groupId>
260+
<artifactId>packetevents-spigot</artifactId>
261+
<version>2.9.5</version>
262262
<scope>provided</scope>
263263
</dependency>
264264
<dependency>

modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/Config.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class Config {
7070
public static boolean useAdminMotd;
7171
public static boolean useCustomDeath;
7272
public static boolean useFirstJoinMotd;
73-
public static boolean useProtocolLib;
73+
public static boolean usePacketevents;
7474
public static boolean useVNP;
7575
public static boolean useWelcome;
7676
public static boolean useWhitelist;
@@ -245,8 +245,8 @@ public void reloadConfiguration() {
245245
updateOldUserdata = c.getBoolean("userdata.update_old", true);
246246
useAdminMotd = c.getBoolean("motd.options.use_first_join_motd", true);
247247
useCustomDeath = c.getBoolean("deathmessages.enabled", true);
248+
usePacketevents = c.getBoolean("items.spawn.tag.plugins.packetevents", true);
248249
useFirstJoinMotd = c.getBoolean("motd.options.use_first_join_motd", true);
249-
useProtocolLib = c.getBoolean("items.spawn.tag.plugins.protocollib", true);
250250
useVNP = c.getBoolean("plugins.use_vanish", true);
251251
useWelcome = c.getBoolean("messages.options.enable_welcome_message", true);
252252
useWhitelist = c.getBoolean("whitelist.enabled", false);

modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/RoyalCommands.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.royaldev.royalcommands;
77

8+
import com.github.retrooper.packetevents.PacketEvents;
89
import com.google.common.base.Charsets;
910
import com.griefcraft.lwc.LWCPlugin;
1011
import org.mvplugins.multiverse.core.MultiverseCore;
@@ -13,6 +14,8 @@
1314
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
1415
import com.sk89q.worldguard.protection.flags.Flags;
1516
import com.sk89q.worldguard.protection.regions.RegionQuery;
17+
18+
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
1619
import me.clip.placeholderapi.PlaceholderAPIPlugin;
1720
import org.bukkit.Bukkit;
1821
import org.bukkit.block.Block;
@@ -94,7 +97,7 @@ public class RoyalCommands extends JavaPlugin {
9497
private VanishPlugin vp = null;
9598
private WorldGuardPlugin wg = null;
9699
private LWCPlugin lwc = null;
97-
public PlaceholderAPIPlugin pa = null;
100+
public PlaceholderAPIPlugin pa = null;
98101
private ProtocolListener pl = null;
99102

100103
/**
@@ -406,6 +409,20 @@ public void loadConfiguration() {
406409
}
407410
}
408411

412+
@Override
413+
public void onLoad() {
414+
415+
//-- packetevents --//
416+
417+
final Plugin pePlugin = this.getServer().getPluginManager().getPlugin("packetevents");
418+
// If packetevents exists, load it, even if our config file tells us not to use it later
419+
if (pePlugin != null && pePlugin.isEnabled()) {
420+
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
421+
PacketEvents.getAPI().load();
422+
}
423+
424+
}
425+
409426
@Override
410427
public void onDisable() {
411428

@@ -424,7 +441,7 @@ public void onDisable() {
424441
Configuration.saveAllConfigurations();
425442
this.getLogger().info("Userdata saved.");
426443

427-
//-- ProtocolLib --//
444+
//-- packetevents --//
428445

429446
if (this.pl != null) this.pl.uninitialize();
430447

@@ -511,10 +528,10 @@ public void onEnable() {
511528
pm.registerEvents(new InventoryGUIEventListener(), this);
512529
pm.registerEvents(new DeathListener(this), this);
513530

514-
//-- ProtocolLib things --//
531+
//-- packetevents things --//
515532

516-
final Plugin plPlugin = this.getServer().getPluginManager().getPlugin("ProtocolLib");
517-
if (Config.useProtocolLib && plPlugin != null && plPlugin.isEnabled()) {
533+
final Plugin pePlugin = this.getServer().getPluginManager().getPlugin("packetevents");
534+
if (Config.usePacketevents && pePlugin != null && pePlugin.isEnabled()) {
518535
this.pl = new ProtocolListener(this);
519536
this.pl.initialize();
520537
}

0 commit comments

Comments
 (0)