本文整理汇总了Java中org.bukkit.entity.Animals类的典型用法代码示例。如果您正苦于以下问题:Java Animals类的具体用法?Java Animals怎么用?Java Animals使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Animals类属于org.bukkit.entity包,在下文中一共展示了Animals类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onEntityTame
import org.bukkit.entity.Animals; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onEntityTame(EntityTameEvent event) {
// Return if the damaged entity is not a tameable entity.
if (!(event.getEntity() instanceof Tameable))
return;
Player player = (Player) event.getOwner();
Animals animal = (Animals) event.getEntity();
String name = animal.getType().name().toLowerCase();
// Don't cancel if the player has the appropriate permission
if (player.hasPermission("stablemaster.tame." + name))
return;
event.setCancelled(true);
new LangString("error.cannot-tame", getAnimal(animal.getType())).send(player);
}
示例2: onHorseInventoryClick
import org.bukkit.entity.Animals; //导入依赖的package包/类
/**
* 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 (!Util.inWorld(event.getWhoClicked())) {
return;
}
if (event.getInventory().getHolder() instanceof Animals) {
if (actionAllowed((Player)event.getWhoClicked(), event.getWhoClicked().getLocation(), SettingsFlag.MOUNT_INVENTORY)) {
return;
}
// Elsewhere - not allowed
Util.sendMessage(event.getWhoClicked(), plugin.getLocale(event.getWhoClicked().getUniqueId()).get("island.protected"));
event.setCancelled(true);
}
}
示例3: onFakeEntityDamageByEntityEvent
import org.bukkit.entity.Animals; //导入依赖的package包/类
@EventHandler
public void onFakeEntityDamageByEntityEvent(FakeEntityDamageByEntityEvent e){
RedProtect.get().logger.debug("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)){
RPLang.sendMessage(p, "entitylistener.region.cantpassive");
e.setCancelled(true);
}
}
if (e.getEntity() instanceof Player){
if (r != null && !r.canPVP(p, (Player)e.getEntity())){
RPLang.sendMessage(p, "entitylistener.region.cantpvp");
e.setCancelled(true);
}
}
}
}
示例4: onFakeEntityDamageEvent
import org.bukkit.entity.Animals; //导入依赖的package包/类
@EventHandler
public void onFakeEntityDamageEvent(FakeEntityDamageEvent e){
RedProtect.get().logger.debug("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);
}
}
}
示例5: onInteractEvent
import org.bukkit.entity.Animals; //导入依赖的package包/类
@EventHandler
public void onInteractEvent(PlayerInteractEntityEvent e){
RedProtect.get().logger.debug("RPEntityListener - Is PlayerInteractEntityEvent");
if (e.isCancelled()) {
return;
}
Player p = e.getPlayer();
if (p == null){
return;
}
Location l = e.getRightClicked().getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
Entity et = e.getRightClicked();
if (r != null && !r.canInteractPassives(p) && (et instanceof Animals || et instanceof Villager || et instanceof Golem)) {
if (et instanceof Tameable){
Tameable tam = (Tameable) et;
if (tam.isTamed() && tam.getOwner() != null && tam.getOwner().getName().equals(p.getName())){
return;
}
}
e.setCancelled(true);
RPLang.sendMessage(p, "entitylistener.region.cantinteract");
}
}
示例6: onEntityDamage
import org.bukkit.entity.Animals; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent e) {
Region r = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation());
if (r != null){
return;
}
Entity ent = e.getEntity();
if (ent instanceof LivingEntity && !(ent instanceof Monster)){
if (RPConfig.getGlobalFlagBool(ent.getWorld().getName()+".invincible")){
if (ent instanceof Animals){
((Animals)ent).setTarget(null);
}
e.setCancelled(true);
}
}
}
示例7: onEntityDamage
import org.bukkit.entity.Animals; //导入依赖的package包/类
/**
* Protects animals on a beacon from damage
* @param event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageEvent event) {
World world = event.getEntity().getWorld();
if (!world.equals(getBeaconzWorld())) {
return;
}
//getLogger().info("DEBUG: " + event.getEntityType());
if (!(event.getEntity() instanceof Animals || event.getEntity() instanceof LeashHitch)) {
return;
}
// Check beacon defense
BeaconObj beacon = getRegister().getBeaconAt(event.getEntity().getLocation());
if (beacon != null) {
event.setCancelled(true);
}
}
示例8: getCreatureType
import org.bukkit.entity.Animals; //导入依赖的package包/类
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;
}
示例9: onHorseInventoryClick
import org.bukkit.entity.Animals; //导入依赖的package包/类
/**
* 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);
return;
}
}
示例10: handle
import org.bukkit.entity.Animals; //导入依赖的package包/类
public void handle(CommandInfo commandInfo) {
final Player player = (Player) commandInfo.getSender();
if (teleportQueue.containsKey(player) && teleportQueue.get(player) instanceof Animals) {
StableMaster.commandQueue.remove(player);
Animals animal = (Animals) teleportQueue.get(player);
removeFromQueue(player);
// Horses duplicate with cross world teleports...
if (animal.getLocation().getWorld() != (player).getLocation().getWorld()) {
new LangString("command.teleport.cross-world").send(player);
return;
}
new TeleportEval(animal, player).runTask(StableMaster.getPlugin());
} else {
StableMaster.commandQueue.put(player, this);
teleportQueue.put(player, true);
new LangString("punch-animal").send(player);
}
}
示例11: onTick
import org.bukkit.entity.Animals; //导入依赖的package包/类
@Override
public void onTick(ChunkLocation cl) {
int ni = rand.nextInt(4);
EntityType toSpawn = possibleToSpawn[ni];
Entity[] ents = cl.getChunk().getEntities();
if(ents.length > Feudalism.getConfiguration().getPastureEntityLimit()) {
return;
}
for (Entity enty : ents) {
System.out.println(enty.getType());
if (enty instanceof Animals) {
Location locy = enty.getLocation();
for (int i = 1; i <= Feudalism.getConfiguration().getPastureSpawningAnimals(); i++) {
locy.getWorld().spawnEntity(locy, toSpawn);
}
return;
}
}
}
示例12: startLoveMode
import org.bukkit.entity.Animals; //导入依赖的package包/类
public void startLoveMode(Animals animal) {
EntityAnimal entity = getEntityAnimal(animal);
EntityHuman human = null;
try {
Class<?> c = EntityAnimal.class;
Field bx = c.getDeclaredField("bx");
bx.setAccessible(true);
bx.setInt(entity, 600);
Field by = c.getDeclaredField("by");
by.setAccessible(true);
by.set(entity, human);
entity.breedItem = null;
entity.world.broadcastEntityEffect(entity, (byte)18);
} catch (Exception x) {
throw new RuntimeException(x.toString());
}
}
示例13: startLoveMode
import org.bukkit.entity.Animals; //导入依赖的package包/类
public void startLoveMode(Animals animal) {
EntityAnimal entity = getEntityAnimal(animal);
EntityHuman human = null;
try {
Class<?> c = EntityAnimal.class;
Field bx = c.getDeclaredField("bw");
bx.setAccessible(true);
bx.setInt(entity, 600);
Field by = c.getDeclaredField("bx");
by.setAccessible(true);
by.set(entity, human);
entity.breedItem = null;
entity.world.broadcastEntityEffect(entity, (byte)18);
} catch (Exception x) {
throw new RuntimeException(x.toString());
}
}
示例14: getNmsEntityClass
import org.bukkit.entity.Animals; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static Class<? extends net.minecraft.server.v1_7_R1.Entity> getNmsEntityClass(final Class<? extends LivingEntity> entityClass) throws IllegalArgumentException {
if(entityClass==null) throw new IllegalArgumentException("entityClass must not be null");
if(entityClass==HumanEntity.class || entityClass==Player.class) return net.minecraft.server.v1_7_R1.EntityHuman.class;
if(entityClass==Monster.class) return net.minecraft.server.v1_7_R1.EntityMonster.class;
if(entityClass==Creature.class) return net.minecraft.server.v1_7_R1.EntityCreature.class;
if(entityClass==Animals.class) return net.minecraft.server.v1_7_R1.EntityAnimal.class;
if(entityClass==LivingEntity.class) return net.minecraft.server.v1_7_R1.EntityLiving.class;
for(EntityType entityType: EntityType.values()) {
if(entityType.getEntityClass()==null || entityType.getTypeId()==-1) continue;
if(entityClass.equals(entityType.getEntityClass())) {
return getNmsEntityClass(entityType);
}
}
throw new IllegalArgumentException("Class "+entityClass.getSimpleName()+" is not resolvable to an EntityType");
}
示例15: onMobSpawn
import org.bukkit.entity.Animals; //导入依赖的package包/类
/**
* Prevents mobs spawning at spawn or in an island
*
* @param e
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onMobSpawn(final CreatureSpawnEvent e) {
if (DEBUG2) {
plugin.getLogger().info("on Mob spawn" + e.getEventName());
}
// if grid is not loaded yet, return.
if (plugin.getIslands() == null) {
return;
}
// If not in the right world, return
if (!Util.inWorld(e.getEntity())) {
return;
}
// Deal with natural spawning
if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) {
if (!actionAllowed(e.getLocation(), SettingsFlag.MONSTER_SPAWN)) {
if (DEBUG2)
plugin.getLogger().info("Natural monster spawn cancelled.");
// Mobs not allowed to spawn
e.setCancelled(true);
return;
}
}
if (e.getEntity() instanceof Animals) {
if (!actionAllowed(e.getLocation(), SettingsFlag.ANIMAL_SPAWN)) {
// Animals are not allowed to spawn
if (DEBUG2)
plugin.getLogger().info("Natural animal spawn cancelled.");
e.setCancelled(true);
}
}
}