Skip to content

Commit

Permalink
Fix support with new versions of ProtocolLib
Browse files Browse the repository at this point in the history
  • Loading branch information
Leymooo committed Mar 27, 2021
1 parent b60109c commit a11cb25
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/main/java/ru/leymooo/fixer/utils/PlayerUtils.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
package ru.leymooo.fixer.utils;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import com.comphenix.net.sf.cglib.proxy.Factory;
import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;


public class PlayerUtils {

private static boolean isNewProtocolLib = false;

private static boolean isNewestProtocolLib = true;

static {
try {
Class.forName("com.comphenix.protocol.injector.server.TemporaryPlayer");
isNewProtocolLib = true;
} catch (ClassNotFoundException e) {}
} catch (ClassNotFoundException e) {
}
try {
Class.forName("com.comphenix.net.sf.cglib.proxy.Factory");
isNewestProtocolLib = false;
} catch (ClassNotFoundException e) {

}
}

public static Player getPlayerFromEvent(PacketEvent event) {
Player eventPlayer = event.getPlayer();

if (eventPlayer == null || !eventPlayer.isOnline()) return null;

if (isNewProtocolLib && event.isPlayerTemporary()) return null;

String playerName = eventPlayer.getName();
if (playerName == null ) return null;

if (playerName == null) return null;

Player bukkitPlayer = Bukkit.getPlayerExact(playerName);
if (bukkitPlayer == null || !bukkitPlayer.isOnline() || bukkitPlayer instanceof Factory) return null;

if (bukkitPlayer == null || !bukkitPlayer.isOnline() || (!isNewestProtocolLib && bukkitPlayer instanceof Factory)) return null;

return bukkitPlayer;
}
}

0 comments on commit a11cb25

Please sign in to comment.