use of com.bergerkiller.bukkit.common.internal.hooks.EntityHook in project BKCommonLib by bergerhealer.
the class EntityController method bind.
/**
* Binds this Entity Controller to an Entity. This is called from elsewhere,
* and should be ignored entirely.
*
* @param entity to bind with
* @param handleAttachment whether to fire {@link #onAttached()}
*/
@SuppressWarnings("unchecked")
public final void bind(CommonEntity<?> entity, boolean handleAttachment) {
if (entity == null && this.hook == null) {
throw new RuntimeException("WTF");
}
if (entity != null && entity.getWorld() == null) {
throw new RuntimeException("Can not bind to an Entity that has no world set");
}
if (this.entity != null) {
this.onDetached();
}
this.entity = (T) entity;
if (this.entity != null) {
this.hook = EntityHook.get(this.entity.getHandle(), EntityHook.class);
if (this.hook == null) {
this.hook = new EntityHook();
this.hook.mock(this.entity.getHandle());
}
this.hook.setController(this);
if (handleAttachment) {
this.onAttached();
}
}
}
use of com.bergerkiller.bukkit.common.internal.hooks.EntityHook in project BKCommonLib by bergerhealer.
the class CommonEntity method getController.
/**
* Gets the Entity Controller currently assigned to this Entity, checking to make sure
* the controller is of a certain Class type. When no custom controller is set, or the current
* controller can not be assigned to the type specified, <i>null</i> is returned instead.<br>
* <br>
* This method offers performance benefits over {@link #getController()} by not instantiating a new
* default controller when no controller is set.
*
* @param controllerType to get
* @return the controller of controllerType, or <i>null</i> if not found
*/
@SuppressWarnings("unchecked")
public <C extends EntityController<?>> C getController(Class<? extends C> controllerType) {
EntityHook hook = EntityHook.get(getHandle(), EntityHook.class);
if (hook == null || !hook.hasController()) {
return null;
}
EntityController<?> controller = hook.getController();
if (controllerType.isAssignableFrom(controller.getClass())) {
return (C) controller;
} else {
return null;
}
}
use of com.bergerkiller.bukkit.common.internal.hooks.EntityHook in project BKCommonLib by bergerhealer.
the class CommonEntityType method createCommonEntityNull.
public <T extends Entity> CommonEntity<T> createCommonEntityNull() {
EntityHook hook = new EntityHook();
hook.setStack(new Throwable());
Object handle = hook.createInstance(this.nmsType.getType());
CommonEntity<T> entity = createCommonEntityFromHandle(handle);
DefaultEntityController controller = new DefaultEntityController();
controller.bind(entity, false);
return entity;
}
use of com.bergerkiller.bukkit.common.internal.hooks.EntityHook in project BKCommonLib by bergerhealer.
the class CommonEntityType method createNMSHookFromEntity.
public Object createNMSHookFromEntity(CommonEntity<?> entity) {
EntityHook hook = new EntityHook();
hook.setStack(new Throwable());
return hook.hook(entity.getHandle());
}
use of com.bergerkiller.bukkit.common.internal.hooks.EntityHook in project BKCommonLib by bergerhealer.
the class CommonPlugin method notifyRemovedFromServer.
public void notifyRemovedFromServer(org.bukkit.World world, org.bukkit.entity.Entity e, boolean removeFromChangeSet) {
// Also remove from the set tracking these changes
if (removeFromChangeSet) {
this.entitiesRemovedFromServer.remove(e);
}
// Remove from maps
Iterator<SoftReference<EntityMap>> iter = this.maps.iterator();
while (iter.hasNext()) {
EntityMap map = iter.next().get();
if (map == null) {
iter.remove();
} else {
map.remove(e);
}
}
// Fire events
if (CommonUtil.hasHandlers(EntityRemoveFromServerEvent.getHandlerList())) {
CommonUtil.callEvent(new EntityRemoveFromServerEvent(e));
}
// Remove any entity controllers set for the entities that were removed
EntityHook hook = EntityHook.get(HandleConversion.toEntityHandle(e), EntityHook.class);
if (hook != null && hook.hasController()) {
hook.getController().getEntity().setController(null);
}
}
Aggregations