Just use instanceof

This commit is contained in:
Jesse Boyd 2019-04-11 02:17:45 +10:00
parent f0d646a9a1
commit 2e1b7676eb
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 8 additions and 11 deletions

View File

@ -74,17 +74,10 @@ public abstract class FawePlayer<T> extends Metadatable {
} }
if (obj instanceof Player) { if (obj instanceof Player) {
Player actor = LocationMaskedPlayerWrapper.unwrap((Player) obj); Player actor = LocationMaskedPlayerWrapper.unwrap((Player) obj);
if (obj.getClass().getName().endsWith("PlayerProxy")) { if (obj instanceof PlayerProxy) {
try { Player player = ((PlayerProxy) obj).getBasePlayer();
Field fieldBasePlayer = actor.getClass().getDeclaredField("basePlayer"); FawePlayer<Object> result = wrap(player);
fieldBasePlayer.setAccessible(true); return (FawePlayer<V>) (result == null ? wrap(player.getName()) : result);
Player player = (Player) fieldBasePlayer.get(actor);
FawePlayer<Object> result = wrap(player);
return (FawePlayer<V>) (result == null ? wrap(player.getName()) : result);
} catch (Throwable e) {
MainUtil.handleError(e);
return Fawe.imp().wrap(actor.getName());
}
} else if (obj instanceof PlayerWrapper) { } else if (obj instanceof PlayerWrapper) {
return wrap(((PlayerWrapper) obj).getParent()); return wrap(((PlayerWrapper) obj).getParent());
} else { } else {

View File

@ -189,5 +189,9 @@ public class PlayerProxy extends AbstractPlayerActor {
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) { public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
basePlayer.sendFakeBlock(pos, block); basePlayer.sendFakeBlock(pos, block);
} }
public Player getBasePlayer() {
return basePlayer;
}
} }