Skip to content

Commit

Permalink
Spaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Nov 30, 2014
1 parent 5dd5f8b commit 3f515cc
Showing 1 changed file with 58 additions and 58 deletions.
Expand Up @@ -15,63 +15,63 @@
*
*/
public class BridgeMisc {
/**
* Return a shooter of a projectile if we get an entity, null otherwise.
*/
public static Player getShooterPlayer(Projectile projectile) {
Object source;
try {
source = projectile.getClass().getMethod("getShooter").invoke(projectile);
} catch (IllegalArgumentException e) {
return null;
} catch (SecurityException e) {
return null;
} catch (IllegalAccessException e) {
return null;
} catch (InvocationTargetException e) {
return null;
} catch (NoSuchMethodException e) {
return null;
}
if (source instanceof Player) {
return (Player) source;
} else {
return null;
}
}
/**
* Retrieve a player from projectiles or cast to player, if possible.
* @param damager
* @return
*/
public static Player getAttackingPlayer(Entity damager) {
if (damager instanceof Player) {
return (Player) damager;
} else if (damager instanceof Projectile) {
return getShooterPlayer((Projectile) damager);
} else {
return null;
}
}
/**
* Get online players as an array (convenience for reducing IDE markers :p).
* @return
*/
public static Player[] getOnlinePlayers() {
Object obj = Bukkit.getOnlinePlayers();
if (obj instanceof Collection<?>) {
@SuppressWarnings("unchecked")

/**
* Return a shooter of a projectile if we get an entity, null otherwise.
*/
public static Player getShooterPlayer(Projectile projectile) {
Object source;
try {
source = projectile.getClass().getMethod("getShooter").invoke(projectile);
} catch (IllegalArgumentException e) {
return null;
} catch (SecurityException e) {
return null;
} catch (IllegalAccessException e) {
return null;
} catch (InvocationTargetException e) {
return null;
} catch (NoSuchMethodException e) {
return null;
}
if (source instanceof Player) {
return (Player) source;
} else {
return null;
}
}

/**
* Retrieve a player from projectiles or cast to player, if possible.
* @param damager
* @return
*/
public static Player getAttackingPlayer(Entity damager) {
if (damager instanceof Player) {
return (Player) damager;
} else if (damager instanceof Projectile) {
return getShooterPlayer((Projectile) damager);
} else {
return null;
}
}

/**
* Get online players as an array (convenience for reducing IDE markers :p).
* @return
*/
public static Player[] getOnlinePlayers() {
Object obj = Bukkit.getOnlinePlayers();
if (obj instanceof Collection<?>) {
@SuppressWarnings("unchecked")
Collection<? extends Player> players = (Collection<? extends Player>) obj;
return players.toArray(new Player[players.size()]);
}
else if (obj instanceof Player[]) {
return (Player[]) obj;
} else {
return new Player[0];
}
}
return players.toArray(new Player[players.size()]);
}
else if (obj instanceof Player[]) {
return (Player[]) obj;
} else {
return new Player[0];
}
}

}

1 comment on commit 3f515cc

@johnnywoof
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space

Please sign in to comment.