use of net.minecraft.server.v1_10_R1.Entity in project beam by apache.
the class DatastoreV1Test method testDeleteEntities.
/**
* Test that entities with valid keys are transformed to delete mutations.
*/
@Test
public void testDeleteEntities() throws Exception {
Key key = makeKey("bird", "finch").build();
Entity entity = Entity.newBuilder().setKey(key).build();
DeleteEntityFn deleteEntityFn = new DeleteEntityFn();
Mutation exceptedMutation = makeDelete(entity.getKey()).build();
assertEquals(deleteEntityFn.apply(entity), exceptedMutation);
}
use of net.minecraft.server.v1_10_R1.Entity in project GeoGig by boundlessgeo.
the class CreateOSMChangesetOp method _call.
/**
* Executes the diff operation.
*
* @return an iterator to a set of differences between the two trees
* @see DiffEntry
*/
@Override
protected Iterator<ChangeContainer> _call() {
Iterator<DiffEntry> nodeIterator = command(DiffOp.class).setFilter(OSMUtils.NODE_TYPE_NAME).setNewVersion(newRefSpec).setOldVersion(oldRefSpec).setReportTrees(false).call();
Iterator<DiffEntry> wayIterator = command(DiffOp.class).setFilter(OSMUtils.WAY_TYPE_NAME).setNewVersion(newRefSpec).setOldVersion(oldRefSpec).setReportTrees(false).call();
Iterator<DiffEntry> iterator = Iterators.concat(nodeIterator, wayIterator);
final EntityConverter converter = new EntityConverter();
Function<DiffEntry, ChangeContainer> function = new Function<DiffEntry, ChangeContainer>() {
@Override
@Nullable
public ChangeContainer apply(@Nullable DiffEntry diff) {
NodeRef ref = diff.changeType().equals(ChangeType.REMOVED) ? diff.getOldObject() : diff.getNewObject();
RevFeature revFeature = command(RevObjectParse.class).setObjectId(ref.objectId()).call(RevFeature.class).get();
RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(ref.getMetadataId()).call(RevFeatureType.class).get();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) revFeatureType.type());
ImmutableList<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
ImmutableList<Optional<Object>> values = revFeature.getValues();
for (int i = 0; i < descriptors.size(); i++) {
PropertyDescriptor descriptor = descriptors.get(i);
Optional<Object> value = values.get(i);
featureBuilder.set(descriptor.getName(), value.orNull());
}
SimpleFeature feature = featureBuilder.buildFeature(ref.name());
Entity entity = converter.toEntity(feature, id);
EntityContainer container;
if (entity instanceof Node) {
container = new NodeContainer((Node) entity);
} else {
container = new WayContainer((Way) entity);
}
ChangeAction action = diff.changeType().equals(ChangeType.ADDED) ? ChangeAction.Create : diff.changeType().equals(ChangeType.MODIFIED) ? ChangeAction.Modify : ChangeAction.Delete;
return new ChangeContainer(container, action);
}
};
return Iterators.transform(iterator, function);
}
use of net.minecraft.server.v1_10_R1.Entity in project GeoGig by boundlessgeo.
the class EntityConverter method toEntity.
/**
* Converts a Feature to a OSM Entity
*
* @param feature the feature to convert
* @param replaceId. The changesetId to use in case the feature has a negative one indicating a
* temporary value
* @return
*/
public Entity toEntity(SimpleFeature feature, Long changesetId) {
Entity entity;
SimpleFeatureType type = feature.getFeatureType();
long id = Long.parseLong(feature.getID());
int version = ((Integer) feature.getAttribute("version")).intValue();
Long changeset = (Long) feature.getAttribute("changeset");
if (changesetId != null && changeset < 0) {
changeset = changesetId;
}
Long milis = (Long) feature.getAttribute("timestamp");
Date timestamp = new Date(milis);
String user = (String) feature.getAttribute("user");
String[] userTokens = user.split(":");
OsmUser osmuser;
try {
osmuser = new OsmUser(Integer.parseInt(userTokens[1]), userTokens[0]);
} catch (Exception e) {
osmuser = OsmUser.NONE;
}
String tagsString = (String) feature.getAttribute("tags");
Collection<Tag> tags = OSMUtils.buildTagsCollectionFromString(tagsString);
CommonEntityData entityData = new CommonEntityData(id, version, timestamp, osmuser, changeset, tags);
if (type.equals(OSMUtils.nodeType())) {
Point pt = (Point) feature.getDefaultGeometryProperty().getValue();
entity = new Node(entityData, pt.getY(), pt.getX());
} else {
List<WayNode> nodes = Lists.newArrayList();
String nodesString = (String) feature.getAttribute("nodes");
for (String s : nodesString.split(";")) {
nodes.add(new WayNode(Long.parseLong(s)));
}
entity = new Way(entityData, nodes);
}
return entity;
}
use of net.minecraft.server.v1_10_R1.Entity in project MyPet by xXKeyleXx.
the class PlatformHelper method applyTagToEntity.
@Override
public void applyTagToEntity(TagCompound tag, Entity bukkitEntity) {
net.minecraft.server.v1_10_R1.Entity entity = ((CraftEntity) bukkitEntity).getHandle();
NBTTagCompound vanillaNBT = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
// Just a temporary fix until I come up with a better solution
if (bukkitEntity instanceof Villager) {
EntityVillager villager = (EntityVillager) entity;
villager.setProfession(vanillaNBT.getInt("Profession"));
villager.riches = vanillaNBT.getInt("Riches");
ReflectionUtil.setFieldValue("bJ", villager, vanillaNBT.getInt("Career"));
ReflectionUtil.setFieldValue("bK", villager, vanillaNBT.getInt("CareerLevel"));
ReflectionUtil.setFieldValue("bG", villager, vanillaNBT.getBoolean("Willing"));
if (vanillaNBT.hasKeyOfType("Offers", 10)) {
NBTTagCompound nbttaglist = vanillaNBT.getCompound("Offers");
ReflectionUtil.setFieldValue("trades", villager, new MerchantRecipeList(nbttaglist));
}
NBTTagList invTag = vanillaNBT.getList("Inventory", 10);
for (int i = 0; i < invTag.size(); ++i) {
ItemStack itemstack = ItemStack.createStack(invTag.get(i));
if (itemstack != null) {
villager.inventory.a(itemstack);
}
}
villager.m(true);
if (villager.isBaby()) {
villager.goalSelector.a(8, new PathfinderGoalPlay(villager, 0.32D));
} else if (villager.getProfession() == 0) {
villager.goalSelector.a(6, new PathfinderGoalVillagerFarm(villager, 0.6D));
}
}
// can not be used in 1.10
// entity.f(vanillaNBT);
}
use of net.minecraft.server.v1_10_R1.Entity in project java-docs-samples by GoogleCloudPlatform.
the class Analyze method analyzeEntitiesText.
/**
* Identifies entities in the string {@code text}.
*/
public static void analyzeEntitiesText(String text) throws Exception {
// Instantiate the Language client com.google.cloud.language.v1.LanguageServiceClient
try (LanguageServiceClient language = LanguageServiceClient.create()) {
Document doc = Document.newBuilder().setContent(text).setType(Type.PLAIN_TEXT).build();
AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder().setDocument(doc).setEncodingType(EncodingType.UTF16).build();
AnalyzeEntitiesResponse response = language.analyzeEntities(request);
// Print the response
for (Entity entity : response.getEntitiesList()) {
System.out.printf("Entity: %s", entity.getName());
System.out.printf("Salience: %.3f\n", entity.getSalience());
System.out.println("Metadata: ");
for (Map.Entry<String, String> entry : entity.getMetadataMap().entrySet()) {
System.out.printf("%s : %s", entry.getKey(), entry.getValue());
}
for (EntityMention mention : entity.getMentionsList()) {
System.out.printf("Begin offset: %d\n", mention.getText().getBeginOffset());
System.out.printf("Content: %s\n", mention.getText().getContent());
System.out.printf("Type: %s\n\n", mention.getType());
}
}
}
// [END analyze_entities_text]
}
Aggregations