-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix support with new versions of ProtocolLib
- Loading branch information
Showing
1 changed file
with
23 additions
and
16 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,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; | ||
} | ||
} |