当前位置: 首页>>代码示例>>Java>>正文


Java Entity.offer方法代码示例

本文整理汇总了Java中org.spongepowered.api.entity.Entity.offer方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.offer方法的具体用法?Java Entity.offer怎么用?Java Entity.offer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongepowered.api.entity.Entity的用法示例。


在下文中一共展示了Entity.offer方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
    ItemTag item = ItemTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
    LocationTag locationTag = LocationTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
    UtilLocation location = locationTag.getInternal();
    if (location.world == null) {
        queue.handleError(entry, "Invalid location with no world in Spawn command!");
        return;
    }
    Entity entity = location.world.createEntity(EntityTypes.ITEM, location.toVector3d());
    entity.offer(Keys.REPRESENTED_ITEM, item.getInternal().createSnapshot());
    location.world.spawnEntity(entity);
    if (queue.shouldShowGood()) {
        queue.outGood("Dropped item " + ColorSet.emphasis + item.debug() + ColorSet.good
                + " at location " + ColorSet.emphasis + locationTag.debug() + ColorSet.good + "!");
    }
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:18,代码来源:DropCommand.java

示例2: accept

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
@Override
public void accept(Task task) {

    List<Color> colors = Lists.newArrayList(Color.BLACK, Color.BLUE, Color.CYAN, Color.DARK_CYAN, Color.DARK_GREEN, Color.DARK_MAGENTA,
            Color.GRAY, Color.GREEN, Color.LIME, Color.MAGENTA, Color.NAVY, Color.PINK, Color.PURPLE, Color.RED, Color.WHITE, Color.YELLOW);
    Collections.shuffle(colors);

    FireworkEffect fireworkEffect = FireworkEffect.builder()
            .colors(colors.get(0), colors.get(1), colors.get(2))
            .shape(FireworkShapes.STAR)
            .build();

    Entity firework = this.player.getWorld().createEntity(EntityTypes.FIREWORK, this.player.getLocation().getPosition());
    firework.offer(Keys.FIREWORK_EFFECTS, Lists.newArrayList(fireworkEffect));
    firework.offer(Keys.FIREWORK_FLIGHT_MODIFIER, 2);

    this.player.getWorld().spawnEntity(firework);

    this.counter++;

    if (this.counter >= this.ITERATIONS) {
        task.cancel();
    }
}
 
开发者ID:BadgeUp,项目名称:badgeup-sponge-client,代码行数:25,代码来源:FireworkConsumer.java

示例3: putItemInWorld

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
static public void putItemInWorld(ItemStackSnapshot itemStackSnapshop, Location<World> spawnLocation) {
	Extent extent = spawnLocation.getExtent();
	Entity item = extent.createEntity(EntityTypes.ITEM, spawnLocation.getPosition());
	item.offer(Keys.REPRESENTED_ITEM, itemStackSnapshop);
	extent.spawnEntity(item, Cause.source(EntitySpawnCause.builder()
			.entity(item).type(SpawnTypes.PLUGIN).build()).build());

}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:9,代码来源:Shop.java

示例4: execute

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
    ListTag toRemove = ListTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
    Entity entity = null;
    AbstractTagObject ato = entry.getArgumentObject(queue, 0);
    MapTag basic;
    if (CoreUtilities.toLowerCase(ato.toString()).equals("server")) {
        basic = Denizen2Sponge.instance.serverFlagMap;
    }
    else {
        EntityTag entityTag = EntityTag.getFor(queue.error, ato);
        entity = entityTag.getInternal();
        Optional<FlagMap> fm = entity.get(FlagHelper.FLAGMAP);
        if (fm.isPresent()) {
            basic = fm.get().flags;
        }
        else {
            basic = new MapTag();
        }
    }
    for (AbstractTagObject dat : toRemove.getInternal()) {
        basic.getInternal().remove(CoreUtilities.toLowerCase(dat.toString()));
    }
    if (entity != null) {
        entity.offer(new FlagMapDataImpl(new FlagMap(basic)));
        if (queue.shouldShowGood()) {
            queue.outGood("Removed from the entity "
                    + ColorSet.emphasis + new EntityTag(entity).debug() + ColorSet.good
                    + " the specified flags... (" + toRemove.debug() + ")");
        }
    }
    else {
        if (queue.shouldShowGood()) {
            queue.outGood("Removed from the server the specified flags... (" + toRemove.debug() + ")");
        }
    }
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:38,代码来源:UnflagCommand.java

示例5: applySpawnEffect

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
/**
 * Spawns entities around a player, based on which permissions they have. Schedules the entities it spawns for later
 * deletion.
 *
 * @param player the player to spawn entities at
 */
public void applySpawnEffect(Player player) {
    Location<World> location = player.getLocation();
    Set<Entity> ourEntities = new HashSet<>();

    for (String permission : this.permEntityMap.keySet()) {
        if (player.hasPermission(permission)) {
            for (int i = 0; i < NUM_ENTITIES; i++) {
                Entity entity = location.createEntity(this.permEntityMap.get(permission));

                // Entities should be invulnerable for the duration of time that they'll be alive.
                entity.offer(Keys.INVULNERABILITY_TICKS, LIFE_TICKS);
                entity.offer(Keys.INVULNERABLE, true);

                // Entities should despawn if players move far enough away.
                entity.offer(Keys.PERSISTS, false);

                ourEntities.add(entity);
                this.allEntities.add(entity);
            }
        }
    }

    // Schedule cleanup for later.
    Task.builder()
            .delayTicks(LIFE_TICKS)
            .execute(() -> this.removeEntities(ourEntities))
            .submit(this.plugin);
}
 
开发者ID:KittehOrg,项目名称:Vanish,代码行数:35,代码来源:VanishEntitySpawnEffects.java

示例6: onPlayerRideEntity

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
@Listener
public void onPlayerRideEntity(RideEntityEvent.Mount event, @First Player player) {
	if(event.getTargetEntity() instanceof Horse && player.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL).equals(GameModes.CREATIVE)) {
		Entity entity = event.getTargetEntity();
		if(entity.get(Keys.TAMED_OWNER).isPresent()) {
			if(!entity.get(Keys.TAMED_OWNER).get().isPresent()) {
				entity.offer(Keys.TAMED_OWNER, Optional.ofNullable(player.getUniqueId()));
				
			}
		} else {
			entity.offer(Keys.TAMED_OWNER, Optional.ofNullable(player.getUniqueId()));
		}
	}
}
 
开发者ID:EverCraft,项目名称:EverEssentials,代码行数:15,代码来源:EEPlayerListeners.java

示例7: execute

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
    AbstractTagObject ato = entry.getArgumentObject(queue, 0);
    MapTag basic;
    Entity entity = null;
    TimeTag tt = null;
    if (entry.namedArgs.containsKey("duration")) {
        DurationTag duration = DurationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "duration"));
        LocalDateTime ldt = LocalDateTime.now(ZoneId.of("UTC")).plus((long)(duration.getInternal() * 1000), ChronoField.MILLI_OF_SECOND.getBaseUnit());
        tt = new TimeTag(ldt);
    }
    if (CoreUtilities.toLowerCase(ato.toString()).equals("server")) {
        basic = Denizen2Sponge.instance.serverFlagMap;
    }
    else {
        EntityTag entityTag = EntityTag.getFor(queue.error, ato);
        entity = entityTag.getInternal();
        Optional<FlagMap> fm = entity.get(FlagHelper.FLAGMAP);
        if (fm.isPresent()) {
            basic = fm.get().flags;
        }
        else {
            basic = new MapTag();
        }
    }
    MapTag propertyMap = MapTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
    for (Map.Entry<String, AbstractTagObject> dat : propertyMap.getInternal().entrySet()) {
        MapTag gen = new MapTag();
        gen.getInternal().put("value", dat.getValue());
        if (tt != null) {
            gen.getInternal().put("duration", tt);
        }
        basic.getInternal().put(CoreUtilities.toLowerCase(dat.getKey()), gen);
    }
    if (entity != null) {
        entity.offer(new FlagMapDataImpl(new FlagMap(basic)));
        if (queue.shouldShowGood()) {
            queue.outGood("Flagged the entity "
                    + ColorSet.emphasis + new EntityTag(entity).debug() + ColorSet.good
                    + " with the specified data... (" + propertyMap.debug() + ")"
                    + (tt == null ? " For unlimited time. " : " Until time: " + tt.debug()));
        }
    }
    else {
        if (queue.shouldShowGood()) {
            queue.outGood("Flagged the server with the specified data... (" + propertyMap.debug() + ")"
                    + (tt == null ? " For unlimited time. " : " Until time: " + tt.debug()));
        }
    }
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:51,代码来源:FlagCommand.java

示例8: dropItem

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
public static void dropItem(final Location<World> location, final ItemStack itemstack, final Cause cause) {
	Entity entity = location.getExtent().createEntity(EntityTypes.ITEM, location.getPosition());
	entity.offer(Keys.REPRESENTED_ITEM, itemstack.createSnapshot());
	location.getExtent().spawnEntity(entity, cause);
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:6,代码来源:UtilsItemStack.java

示例9: tick

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
public void tick() {
		World w = loc.getExtent();
		Optional<Chunk> chunk = w.getChunkAtBlock(loc.getBlockPosition()); 
		if (le == null) {
			if (chunk.isPresent() && chunk.get().isLoaded()) {
				//first try to link the entity again:
				Collection<Entity> ents = chunk.get().getEntities();
				for (Entity ent : ents) {
					if (( ent.isLoaded() && ent.getType().equals(npcType) && (ent.getUniqueId().equals(lastKnown) || 
						( ent.getLocation().getExtent().equals(loc.getExtent()) && ent.getLocation().getPosition().distanceSquared(loc.getPosition())<1.5) ) ) &&
						( !VillagerShops.isNPCused(ent) &&
						  displayName.equals(ent.get(Keys.DISPLAY_NAME).orElse(null))))
					{	//check if npc already belongs to a different shop
							le = ent; le.setLocationAndRotation(loc, rot); break;
					}
				}
				if (le == null) { //unable to restore
//					Optional<Entity> ent = w.createEntity(npcType, loc.getPosition());
					Entity shop = w.createEntity(npcType, loc.getPosition());
//				    if (ent.isPresent()) {
//				        Entity shop = ent.get();
				        shop.offer(Keys.AI_ENABLED, false);
				        shop.offer(Keys.IS_SILENT, true);
				        
				        //setting variant. super consistent ;D
				        if (variant != null)
					        try {
						        if (npcType.equals(EntityTypes.HORSE)) {
						        	shop.tryOffer(Keys.HORSE_COLOR, (HorseColor)variant);	
		//							((Horse)shop).variant().set((HorseVariant)variant);
								} else if (npcType.equals(EntityTypes.OCELOT)) {
									shop.tryOffer(Keys.OCELOT_TYPE, (OcelotType)variant);
								} else if (npcType.equals(EntityTypes.VILLAGER)) {
									shop.tryOffer(Keys.CAREER, (Career)variant);
								} else if (npcType.equals(EntityTypes.LLAMA)) {
									shop.tryOffer(Keys.LLAMA_VARIANT, (LlamaVariant)variant);
								} else if (npcType.equals(EntityTypes.RABBIT)) {
									shop.tryOffer(Keys.RABBIT_TYPE, (RabbitType)variant);
								} else if (npcType.equals(EntityTypes.PARROT)) {
									shop.tryOffer(Keys.PARROT_VARIANT, (ParrotVariant)variant);
								}
					        } catch (Exception e) { System.err.println("Variant no longer suported! Did the EntityType change?"); }
				        
				        shop.offer(Keys.DISPLAY_NAME, displayName);
				        
				        if (w.spawnEntity(shop)) {
				        	lastKnown = shop.getUniqueId();
				        }
//				    }
				}
			}
		} else if (le != null) {
			if (!le.isLoaded() || !chunk.isPresent() || !chunk.get().isLoaded()) {
				le = null;	//allowing minecraft to free the resources
			} else  if (le.isRemoved() || le.get(Keys.HEALTH).orElse(1.0)<=0) { 
				le = null;
			} else {
				le.setLocationAndRotation(loc, rot);
				if (le instanceof Living) {
					if ((++lookAroundTicks>15 && VillagerShops.rng.nextInt(10) == 0) || lookAroundTicks>100) {
						Living mo = (Living)le;
						lookAroundTicks = 0;
						mo.setHeadRotation(new Vector3d(VillagerShops.rng.nextFloat()*30-14, rot.getY()+VillagerShops.rng.nextFloat()*60-30, 0.0));
					}
				}
			}
		}
	}
 
开发者ID:DosMike,项目名称:VillagerShops,代码行数:69,代码来源:NPCguard.java

示例10: dropAsItem

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
private void dropAsItem() {
    Entity item = this.world.createEntity(EntityTypes.ITEM, this.pos.add(0.5, 0.5, 0.5));
    ItemStack stack = ItemRegistry.get("turtle").createItemStack();
    item.offer(Keys.REPRESENTED_ITEM, stack.createSnapshot());
    this.world.spawnEntity(item, WorldManager.SPAWN_CAUSE);
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:7,代码来源:TurtleEntity.java

示例11: dropItem

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
private void dropItem(ItemStack stack) {
    Entity item = this.world.getWorld().createEntity(EntityTypes.ITEM, getPosition().toDouble().add(0.5, 0.5, 0.5));
    item.offer(Keys.REPRESENTED_ITEM, stack.createSnapshot());
    this.world.getWorld().spawnEntity(item, WorldManager.SPAWN_CAUSE);
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:6,代码来源:TileAutoCrafting.java

示例12: createItemDrop

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
protected Entity createItemDrop(World world, Vector3i pos, ItemStack stack) {
    Entity entity = world.createEntity(EntityTypes.ITEM, pos.toDouble().add(0.5, 0.5, 0.5));
    entity.offer(Keys.REPRESENTED_ITEM, stack.createSnapshot());
    return entity;
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:6,代码来源:CustomBlock.java

示例13: awardPlayer

import org.spongepowered.api.entity.Entity; //导入方法依赖的package包/类
@Override
public boolean awardPlayer(Player player) {
    Optional<String> entityTypeIDOpt = Util.safeGetString(this.data, "entityType");
    if (!entityTypeIDOpt.isPresent()) {
        this.plugin.getLogger().error("No entity type specified. Aborting.");
        return false;
    }

    String entityTypeID = entityTypeIDOpt.get();

    final Optional<EntityType> optType = Sponge.getRegistry().getType(EntityType.class, entityTypeID);
    if (!optType.isPresent()) {
        this.plugin.getLogger().error("Entity type " + entityTypeID + " not found. Aborting.");
        return false;
    }

    // Default to the player's position
    JSONObject rawPosition = Util.safeGetJSONObject(this.data, "position")
            .orElse(new JSONObject().put("x", "~").put("y", "~").put("z", "~"));

    Optional<Vector3d> positionOpt = resolvePosition(rawPosition, player.getLocation().getPosition());
    if (!positionOpt.isPresent()) {
        this.plugin.getLogger().error("Malformed entity position. Aborting.");
        return false;
    }

    Vector3d position = positionOpt.get();
    Entity entity = player.getWorld().createEntity(optType.get(), position);

    Optional<String> colorIdOpt = Util.safeGetString(this.data, "color");
    if (colorIdOpt.isPresent()) {
        Optional<DyeColor> colorOpt = Sponge.getRegistry().getType(DyeColor.class, colorIdOpt.get());
        if (colorOpt.isPresent()) {
            entity.offer(Keys.DYE_COLOR, colorOpt.get());
        } else {
            this.plugin.getLogger().error("Could not retrieve DyeColor with ID " + colorIdOpt.get() + ". Skipping.");
        }
    }

    final Optional<Text> displayNameOpt = Util.deserializeText(Util.safeGet(this.data, "displayName").orElse(null));
    if (displayNameOpt.isPresent()) {
        entity.offer(Keys.DISPLAY_NAME, displayNameOpt.get());
    }

    return player.getWorld().spawnEntity(entity);
}
 
开发者ID:BadgeUp,项目名称:badgeup-sponge-client,代码行数:47,代码来源:EntityAward.java


注:本文中的org.spongepowered.api.entity.Entity.offer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。