Java 类org.bukkit.entity.Villager.Profession 实例源码

项目:Chambers    文件:VillagerManager.java   
/**
 * Spawns a Villager of the given VillagerType at the provided Location
 * 
 * @param type - the Type of the Villager you wish to Spawn
 * @param location - the Location at which you want the Villager to be
 * @return Villager - the Villager that you had set at the provided Location if you wish to use it
 */
public Villager spawnVillager(VillagerType type, Location location) {
    if (!location.getChunk().isLoaded()) {
        location.getChunk().load();
    }
    Villager villager = (Villager) location.getWorld().spawnEntity(location, EntityType.VILLAGER);
    villager.setAdult();
    villager.setAgeLock(true);
    villager.setProfession(Profession.FARMER);
    villager.setRemoveWhenFarAway(false);
    villager.setCustomName(type.getColor() + type.getName());
    villager.setCustomNameVisible(true);
    villager.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, -6, true), true);
    villager.teleport(location, TeleportCause.PLUGIN);
    villager.setHealth(20.0D);
    return villager;
}
项目:Shopkeepers    文件:VillagerShop.java   
@Override
protected void load(ConfigurationSection config) {
    super.load(config);

    // load profession:
    String professionInput;
    if (config.isInt("prof")) {
        // import from pre 1.10 profession ids:
        int profId = config.getInt("prof");
        professionInput = String.valueOf(profId);
        this.profession = getProfessionFromOldId(profId);
    } else {
        professionInput = config.getString("prof");
        this.profession = getProfession(professionInput);
    }
    // validate:
    if (!isVillagerProfession(profession)) {
        // fallback:
        Log.warning("Missing or invalid villager profession '" + professionInput
                + "'. Using '" + Profession.FARMER + "' now.");
        this.profession = Profession.FARMER;
    }
}
项目:Shopkeepers    文件:VillagerShop.java   
private Profession getNextVillagerProfession() {
    Profession[] professions = Profession.values();
    int id = profession.ordinal();
    while (true) {
        id += 1;
        if (id >= professions.length) {
            id = 0;
        }
        Profession nextProfession = professions[id];
        if (isVillagerProfession(nextProfession)) {
            return nextProfession;
        } else {
            continue;
        }
    }
}
项目:Shopkeepers    文件:VillagerShop.java   
private static Profession getProfessionFromOldId(int oldProfessionId) {
    switch (oldProfessionId) {
    case 0:
        return Profession.FARMER;
    case 1:
        return Profession.LIBRARIAN;
    case 2:
        return Profession.PRIEST;
    case 3:
        return Profession.BLACKSMITH;
    case 4:
        return Profession.BUTCHER;
    default:
        return null;
    }
}
项目:ZentrelaRPG    文件:NPCEntity.java   
protected boolean spawn() {
    if (loc.getChunk().isLoaded()) {
        despawn();
        le = type.createEntity(loc.clone().add(0, 0.5, 0));
        boolean mobile = false;
        if (this instanceof GenericNPC) {
            ((Leashable) ((CraftLivingEntity) le).getHandle()).allowWalk(((GenericNPC) this).leash);
            mobile = true;
        }
        String displayName = getColor() + name;
        le.setCustomName(displayName);
        le.setCustomNameVisible(true);
        if (le instanceof Villager) {
            if (this instanceof QuestVillager) {
                ((Villager) le).setProfession(Profession.PRIEST);
            } else if (this instanceof ShopVillager) {
                ((Villager) le).setProfession(Profession.LIBRARIAN);
            } else if (this instanceof DungeonVillager) {
                ((Villager) le).setProfession(Profession.BUTCHER);
            } else if (this instanceof HorseVillager) {
                ((Villager) le).setProfession(Profession.BLACKSMITH);
            }
        }
        if (!mobile) {
            double mult = type.tagHeight;
            as = RTags.makeStand(ChatColor.GRAY + getSub(), loc.clone().add(0, ((CraftLivingEntity) le).getHandle().getHeadHeight() * mult, 0), true);
            NPCManager.npcs.put(as.getUniqueId(), this);
        }
        NPCManager.npcs.put(le.getUniqueId(), this);
        RScheduler.schedule(NPCManager.plugin, new Runnable() {
            public void run() {
                if (loc.getChunk().isLoaded() && le != null && le.isValid()) {
                    le.teleport(loc);
                }
            }
        }, RTicks.seconds(1));
        return true;
    }
    return false;
}
项目:FactionsXL    文件:FMob.java   
/**
 * @param location
 * the location where the villager will spawn
 * @return
 * the spawned villager
 */
public static Villager spawnVillager(Location location) {
    Villager villager = (Villager) location.getWorld().spawnEntity(location, EntityType.VILLAGER);
    if (Version.andHigher(Version.MC1_11).contains(CompatibilityHandler.getInstance().getVersion())) {
        villager.setProfession(Profession.NITWIT);
    } else {
        villager.setProfession(Profession.FARMER);
    }
    villager.setCustomName(MOB_VILLAGER.getMessage());
    villager.setCustomNameVisible(true);
    return villager;
}
项目:FactionsXL    文件:FMob.java   
/**
 * @param location
 * the location where the trader will spawn
 * @return
 * the spawned trader
 */
public static Villager spawnTrader(Location location) {
    Villager villager = (Villager) location.getWorld().spawnEntity(location, EntityType.VILLAGER);
    villager.setProfession(Profession.LIBRARIAN);
    villager.setCustomName(MOB_TRADER.getMessage());
    villager.setCustomNameVisible(true);
    return villager;
}
项目:Skript    文件:VillagerData.java   
@Override
@Nullable
public Villager spawn(final Location loc) {
    final Villager v = super.spawn(loc);
    if (v == null)
        return null;
    if (profession == null)
        v.setProfession(CollectionUtils.getRandom(Profession.values()));
    return v;
}
项目:Skript    文件:VillagerData.java   
@Override
protected boolean deserialize(final String s) {
    if (s.isEmpty())
        return true;
    try {
        profession = Profession.valueOf(s);
        return true;
    } catch (final IllegalArgumentException e) {
        return false;
    }
}
项目:SwornAPI    文件:SpecialEntities.java   
@Override
public LivingEntity spawnZombieVillager(Location loc, Profession profession)
{
    ZombieVillager entity = (ZombieVillager) loc.getWorld().spawnEntity(loc, EntityType.ZOMBIE_VILLAGER);
    entity.setVillagerProfession(profession);
    return entity;
}
项目:SwornAPI    文件:SpecialEntities.java   
@Override
public LivingEntity spawnZombieVillager(Location loc, Profession profession)
{
    Zombie zombie = (Zombie) loc.getWorld().spawnEntity(loc, EntityType.ZOMBIE);
    zombie.setVillagerProfession(profession);
    return zombie;
}
项目:SwornAPI    文件:SpecialEntities.java   
/**
 * Spawns a Zombie Villager at a given location with a given profession.
 * @param loc Location to spawn at
 * @param profession Villager profession, random if null
 * @return The Zombie Villager
 */
public static LivingEntity spawnZombieVillager(Location loc, Profession profession)
{
    if (profession == null) profession = randomElement(Profession.values());

    return provider.spawnZombieVillager(loc, profession);
}
项目:tregmine    文件:GrinchListener.java   
@EventHandler
public void onGrinchDeath(EntityDeathEvent e) {
    final Location loc = e.getEntity().getLocation();
    final World wLoc = loc.getWorld();

    if(e.getEntity().getCustomName() == null){
        return;
    }

    Player player = e.getEntity().getKiller();

    if(e.getEntity().getCustomName().contains("The Grinch!") && (e.getEntityType() == EntityType.GIANT)){

        spawnedGrinch = 0;
        dropXmasBoots(player);
        GrinchDefeatSpeech.speech(player);
        dropExp(e.getEntity().getLocation());

        for(Player p : Bukkit.getOnlinePlayers()){
            if (p.getWorld().getName() == "Christmas"){
                giveCake(p);
            }
        }

        final Villager v = (Villager)wLoc.spawnEntity(loc.add(0,1,0), EntityType.VILLAGER);
        v.setCanPickupItems(false);
        v.setCustomName(ChatColor.GREEN + "The Grinch!");
        v.setProfession(Profession.PRIEST);         
    }
}
项目:Shopkeepers    文件:VillagerShop.java   
private static Profession getProfession(String professionName) {
    if (professionName != null) {
        try {
            return Profession.valueOf(professionName);
        } catch (IllegalArgumentException e) {
        }
    }
    return null;
}
项目:Shopkeepers    文件:VillagerShop.java   
private static boolean isVillagerProfession(Profession profession) {
    if (profession == null) return false;
    if (profession.ordinal() >= Profession.FARMER.ordinal()
            && profession.ordinal() <= Profession.BUTCHER.ordinal()) {
        return true;
    }
    // TODO: update this once we only support MC 1.11 upwards
    if (profession.name().equals("NITWIT")) {
        return true;
    }
    return false;
}
项目:Skript    文件:VillagerData.java   
@Override
protected boolean init(final Literal<?>[] exprs, final int matchedPattern, final ParseResult parseResult) {
    if (matchedPattern > 0)
        profession = Profession.values()[matchedPattern - 1];
    return true;
}
项目:world-of-icerealm    文件:TradingPlugin.java   
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockPlaced(BlockPlaceEvent evt) {
    Block block = evt.getBlock();
    if (block.getType().equals(Material.EMERALD_BLOCK) || block.getType().equals(Material.DIAMOND_BLOCK) || block.getType().equals(Material.IRON_BLOCK)) {
        World world = block.getWorld();

        Block below = world.getBlockAt(new Location(world, block.getX(), block.getY() - 1, block.getZ()));
        Block below2 = world.getBlockAt(new Location(world, block.getX(), block.getY() - 2, block.getZ()));

        if (below != null && below.getType().equals(Material.OBSIDIAN) && below2.getType().equals(Material.OBSIDIAN)) {

            VillagerTradeOffer[] offers = null;

            Profession profession = Profession.FARMER;


            if (block.getType().equals(Material.DIAMOND_BLOCK)) { 
                offers = new VillagerTradeOffer[] {
                        new VillagerTradeOffer(new ItemStack(Material.EMERALD, 24), new ItemStack(Material.DIAMOND_SWORD, 1)),
                        new VillagerTradeOffer(new ItemStack(Material.EMERALD, 64), new ItemStack(Material.DIAMOND_LEGGINGS, 1)),
                        new VillagerTradeOffer(new ItemStack(Material.EMERALD, 64), new ItemStack(Material.DIAMOND_CHESTPLATE, 1)),
                        new VillagerTradeOffer(new ItemStack(Material.EMERALD, 32), new ItemStack(Material.DIAMOND_HELMET, 1)),                 
                        new VillagerTradeOffer(new ItemStack(Material.EMERALD, 32), new ItemStack(Material.DIAMOND_BOOTS, 1)),                  
                        new VillagerTradeOffer(new ItemStack(Material.EMERALD, 24), new ItemStack(Material.DIAMOND_PICKAXE, 1))
                };

                profession = Profession.BLACKSMITH;
            } else if (block.getType().equals(Material.EMERALD_BLOCK)) {
                offers = new VillagerTradeOffer[] {
                        new VillagerTradeOffer(new ItemStack(Material.BONE, 64), new ItemStack(Material.EMERALD, 1)),
                        new VillagerTradeOffer(new ItemStack(Material.ROTTEN_FLESH, 64), new ItemStack(Material.EMERALD, 1)),
                        new VillagerTradeOffer(new ItemStack(Material.SPIDER_EYE, 64), new ItemStack(Material.EMERALD, 1)),
                        new VillagerTradeOffer(new ItemStack(Material.STRING, 64), new ItemStack(Material.EMERALD, 1)),
                };
                profession = Profession.FARMER;
            }

            if (offers != null) {
                block.setType(Material.AIR);
                below.setType(Material.AIR);
                below2.setType(Material.AIR);

                Villager villager = world.spawn(block.getLocation(), Villager.class);
                villager.setAdult();
                villager.setBreed(false);
                villager.setProfession(profession);                 

                EntityVillager entityVillager = ((CraftVillager)villager).getHandle();
                MerchantRecipeList recipes = entityVillager.getOffers(((CraftPlayer)evt.getPlayer()).getHandle());
                recipes.clear();

                for(VillagerTradeOffer offer : offers) {
                    recipes.add(offer.getMerchantRecipie());
                }
            }
        }
    }
}
项目:SonarPet    文件:VillagerPet.java   
@Override
public Profession getProfession() {
    return profession;
}
项目:SonarPet    文件:VillagerPet.java   
@Override
public void setProfession(Profession prof) {
    ((IEntityVillagerPet) getEntityPet()).setProfession(prof);
    this.profession = prof;
}
项目:CanaryBukkit    文件:ProfessionConverter.java   
public static Villager.Profession of(Profession profession) {
    return ProfessionConverter.map.get(profession);
}
项目:CanaryBukkit    文件:ProfessionConverter.java   
public static Profession of(Villager.Profession profession) {
    return ProfessionConverter.map.inverse().get(profession);
}
项目:BedrockAPI    文件:Villager.java   
@Deprecated public static Profession getProfession(int id) {
    return null;
}
项目:Gorm    文件:Castle.java   
/**
 * Private ctor so this is a singleton
 */
private Castle() {
    for (Profession p : Profession.values()) {
        denizenCounts.put(p, 0);
    }
}
项目:Gorm    文件:Castle.java   
public Map<Profession, Integer> getDenizenCounts() {
    return denizenCounts;
}
项目:VillagerNames    文件:VillagerNames.java   
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event)
{
    // Check if Creature is a VILLAGER
    if(event.getEntityType() == EntityType.VILLAGER)
    {
        // Check if event is instance of Villager
        if(event.getEntity() instanceof org.bukkit.entity.Villager){
            // Store the current profession in variable
            Profession currentProfession = ((Villager) event.getEntity()).getProfession();

            // Initialize variable
            String professionConfig = null;

            // If profession == null
            if (currentProfession == null) {
                professionConfig = "other";
            // If profession == FARMER
            } else if (currentProfession.getId() == 0){
                professionConfig = "farmer";
            // If profession == LIBRARIAN
            } else if (currentProfession.getId() == 1){
                professionConfig = "librarian";
            // If profession == PRIEST
            } else if (currentProfession.getId() == 2){
                professionConfig = "priest";
            // If profession == BLACKSMITH
            } else if (currentProfession.getId() == 3){
                professionConfig = "blacksmith";
            // If profession == BUTCHER
            } else if (currentProfession.getId() == 4){
                professionConfig = "butcher";
            }

            // Load the FARMER names out of config.yml into a List
            List<?> names = this.getConfig().getList(professionConfig);
            // Shuffle that list
            java.util.Collections.shuffle(names);
            // Get the first element of the list
            String randomname = names.get(0).toString();

            // Set the custom name of the Villager
            event.getEntity().setCustomName(randomname);
            event.getEntity().setCustomNameVisible(true);

            // Check if log mode is enabled
            if (this.getConfig().getBoolean("log")){
                // Log the actions
                this.getLogger().info("Villager '"+ randomname +"' spawned at location: '" + event.getLocation().getWorld().toString() + "," + event.getLocation().getX() + "," + event.getLocation().getY() + "," + event.getLocation().getZ() +"'");
            }
        }
    }
}
项目:Gorm    文件:Castle.java   
public void incDenizenCount(Profession p) {
    denizenCounts.put(p, denizenCounts.get(p) + 1);

}
项目:SwornAPI    文件:SpecialEntities.java   
LivingEntity spawnZombieVillager(Location loc, Profession profession);
项目:BedrockAPI    文件:Villager.java   
Villager.Profession getProfession();
项目:BedrockAPI    文件:Villager.java   
void setProfession(Villager.Profession profession);