The manager is always null :( (Please help me , i have a family)
sussolinoss opened this issue · 2 comments
Discussed in #2520
Originally posted by sussolinoss August 25, 2023
Main Class:
public final class JuicePvPAC extends JavaPlugin {
public static JuicePvPAC plugin;
public static String prefix = Verbose.color("&6『&eVanessa&6』&7>> &f");
public void onEnable() {
plugin = this;
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) {
ProtocolLibHook.register();
}
}
}
ProtocolLib Hook:
public final class ProtocolLibHook {
public static void register() {
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
if (manager != null) {
manager.addPacketListener(new PacketAdapter(JuicePvPAC.plugin, PacketType.Play.Client.USE_ENTITY) {
@OverRide
public void onPacketReceiving(PacketEvent e) {
if (e.getPacketType() == PacketType.Play.Client.USE_ENTITY) {
PacketContainer packet = e.getPacket();
UUID id = packet.getUUIDs().read(0);
Entity t = Bukkit.getEntity(id);
Player p = e.getPlayer();
double x = packet.getDoubles().read(0);
double y = packet.getDoubles().read(1);
double z = packet.getDoubles().read(2);
Location pLoc = new Location(p.getWorld(), x, y, z);
if (t != null) {
Location tLoc = t.getLocation();
controlCheck(p, pLoc, tLoc);
}
}
}
private void controlCheck(Player suspect, Location p, Location t) {
double distance = p.distance(t);
Verbose.debug("Distance: " + distance);
if (distance <= 3) {
Verbose.debug("Flag [OK] distance = " + distance);
} else if (distance >= 3.3 && distance <= 3.50) {
Verbose.verbose(suspect, "Reach [C]");
} else if (distance >= 3.50 && distance < 4) {
Verbose.verbose(suspect, "Reach [B]");
} else if (distance >= 4) {
Verbose.verbose(suspect, "Reach [A]");
}
}
}
);
} else {
getLogger().warning("(!) ProtocolLib non si è caricato (!)");
}
}
}
Hi,
the problem probably is that you include a Copy of ProtocolLib in your plugin. This is not supported as this copy won't be initialized correctly resulting in the issue you describe.
To fix this, you need to modify your build script:
Maven: Add <scope>provided</scope>
to the ProtocolLib Dependecy.
Gradle: Change the scope of the ProtocolLib dependency from implementation('...')
to compileOnly('..')
Another cause for this could be an error in the initialization of ProtocolLib. Please also check your log for any Exceptions related to ProtocolLib.
Hi,
the problem probably is that you include a Copy of ProtocolLib in your plugin. This is not supported as this copy won't be initialized correctly resulting in the issue you describe.
To fix this, you need to modify your build script:
Maven: Add
<scope>provided</scope>
to the ProtocolLib Dependecy. Gradle: Change the scope of the ProtocolLib dependency fromimplementation('...')
tocompileOnly('..')
Another cause for this could be an error in the initialization of ProtocolLib. Please also check your log for any Exceptions related to ProtocolLib.
Ye the scope is the problem....
Thank you :).