Java LivingHandlerRegistry Example

Introduction

The java livinghandlerregistry example is extracted from the most popular open source projects, you can refer to the following example for usage.

Programming language: Java

Namespace/package name: jas.spawner.modern.spawner.creature.handler

Example#1
File: CommandCanDespawnHere.javaProject: sylphio/JustAnotherSpawner

 private boolean canEntityDespawnHere(EntityLiving entity) {
   LivingHandlerRegistry livingHandlerRegistry =
       MVELProfile.worldSettings().livingHandlerRegistry();
   List<LivingHandler> livingHandlers = livingHandlerRegistry.getLivingHandlers(entity.getClass());
   CountInfo info = CustomSpawner.spawnCounter.countEntities(entity.worldObj);
   if (!livingHandlers.isEmpty()) {
     for (LivingHandler livingHandler : livingHandlers) {
       if (livingHandler.canDespawn(entity, info)) {
         return true;
       }
     }
     return false;
   }
   return LivingHelper.canDespawn(entity);
 }

Example#2
File: EntityDespawner.javaProject: sylphio/JustAnotherSpawner

 @SubscribeEvent
 public void entityPersistance(AllowDespawn event) {
   if (!event.entity.worldObj.isRemote) {
     LivingHandlerRegistry livingHandlerRegistry =
         MVELProfile.worldSettings().livingHandlerRegistry();
     @SuppressWarnings("unchecked")
     List<LivingHandler> livingHandlers =
         livingHandlerRegistry.getLivingHandlers(
             (Class<? extends EntityLiving>) event.entityLiving.getClass());
     for (LivingHandler livingHandler : livingHandlers) {
       if (livingHandler != null
           && livingHandler.getDespawning() != null
           && livingHandler.getDespawning().isPresent()) {
         event.setResult(Result.DENY);
       }
     }
   }
 }

Example#3
File: EntityDespawner.javaProject: sylphio/JustAnotherSpawner

 @SubscribeEvent
 public void despawner(LivingUpdateEvent event) {
   if (event.entityLiving instanceof EntityLiving
       && event.entityLiving.ticksExisted % 60 == 0
       && !event.entityLiving.worldObj.isRemote) {
     LivingHandlerRegistry livingHandlerRegistry =
         MVELProfile.worldSettings().livingHandlerRegistry();
     if (countInfo == null) {
       updateCountInfo(event.entityLiving.worldObj);
     }
     @SuppressWarnings("unchecked")
     List<LivingHandler> livingHandlers =
         livingHandlerRegistry.getLivingHandlers(
             (Class<? extends EntityLiving>) event.entityLiving.getClass());
     for (LivingHandler livingHandler : livingHandlers) {
       if (livingHandler != null
           && livingHandler.getDespawning() != null
           && livingHandler.getDespawning().isPresent()) {
         livingHandler.despawnEntity((EntityLiving) event.entityLiving, countInfo);
       }
     }
   }
 }