org.bukkit.entity.Animals Java Examples

The following examples show how to use org.bukkit.entity.Animals. 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: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prevents visitors picking items from riding horses or other inventories
 * @param event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onHorseInventoryClick(InventoryClickEvent event) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: horse and llama inventory click");
    if (event.getInventory().getHolder() == null) {
        return;
    }
    // World check
    if (!inWorld(event.getWhoClicked())) {
        return;
    }
    if (event.getInventory().getHolder() instanceof Animals) {
        if (actionAllowed((Player)event.getWhoClicked(), event.getWhoClicked().getLocation(), SettingsFlag.HORSE_INVENTORY)) {
            return;
        }
        // Elsewhere - not allowed
        Util.sendMessage(event.getWhoClicked(), ChatColor.RED + plugin.myLocale(event.getWhoClicked().getUniqueId()).islandProtected);
        event.setCancelled(true);
    }
}
 
Example #2
Source File: AutoBreeder.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
protected void tick(Block b) {
    BlockMenu inv = BlockStorage.getInventory(b);

    for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), 4.0, 2.0, 4.0, this::canBreed)) {
        for (int slot : getInputSlots()) {
            if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFood, false)) {
                if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) {
                    return;
                }

                ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
                inv.consumeItem(slot);

                ((Animals) n).setLoveModeTicks(600);
                n.getWorld().spawnParticle(Particle.HEART, ((LivingEntity) n).getEyeLocation(), 8, 0.2F, 0.2F, 0.2F);
                return;
            }
        }
    }
}
 
Example #3
Source File: McMMOHook.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onFakeEntityDamageByEntityEvent(FakeEntityDamageByEntityEvent e) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "McMMO FakeEntityDamageByEntityEvent event.");

    if (e.getDamager() instanceof Player) {
        Player p = (Player) e.getDamager();
        Region r = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation());

        if (e.getEntity() instanceof Animals) {
            if (r != null && !r.canInteractPassives(p)) {
                RedProtect.get().lang.sendMessage(p, "entitylistener.region.cantpassive");
                e.setCancelled(true);
            }
        }

        if (e.getEntity() instanceof Player) {
            if (r != null && !r.canPVP(p, (Player) e.getEntity())) {
                RedProtect.get().lang.sendMessage(p, "entitylistener.region.cantpvp");
                e.setCancelled(true);
            }
        }
    }
}
 
Example #4
Source File: McMMOHook.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onFakeEntityDamageEvent(FakeEntityDamageEvent e) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "McMMO FakeEntityDamageEvent event.");

    Region r = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation());

    if (e.getEntity() instanceof Animals) {
        if (r != null && !r.getFlagBool("passives")) {
            e.setCancelled(true);
        }
    }

    if (e.getEntity() instanceof Player) {
        Player p = (Player) e.getEntity();
        if (r != null && !r.canPVP(p, null)) {
            e.setCancelled(true);
        }
    }
}
 
Example #5
Source File: LimitLogic.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public CreatureType getCreatureType(EntityType entityType) {
    if (Monster.class.isAssignableFrom(entityType.getEntityClass())
            || WaterMob.class.isAssignableFrom(entityType.getEntityClass())
            || Slime.class.isAssignableFrom(entityType.getEntityClass())
            || Ghast.class.isAssignableFrom(entityType.getEntityClass())
            ) {
        return CreatureType.MONSTER;
    } else if (Animals.class.isAssignableFrom(entityType.getEntityClass())) {
        return CreatureType.ANIMAL;
    } else if (Villager.class.isAssignableFrom(entityType.getEntityClass())) {
        return CreatureType.VILLAGER;
    } else if (Golem.class.isAssignableFrom(entityType.getEntityClass())) {
        return CreatureType.GOLEM;
    }
    return CreatureType.UNKNOWN;
}
 
Example #6
Source File: EntityCustomNbtInjectorTest.java    From Item-NBT-API with MIT License 6 votes vote down vote up
@Override
public void test() throws Exception {
	if(!NBTInjector.isInjected())return;
	if (!Bukkit.getWorlds().isEmpty()) {
		World world = Bukkit.getWorlds().get(0);
		try {
			if (!world.getEntitiesByClasses(Animals.class, Monster.class).isEmpty()) {
				Entity ent = world.getEntitiesByClasses(Animals.class, Monster.class).iterator().next();
				ent = NBTInjector.patchEntity(ent);
				NBTCompound comp = NBTInjector.getNbtData(ent);
				comp.setString("Hello", "World");
				NBTEntity nbtent = new NBTEntity(ent);
				if (!nbtent.toString().contains("__extraData:{Hello:\"World\"}")) {
					throw new NbtApiException("Custom Data did not save to the Entity!");
				}
				comp.removeKey("Hello");

			}
		} catch (Exception ex) {
			throw new NbtApiException("Wasn't able to use NBTEntities!", ex);
		}
	}
}
 
Example #7
Source File: EntityCustomNbtPersistentTest.java    From Item-NBT-API with MIT License 6 votes vote down vote up
@Override
public void test() throws Exception {
	if(MinecraftVersion.getVersion().getVersionId() < MinecraftVersion.MC1_14_R1.getVersionId())return;
	if (!Bukkit.getWorlds().isEmpty()) {
		World world = Bukkit.getWorlds().get(0);
		try {
			if (!world.getEntitiesByClasses(Animals.class, Monster.class).isEmpty()) {
				Entity ent = world.getEntitiesByClasses(Animals.class, Monster.class).iterator().next();
				NBTEntity nbtEnt = new NBTEntity(ent);
				NBTCompound comp = nbtEnt.getPersistentDataContainer();
				comp.setString("Hello", "World");
				NBTEntity nbtent = new NBTEntity(ent);
				if (!nbtent.toString().contains("Hello:\"World\"")) {
					throw new NbtApiException("Custom Data did not save to the Entity!");
				}
				comp.removeKey("Hello");

			}
		} catch (Exception ex) {
			throw new NbtApiException("Wasn't able to use NBTEntities!", ex);
		}
	}
}
 
Example #8
Source File: AnimalsTrait.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean checkTrait(Entity original, Entity nearby) {
    if(original instanceof Animals){
        return (((Animals) original).canBreed() != ((Animals) nearby).canBreed());
    }
    return false;
}
 
Example #9
Source File: AcidTask.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs repeating tasks to deliver acid damage to mobs, etc.
 * @param plugin - ASkyBlock plugin object - ASkyBlock plugin
 */
public AcidTask(final ASkyBlock plugin) {
    this.plugin = plugin;
    // Initialize water item list
    itemsInWater = new HashSet<>();
    // This part will kill monsters if they fall into the water
    // because it
    // is acid
    if (Settings.mobAcidDamage > 0D || Settings.animalAcidDamage > 0D) {
        plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
            List<Entity> entList = ASkyBlock.getIslandWorld().getEntities();
            for (Entity current : entList) {
                if (plugin.isOnePointEight() && current instanceof Guardian) {
                    // Guardians are immune to acid too
                    continue;
                }
                if ((current instanceof Monster) && Settings.mobAcidDamage > 0D) {
                    if ((current.getLocation().getBlock().getType() == Material.WATER)
                            || (current.getLocation().getBlock().getType() == Material.STATIONARY_WATER)) {
                        ((Monster) current).damage(Settings.mobAcidDamage);
                    }
                } else if ((current instanceof Animals) && Settings.animalAcidDamage > 0D) {
                    if ((current.getLocation().getBlock().getType() == Material.WATER)
                            || (current.getLocation().getBlock().getType() == Material.STATIONARY_WATER)) {
                        if (!current.getType().equals(EntityType.CHICKEN) || Settings.damageChickens) {
                            ((Animals) current).damage(Settings.animalAcidDamage);
                        }
                    }
                }
            }
        }, 0L, 20L);
    }
    runAcidItemRemovalTask();
}
 
Example #10
Source File: AutoBreeder.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private boolean canBreed(Entity n) {
    if (n.isValid() && n instanceof Animals) {
        Animals animal = (Animals) n;

        return animal.isAdult() && animal.canBreed() && !animal.isLoveMode();
    }

    return false;
}
 
Example #11
Source File: GriefEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private void cancelMobDamage(EntityDamageByEntityEvent event) {
    if (killAnimalsEnabled && event.getEntity() instanceof Animals) {
        event.setCancelled(true);
    } else if (killMonstersEnabled && event.getEntity() instanceof Monster) {
        event.setCancelled(true);
    }
}
 
Example #12
Source File: LimitLogic.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public CreatureType getCreatureType(LivingEntity creature) {
    if (creature instanceof Monster
            || creature instanceof WaterMob
            || creature instanceof Slime
            || creature instanceof Ghast) {
        return CreatureType.MONSTER;
    } else if (creature instanceof Animals) {
        return CreatureType.ANIMAL;
    } else if (creature instanceof Villager) {
        return CreatureType.VILLAGER;
    } else if (creature instanceof Golem) {
        return CreatureType.GOLEM;
    }
    return CreatureType.UNKNOWN;
}
 
Example #13
Source File: GameArena.java    From ZombieEscape with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes the game state, and sets up defaults
 */
public void startGame() {
    Bukkit.getPluginManager().callEvent(new GameStartEvent());

    final String MAPS_PATH = PLUGIN.getConfiguration().getSettingsConfig().getString("MapsPath");
    final String ARENAS_PATH = PLUGIN.getConfiguration().getSettingsConfig().getString("ArenasPath");

    this.mapSelection = VOTE_MANAGER.getWinningMap();
    this.gameFile = new GameFile(ARENAS_PATH, mapSelection + ".yml");
    this.arenaWorld = Bukkit.createWorld(new WorldCreator(MAPS_PATH + gameFile.getConfig().getString("World")));
    this.arenaWorld.setSpawnFlags(false, false);
    this.arenaWorld.setGameRuleValue("doMobSpawning", "false");
    this.spawns = gameFile.getLocations(arenaWorld, "Spawns");
    this.doors = gameFile.getDoors(arenaWorld);
    this.checkpoints = gameFile.getCheckpoints(arenaWorld);
    this.nukeRoom = gameFile.getLocation(arenaWorld, "Nukeroom");
    this.handleStart();

    VOTE_MANAGER.resetVotes();

    Bukkit.getConsoleSender().sendMessage(Utils.color("&6Start game method"));

    // Clear entities
    for (Entity entity : arenaWorld.getEntities()) {
        if (!(entity instanceof Player) && (entity instanceof Animals || entity instanceof Monster)) {
            entity.remove();
        }
    }
}
 
Example #14
Source File: BukkitFightListener.java    From Parties with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onEntityDieKill(EntityDeathEvent event) {
	if (BukkitConfigParties.KILLS_ENABLE
			&& event.getEntity().getKiller() != null) {
		Player killer = event.getEntity().getKiller();
		PartyPlayerImpl ppKiller = plugin.getPlayerManager().getPlayer(killer.getUniqueId());
		
		if (!ppKiller.getPartyName().isEmpty()) {
			PartyImpl party = plugin.getPartyManager().getParty(ppKiller.getPartyName());
			boolean gotKill = false;
			
			if (BukkitConfigParties.KILLS_MOB_HOSTILE
					&& event.getEntity() instanceof Monster)
				gotKill = true;
			else if (BukkitConfigParties.KILLS_MOB_NEUTRAL
					&& event.getEntity() instanceof Animals)
				gotKill = true;
			else if (BukkitConfigParties.KILLS_MOB_PLAYERS
					&& event.getEntity() instanceof Player)
				gotKill = true;
			
			if (gotKill) {
				party.setKills(party.getKills() + 1);
				party.updateParty();
				plugin.getLoggerManager().logDebug(PartiesConstants.DEBUG_KILL_ADD
						.replace("{party}", party.getName())
						.replace("{player}", killer.getName()), true);
			}
		}
	}
}
 
Example #15
Source File: LoveTrait.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean checkTrait(Entity original, Entity nearby) {
    if (original instanceof Animals) {
        return ((Animals) original).isLoveMode() || ((Animals) nearby).isLoveMode();
    }
    return false;
}
 
Example #16
Source File: BehaviourGoalBreed.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void breed() {
    ControllableEntityPreBreedEvent preBreedEvent = new ControllableEntityPreBreedEvent(this.getControllableEntity(), (Animals) this.mate.getBukkitEntity(), (CraftPlayer) this.getHandle().cb().getBukkitEntity());
    EntityAPI.getCore().getServer().getPluginManager().callEvent(preBreedEvent);
    if (!preBreedEvent.isCancelled()) {
        EntityAgeable child = this.getHandle().createChild(this.mate);

        ControllableEntityBreedEvent breedEvent = new ControllableEntityBreedEvent(this.getControllableEntity(), (Animals) this.mate.getBukkitEntity(), (Animals) child.getBukkitEntity(), (CraftPlayer) this.getHandle().cb().getBukkitEntity());
        EntityAPI.getCore().getServer().getPluginManager().callEvent(breedEvent);

        if (child != null) {
            // CraftBukkit start - set persistence for tame animals
            if (child instanceof EntityTameableAnimal && ((EntityTameableAnimal) child).isTamed()) {
                child.persistent = true;
            }
            // CraftBukkit end

            EntityHuman human = this.getHandle().cb();

            if (human == null && this.mate.cb() != null) {
                human = this.mate.cb();
            }

            if (human != null) {
                human.a(StatisticList.x);
                if (this.getHandle() instanceof EntityCow) {
                    human.a((Statistic) AchievementList.H);
                }
            }

            this.getHandle().setAge(6000);
            this.mate.setAge(6000);
            this.getHandle().cd();
            this.mate.cd();
            child.setAge(-24000);
            child.setPositionRotation(this.getHandle().locX, this.getHandle().locY, this.getHandle().locZ, 0.0F, 0.0F);
            this.getHandle().world.addEntity(child, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason
            Random random = this.getHandle().aI();

            for (int i = 0; i < 7; ++i) {
                double d0 = random.nextGaussian() * 0.02D;
                double d1 = random.nextGaussian() * 0.02D;
                double d2 = random.nextGaussian() * 0.02D;

                this.getHandle().world.addParticle("heart", this.getHandle().locX + (double) (random.nextFloat() * this.getHandle().width * 2.0F) - (double) this.getHandle().width, this.getHandle().locY + 0.5D + (double) (random.nextFloat() * this.getHandle().length), this.getHandle().locZ + (double) (random.nextFloat() * this.getHandle().width * 2.0F) - (double) this.getHandle().width, d0, d1, d2);
            }

            if (this.getHandle().world.getGameRules().getBoolean("doMobLoot")) {
                this.getHandle().world.addEntity(new EntityExperienceOrb(this.getHandle().world, this.getHandle().locX, this.getHandle().locY, this.getHandle().locZ, random.nextInt(7) + 1));
            }
        }
    }
}
 
Example #17
Source File: PlayerInteractListener.java    From PetMaster with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Displays a hologram, and automatically delete it after a given delay.
 * 
 * @param player
 * @param owner
 * @param tameable
 */
@SuppressWarnings("deprecation")
private void displayHologramAndMessage(Player player, AnimalTamer owner, Tameable tameable) {
	if (hologramMessage) {
		double offset = HORSE_OFFSET;
		if (tameable instanceof Ocelot || version >= 14 && tameable instanceof Cat) {
			if (!displayCat || !player.hasPermission("petmaster.showowner.cat")) {
				return;
			}
			offset = CAT_OFFSET;
		} else if (tameable instanceof Wolf) {
			if (!displayDog || !player.hasPermission("petmaster.showowner.dog")) {
				return;
			}
			offset = DOG_OFFSET;
		} else if (version >= 11 && tameable instanceof Llama) {
			if (!displayLlama || !player.hasPermission("petmaster.showowner.llama")) {
				return;
			}
			offset = LLAMA_OFFSET;
		} else if (version >= 12 && tameable instanceof Parrot) {
			if (!displayParrot || !player.hasPermission("petmaster.showowner.parrot")) {
				return;
			}
			offset = PARROT_OFFSET;
		} else if (!displayHorse || !player.hasPermission("petmaster.showowner.horse")) {
			return;
		}

		Location eventLocation = tameable.getLocation();
		// Create location with offset.
		Location hologramLocation = new Location(eventLocation.getWorld(), eventLocation.getX(),
				eventLocation.getY() + offset, eventLocation.getZ());

		final Hologram hologram = HologramsAPI.createHologram(plugin, hologramLocation);
		hologram.appendTextLine(
				ChatColor.GRAY + plugin.getPluginLang().getString("petmaster-hologram", "Pet owned by ")
						+ ChatColor.GOLD + owner.getName());

		// Runnable to delete hologram.
		new BukkitRunnable() {

			@Override
			public void run() {

				hologram.delete();
			}
		}.runTaskLater(plugin, hologramDuration);
	}

	String healthInfo = "";
	if (showHealth) {
		Animals animal = (Animals) tameable;
		String currentHealth = String.format("%.1f", animal.getHealth());
		String maxHealth = version < 9 ? String.format("%.1f", animal.getMaxHealth())
				: String.format("%.1f", animal.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
		healthInfo = ChatColor.GRAY + ". " + plugin.getPluginLang().getString("petmaster-health", "Health: ")
				+ ChatColor.GOLD + currentHealth + "/" + maxHealth;
	}

	if (chatMessage) {
		player.sendMessage(plugin.getChatHeader() + plugin.getPluginLang().getString("petmaster-chat", "Pet owned by ")
				+ ChatColor.GOLD + owner.getName() + healthInfo);
	}

	if (actionBarMessage) {
		try {
			FancyMessageSender.sendActionBarMessage(player, "&o" + ChatColor.GRAY
					+ plugin.getPluginLang().getString("petmaster-action-bar", "Pet owned by ") + ChatColor.GOLD
					+ owner.getName() + healthInfo);
		} catch (Exception e) {
			plugin.getLogger().warning("Errors while trying to display action bar message for pet ownership.");
		}
	}
}
 
Example #18
Source File: ControllableEntityPreBreedEvent.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Animals getMate() {
    return mate;
}
 
Example #19
Source File: ControllableEntityPreBreedEvent.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ControllableEntityPreBreedEvent(ControllableEntity<? extends Animals, ?> firstParent, Animals mate, Player breeder) {
    super(firstParent);
    this.mate = mate;
    this.breeder = breeder;
}
 
Example #20
Source File: ControllableEntityBreedEvent.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Animals getMate() {
    return mate;
}
 
Example #21
Source File: ControllableEntityBreedEvent.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Animals getChild() {
    return child;
}
 
Example #22
Source File: ControllableEntityBreedEvent.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ControllableEntityBreedEvent(ControllableEntity<? extends Animals, ?> firstParent, Animals mate, Animals child, Player breeder) {
    super(firstParent);
    this.child = child;
    this.mate = mate;
    this.breeder = breeder;
}
 
Example #23
Source File: BehaviourGoalBreed.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void breed() {
    ControllableEntityPreBreedEvent preBreedEvent = new ControllableEntityPreBreedEvent(this.getControllableEntity(), (Animals) this.mate.getBukkitEntity(), (CraftPlayer) this.getHandle().cb().getBukkitEntity());
    EntityAPI.getCore().getServer().getPluginManager().callEvent(preBreedEvent);
    if (!preBreedEvent.isCancelled()) {
        EntityAgeable child = this.getHandle().createChild(this.mate);

        ControllableEntityBreedEvent breedEvent = new ControllableEntityBreedEvent(this.getControllableEntity(), (Animals) this.mate.getBukkitEntity(), (Animals) child.getBukkitEntity(), (CraftPlayer) this.getHandle().cb().getBukkitEntity());
        EntityAPI.getCore().getServer().getPluginManager().callEvent(breedEvent);

        if (child != null) {
            // CraftBukkit start - set persistence for tame animals
            if (child instanceof EntityTameableAnimal && ((EntityTameableAnimal) child).isTamed()) {
                child.persistent = true;
            }
            // CraftBukkit end

            EntityHuman human = this.getHandle().cb();

            if (human == null && this.mate.cb() != null) {
                human = this.mate.cb();
            }

            if (human != null) {
                human.a(StatisticList.x);
                if (this.getHandle() instanceof EntityCow) {
                    human.a((Statistic) AchievementList.H);
                }
            }

            this.getHandle().setAge(6000);
            this.mate.setAge(6000);
            this.getHandle().cd();
            this.mate.cd();
            child.setAge(-24000);
            child.setPositionRotation(this.getHandle().locX, this.getHandle().locY, this.getHandle().locZ, 0.0F, 0.0F);
            this.getHandle().world.addEntity(child, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason
            Random random = this.getHandle().aI();

            for (int i = 0; i < 7; ++i) {
                double d0 = random.nextGaussian() * 0.02D;
                double d1 = random.nextGaussian() * 0.02D;
                double d2 = random.nextGaussian() * 0.02D;

                this.getHandle().world.addParticle("heart", this.getHandle().locX + (double) (random.nextFloat() * this.getHandle().width * 2.0F) - (double) this.getHandle().width, this.getHandle().locY + 0.5D + (double) (random.nextFloat() * this.getHandle().length), this.getHandle().locZ + (double) (random.nextFloat() * this.getHandle().width * 2.0F) - (double) this.getHandle().width, d0, d1, d2);
            }

            if (this.getHandle().world.getGameRules().getBoolean("doMobLoot")) {
                this.getHandle().world.addEntity(new EntityExperienceOrb(this.getHandle().world, this.getHandle().locX, this.getHandle().locY, this.getHandle().locZ, random.nextInt(7) + 1));
            }
        }
    }
}
 
Example #24
Source File: BehaviourGoalBreed.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void breed() {
    ControllableEntityPreBreedEvent preBreedEvent = new ControllableEntityPreBreedEvent(this.getControllableEntity(), (Animals) this.mate.getBukkitEntity(), (CraftPlayer) this.getHandle().cb().getBukkitEntity());
    EntityAPI.getCore().getServer().getPluginManager().callEvent(preBreedEvent);
    if (!preBreedEvent.isCancelled()) {
        EntityAgeable child = this.getHandle().createChild(this.mate);

        ControllableEntityBreedEvent breedEvent = new ControllableEntityBreedEvent(this.getControllableEntity(), (Animals) this.mate.getBukkitEntity(), (Animals) child.getBukkitEntity(), (CraftPlayer) this.getHandle().cb().getBukkitEntity());
        EntityAPI.getCore().getServer().getPluginManager().callEvent(breedEvent);

        if (child != null) {
            // CraftBukkit start - set persistence for tame animals
            if (child instanceof EntityTameableAnimal && ((EntityTameableAnimal) child).isTamed()) {
                child.persistent = true;
            }
            // CraftBukkit end

            EntityHuman human = this.getHandle().cb();

            if (human == null && this.mate.cb() != null) {
                human = this.mate.cb();
            }

            if (human != null) {
                human.a(StatisticList.x);
                if (this.getHandle() instanceof EntityCow) {
                    human.a((Statistic) AchievementList.H);
                }
            }

            this.getHandle().setAge(6000);
            this.mate.setAge(6000);
            this.getHandle().cd();
            this.mate.cd();
            child.setAge(-24000);
            child.setPositionRotation(this.getHandle().locX, this.getHandle().locY, this.getHandle().locZ, 0.0F, 0.0F);
            this.getHandle().world.addEntity(child, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason
            Random random = this.getHandle().aI();

            for (int i = 0; i < 7; ++i) {
                double d0 = random.nextGaussian() * 0.02D;
                double d1 = random.nextGaussian() * 0.02D;
                double d2 = random.nextGaussian() * 0.02D;

                this.getHandle().world.addParticle("heart", this.getHandle().locX + (double) (random.nextFloat() * this.getHandle().width * 2.0F) - (double) this.getHandle().width, this.getHandle().locY + 0.5D + (double) (random.nextFloat() * this.getHandle().length), this.getHandle().locZ + (double) (random.nextFloat() * this.getHandle().width * 2.0F) - (double) this.getHandle().width, d0, d1, d2);
            }

            if (this.getHandle().world.getGameRules().getBoolean("doMobLoot")) {
                this.getHandle().world.addEntity(new EntityExperienceOrb(this.getHandle().world, this.getHandle().locX, this.getHandle().locY, this.getHandle().locZ, random.nextInt(7) + 1));
            }
        }
    }
}
 
Example #25
Source File: BehaviourGoalBreed.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void breed() {
    ControllableEntityPreBreedEvent preBreedEvent = new ControllableEntityPreBreedEvent(this.getControllableEntity(), (Animals) this.mate.getBukkitEntity(), (CraftPlayer) this.getHandle().cb().getBukkitEntity());
    EntityAPI.getCore().getServer().getPluginManager().callEvent(preBreedEvent);
    if (!preBreedEvent.isCancelled()) {
        EntityAgeable child = this.getHandle().createChild(this.mate);

        ControllableEntityBreedEvent breedEvent = new ControllableEntityBreedEvent(this.getControllableEntity(), (Animals) this.mate.getBukkitEntity(), (Animals) child.getBukkitEntity(), (CraftPlayer) this.getHandle().cb().getBukkitEntity());
        EntityAPI.getCore().getServer().getPluginManager().callEvent(breedEvent);

        if (child != null) {
            // CraftBukkit start - set persistence for tame animals
            if (child instanceof EntityTameableAnimal && ((EntityTameableAnimal) child).isTamed()) {
                child.persistent = true;
            }
            // CraftBukkit end

            EntityHuman human = this.getHandle().cb();

            if (human == null && this.mate.cb() != null) {
                human = this.mate.cb();
            }

            if (human != null) {
                human.a(StatisticList.x);
                if (this.getHandle() instanceof EntityCow) {
                    human.a((Statistic) AchievementList.H);
                }
            }

            this.getHandle().setAge(6000);
            this.mate.setAge(6000);
            this.getHandle().cd();
            this.mate.cd();
            child.setAge(-24000);
            child.setPositionRotation(this.getHandle().locX, this.getHandle().locY, this.getHandle().locZ, 0.0F, 0.0F);
            this.getHandle().world.addEntity(child, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason
            Random random = this.getHandle().aI();

            for (int i = 0; i < 7; ++i) {
                double d0 = random.nextGaussian() * 0.02D;
                double d1 = random.nextGaussian() * 0.02D;
                double d2 = random.nextGaussian() * 0.02D;

                this.getHandle().world.addParticle("heart", this.getHandle().locX + (double) (random.nextFloat() * this.getHandle().width * 2.0F) - (double) this.getHandle().width, this.getHandle().locY + 0.5D + (double) (random.nextFloat() * this.getHandle().length), this.getHandle().locZ + (double) (random.nextFloat() * this.getHandle().width * 2.0F) - (double) this.getHandle().width, d0, d1, d2);
            }

            if (this.getHandle().world.getGameRules().getBoolean("doMobLoot")) {
                this.getHandle().world.addEntity(new EntityExperienceOrb(this.getHandle().world, this.getHandle().locX, this.getHandle().locY, this.getHandle().locZ, random.nextInt(7) + 1));
            }
        }
    }
}
 
Example #26
Source File: EntityLimits.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Prevents mobs spawning naturally at spawn or in an island
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onNaturalMobSpawn(final CreatureSpawnEvent e) {
    // if grid is not loaded yet, return.
    if (plugin.getGrid() == null) {
        return;
    }
    // If not in the right world, return
    if (!IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    // Deal with natural spawning
    if (e.getSpawnReason().equals(SpawnReason.NATURAL)
            || e.getSpawnReason().equals(SpawnReason.CHUNK_GEN)
            || e.getSpawnReason().equals(SpawnReason.DEFAULT)
            || e.getSpawnReason().equals(SpawnReason.MOUNT)
            || e.getSpawnReason().equals(SpawnReason.JOCKEY)
            || e.getSpawnReason().equals(SpawnReason.NETHER_PORTAL)) {
        if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) {
            if (!actionAllowed(e.getLocation(), SettingsFlag.MONSTER_SPAWN)) {                
                if (DEBUG3)
                    plugin.getLogger().info("Natural monster spawn cancelled.");
                // Mobs not allowed to spawn
                e.setCancelled(true);
                return;
            }
        } else if (e.getEntity() instanceof Animals) {
            if (!actionAllowed(e.getLocation(), SettingsFlag.MOB_SPAWN)) {
                // Animals are not allowed to spawn
                if (DEBUG2)
                    plugin.getLogger().info("Natural animal spawn cancelled.");
                e.setCancelled(true);
                return;
            }
        }
    }
    if (DEBUG2) {
        plugin.getLogger().info("Mob spawn allowed " + e.getEventName());
        plugin.getLogger().info(e.getSpawnReason().toString());
        plugin.getLogger().info(e.getEntityType().toString());
    }
}
 
Example #27
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
                }
            }
        }
    }
}
 
Example #28
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onFishing(final PlayerFishEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("Player fish event " + e.getEventName());
        plugin.getLogger().info("Player fish event " + e.getCaught());
    }
    if (e.getCaught() == null)
        return;
    Player p = e.getPlayer();
    if (!inWorld(p)) {
        return;
    }
    if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
        // You can do anything if you are Op of have the bypass
        return;
    }
    // Handle rods
    Island island = plugin.getGrid().getProtectedIslandAt(e.getCaught().getLocation());
    // PVP check
    if (e.getCaught() instanceof Player) {
        // Check if this is the player who is holding the rod
        if (e.getCaught().equals(e.getPlayer())) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: player cught themselves!");
            return;
        }
        if (island == null
                && (e.getCaught().getWorld().getEnvironment().equals(Environment.NORMAL)
                        && !Settings.defaultWorldSettings.get(SettingsFlag.PVP))
                || ((e.getCaught().getWorld().getEnvironment().equals(Environment.NETHER)
                        && !Settings.defaultWorldSettings.get(SettingsFlag.NETHER_PVP)))) {
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).targetInNoPVPArea);
            e.setCancelled(true);
            e.getHook().remove();
            return;
        }
        if (island != null && ((e.getCaught().getWorld().getEnvironment().equals(Environment.NORMAL) && !island.getIgsFlag(SettingsFlag.PVP))
                || (e.getCaught().getWorld().getEnvironment().equals(Environment.NETHER) && !island.getIgsFlag(SettingsFlag.NETHER_PVP)))) {
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).targetInNoPVPArea);
            e.setCancelled(true);
            e.getHook().remove();
            return;
        }
    }
    if (!plugin.getGrid().playerIsOnIsland(e.getPlayer())) {
        if (e.getCaught() instanceof Animals) {
            if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HURT_MOBS)) {
                Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                e.setCancelled(true);
                e.getHook().remove();
                return;
            }
            if (island != null) {
                if ((!island.getIgsFlag(SettingsFlag.HURT_MOBS) && !island.getMembers().contains(p.getUniqueId()))) {
                    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                    e.setCancelled(true);
                    e.getHook().remove();
                    return;
                }
            }
        }
        // Monster protection
        if (e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime) {
            if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HURT_MONSTERS)) {
                Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                e.setCancelled(true);
                e.getHook().remove();
                return;
            }
            if (island != null) {
                if ((!island.getIgsFlag(SettingsFlag.HURT_MONSTERS) && !island.getMembers().contains(p.getUniqueId()))) {
                    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                    e.setCancelled(true);
                    e.getHook().remove();
                }
            }
        }
    }
}
 
Example #29
Source File: MobkillingTaskType.java    From Quests with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMobKill(EntityDeathEvent event) {
    Player killer = event.getEntity().getKiller(); //The killer is a player
    Entity mob = event.getEntity();

    if (mob == null || mob instanceof Player) {
        return;
    }

    if (killer == null) {
        return;
    }

    QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(killer.getUniqueId(), true);
    QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();

    for (Quest quest : super.getRegisteredQuests()) {
        if (questProgressFile.hasStartedQuest(quest)) {
            QuestProgress questProgress = questProgressFile.getQuestProgress(quest);

            for (Task task : quest.getTasksOfType(super.getType())) {
                TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());

                if (taskProgress.isCompleted()) {
                    continue;
                }

                boolean hostilitySpecified = false;
                boolean hostile = false;
                if (task.getConfigValue("hostile") != null) {
                    hostilitySpecified = true;
                    hostile = (boolean) task.getConfigValue("hostile");
                }

                if (hostilitySpecified) {
                    if (!hostile && !(mob instanceof Animals)) {
                        continue;
                    } else if (hostile && !(mob instanceof Monster)) {
                        continue;
                    }
                }

                int mobKillsNeeded = (int) task.getConfigValue("amount");

                int progressKills;
                if (taskProgress.getProgress() == null) {
                    progressKills = 0;
                } else {
                    progressKills = (int) taskProgress.getProgress();
                }

                taskProgress.setProgress(progressKills + 1);

                if (((int) taskProgress.getProgress()) >= mobKillsNeeded) {
                    taskProgress.setCompleted(true);
                }
            }
        }
    }
}
 
Example #30
Source File: IslandGuard1_9.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@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);
            }
        }
    }
}