private boolean entityInRange(BaseEntity entity) { switch (TYPE) { case 0: Player player = (Player) entity; return SETTINGS.isEmpty() || (SETTINGS.charAt(0) == 'g' && player.isInGroup(SETTINGS.substring(2))) || (SETTINGS.charAt(0) == 'p' && player.getName().equalsIgnoreCase(SETTINGS.substring(2))); case 1: case 2: return true; case 3: if ((entity.isMob() || entity.isAnimal()) && entity instanceof Mob) { Mob mob = (Mob) entity; if (SETTINGS.isEmpty() || mob.getName().equalsIgnoreCase(SETTINGS)) return true; } break; case 4: case 5: return true; } return false; }
public Long save(BaseEntity instance) { if (instance.getId() == null) { em.persist(instance); } else { instance = em.merge(instance); em.flush(); } return instance.getId(); }
public void remove(BaseEntity instance) { if (em.contains(instance)) { em.remove(instance); } else { BaseEntity persistentInstance = em.find(instance.getClass(), instance.getId()); if (persistentInstance != null) { em.remove(persistentInstance); } } }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || !(obj instanceof BaseEntity<?>)) { return false; } BaseEntity<?> other = (BaseEntity<?>) obj; return (getId() == null ? super.equals(obj) : getId().equals(other.getId())); }
/* (non-Javadoc) * @see rezeptManager.entity.DataEntity#save() */ @Override public LinkedEntity save() { LinkedEntity savedEntity = (LinkedEntity) super.save(); for (LinkedEntity c : childList.values()) { ((BaseEntity) c).save(); } return savedEntity; }
@Override public void delete(Session session) { if (getMemberships() != null) { for (GroupMembership m : getMemberships()) { session.delete(m); } setMemberships(null); } super.delete(session); }
@Test public void isNew() { assertFalse("entity is new.", entity.isNew()); entity.setVersion(null); assertFalse("entity is new.", entity.isNew()); entity.setId(null); assertTrue("entity not new.", entity.isNew()); entity.setVersion(VERSION); assertTrue("entity not new.", entity.isNew()); }
@Override public void run() { @SuppressWarnings("rawtypes") List entities = null; try { switch (TYPE) { case 0: entities = etc.getServer().getPlayerList(); break; case 1: entities = this.WORLD.getMobList(); break; case 2: entities = this.WORLD.getAnimalList(); break; case 3: entities = this.WORLD.getLivingEntityList(); break; case 4: entities = entitiesExceptPlayers(this.WORLD.getWorld()); break; case 5: entities = entitiesExceptPlayersItems(this.WORLD.getWorld()); break; } } catch (ConcurrentModificationException e) { e.printStackTrace(); return; } if (entities == null) return; boolean found = false; for (Object obj : entities) { BaseEntity entity = (BaseEntity) obj; if (entity.getWorld().getType().getId() != WORLD.getType().getId()) continue; double diffX = BLOCK.getBlockX() - entity.getX(); double diffY = BLOCK.getBlockY() - entity.getY(); double diffZ = BLOCK.getBlockZ() - entity.getZ(); if (diffX * diffX + diffY * diffY + diffZ * diffZ < DISTANCE) { boolean result = entityInRange(entity); if (result) { found = true; if (DESTROY) { entity.destroy(); } else { break; } } } } Redstone.setOutput(CraftBook.getCBWorld(WORLD), LEVER, found); }
@Test public void testUpdateProperty() throws IOException { List<BaseEntity> entityList = client.queryByProperty("abstract", "value_1.0", QueryAttributeType.PROPERTY); for (BaseEntity entity : entityList) { Iterator props = entity.getProperties().iterator(); Set<Property> updatesProperties = new HashSet<Property>(); while (props.hasNext()) { Property property = (Property) props.next(); if (property.getMetadata().getMetadataElement().contains("abstract")) property.setValuestr("value_2.0"); updatesProperties.add(property); props.remove(); } entity.setProperties(updatesProperties); client.postEntity(entity); } List<BaseEntity> entityList2 = client.queryByProperty("abstract", "value_2.0", QueryAttributeType.PROPERTY); assertTrue(entityList2.size() > 0); }
@Test public void copyConstructor() { BaseEntity another = new BaseEntity(entity); assertEquals("id not same.", entity.getId(), another.getId()); assertEquals("version not same.", entity.getVersion(), another.getVersion()); }
@Test public void basics() { BaseEntity another = new BaseEntity(); assertNull("id is set.", another.getId()); assertNull("version is set.", another.getVersion()); another.setId(ID); assertNotNull("id is null.", another.getId()); another.setId(null); assertNull("id not cleared.", another.getId()); another.setVersion(VERSION); assertNotNull("version is null.", another.getVersion()); another.setVersion(null); assertNull("version not cleared.", another.getVersion()); }
@SuppressWarnings("rawtypes") protected static boolean damageEntities( List list, World world, int x, int y, int z, int damage, String id) { y = getSafeY(world, x, y, z); boolean damaged = false; boolean isNamed = !id.isEmpty() && !id.equalsIgnoreCase("animal") && !id.equalsIgnoreCase("animals") && !id.equalsIgnoreCase("mob") && !id.equalsIgnoreCase("mobs"); for (Object obj : list) { BaseEntity entity = (BaseEntity) obj; if (entity != null && entity .getWorld() .isChunkLoaded((int) entity.getX(), (int) entity.getY(), (int) entity.getZ()) && (entity.isMob() || entity.isAnimal())) { Vector pVec = new Vector(entity.getX(), entity.getY(), entity.getZ()); if (entity.getWorld() == world && (pVec.getBlockX() == x || pVec.getBlockX() == x + 1 || pVec.getBlockX() == x - 1) && pVec.getBlockY() == y && (pVec.getBlockZ() == z || pVec.getBlockZ() == z + 1 || pVec.getBlockZ() == z - 1)) { if (isNamed) { // Mob mob = (Mob)entity; if (entity.getName().equalsIgnoreCase(id)) { entity.getEntity().a(ODamageSource.j, damage); damaged = true; } } else { entity.getEntity().a(ODamageSource.j, damage); damaged = true; } } } } return damaged; }
public Client withBaseEntity(BaseEntity baseEntity) { this.baseEntity = baseEntity; this.baseEntityId = baseEntity.getId(); return this; }
public void setBaseEntity(BaseEntity baseEntity) { this.baseEntity = baseEntity; this.baseEntityId = baseEntity.getId(); }