Throwing snowball still possible when unlogged

This commit is contained in:
ljacqu 2016-05-30 17:09:10 +02:00
parent 4c51b33b22
commit cc67624a46

View File

@ -25,14 +25,15 @@ import static fr.xephi.authme.listener.ListenerService.shouldCancelEvent;
public class AuthMeEntityListener implements Listener { public class AuthMeEntityListener implements Listener {
private static Method getShooter; private Method getShooter;
private static boolean shooterIsProjectileSource; private boolean shooterIsProjectileSource;
public AuthMeEntityListener() { public AuthMeEntityListener() {
try { try {
Method m = Projectile.class.getDeclaredMethod("getShooter"); getShooter = Projectile.class.getDeclaredMethod("getShooter");
shooterIsProjectileSource = m.getReturnType() != LivingEntity.class; shooterIsProjectileSource = getShooter.getReturnType() != LivingEntity.class;
} catch (Exception ignored) { } catch (NoSuchMethodException | SecurityException e) {
ConsoleLogger.logException("Cannot load getShooter() method on Projectile class", e);
} }
} }
@ -90,7 +91,7 @@ public class AuthMeEntityListener implements Listener {
} }
} }
// In old versions of the Bukkit API getShooter() returns a Player Object instead of a ProjectileSource // TODO #733: Player can't throw snowball but the item is taken.
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onProjectileLaunch(ProjectileLaunchEvent event) { public void onProjectileLaunch(ProjectileLaunchEvent event) {
if (event.getEntity() == null) { if (event.getEntity() == null) {
@ -99,6 +100,7 @@ public class AuthMeEntityListener implements Listener {
Player player = null; Player player = null;
Projectile projectile = event.getEntity(); Projectile projectile = event.getEntity();
// In old versions of the Bukkit API getShooter() returns a Player object instead of a ProjectileSource
if (shooterIsProjectileSource) { if (shooterIsProjectileSource) {
ProjectileSource shooter = projectile.getShooter(); ProjectileSource shooter = projectile.getShooter();
if (shooter == null || !(shooter instanceof Player)) { if (shooter == null || !(shooter instanceof Player)) {