Java 类org.bukkit.entity.Sheep 实例源码

项目:OpenUHC    文件:GoldenFleece.java   
/**
 * Utilizes a random chance to either spawn a skeleton with gold armor or resources.
 *
 * @param event The event
 */
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
  Entity entity = event.getEntity();
  if (entity instanceof Sheep) {
    double chance = Math.random();
    if (0.25 > chance) {
      Skeleton skeleton = entity.getWorld().spawn(entity.getLocation(), Skeleton.class);
      skeleton.getEquipment().setArmorContents(
          new ItemStack[]{
              new ItemStack(Material.GOLD_HELMET),
              new ItemStack(Material.GOLD_CHESTPLATE),
              new ItemStack(Material.GOLD_LEGGINGS),
              new ItemStack(Material.GOLD_BOOTS)
          }
      );
    } else if (0.5 > chance) {
      event.getDrops().add(new ItemStack(Material.IRON_INGOT));
    } else if (0.75 > chance) {
      event.getDrops().add(new ItemStack(Material.GOLD_INGOT));
    } else {
      event.getDrops().add(new ItemStack(Material.DIAMOND));
    }
  }
}
项目:buildinggame    文件:SheepMenu.java   
/**
 * {@inheritDoc}
 */
public SheepMenu(Plot plot, Sheep sheep) {
    super(plot, sheep);

    //sheared
    ItemStack shears = new ItemStack(Material.SHEARS);
    ItemMeta shearsMeta = shears.getItemMeta();
    shearsMeta.setDisplayName(ChatColor.GREEN + "Change whether this sheep is sheared");
    shears.setItemMeta(shearsMeta);

    insertItem(shears, event -> {
        sheep.setSheared(!sheep.isSheared());

        event.setCancelled(true);
    }, 0);
}
项目:BetonQuest    文件:ShearObjective.java   
@EventHandler
public void onShear(PlayerShearEntityEvent event) {
    if (event.getEntity().getType() != EntityType.SHEEP)
        return;
    String playerID = PlayerConverter.getID(event.getPlayer());
    if (!containsPlayer(playerID))
        return;
    if (name != null && (event.getEntity().getCustomName() == null || !event.getEntity().getCustomName().equals(name)))
        return;
    if (color != null && !((Sheep) event.getEntity()).getColor().toString().equalsIgnoreCase(color))
        return;
    SheepData data = (SheepData) dataMap.get(playerID);
    if (checkConditions(playerID))
        data.shearSheep();
    if (data.getAmount() <= 0)
        completeObjective(playerID);
    else if (notify)
        Config.sendMessage(playerID, "sheep_to_shear", new String[] { String.valueOf(data.getAmount()) });
}
项目:mczone    文件:PetInstance.java   
public void setColor(DyeColor color) {
    if (type != EntityType.SHEEP)
        return;
    this.color = color;
    if (entity != null)
        ((Sheep) entity).setColor(color);

    Pets.getDB().update("UPDATE pets SET color='" + color.toString() + "' WHERE id=" + id);
}
项目:mczone    文件:PetInstance.java   
public void update() {
    if (entity != null) {
        //((CraftEntity) entity).getHandle().setEquipment(4, new net.minecraft.server.v1_5_R2.ItemStack(Item.DIAMOND_HELMET));
        //Chat.server(((CraftEntity) entity).getHandle().getEquipment().toString());
        Player owner = Bukkit.getPlayerExact(this.owner);
        if (owner == null)
            return;
        entity.setCustomName(nameColor + name);
        entity.setCustomNameVisible(true);
        if (entity instanceof Tameable) {
            tamed = true;
            ((Tameable) entity).setTamed(true);
            ((Tameable) entity).setOwner(owner);
        }
        if (entity instanceof Ageable && age != null) {
            if (getAge() == Age.BABY)
                ((Ageable) entity).setBaby();
            ((Ageable) entity).setAgeLock(true);
        }
        if (entity instanceof Zombie && age != null) {
            if (getAge() == Age.BABY)
                ((Zombie) entity).setBaby(true);
        }
        if (entity instanceof Sheep && color != null) {
            ((Sheep) entity).setColor(getColor());
        }
    }
}
项目:WebSandboxMC    文件:WebPlayerBridge.java   
public WebPlayerBridge(WebSocketServerThread webSocketServerThread, Settings settings) {
    this.webSocketServerThread = webSocketServerThread;
    this.setCustomNames = settings.setCustomNames;
    this.disableGravity = settings.disableGravity;
    this.disableAI = settings.disableAI;

    if (settings.entityClassName == null || "".equals(settings.entityClassName)) {
        this.entityClass = null;
    } else {
        try {
            this.entityClass = Class.forName("org.bukkit.entity." + settings.entityClassName);
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();

            // HumanEntity.class fails on Glowstone with https://gist.github.com/satoshinm/ebc87cdf1d782ba91b893fe24cd8ffd2
            // so use sheep instead for now. TODO: spawn ala GlowNPC: https://github.com/satoshinm/WebSandboxMC/issues/13
            webSocketServerThread.log(Level.WARNING, "No such entity class " + settings.entityClassName + ", falling back to Sheep");
            this.entityClass = Sheep.class;
        }
    }

    this.constrainToSandbox = settings.entityMoveSandbox;
    this.dieDisconnect = settings.entityDieDisconnect;

    this.clickableLinks = settings.clickableLinks;
    this.clickableLinksTellraw = settings.clickableLinksTellraw;
    this.publicURL = settings.publicURL;

    this.allowAnonymous = settings.allowAnonymous;
    this.lastPlayerID = 0;
    this.channelId2name = new HashMap<ChannelId, String>();
    this.channelId2Entity = new HashMap<ChannelId, Entity>();
    this.entityId2Username = new HashMap<Integer, String>();
    this.name2channel = new HashMap<String, Channel>();
}
项目:PA    文件:ExplosiveSheep.java   
@Override
public void play(PAUser u) {
    if (isInCooldown(u, getName())) return;

    final Sheep o = (Sheep) spawnEntity(u.getLoc(), EntityType.SHEEP);
    o.setAdult();
    o.setColor(DyeColor.values()[r.nextInt(DyeColor.values().length)]);
    o.setCustomName(Utils.colorize("&dOveja Fiestera"));
    o.setCustomNameVisible(true);
    o.setNoDamageTicks(Integer.MAX_VALUE);
    o.setVelocity(u.getPlayer().getLocation().getDirection().multiply(2));

    PAServer.users.forEach(h -> h.sendSound(Sounds.SHEEP_IDLE));

    bt = plugin.getServer().getScheduler().runTaskTimer(plugin, () -> {
        ColorParser dc = ColorParser.values()[r.nextInt(ColorParser.values().length)];
        o.setColor(dc.getDyeColor());
        o.setCustomName(Utils.colorize(dc.getChatColor() + "Oveja Fiestera"));

        if (count <= 0) {
            PAServer.users.forEach(h -> h.sendSound(Sounds.EXPLODE));
            ParticleEffect.EXPLOSION_HUGE.send(plugin.getServer().getOnlinePlayers(), o.getLocation(), 0, 0, 0, 1, 20, 50);
            o.remove();
            bt.cancel();
            return;
        }
        count--;
    }, 0, 20);
}
项目:Skript    文件:SheepData.java   
@SuppressWarnings("null")
@Override
protected boolean init(final @Nullable Class<? extends Sheep> c, final @Nullable Sheep e) {
    sheared = e == null ? 0 : e.isSheared() ? 1 : -1;
    colors = e == null ? null : new Color[] {Color.byWoolColor(e.getColor())};
    return true;
}
项目:Skript    文件:SheepData.java   
@Override
public void set(final Sheep entity) {
    if (colors != null) {
        final Color c = CollectionUtils.getRandom(colors);
        assert c != null;
        entity.setColor(c.getWoolColor());
    }
}
项目:Skript    文件:SheepData.java   
@Override
public boolean match(final Sheep entity) {
    return (sheared == 0 || entity.isSheared() == (sheared == 1))
            && (colors == null || SimpleExpression.check(colors, new Checker<Color>() {
                @Override
                public boolean check(final @Nullable Color c) {
                    return c != null && entity.getColor() == c.getWoolColor();
                }
            }, false, false));
}
项目:Skript    文件:EffShear.java   
@Override
protected void execute(final Event e) {
    for (final LivingEntity en : sheep.getArray(e)) {
        if (en instanceof Sheep) {
            ((Sheep) en).setSheared(shear);
        }
    }
}
项目:AdvancedAchievements    文件:AchieveShearListener.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerShearEntity(PlayerShearEntityEvent event) {
    if (!(event.getEntity() instanceof Sheep)) {
        return;
    }

    Player player = event.getPlayer();
    NormalAchievements category = NormalAchievements.SHEARS;
    if (!shouldIncreaseBeTakenIntoAccount(player, category)) {
        return;
    }

    updateStatisticAndAwardAchievementsIfAvailable(player, category, 1);
}
项目:modules-extra    文件:ListenerPlayerEntity.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event)
{
    if (!(event.getRightClicked() instanceof LivingEntity))
    {
        return;
    }
    Player player = event.getPlayer();
    Entity entity = event.getRightClicked();
    ActionPlayerEntity action;
    if (player.getItemInHand().getType() == COAL && entity instanceof PoweredMinecart)
    {
        action = this.newAction(UseFurnaceMinecart.class, entity.getWorld());
    }
    else if (player.getItemInHand().getType() == INK_SACK && entity instanceof Sheep || entity instanceof Wolf)
    {
        action = this.newAction(EntityDye.class, entity.getWorld());
        if (action != null)
        {
            ((EntityDye)action).setColor(((Dye)player.getItemInHand().getData()).getColor());
        }
    }
    else if (player.getItemInHand().getType().equals(BOWL) && entity instanceof MushroomCow)
    {
        action = this.newAction(EntityFillSoup.class, entity.getWorld());
    }
    else
    {
        return;
    }
    if (action != null)
    {
        action.setEntity(entity);
        action.setPlayer(player);
        action.setLocation(entity.getLocation());
        this.logAction(action);
    }
}
项目:TheSurvivalGames    文件:ThrowableSpawnEggs.java   
@EventHandler
public void throwEgg(PlayerEggThrowEvent event) {
    Egg egg = event.getEgg();
    if (this.eggs.containsKey(egg)) {
        EntityType entityType = (EntityType) this.eggs.get(egg);
        Entity entity = egg.getWorld().spawnEntity(egg.getLocation(), entityType);
        if (entityType == EntityType.SHEEP) {
            ((Sheep) entity).setColor(org.bukkit.DyeColor.values()[((int) (java.lang.Math.random() * org.bukkit.DyeColor.values().length))]);
            event.setHatching(false);
        }
    }
}
项目:NucleusFramework    文件:SheepAnimal.java   
public SheepAnimal(Entity entity) {
    PreCon.notNull(entity);
    PreCon.isValid(entity instanceof Sheep, "org.bukkit.entity.Sheep expected.");

    Sheep sheep = (Sheep)entity;

    _isSheared = sheep.isSheared();
}
项目:NucleusFramework    文件:SheepAnimal.java   
@Override
public boolean apply(Entity entity) {
    PreCon.notNull(entity);
    PreCon.isValid(entity instanceof Sheep, "org.bukkit.entity.Sheep expected.");

    Sheep sheep = (Sheep)entity;

    sheep.setSheared(_isSheared);

    return true;
}
项目:DiscoSheep    文件:LightningParty.java   
/**
 * Strike a certain percentage of the spawned sheep with lightning effects.
 * The lightning effects should be purely visual, ie. not set anything on fire.
 * @return The sheep that was spawned.
 */
@Override
protected Sheep spawnSheep() {
    Sheep sheep = super.spawnSheep();
    if (count > 0) {
        --count;
        sheep.getWorld().strikeLightningEffect(sheep.getLocation());
    }
    return sheep;
}
项目:DiscoSheep    文件:LightningParty.java   
/**
 * Strike sheep with lightning 0.05% of the time.
 */
@Override
protected void updateSheep(Sheep sheep) {
    super.updateSheep(sheep);
    Random r = new Random();
    if (r.nextDouble() < 0.005) {
        sheep.getWorld().strikeLightningEffect(sheep.getLocation());
    }
}
项目:DiscoSheep    文件:JebParty.java   
/**
 * Spawns a sheep and sets its name to "jeb_", using the easter egg to change colours
 * This feature has been around for long enough so it should be safe to use.
 * @return The sheep that was spawned
 */
@Override
protected Sheep spawnSheep() {
    Sheep sheep = super.spawnSheep();
    sheep.setCustomName("jeb_");
    sheep.setCustomNameVisible(false);
    return sheep;
}
项目:DiscoSheep    文件:BabyParty.java   
@Override
protected Sheep spawnSheep() {
    Sheep sheep = super.spawnSheep();
    if (sheepBabyCount > 0) {
        sheep.setBaby();
        --sheepBabyCount;
    }
    return sheep;
}
项目:DiscoSheep    文件:FireworkParty.java   
@Override
protected void updateSheep(Sheep sheep) {
    super.updateSheep(sheep);
    if (getState() % 8 == 0 && r.nextDouble() < 0.5) {
        spawnRandomFireworkAtSheep(sheep);
    }
}
项目:DiscoSheep    文件:PartyEvents.java   
/**
 * Handler that prevents sheep shearing
 *
 * @param e The event
 */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerShear(PlayerShearEntityEvent e) {
    if (e.getEntity() instanceof Sheep && isFromParty(e.getEntity())) {
        e.setCancelled(true);
    }
}
项目:EntityAPI    文件:ControllableWolfBase.java   
@Override
public BehaviourItem[] getDefaultTargetingBehaviours() {
    return new BehaviourItem[]{
            new BehaviourItem(1, new BehaviourHelpTamerTarget(this)),
            new BehaviourItem(2, new BehaviourDefendTamer(this)),
            new BehaviourItem(3, new BehaviourHurtByTarget(this, true)),
            new BehaviourItem(4, new BehaviourRandomTargetNonTamed(this, Sheep.class, 200, false))
    };
}
项目:Hub    文件:MoutMout2000Displayer.java   
@Override
public void display()
{
    World craftbukkitWorld = ((CraftWorld) this.player.getWorld()).getHandle();
    MoutMout2000Sheep craftbukkitSheep = new MoutMout2000Sheep(craftbukkitWorld);
    craftbukkitSheep.setPosition(this.player.getLocation().getX(), this.player.getLocation().getY(), this.player.getLocation().getZ());
    craftbukkitWorld.addEntity(craftbukkitSheep, CreatureSpawnEvent.SpawnReason.CUSTOM);

    Sheep sheep = (Sheep) craftbukkitSheep.getBukkitEntity();
    sheep.setCustomName(ChatColor.GOLD + "" + ChatColor.BOLD + "MoutMout 2000");
    sheep.setCustomNameVisible(true);
    sheep.setColor(DyeColor.WHITE);

    this.loopTask = this.hub.getServer().getScheduler().runTaskTimer(this.hub, new Runnable()
    {
        int timer = 0;
        int ticks = 0;

        @Override
        public void run()
        {
            this.ticks++;

            if (ticks == 10)
            {
                int r1i = GadgetManager.RANDOM.nextInt(17) + 1;
                int r2i = GadgetManager.RANDOM.nextInt(17) + 1;
                Color c1 = ColorUtils.getColor(r1i);
                Color c2 = ColorUtils.getColor(r2i);

                sheep.setColor(DyeColor.values()[GadgetManager.RANDOM.nextInt(DyeColor.values().length)]);
                craftbukkitSheep.lastDamager = ((CraftPlayer) player).getHandle();

                FireworkEffect effect = FireworkEffect.builder().flicker(GadgetManager.RANDOM.nextBoolean()).withColor(c1).withFade(c2).with(FireworkEffect.Type.BURST).trail(GadgetManager.RANDOM.nextBoolean()).build();
                FireworkUtils.launchfw(hub, sheep.getLocation(), effect);
            }
            else if (ticks == 20)
            {
                this.ticks = 0;
                this.timer++;
            }

            if (timer == 15)
            {
                sheep.getLocation().getWorld().createExplosion(sheep.getLocation().getX(), sheep.getLocation().getY(), sheep.getLocation().getZ(), 5, false, false);
                sheep.remove();
                end();
                callback();
            }
        }
    }, 1L, 1L);
}
项目:Skript    文件:SheepData.java   
@Override
public Class<Sheep> getType() {
    return Sheep.class;
}
项目:Thermos-Bukkit    文件:SheepDyeWoolEvent.java   
public SheepDyeWoolEvent(final Sheep sheep, final DyeColor color) {
    super(sheep);
    this.cancel = false;
    this.color = color;
}
项目:Thermos-Bukkit    文件:SheepDyeWoolEvent.java   
@Override
public Sheep getEntity() {
    return (Sheep) entity;
}
项目:Thermos-Bukkit    文件:SheepRegrowWoolEvent.java   
public SheepRegrowWoolEvent(final Sheep sheep) {
    super(sheep);
    this.cancel = false;
}
项目:Thermos-Bukkit    文件:SheepRegrowWoolEvent.java   
@Override
public Sheep getEntity() {
    return (Sheep) entity;
}
项目:SonarPet    文件:EntitySheepPet.java   
@Override
public Sheep getBukkitEntity() {
    return (Sheep) super.getBukkitEntity();
}
项目:CauldronGit    文件:SheepDyeWoolEvent.java   
public SheepDyeWoolEvent(final Sheep sheep, final DyeColor color) {
    super(sheep);
    this.cancel = false;
    this.color = color;
}
项目:CauldronGit    文件:SheepDyeWoolEvent.java   
@Override
public Sheep getEntity() {
    return (Sheep) entity;
}
项目:CauldronGit    文件:SheepRegrowWoolEvent.java   
public SheepRegrowWoolEvent(final Sheep sheep) {
    super(sheep);
    this.cancel = false;
}
项目:CauldronGit    文件:SheepRegrowWoolEvent.java   
@Override
public Sheep getEntity() {
    return (Sheep) entity;
}
项目:CanaryBukkit    文件:CanarySheep.java   
public CanarySheep(net.canarymod.api.entity.living.animal.Sheep entity) {
    super(entity);
}
项目:CanaryBukkit    文件:CanarySheep.java   
@Override
protected net.canarymod.api.entity.living.animal.Sheep getHandle() {
    return (net.canarymod.api.entity.living.animal.Sheep) super.getHandle();
}
项目:SimpleEgg    文件:LorePacker.java   
/**
 * Assembles an ArrayList of the properties for the specified Entity that
 * is to be used for a spawn egg. All instanceof checks are done internally
 * by the LorePackager, so no type checking is required prior to calling
 * this method. Null Entities will throw an IllegalArgumentException. <b>The
 * actual ArrayList is returned by {@link #getLore() LorePacker.getLore()}.
 * </b>
 * @param livingEntity - The Entity to assemble a lore for.
 * @return An ArrayList of Strings
 * @throws IllegalArgumentException If entity parameter is null
 */
public LorePacker(LivingEntity livingEntity) throws IllegalArgumentException {
    if (livingEntity == null) {
        throw new IllegalArgumentException("Can't assemble lore for a null entity!");
    }

    lore = new ArrayList<String>();
    // This needs to always be on top of an egg's lore
    lore.add("Identifier: SimpleEgg." + livingEntity.getType().getEntityClass().getSimpleName() + "." + Main.getSelf().getDescription().getVersion());
    lore.addAll(livingEntity(livingEntity));

    if (livingEntity instanceof Ageable) {
        lore.addAll(ageable((Ageable) livingEntity));

        if (livingEntity instanceof Sheep) {
            lore.addAll(sheep((Sheep) livingEntity));
        } else if (livingEntity instanceof Pig) {
            lore.addAll(pig((Pig) livingEntity));
        } else if (livingEntity instanceof Rabbit) {
            lore.addAll(rabbit((Rabbit) livingEntity));
        } else if (livingEntity instanceof Villager) {
            lore.addAll(villager((Villager) livingEntity));
        } else if (livingEntity instanceof Tameable) {
            lore.addAll(tameable((Tameable) livingEntity));

            if (livingEntity instanceof AbstractHorse) {
                lore.addAll(abstractHorse((AbstractHorse) livingEntity));

                if (livingEntity instanceof Horse) {
                    lore.addAll(horse((Horse) livingEntity));
                } else if (livingEntity instanceof ChestedHorse) {
                    lore.addAll(chestedHorse((ChestedHorse) livingEntity));

                    if (livingEntity instanceof Llama) {
                        lore.addAll(llama((Llama) livingEntity));
                    }
                }
            } else if (livingEntity instanceof Sittable) {
                lore.addAll(sittable((Sittable) livingEntity));

                if (livingEntity instanceof Wolf) {
                    lore.addAll(wolf((Wolf) livingEntity));
                } else if (livingEntity instanceof Ocelot) {
                    lore.addAll(ocelot((Ocelot) livingEntity));
                } else if (livingEntity instanceof Parrot) {
                    lore.addAll(parrot((Parrot) livingEntity));
                }
            }
        }
    } else if (livingEntity instanceof Slime) {
        lore.addAll(slime((Slime) livingEntity));
    } else if (livingEntity instanceof Creeper) {
        lore.addAll(creeper((Creeper) livingEntity));
    } else if (livingEntity instanceof Zombie) {
        lore.addAll(zombie((Zombie) livingEntity));

        if (livingEntity instanceof PigZombie) {
            lore.addAll(pigZombie((PigZombie) livingEntity));
        } else if (livingEntity instanceof ZombieVillager) {
            lore.addAll(zombieVillager((ZombieVillager) livingEntity));
        }
    } else if (livingEntity instanceof Spellcaster) {
        lore.addAll(spellCaster((Spellcaster) livingEntity));
    } else if (livingEntity instanceof IronGolem) {
        lore.addAll(ironGolem((IronGolem) livingEntity));
    } else if (livingEntity instanceof Snowman) {
        lore.addAll(snowman((Snowman) livingEntity));
    }
}
项目:AncientGates    文件:EntityUtil.java   
public static String getEntityTypeData(final Entity entity) {
    String data = "";

    if (entity instanceof LivingEntity) {
        data += String.valueOf(((LivingEntity) entity).getHealth()) + ",";
        data += String.valueOf(((LivingEntity) entity).getMaxHealth()) + ",";
        data += String.valueOf(((LivingEntity) entity).getCustomName()) + ",";
        if (entity instanceof Animals) {
            data += String.valueOf(((Animals) entity).getAge()) + ",";
            if (entity instanceof Sheep) {
                data += String.valueOf(((Sheep) entity).isSheared()) + ",";
                data += ((Sheep) entity).getColor().name() + ",";
            } else if (entity instanceof Wolf) {
                data += String.valueOf(((Wolf) entity).isAngry()) + ",";
                if (((Wolf) entity).isTamed()) {
                    data += ((Tameable) entity).getOwner().getName() + ",";
                    data += String.valueOf(((Wolf) entity).getCollarColor()) + ",";
                }
            } else if (entity instanceof Ocelot) {
                if (((Ocelot) entity).isTamed()) {
                    data += ((Tameable) entity).getOwner().getName() + ",";
                    data += String.valueOf(((Ocelot) entity).getCatType().name()) + ",";
                }
            } else if (entity instanceof Pig) {
                data += String.valueOf(((Pig) entity).hasSaddle()) + ",";
            } else if (entity instanceof Horse) {
                data += "deprecated" + ",";
                data += String.valueOf(((Horse) entity).getStyle().name()) + ",";
                data += String.valueOf(((Horse) entity).getColor().name()) + ",";
                data += String.valueOf(((Horse) entity).getDomestication()) + ",";
                data += String.valueOf(((Horse) entity).getMaxDomestication()) + ",";
                data += String.valueOf(((Horse) entity).getJumpStrength()) + ",";
                if (((Horse) entity).isTamed()) {
                    data += (((Tameable) entity).getOwner() != null ? ((Tameable) entity).getOwner().getName() : null) + ",";
                    data += ItemStackUtil.itemStackToString(((Horse) entity).getInventory().getSaddle()) + ",";
                    data += ItemStackUtil.itemStackToString(((Horse) entity).getInventory().getArmor()) + ",";
                    if (((Horse) entity).isCarryingChest()) {
                        data += ItemStackUtil.itemStackToString(((Horse) entity).getInventory().getContents()) + ",";
                    }
                }
            }
        } else if (entity instanceof Villager) {
            data += String.valueOf(((Villager) entity).getProfession().name()) + ",";
            data += String.valueOf(((Villager) entity).getAge()) + ",";
        } else if (entity instanceof Creeper) {
            data += String.valueOf(((Creeper) entity).isPowered()) + ",";
        } else if (entity instanceof Slime) {
            data += String.valueOf(((Slime) entity).getSize()) + ",";
        } else if (entity instanceof Skeleton) {
            data += String.valueOf(((Skeleton) entity).getSkeletonType().name()) + ",";
        }
    }

    return data;
}
项目:AncientGates    文件:EntityUtil.java   
public static void setEntityTypeData(final Entity entity, final String data) {
    if (data == "")
        return;

    final String parts[] = data.split(",");
    if (entity instanceof LivingEntity) {
        ((LivingEntity) entity).setMaxHealth(Double.parseDouble(parts[1]));
        ((LivingEntity) entity).setHealth(Double.parseDouble(parts[0]));
        if (!parts[2].equals("null"))
            ((LivingEntity) entity).setCustomName(parts[2]);
        if (entity instanceof Animals) {
            ((Animals) entity).setAge(Integer.parseInt(parts[3]));
            if (entity instanceof Sheep) {
                ((Sheep) entity).setSheared(Boolean.parseBoolean(parts[4]));
                ((Sheep) entity).setColor(sheepColors.get(parts[5]));
            } else if (entity instanceof Wolf) {
                if (Boolean.parseBoolean(parts[4])) {
                    ((Wolf) entity).setAngry(Boolean.parseBoolean(parts[4]));
                } else if (parts.length > 5) {
                    ((Tameable) entity).setTamed(true);
                    ((Tameable) entity).setOwner(getPlayer(parts[5]));
                    ((Wolf) entity).setCollarColor(DyeColor.valueOf(parts[6]));
                }
            } else if (entity instanceof Ocelot) {
                if (parts.length > 4) {
                    ((Tameable) entity).setTamed(true);
                    ((Tameable) entity).setOwner(getPlayer(parts[4]));
                    ((Ocelot) entity).setCatType(catTypes.get(parts[5]));
                }
            } else if (entity instanceof Pig) {
                ((Pig) entity).setSaddle(Boolean.parseBoolean(parts[4]));
            } else if (entity instanceof Horse) {
                // ((Horse) entity).setVariant(horseVariants.get(parts[4]));
                ((Horse) entity).setStyle(horseStyles.get(parts[5]));
                ((Horse) entity).setColor(horseColors.get(parts[6]));
                ((Horse) entity).setDomestication(Integer.parseInt(parts[7]));
                ((Horse) entity).setMaxDomestication(Integer.parseInt(parts[8]));
                ((Horse) entity).setJumpStrength(Double.parseDouble(parts[9]));
                if (parts.length > 10) {
                    ((Tameable) entity).setTamed(true);
                    if (!parts[10].equals("null"))
                        ((Tameable) entity).setOwner(getPlayer(parts[10]));
                    ((Horse) entity).getInventory().setSaddle(ItemStackUtil.stringToItemStack(parts[11])[0]);
                    ((Horse) entity).getInventory().setArmor(ItemStackUtil.stringToItemStack(parts[12])[0]);
                    if (parts.length > 13) {
                        ((Horse) entity).setCarryingChest(true);
                        ((Horse) entity).getInventory().setContents(ItemStackUtil.stringToItemStack(parts[13]));
                    }
                }
            }
        } else if (entity instanceof Villager) {
            ((Villager) entity).setProfession(villagerProfessions.get(parts[3]));
            ((Villager) entity).setAge(Integer.parseInt(parts[4]));
        } else if (entity instanceof Creeper) {
            ((Creeper) entity).setPowered(Boolean.parseBoolean(parts[3]));
        } else if (entity instanceof Slime) {
            ((Slime) entity).setSize(Integer.parseInt(parts[3]));
        } else if (entity instanceof Skeleton) {
            ((Skeleton) entity).setSkeletonType(skeletonTypes.get(parts[3]));
            if (parts[3].equals("0")) {
                ((Skeleton) entity).getEquipment().setItemInHand(new ItemStack(Material.BOW));
            } else {
                ((Skeleton) entity).getEquipment().setItemInHand(new ItemStack(Material.BOW));
            }
        } else if (entity instanceof PigZombie) {
            ((LivingEntity) entity).getEquipment().setItemInHand(new ItemStack(Material.GOLD_SWORD));
        }
    }
}
项目:PwnBreeding    文件:FeedListener.java   
@EventHandler(ignoreCancelled = true)
  public void onAnimalClick(PlayerInteractEntityEvent e)
  {
// THIS EVENT FIRES TOO FAST WE NEED A TIMER


World eworld = e.getPlayer().getLocation().getWorld();

// If plugin is not enabled in this world, return
if (!PwnBreeding.isEnabledIn(eworld.getName())) return; 

      Player player = e.getPlayer(); 
      String thisItem = player.getItemInHand().getType().toString();

      if(e.getRightClicked() instanceof Chicken)
      {          

        e.setCancelled(true);

          player.sendMessage(ChatColor.GOLD + "Player has " + thisItem + " for a " + e.getRightClicked().getType().toString());
          if (player.getItemInHand().getType() == Material.SEEDS) 
          {
              if(player.getItemInHand().getAmount() > 1) 
              {
                    player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1);
              } 
              else 
              {
                  player.getItemInHand().setAmount(0);
              }
          }
      }
      else if(e.getRightClicked() instanceof Cow)
      {
          player.sendMessage(ChatColor.GOLD + "Player has " + thisItem + " for a " + e.getRightClicked().getType().toString());
      }
      else if(e.getRightClicked() instanceof Sheep)
      {
          player.sendMessage(ChatColor.GOLD + "Player has " + thisItem + " for a " + e.getRightClicked().getType().toString());
      }
      else if(e.getRightClicked() instanceof Pig)
      {
          player.sendMessage(ChatColor.GOLD + "Player has " + thisItem + " for a " + e.getRightClicked().getType().toString());
      }
      else if(e.getRightClicked() instanceof Horse)
      {
          player.sendMessage(ChatColor.GOLD + "Player has " + thisItem + " for a " + e.getRightClicked().getType().toString());
      }
      else if(e.getRightClicked() instanceof Wolf)
      {
          player.sendMessage(ChatColor.GOLD + "Player has " + thisItem + " for a " + e.getRightClicked().getType().toString());
      }
      else if(e.getRightClicked() instanceof Ocelot)
      {
          player.sendMessage(ChatColor.GOLD + "Player has " + thisItem + " for a " + e.getRightClicked().getType().toString());
      }
      else if(e.getRightClicked() instanceof Rabbit)
      {
          player.sendMessage(ChatColor.GOLD + "Player has " + thisItem + " for a " + e.getRightClicked().getType().toString());
      }        
  }