org.bukkit.entity.IronGolem Java Examples
The following examples show how to use
org.bukkit.entity.IronGolem.
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: GolemListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onGolemDeath(EntityDeathEvent event) { if (!(event.getEntity() instanceof IronGolem)) { return; } IronGolem ironGolem = (IronGolem) event.getEntity(); for (String name : Main.getGameNames()) { Game game = Main.getGame(name); if ((game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) && ironGolem.getWorld().equals(game.getGameWorld())) { List<SpecialItem> golems = game.getActivedSpecialItems(Golem.class); for (SpecialItem item : golems) { if (item instanceof Golem) { Golem golem = (Golem) item; if (golem.getEntity().equals(ironGolem)) { event.getDrops().clear(); } } } } } }
Example #2
Source File: GolemListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onGolemDeath(EntityDeathEvent event) { if (!(event.getEntity() instanceof IronGolem)) { return; } IronGolem ironGolem = (IronGolem) event.getEntity(); for (String name : Main.getGameNames()) { Game game = Main.getGame(name); if ((game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) && ironGolem.getWorld().equals(game.getGameWorld())) { List<SpecialItem> golems = game.getActivedSpecialItems(Golem.class); for (SpecialItem item : golems) { if (item instanceof Golem) { Golem golem = (Golem) item; if (golem.getEntity().equals(ironGolem)) { event.getDrops().clear(); } } } } } }
Example #3
Source File: MobListener.java From civcraft with GNU General Public License v2.0 | 6 votes |
@EventHandler(priority = EventPriority.NORMAL) public void onChunkLoad(ChunkLoadEvent event) { for (Entity e : event.getChunk().getEntities()) { if (e instanceof Monster) { e.remove(); return; } if (e instanceof IronGolem) { e.remove(); return; } } }
Example #4
Source File: TestIronGolemListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private PlayerInteractEntityEvent callIronGolemEvent(EquipmentSlot hand, ItemStack itemInHand) { // Fake Player with an Iron Ingot Player player = server.addPlayer(); if (hand == EquipmentSlot.HAND) { player.getInventory().setItemInMainHand(itemInHand); } else { player.getInventory().setItemInOffHand(itemInHand); } // Fake Iron Golem IronGolem golem = Mockito.mock(IronGolem.class); Mockito.when(golem.getType()).thenReturn(EntityType.IRON_GOLEM); // Fake Event PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, golem, hand); listener.onIronGolemHeal(event); return event; }
Example #5
Source File: GolemListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onGolemTargetDie(PlayerDeathEvent event) { if (Main.isPlayerInGame(event.getEntity())) { Game game = Main.getPlayerGameProfile(event.getEntity()).getGame(); List<SpecialItem> golems = game.getActivedSpecialItems(Golem.class); for (SpecialItem item : golems) { Golem golem = (Golem) item; IronGolem iron = (IronGolem) golem.getEntity(); if (iron.getTarget() != null && iron.getTarget().equals(event.getEntity())) { iron.setTarget(null); } } } }
Example #6
Source File: Golem.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
public void spawn() { final TeamColor color = TeamColor.fromApiColor(team.getColor()); final IronGolem golem = (IronGolem) location.getWorld().spawnEntity(location, EntityType.IRON_GOLEM); golem.setHealth(health); golem.setCustomName(name .replace("%teamcolor%", color.chatColor.toString()) .replace("%team%", team.getName())); golem.setCustomNameVisible(showName); try { golem.setInvulnerable(false); } catch (Throwable ignored) { // Still can throw an exception on some old versions } entity = golem; EntityUtils.makeMobAttackTarget(golem, speed, followRange, -1) .getTargetSelector() .attackNearestTarget(0, "EntityPlayer"); game.registerSpecialItem(this); Main.registerGameEntity(golem, (org.screamingsandals.bedwars.game.Game) game); MiscUtils.sendActionBarMessage(player, i18nonly("specials_golem_created")); //TODO - make this better by checking full inventory if (item.getAmount() > 1) { item.setAmount(item.getAmount() - 1); } else { player.getInventory().remove(item); } player.updateInventory(); }
Example #7
Source File: GolemListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onGolemTargetDie(PlayerDeathEvent event) { if (Main.isPlayerInGame(event.getEntity())) { Game game = Main.getPlayerGameProfile(event.getEntity()).getGame(); List<SpecialItem> golems = game.getActivedSpecialItems(Golem.class); for (SpecialItem item : golems) { Golem golem = (Golem) item; IronGolem iron = (IronGolem) golem.getEntity(); if (iron.getTarget() != null && iron.getTarget().equals(event.getEntity())) { iron.setTarget(null); } } } }
Example #8
Source File: Golem.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
public void spawn() { final TeamColor color = TeamColor.fromApiColor(team.getColor()); final IronGolem golem = (IronGolem) location.getWorld().spawnEntity(location, EntityType.IRON_GOLEM); golem.setHealth(health); golem.setCustomName(name .replace("%teamcolor%", color.chatColor.toString()) .replace("%team%", team.getName())); golem.setCustomNameVisible(showName); try { golem.setInvulnerable(false); } catch (Throwable ignored) { // Still can throw an exception on some old versions } entity = golem; EntityUtils.makeMobAttackTarget(golem, speed, followRange, -1) .getTargetSelector() .attackNearestTarget(0, "EntityPlayer"); game.registerSpecialItem(this); Main.registerGameEntity(golem, (org.screamingsandals.bedwars.game.Game) game); MiscUtils.sendActionBarMessage(player, i18nonly("specials_golem_created")); //TODO - make this better by checking full inventory if (item.getAmount() > 1) { item.setAmount(item.getAmount() - 1); } else { player.getInventory().remove(item); } player.updateInventory(); }
Example #9
Source File: AggroPrevention.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onTarget(EntityTargetLivingEntityEvent event) { if (EntityTracker.isEliteMob(event.getEntity()) && event.getTarget() != null && EntityTracker.isEliteMob(event.getTarget()) && !(event.getTarget() instanceof IronGolem) && !(event.getEntity() instanceof IronGolem)) event.setCancelled(true); }
Example #10
Source File: GolemListener.java From BedWars with GNU Lesser General Public License v3.0 | 4 votes |
@EventHandler public void onGolemTarget(EntityTargetEvent event) { if (!(event.getEntity() instanceof IronGolem)) { return; } IronGolem ironGolem = (IronGolem) event.getEntity(); for (String name : Main.getGameNames()) { Game game = Main.getGame(name); if ((game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) && ironGolem.getWorld().equals(game.getGameWorld())) { List<SpecialItem> golems = game.getActivedSpecialItems(Golem.class); for (SpecialItem item : golems) { if (item instanceof Golem) { Golem golem = (Golem) item; if (golem.getEntity().equals(ironGolem)) { if (event.getTarget() instanceof Player) { final Player player = (Player) event.getTarget(); if (game.isProtectionActive(player)) { event.setCancelled(true); return; } if (Main.isPlayerInGame(player)) { if (golem.getTeam() == game.getTeamOfPlayer(player)) { event.setCancelled(true); // Try to find enemy Player playerTarget = MiscUtils.findTarget(game, player, golem.getFollowRange()); if (playerTarget != null) { // Oh. We found enemy! ironGolem.setTarget(playerTarget); return; } } } } } } } } } }
Example #11
Source File: GolemListener.java From BedWars with GNU Lesser General Public License v3.0 | 4 votes |
@EventHandler public void onGolemTarget(EntityTargetEvent event) { if (!(event.getEntity() instanceof IronGolem)) { return; } IronGolem ironGolem = (IronGolem) event.getEntity(); for (String name : Main.getGameNames()) { Game game = Main.getGame(name); if ((game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) && ironGolem.getWorld().equals(game.getGameWorld())) { List<SpecialItem> golems = game.getActivedSpecialItems(Golem.class); for (SpecialItem item : golems) { if (item instanceof Golem) { Golem golem = (Golem) item; if (golem.getEntity().equals(ironGolem)) { if (event.getTarget() instanceof Player) { final Player player = (Player) event.getTarget(); if (game.isProtectionActive(player)) { event.setCancelled(true); return; } if (Main.isPlayerInGame(player)) { if (golem.getTeam() == game.getTeamOfPlayer(player)) { event.setCancelled(true); // Try to find enemy Player playerTarget = MiscUtils.findTarget(game, player, golem.getFollowRange()); if (playerTarget != null) { // Oh. We found enemy! ironGolem.setTarget(playerTarget); return; } } } } } } } } } }
Example #12
Source File: IslandGuard1_9.java From askyblock with GNU General Public License v2.0 | 4 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onLingeringPotionDamage(final EntityDamageByEntityEvent e) { if (!IslandGuard.inWorld(e.getEntity().getLocation())) { return; } if (e.getEntity() == null || e.getEntity().getUniqueId() == null) { return; } if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) { UUID attacker = thrownPotions.get(e.getDamager().getEntityId()); // Self damage if (attacker.equals(e.getEntity().getUniqueId())) { return; } Island island = plugin.getGrid().getIslandAt(e.getEntity().getLocation()); boolean inNether = false; if (e.getEntity().getWorld().equals(ASkyBlock.getNetherWorld())) { inNether = true; } // Monsters being hurt if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime || e.getEntity() instanceof Squid) { // Normal island check if (island != null && island.getMembers().contains(attacker)) { // Members always allowed return; } if (actionAllowed(attacker, e.getEntity().getLocation(), SettingsFlag.HURT_MONSTERS)) { return; } // Not allowed e.setCancelled(true); return; } // Mobs being hurt if (e.getEntity() instanceof Animals || e.getEntity() instanceof IronGolem || e.getEntity() instanceof Snowman || e.getEntity() instanceof Villager) { if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker))) { return; } e.setCancelled(true); return; } // Establish whether PVP is allowed or not. boolean pvp = false; if ((inNether && island != null && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island != null && island.getIgsFlag(SettingsFlag.PVP)))) { pvp = true; } // Players being hurt PvP if (e.getEntity() instanceof Player) { if (pvp) { } else { e.setCancelled(true); } } } }
Example #13
Source File: IslandGuard.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Checks for splash damage. If there is any to any affected entity and it's not allowed, it won't work on any of them. * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onSplashPotionSplash(final PotionSplashEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); plugin.getLogger().info("splash entity = " + e.getEntity()); plugin.getLogger().info("splash entity type = " + e.getEntityType()); plugin.getLogger().info("splash affected entities = " + e.getAffectedEntities()); //plugin.getLogger().info("splash hit entity = " + e.getHitEntity()); } if (!IslandGuard.inWorld(e.getEntity().getLocation())) { return; } // Try to get the shooter Projectile projectile = e.getEntity(); if (DEBUG) plugin.getLogger().info("splash shooter = " + projectile.getShooter()); if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) { Player attacker = (Player)projectile.getShooter(); // Run through all the affected entities for (LivingEntity entity: e.getAffectedEntities()) { if (DEBUG) plugin.getLogger().info("DEBUG: affected splash entity = " + entity); // Self damage if (attacker.equals(entity)) { if (DEBUG) plugin.getLogger().info("DEBUG: Self damage from splash potion!"); continue; } Island island = plugin.getGrid().getIslandAt(entity.getLocation()); boolean inNether = false; if (entity.getWorld().equals(ASkyBlock.getNetherWorld())) { inNether = true; } // Monsters being hurt if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) { // Normal island check if (island != null && island.getMembers().contains(attacker.getUniqueId())) { // Members always allowed continue; } if (actionAllowed(attacker, entity.getLocation(), SettingsFlag.HURT_MONSTERS)) { continue; } // Not allowed Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected); e.setCancelled(true); return; } // Mobs being hurt if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman || entity instanceof Villager) { if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker.getUniqueId()))) { continue; } if (DEBUG) plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking"); Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected); e.setCancelled(true); return; } // Establish whether PVP is allowed or not. boolean pvp = false; if ((inNether && island != null && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island != null && island.getIgsFlag(SettingsFlag.PVP)))) { if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed"); pvp = true; } // Players being hurt PvP if (entity instanceof Player) { if (pvp) { if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed"); } else { if (DEBUG) plugin.getLogger().info("DEBUG: PVP not allowed"); Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).targetInNoPVPArea); e.setCancelled(true); return; } } } } }