本文整理匯總了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 + "!");
}
}
示例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();
}
}
示例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());
}
示例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() + ")");
}
}
}
示例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);
}
示例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()));
}
}
}
示例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()));
}
}
}
示例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);
}
示例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));
}
}
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}