mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-28 18:31:24 +01:00
Spaces.
This commit is contained in:
parent
5dd5f8b87c
commit
3f515cc616
@ -15,63 +15,63 @@ import org.bukkit.entity.Projectile;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class BridgeMisc {
|
public class BridgeMisc {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a shooter of a projectile if we get an entity, null otherwise.
|
* Return a shooter of a projectile if we get an entity, null otherwise.
|
||||||
*/
|
*/
|
||||||
public static Player getShooterPlayer(Projectile projectile) {
|
public static Player getShooterPlayer(Projectile projectile) {
|
||||||
Object source;
|
Object source;
|
||||||
try {
|
try {
|
||||||
source = projectile.getClass().getMethod("getShooter").invoke(projectile);
|
source = projectile.getClass().getMethod("getShooter").invoke(projectile);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return null;
|
return null;
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
return null;
|
return null;
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
return null;
|
return null;
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
return null;
|
return null;
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (source instanceof Player) {
|
if (source instanceof Player) {
|
||||||
return (Player) source;
|
return (Player) source;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a player from projectiles or cast to player, if possible.
|
* Retrieve a player from projectiles or cast to player, if possible.
|
||||||
* @param damager
|
* @param damager
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Player getAttackingPlayer(Entity damager) {
|
public static Player getAttackingPlayer(Entity damager) {
|
||||||
if (damager instanceof Player) {
|
if (damager instanceof Player) {
|
||||||
return (Player) damager;
|
return (Player) damager;
|
||||||
} else if (damager instanceof Projectile) {
|
} else if (damager instanceof Projectile) {
|
||||||
return getShooterPlayer((Projectile) damager);
|
return getShooterPlayer((Projectile) damager);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get online players as an array (convenience for reducing IDE markers :p).
|
* Get online players as an array (convenience for reducing IDE markers :p).
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Player[] getOnlinePlayers() {
|
public static Player[] getOnlinePlayers() {
|
||||||
Object obj = Bukkit.getOnlinePlayers();
|
Object obj = Bukkit.getOnlinePlayers();
|
||||||
if (obj instanceof Collection<?>) {
|
if (obj instanceof Collection<?>) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Collection<? extends Player> players = (Collection<? extends Player>) obj;
|
Collection<? extends Player> players = (Collection<? extends Player>) obj;
|
||||||
return players.toArray(new Player[players.size()]);
|
return players.toArray(new Player[players.size()]);
|
||||||
}
|
}
|
||||||
else if (obj instanceof Player[]) {
|
else if (obj instanceof Player[]) {
|
||||||
return (Player[]) obj;
|
return (Player[]) obj;
|
||||||
} else {
|
} else {
|
||||||
return new Player[0];
|
return new Player[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user