下面列出了怎么用org.bukkit.entity.Animals的API类实例代码及写法,或者点击链接到github查看源代码。
@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);
}
}
}
}
@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);
}
}
}
@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);
}
}
}
@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);
}
}
}
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;
}
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;
}
}
}
}
/**
* 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);
}
}
@Override
public boolean checkTrait(Entity original, Entity nearby) {
if(original instanceof Animals){
return (((Animals) original).canBreed() != ((Animals) nearby).canBreed());
}
return false;
}
@Override
public boolean checkTrait(Entity original, Entity nearby) {
if (original instanceof Animals) {
return ((Animals) original).isLoveMode() || ((Animals) nearby).isLoveMode();
}
return false;
}
@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);
}
}
}
}
/**
* 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();
}
}
}
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;
}
private void cancelMobDamage(EntityDamageByEntityEvent event) {
if (killAnimalsEnabled && event.getEntity() instanceof Animals) {
event.setCancelled(true);
} else if (killMonstersEnabled && event.getEntity() instanceof Monster) {
event.setCancelled(true);
}
}
private boolean canBreed(Entity n) {
if (n.isValid() && n instanceof Animals) {
Animals animal = (Animals) n;
return animal.isAdult() && animal.canBreed() && !animal.isLoveMode();
}
return false;
}
/**
* 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();
}
@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);
}
}
}
}
}
@Override
public void applyTrait(Entity original, Entity spawned) {
if(original instanceof Animals){
((Animals) spawned).setBreed(((Animals) original).canBreed());
}
}
@Override
public void applyTrait(Entity original, Entity spawned) {
if (original instanceof Animals) {
((Animals) spawned).setLoveModeTicks(((Animals) original).getLoveModeTicks());
}
}
/**
* 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.");
}
}
}
@Test
public void testGetEntity() {
List<Entity> testList = new ArrayList<>();
ArmorStand fakeArmorStand = mock(ArmorStand.class);
Cow fakeCow = mock(Cow.class);
Evoker fakeEvoker = mock(Evoker.class);
Guardian fakeGuardian = mock(Guardian.class);
Pig fakePig = mock(Pig.class);
PigZombie fakePigZombie = mock(PigZombie.class);
Pillager fakePillager = mock(Pillager.class);
Sheep fakeSheep = mock(Sheep.class);
Skeleton fakeSkeleton = mock(Skeleton.class);
Turtle fakeTurtle = mock(Turtle.class);
Villager fakeVillager = mock(Villager.class);
WanderingTrader fakeWanderingTrader = mock(WanderingTrader.class);
testList.add(fakeArmorStand);
testList.add(fakeCow);
testList.add(fakeEvoker);
testList.add(fakeGuardian);
testList.add(fakePig);
testList.add(fakePigZombie);
testList.add(fakePillager);
testList.add(fakeSheep);
testList.add(fakeSkeleton);
testList.add(fakeTurtle);
testList.add(fakeVillager);
testList.add(fakeWanderingTrader);
List<Sheep> sheepList = EntityUtil.getEntity(testList, Sheep.class);
assertEquals(1, sheepList.size());
assertEquals(fakeSheep, sheepList.get(0));
List<Animals> animalsList = EntityUtil.getAnimals(testList);
assertEquals(4, animalsList.size());
assertTrue(animalsList.contains(fakeCow));
assertTrue(animalsList.contains(fakePig));
assertTrue(animalsList.contains(fakeSheep));
assertTrue(animalsList.contains(fakeTurtle));
List<Monster> monsterList = EntityUtil.getMonsters(testList);
assertEquals(5, monsterList.size());
assertTrue(monsterList.contains(fakeEvoker));
assertTrue(monsterList.contains(fakeGuardian));
assertTrue(monsterList.contains(fakePigZombie));
assertTrue(monsterList.contains(fakePillager));
assertTrue(monsterList.contains(fakeSkeleton));
List<NPC> npcList = EntityUtil.getNPCs(testList);
assertEquals(2, npcList.size());
assertTrue(npcList.contains(fakeVillager));
assertTrue(npcList.contains(fakeWanderingTrader));
}
@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);
}
}
}
}
@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();
}
}
}
}
}
/**
* 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;
}
}
}
}
}
/**
* 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());
}
}
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));
}
}
}
}
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));
}
}
}
}
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));
}
}
}
}
public ControllableEntityBreedEvent(ControllableEntity<? extends Animals, ?> firstParent, Animals mate, Animals child, Player breeder) {
super(firstParent);
this.child = child;
this.mate = mate;
this.breeder = breeder;
}
public Animals getChild() {
return child;
}
public Animals getMate() {
return mate;
}