下面列出了怎么用org.bukkit.entity.Mob的API类实例代码及写法,或者点击链接到github查看源代码。
private Collection<ItemStack> generateLoot(LivingEntity dead, List<ItemStack> drops){
if(sm.getHookManager().isHookRegistered(PluginCompat.CUSTOMDROPS)){
CustomDropsHook cdh = (CustomDropsHook) sm.getHookManager().getHook(PluginCompat.CUSTOMDROPS);
if(cdh.hasCustomDrops(dead)){
return cdh.getDrops(dead);
}
}
if(dead instanceof Ageable){
if(!((Ageable) dead).isAdult()){
return Collections.emptySet();
}
}
// Default to true to keep the usual behaviour
if (sm.getConfig().getBoolean("use-loot-table-for-drops", true)) {
LootContext lootContext = new LootContext.Builder(dead.getLocation()).lootedEntity(dead).killer(dead.getKiller()).build();
return ((Mob) dead).getLootTable().populateLoot(ThreadLocalRandom.current(), lootContext);
} else
return drops;
}
@Override
public void run(){
for(Entity entity : world.getLivingEntities()){
if(!(entity instanceof Mob)){
continue;
}
if(sm.getLogic().incrementWaiting(entity)){
continue;
}
if(StackTools.hasNotEnoughNear(entity)) {
if(sm.getLogic().notEnoughNearby(entity)){
continue;
}
}
if(sm.getLogic().notSuitableForStacking(entity)){
continue;
}
sm.getLogic().foundMatch(entity);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent e){
LivingEntity entity = e.getEntity();
// IEntityTools before running task
if(!(entity instanceof Mob)){
return;
}
if(sm.getLogic().doSpawnChecks(entity, e.getSpawnReason().toString())){
return;
}
if(sm.getLogic().makeWaiting(entity, e.getSpawnReason())){
return;
}
// BukkitRunnable to delay this, so the needed metadata can be set before attempting to merge.
new SpawnTask(sm, entity).runTask(sm);
}
@EventHandler
public void onStickInteract(PlayerInteractEntityEvent event){
Player player = event.getPlayer();
Entity entity = event.getRightClicked();
if(!(entity instanceof Mob)){
return;
}
if(event.getHand() != EquipmentSlot.HAND) {
return;
}
if (sm.getStickTools().isStackingStick(player.getInventory().getItemInMainHand())) {
if (player.isSneaking()) {
sm.getStickTools().toggleMode(player);
} else {
if(!(StackTools.hasValidMetadata(player, GlobalValues.STICK_MODE))){
player.setMetadata(GlobalValues.STICK_MODE, new FixedMetadataValue(sm, 1));
}
sm.getStickTools().performAction(player, entity);
}
}
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent e) {
if(sm.getCustomConfig().getStringList("no-stack-worlds")
.contains(e.getWorld().getName())){
return;
}
for(Entity currentEntity : e.getChunk().getEntities()){
if(!(currentEntity instanceof Mob)){
continue;
}
// Check if has been cached.
if(sm.getCache().containsKey(currentEntity.getUniqueId())){
int cacheSize = sm.getCache().get(currentEntity.getUniqueId());
sm.getCache().remove(currentEntity.getUniqueId());
StackTools.setSize(currentEntity, cacheSize);
continue;
}
if(currentEntity.getCustomName() != null){
continue;
}
if(sm.getTraitManager().checkTraits(currentEntity)){
continue;
}
if(sm.getHookManager().cantStack(currentEntity)){
continue;
}
if(sm.getLogic().doChecks(currentEntity)){
continue;
}
StackTools.setSize(currentEntity, GlobalValues.NOT_ENOUGH_NEAR);
}
}
private boolean isDamagedTargettingDamager(Entity damager, Entity damaged) {
if (damaged instanceof Mob) {
Mob mob = (Mob) damaged;
return mob.getTarget() != null && mob.getTarget().getUniqueId().equals(damager.getUniqueId());
}
return false;
}
public void run() {
MythicMobsHook mobsHook = (MythicMobsHook) sm.getHookManager().getHook(PluginCompat.MYTHICMOBS);
for (Entity e : WorldTools.getLoadedEntities()) {
if (!sm.getCustomConfig().getStringList("no-stack-worlds").contains(e.getWorld().getName())) {
if(!(e instanceof Mob)){
continue;
}
if (StackTools.hasValidStackData(e)) {
String typeString = e.getType().toString();
int stackSize = StackTools.getSize(e);
int removeAt = sm.getCustomConfig().getInt("tag.remove-at");
if (sm.getCustomConfig().isString("custom." + typeString + ".tag.remove-at")) {
removeAt = sm.getCustomConfig().getInt("custom." + typeString + ".tag.remove-at");
}
if (stackSize > removeAt) {
String format = sm.getCustomConfig().getString("tag.format");
if (sm.getCustomConfig().isString("custom." + typeString + ".tag.format")) {
format = sm.getCustomConfig().getString("custom." + typeString + ".tag.format");
}
// Change if it is a mythic mob.
if (sm.getHookManager().isHookRegistered(PluginCompat.MYTHICMOBS) && mobsHook.isMythicMob(e)) {
typeString = mobsHook.getDisplayName(e);
} else if (sm.getCustomConfig().getBoolean("tag.use-translations")) {
typeString = "" + sm.getTranslationConfig().getString(e.getType().toString());
}
String formattedType = WordUtils.capitalizeFully(typeString.replaceAll("[^A-Za-z0-9]", " "));
String nearlyFinal = StringUtils.replace(StringUtils.replace(StringUtils.replace(format,
"%bukkit_type%", e.getType().toString()),
"%type%", formattedType),
"%size%", String.valueOf(stackSize));
String finalString = ChatColor.translateAlternateColorCodes('&', nearlyFinal);
if(!finalString.equals(e.getCustomName())){
e.setCustomName(finalString);
}
if(!(sm.getHookManager().isHookRegistered(PluginCompat.PROCOTOLLIB))){
boolean alwaysVisible = sm.getCustomConfig().getBoolean("tag.always-visible");
if (sm.getCustomConfig().isString("custom." + typeString + ".tag.always-visible")) {
alwaysVisible = sm.getCustomConfig().getBoolean("custom." + typeString + ".tag.always-visible");
}
e.setCustomNameVisible(alwaysVisible);
}
}
}
}
}
}