mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-28 13:15:28 +01:00
Revert "Use local shooter"
This commit is contained in:
parent
3dad427398
commit
9a5c84f3fc
@ -1,5 +1,6 @@
|
|||||||
package fr.xephi.authme.listener;
|
package fr.xephi.authme.listener;
|
||||||
|
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -15,11 +16,22 @@ import org.bukkit.event.entity.FoodLevelChangeEvent;
|
|||||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||||
import org.bukkit.projectiles.ProjectileSource;
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static fr.xephi.authme.listener.ListenerService.shouldCancelEvent;
|
import static fr.xephi.authme.listener.ListenerService.shouldCancelEvent;
|
||||||
|
|
||||||
public class AuthMeEntityListener implements Listener {
|
public class AuthMeEntityListener implements Listener {
|
||||||
|
|
||||||
public AuthMeEntityListener() {}
|
private static Method getShooter;
|
||||||
|
private static boolean shooterIsProjectileSource;
|
||||||
|
|
||||||
|
public AuthMeEntityListener() {
|
||||||
|
try {
|
||||||
|
Method m = Projectile.class.getDeclaredMethod("getShooter");
|
||||||
|
shooterIsProjectileSource = m.getReturnType() != LivingEntity.class;
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO #360: npc status can be used to bypass security!!!
|
// TODO #360: npc status can be used to bypass security!!!
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||||
@ -84,12 +96,22 @@ public class AuthMeEntityListener implements Listener {
|
|||||||
|
|
||||||
Player player = null;
|
Player player = null;
|
||||||
Projectile projectile = event.getEntity();
|
Projectile projectile = event.getEntity();
|
||||||
if (projectile != null && (projectile.getShooter() instanceof ProjectileSource)) {
|
if (shooterIsProjectileSource) {
|
||||||
ProjectileSource shooter = projectile.getShooter();
|
ProjectileSource shooter = projectile.getShooter();
|
||||||
if (shooter == null || !(shooter instanceof Player)) {
|
if (shooter == null || !(shooter instanceof Player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player = (Player) shooter;
|
player = (Player) shooter;
|
||||||
|
} else {
|
||||||
|
// TODO ljacqu 20151220: Invoking getShooter() with null but method isn't static
|
||||||
|
try {
|
||||||
|
if (getShooter == null) {
|
||||||
|
getShooter = Projectile.class.getMethod("getShooter");
|
||||||
|
}
|
||||||
|
Object obj = getShooter.invoke(null);
|
||||||
|
player = (Player) obj;
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ListenerService.shouldCancelEvent(player)) {
|
if (ListenerService.shouldCancelEvent(player)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user