本文整理汇总了Java中org.spongepowered.api.entity.Entity类的典型用法代码示例。如果您正苦于以下问题:Java Entity类的具体用法?Java Entity怎么用?Java Entity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Entity类属于org.spongepowered.api.entity包,在下文中一共展示了Entity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPlayerDamage
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
@Listener
public void onPlayerDamage(DamageEntityEvent event) {
if (!Config.Values.Synchronize.getEnableHealth())
return;
Entity player = event.getTargetEntity();
if (!(player instanceof Player))
return;
synchronized (waitingPlayers) {
if (waitingPlayers.containsKey(player.getUniqueId())) {
event.setCancelled(true);
}
}
}
示例2: onServerSTarted
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
@Listener
public void onServerSTarted(GameStartedServerEvent event) {
Task.builder()
.delay(5, TimeUnit.SECONDS)
.interval(1, TimeUnit.SECONDS)
.name("Disco Changer")
.execute(() -> {
// DISCO DISCO TIME
ImmutableList<Aspect> aspects = ImmutableList.copyOf(Sponge.getRegistry().getAllOf(Aspect.class));
for (Map.Entry<UUID, UUID> entry : this.auraMap.entrySet()) {
Optional<World> world = Sponge.getServer().getWorld(entry.getKey());
world.ifPresent(spongeWorld -> {
Optional<Entity> aura = spongeWorld.getEntity(entry.getValue());
aura.ifPresent(auraNode -> {
AuraNodeData nodeData = ((AuraNode) auraNode).auraNodeData();
Aspect value = aspects.get(RANDOM.nextInt(aspects.size()));
nodeData.set(ThaumicKeys.AURA_NODE_ASPECT, value);
nodeData.set(ThaumicKeys.AURA_NODE_SIZE, RANDOM.nextInt(400));
auraNode.offer(nodeData);
});
});
}
})
.submit(this);
}
示例3: 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();
}
}
示例4: CachedEntity
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
public CachedEntity(Entity entity) {
super(entity);
this.type = new CachedCatalogType(entity.getType());
this.uuid = UUID.fromString(entity.getUniqueId().toString());
this.location = new CachedLocation(entity.getLocation());
this.rotation = entity.getRotation().clone();
this.velocity = entity.getVelocity().clone();
this.scale = entity.getScale().clone();
if (entity instanceof Carrier) {
try {
this.inventory = new CachedInventory(((Carrier) entity).getInventory());
} catch (AbstractMethodError ignored) {}
}
}
示例5: execute
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag entityTag = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
Entity entity = entityTag.getInternal();
MapTag propertyMap = MapTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
for (Map.Entry<String, AbstractTagObject> mapEntry : propertyMap.getInternal().entrySet()) {
if (mapEntry.getKey().equalsIgnoreCase("rotation")) {
LocationTag rot = LocationTag.getFor(queue.error, mapEntry.getValue());
entity.setRotation(rot.getInternal().toVector3d());
}
else {
Key found = DataKeys.getKeyForName(mapEntry.getKey());
if (found == null) {
queue.handleError(entry, "Invalid property '" + mapEntry.getKey() + "' in EditEntity command!");
return;
}
DataKeys.tryApply(entity, found, mapEntry.getValue(), queue.error);
}
}
if (queue.shouldShowGood()) {
queue.outGood("Edited the entity "
+ ColorSet.emphasis + entityTag.debug() + ColorSet.good
+ " to have the following properties: "
+ ColorSet.emphasis + propertyMap.debug());
}
}
示例6: fireDropItemEvent
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
private void fireDropItemEvent(World world, Vector3i pos) {
List<ItemStack> stacks = getDroppedItems();
if (stacks.isEmpty()) {
return;
}
List<Entity> entities = Lists.newArrayList();
for (ItemStack stack : stacks) {
Entity drop = createItemDrop(world, pos, stack);
entities.add(drop);
}
Cause cause = Cause.source(BlockSpawnCause.builder()
.type(SpawnTypes.DROPPED_ITEM)
.block(world.createSnapshot(pos))
.build())
.build();
DropItemEvent.Destruct harvestEvent = SpongeEventFactory.createDropItemEventDestruct(cause, entities);
if (Sponge.getEventManager().post(harvestEvent)) {
return;
}
for (Entity entity : harvestEvent.getEntities()) {
world.spawnEntity(entity, cause);
}
}
示例7: clickEntity
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
/** return true to cancel the event in the parent */
static boolean clickEntity(Player source, Entity target, Button side) {
//try to get shop:
Location<World> tl = target.getLocation();
Optional<NPCguard> npc = VillagerShops.getNPCfromLocation(tl);
if (npc.isPresent()) {
// VillagerShops.l("NPC: " + npc.get().getDisplayName().toPlain());
// if (side == Button.right) {
if (npc.get().getPreparator().size()>0) {
npc.get().updateStock();
source.openInventory(npc.get().getInventory(source.getUniqueId()));
VillagerShops.openShops.put(source.getUniqueId(), npc.get().getIdentifier());
}
// }
return true;
}
return false;
}
示例8: teleport
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
public boolean teleport(final World world, final Vector3d vector){
if (this.getVehicle().isPresent()){
final Entity horse = this.getVehicle().get();
if (horse.toContainer().getView(DataQuery.of("UnsafeData")).isPresent()){
if (horse.toContainer().getView(DataQuery.of("UnsafeData")).get().getString(DataQuery.of("OwnerUUID")).isPresent()){
UUID owner = UUID.fromString(horse.toContainer().getView(DataQuery.of("UnsafeData")).get().getString(DataQuery.of("OwnerUUID")).get());
if (this.getUniqueId().equals(owner)){
this.setVehicle(null);
horse.transferToWorld(world, vector);
if (this.setLocation(world.getLocation(vector))) {
this.setVehicle(horse);
return true;
}
}
}
}
}
return this.setLocation(world.getLocation(vector));
}
示例9: commandButcherType
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
private CompletableFuture<Boolean> commandButcherType(EPlayer player, EntityType type, int radius) {
Collection<Entity> list = player.getWorld().getEntities(entity ->
entity.getType().equals(type) && entity.getLocation().getPosition().distance(player.getLocation().getPosition()) <= radius);
if (!list.isEmpty()){
list.forEach(entity -> entity.remove());
EEMessages.BUTCHER_TYPE_RADIUS.sender()
.replace("{radius}", String.valueOf(radius))
.replace("{count}", String.valueOf(list.size()))
.replace("{entity}", getButtomEntity(type))
.sendTo(player);
return CompletableFuture.completedFuture(true);
} else {
EEMessages.BUTCHER_NOENTITY.sendTo(player);
return CompletableFuture.completedFuture(false);
}
}
示例10: removeEntity
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
@Endpoint(method = HttpMethod.DELETE, path = "/:entity", perm = "delete")
public void removeEntity(ServletData data, CachedEntity entity) {
Optional<Boolean> deleted = WebAPI.runOnMain(() -> {
Optional<Entity> live = entity.getLive();
if (!live.isPresent())
return false;
live.get().remove();
return true;
});
if (!deleted.isPresent() || !deleted.get()) {
data.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not delete entity " + entity.getUUID());
return;
}
cacheService.removeEntity(entity.getUUID());
data.addData("ok", true, false);
data.addData("entity", entity, true);
}
示例11: moveListener
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
@Listener(order = Order.LATE)
public void moveListener(MoveEntityEvent event) {
Entity entity = event.getTargetEntity();
if (!entity.getType().equals(EntityTypes.PLAYER)) return;
Player player = (Player) entity;
if (!Animation1OpenManager.PLAYERS_OPENING_ANIMATION1.containsKey(player) || OPENED_PLAYERS.containsKey(player)) return;
if (Utils.isLocationChanged(event.getFromTransform(), event.getToTransform(), true)) {
event.setCancelled(true);
}
}
示例12: onEntitySpawn
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
@Listener
public void onEntitySpawn(SpawnEntityEvent event)
{
for (Entity entity: event.getEntities())
{
//EagleFactions.getEagleFactions().getLogger().info(entity.toString());
if(entity.toString().contains("EntityCustomNpc")) return;
if(entity instanceof Hostile)
{
if((MainLogic.getMobSpawning() == false) && FactionLogic.isClaimed(entity.getWorld().getUniqueId(), entity.getLocation().getChunkPosition()))
{
// EagleFactions.getEagleFactions().getLogger().info("Entity is a Hostile!!!! :O");
// EagleFactions.getEagleFactions().getLogger().info("Printing enity: " + entity.toString());
// EagleFactions.getEagleFactions().getLogger().info("Prining spawn cause: " + event.getCause().toString());
event.setCancelled(true);
return;
}
}
else
{
// if(FactionLogic.getFactionNameByChunk(entity.getWorld().getUniqueId(), entity.getLocation().getChunkPosition()).equals("SafeZone"))
// {
// EagleFactions.getEagleFactions().getLogger().info("Entity is friendly. :D");
// EagleFactions.getEagleFactions().getLogger().info("Printing enity: " + entity.toString());
// EagleFactions.getEagleFactions().getLogger().info("Prining spawn cause: " + event.getCause().toString());
// }
return;
}
//EntityType for CustomNPC (it isn't count as a monster) => EntityCustomNpc
}
}
示例13: removeArmorstands
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
public void removeArmorstands() {
for(World bit: Sponge.getServer().getWorlds()) {
for (Entity ent : bit.getEntities()) {
if (ent instanceof ArmorStand) {
ArmorStand arm = (ArmorStand) ent;
if (arm.getCreator().isPresent()) {
if (arm.getCreator().get().equals(UUID.fromString(armorStandIdentifier))) {
arm.remove();
}
}
}
}
}
}
示例14: onArmorStand
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
@Listener
public void onArmorStand(SpawnEntityEvent.ChunkLoad event){
for(Entity e : event.getEntities()){
if(!(e instanceof ArmorStand))
continue;
ArmorStand as = (ArmorStand) e;
if (as.getCreator().isPresent()) {
if (as.getCreator().get().equals(UUID.fromString(armorStandIdentifier))) {
as.remove();
}
}
}
}
示例15: parseValue
import org.spongepowered.api.entity.Entity; //导入依赖的package包/类
@Override
public ParseResult<ClanPlayer> parseValue(CommandSource commandSource, String value, NormalFilledParameter parameter) {
ClanPlayerImpl clanPlayer = null;
if (value.startsWith("@")) {
Set<Entity> entities = Selector.parse(value).resolve(commandSource);
if (entities.size() > 0 && entities.toArray()[0] instanceof Player) {
UUID uuid = ((Player) entities.toArray()[0]).getUniqueId();
clanPlayer = ClansImpl.getInstance().getClanPlayer(uuid);
} else {
return ParseResult.newErrorResult("Selector produced no results");
}
} else {
clanPlayer = ClansImpl.getInstance().getClanPlayer(value);
}
if (clanPlayer != null) {
return ParseResult.newSuccessResult((ClanPlayer) clanPlayer);
} else {
UUID playerUUID = UUIDUtils.getUUID(value);
Optional<Player> playerOp = playerUUID == null ? Optional.empty() : Sponge.getServer().getPlayer(playerUUID);
if (playerOp.isPresent()) {
return ParseResult.newSuccessResult(ClansImpl.getInstance().createClanPlayer(playerUUID, value));
} else {
return ParseResult.newErrorResult(Messages.PLAYER_DOES_NOT_EXIST);
}
}
}