org.bukkit.entity.EnderDragonPart Java Examples

The following examples show how to use org.bukkit.entity.EnderDragonPart. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EffKill.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(final Event e) {
	for (Entity entity : entities.getArray(e)) {

		if (entity instanceof EnderDragonPart) {
			entity = ((EnderDragonPart) entity).getParent();
		}

		if (entity instanceof Damageable) {
			final boolean creative = entity instanceof Player && ((Player) entity).getGameMode() == GameMode.CREATIVE;
			if (creative) // Set player to survival before applying damage
				((Player) entity).setGameMode(GameMode.SURVIVAL);

			HealthUtils.damage((Damageable) entity, HealthUtils.getMaxHealth((Damageable) entity) * 100); // just to make sure that it really dies >:)

			if (creative) // Set creative player back to creative
				((Player) entity).setGameMode(GameMode.CREATIVE);
		}

		// if everything done so far has failed to kill this thing
		// We also don't want to remove a player as this would remove the player's data from the server.
		if (entity.isValid() && !(entity instanceof Player))
			entity.remove();
		
	}
}