Search in sources :

Example 1 with GlowEntity

use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.

the class ItemSpawn method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc) {
    Location location = against.getLocation().add(face.getModX(), face.getModY(), face.getModZ());
    // TODO: change mob spawner when clicked by monster egg
    if (holding.hasItemMeta() && holding.getItemMeta() instanceof GlowMetaSpawn) {
        GlowMetaSpawn meta = (GlowMetaSpawn) holding.getItemMeta();
        EntityType type = meta.getSpawnedType();
        CompoundTag tag = meta.getEntityTag();
        if (type != null) {
            GlowEntity entity = against.getWorld().spawn(location.add(0.5, 0, 0.5), EntityRegistry.getEntity(type), SpawnReason.SPAWNER_EGG);
            if (tag != null) {
                EntityStorage.load(entity, tag);
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) GlowEntity(net.glowstone.entity.GlowEntity) GlowMetaSpawn(net.glowstone.inventory.GlowMetaSpawn) CompoundTag(net.glowstone.util.nbt.CompoundTag) Location(org.bukkit.Location)

Example 2 with GlowEntity

use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.

the class VehicleMoveHandler method handle.

@Override
public void handle(GlowSession session, VehicleMoveMessage message) {
    GlowPlayer player = session.getPlayer();
    if (!player.isInsideVehicle() || !(player.getVehicle() instanceof Vehicle)) {
        return;
    }
    GlowEntity vehicle = (GlowEntity) player.getVehicle();
    Location oldLocation = vehicle.getLocation();
    Location newLocation = oldLocation.clone();
    message.update(newLocation);
    // don't let players reach an illegal position
    if (Math.abs(newLocation.getBlockX()) > 32000000 || Math.abs(newLocation.getBlockZ()) > 32000000) {
        session.getPlayer().kickPlayer("Illegal position");
        return;
    }
    /*
          don't let players move more than 100 blocks in a single packet
          if they move greater than 10 blocks, but less than 100, just warn
          this is NOT robust hack prevention - only to prevent client
          confusion about where its actual location is (e.g. during login)
        */
    if (Position.hasMoved(oldLocation, newLocation) && !player.isDead() && !vehicle.isDead()) {
        double distance = newLocation.distanceSquared(oldLocation);
        if (distance > 100 * 100) {
            session.getPlayer().kickPlayer("You moved too quickly :( (Hacking?)");
            return;
        } else if (distance > 100) {
            GlowServer.logger.warning(session.getPlayer().getName() + " moved too quickly!");
        }
    }
    if (!isValidMovement(vehicle, oldLocation, newLocation)) {
        vehicle.teleport(oldLocation);
        return;
    }
    // call move event if movement actually occurred and there are handlers registered
    if (!oldLocation.equals(newLocation) && VehicleMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
        EventFactory.getInstance().callEvent(new VehicleMoveEvent((Vehicle) vehicle, oldLocation, newLocation.clone()));
    }
    // simply update location
    vehicle.setRawLocation(newLocation);
    player.setRawLocation(vehicle.getMountLocation());
    // track movement stats
    Vector delta = newLocation.clone().subtract(oldLocation).toVector();
    delta.setX(Math.abs(delta.getX()));
    delta.setY(Math.abs(delta.getY()));
    delta.setZ(Math.abs(delta.getZ()));
    int flatDistance = (int) Math.round(Math.hypot(delta.getX(), delta.getZ()) * 100.0);
    if (vehicle instanceof Boat) {
        player.incrementStatistic(Statistic.BOAT_ONE_CM, flatDistance);
    } else if (vehicle instanceof Minecart) {
        player.incrementStatistic(Statistic.MINECART_ONE_CM, flatDistance);
    }
}
Also used : Vehicle(org.bukkit.entity.Vehicle) GlowPlayer(net.glowstone.entity.GlowPlayer) GlowEntity(net.glowstone.entity.GlowEntity) VehicleMoveEvent(org.bukkit.event.vehicle.VehicleMoveEvent) Minecart(org.bukkit.entity.Minecart) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) Boat(org.bukkit.entity.Boat)

Example 3 with GlowEntity

use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.

the class EntityStore method savePassengers.

private void savePassengers(GlowEntity vehicle, CompoundTag tag) {
    List<CompoundTag> passengers = new ArrayList<>();
    for (Entity passenger : vehicle.getPassengers()) {
        if (!(passenger instanceof GlowEntity)) {
            continue;
        }
        GlowEntity glowEntity = (GlowEntity) passenger;
        if (!glowEntity.shouldSave()) {
            continue;
        }
        try {
            CompoundTag compound = new CompoundTag();
            EntityStorage.save(glowEntity, compound);
            passengers.add(compound);
            savePassengers(glowEntity, compound);
        } catch (Exception e) {
            ConsoleMessages.Warn.Entity.SAVE_FAILED_PASSENGER.log(passenger, e);
        }
    }
    if (!passengers.isEmpty()) {
        tag.putCompoundList("Passengers", passengers);
    }
}
Also used : Entity(org.bukkit.entity.Entity) GlowEntity(net.glowstone.entity.GlowEntity) ArrayList(java.util.ArrayList) GlowEntity(net.glowstone.entity.GlowEntity) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 4 with GlowEntity

use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.

the class GlowWorld method pulse.

/**
 * Updates all the entities within this world.
 */
public void pulse() {
    List<GlowEntity> allEntities = new ArrayList<>(entityManager.getAll());
    List<GlowPlayer> players = new LinkedList<>();
    activeChunksSet.clear();
    // We should pulse our tickmap, so blocks get updated.
    pulseTickMap();
    // their position is modified by session ticking.
    for (GlowEntity entity : entityManager) {
        if (entity instanceof GlowPlayer) {
            players.add((GlowPlayer) entity);
            updateActiveChunkCollection(entity);
        } else {
            entity.pulse();
        }
    }
    updateBlocksInActiveChunks();
    // why update blocks before Players or Entities? if there is a specific reason we should
    // document it here.
    pulsePlayers(players);
    chunkManager.clearChunkBlockChanges();
    resetEntities(allEntities);
    worldBorder.pulse();
    updateWorldTime();
    informPlayersOfTime();
    updateOverworldWeather();
    handleSleepAndWake(players);
    saveWorld();
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) GlowEntity(net.glowstone.entity.GlowEntity) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 5 with GlowEntity

use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.

the class GlowWorld method spawnGlowEntity.

/**
 * Spawns an entity.
 *
 * @param location the {@link Location} to spawn the entity at
 * @param clazz    the class of the {@link Entity} to spawn
 * @param reason   the reason for the spawning of the entity
 * @return an instance of the spawned {@link Entity}
 * @throws IllegalArgumentException TODO: document the reason this can happen
 */
public <T extends GlowEntity, E extends Entity> GlowEntity spawnGlowEntity(Location location, Class<T> clazz, SpawnReason reason, @Nullable Consumer<E> function) throws IllegalArgumentException {
    checkNotNull(location);
    checkNotNull(clazz);
    GlowEntity entity = null;
    try {
        if (EntityRegistry.getEntity(clazz) != null) {
            entity = EntityStorage.create(clazz, location);
        }
        if (entity != null && function != null) {
            function.accept((E) entity);
        }
        EntitySpawnEvent spawnEvent = null;
        if (entity instanceof LivingEntity) {
            spawnEvent = EventFactory.getInstance().callEvent(new CreatureSpawnEvent((LivingEntity) entity, reason));
        } else if (!(entity instanceof Item)) {
            // ItemSpawnEvent is called elsewhere
            spawnEvent = EventFactory.getInstance().callEvent(new EntitySpawnEvent(entity));
        }
        if (spawnEvent != null && spawnEvent.isCancelled()) {
            // TODO: separate spawning and construction for better event cancellation
            entity.remove();
        } else {
            List<Message> spawnMessage = entity.createSpawnMessage();
            final GlowEntity finalEntity = entity;
            getRawPlayers().stream().filter(player -> player.canSeeEntity(finalEntity)).forEach(player -> player.getSession().sendAll(spawnMessage.toArray(new Message[spawnMessage.size()])));
        }
    } catch (NoSuchMethodError | IllegalAccessError e) {
        GlowServer.logger.log(Level.WARNING, "Invalid entity spawn: ", e);
    } catch (Throwable t) {
        GlowServer.logger.log(Level.SEVERE, "Unable to spawn entity: ", t);
    }
    if (entity != null) {
        return entity;
    }
    throw new UnsupportedOperationException("Not supported yet.");
}
Also used : TreeType(org.bukkit.TreeType) GlowBlock(net.glowstone.block.GlowBlock) Arrays(java.util.Arrays) BlockType(net.glowstone.block.blocktype.BlockType) DragonBattle(org.bukkit.boss.DragonBattle) ItemTable(net.glowstone.block.ItemTable) EntitySpawnEvent(org.bukkit.event.entity.EntitySpawnEvent) ItemSpawnEvent(org.bukkit.event.entity.ItemSpawnEvent) EntityManager(net.glowstone.entity.EntityManager) MaterialData(org.bukkit.material.MaterialData) Location(org.bukkit.Location) CustomEntityDescriptor(net.glowstone.entity.CustomEntityDescriptor) World(org.bukkit.World) Map(java.util.Map) WorldSaveEvent(org.bukkit.event.world.WorldSaveEvent) WorldConfig(net.glowstone.util.config.WorldConfig) Chunk(org.bukkit.Chunk) BoundingBox(net.glowstone.entity.physics.BoundingBox) ChunkDataMessage(net.glowstone.net.message.play.game.ChunkDataMessage) Material(org.bukkit.Material) LightningStrikeEvent(org.bukkit.event.weather.LightningStrikeEvent) BlockData(org.bukkit.block.data.BlockData) Entity(org.bukkit.entity.Entity) GlowEffect(net.glowstone.constants.GlowEffect) StructureType(org.bukkit.StructureType) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) ItemStack(org.bukkit.inventory.ItemStack) WorldFinalValues(net.glowstone.io.WorldMetadataService.WorldFinalValues) EntityStorage(net.glowstone.io.entity.EntityStorage) ChunkLock(net.glowstone.chunk.ChunkManager.ChunkLock) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) GlowFallingBlock(net.glowstone.entity.objects.GlowFallingBlock) FallingBlock(org.bukkit.entity.FallingBlock) GlowStructure(net.glowstone.generator.structures.GlowStructure) GameRule(org.bukkit.GameRule) GlowLightningStrike(net.glowstone.entity.GlowLightningStrike) Message(com.flowpowered.network.Message) ArrayList(java.util.ArrayList) GameRules(net.glowstone.constants.GameRules) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Raid(org.bukkit.Raid) MetadataStore(org.bukkit.metadata.MetadataStore) ChunkSection(net.glowstone.chunk.ChunkSection) SoundCategory(org.bukkit.SoundCategory) StructureGrowEvent(org.bukkit.event.world.StructureGrowEvent) IOException(java.io.IOException) File(java.io.File) HeightMap(org.bukkit.HeightMap) Vector(org.bukkit.util.Vector) BlockStateDelegate(net.glowstone.util.BlockStateDelegate) ChunkManager(net.glowstone.chunk.ChunkManager) SpawnChangeEvent(org.bukkit.event.world.SpawnChangeEvent) EntityRegistry(net.glowstone.entity.EntityRegistry) MetadataStoreBase(org.bukkit.metadata.MetadataStoreBase) Plugin(org.bukkit.plugin.Plugin) GameRuleManager(net.glowstone.util.GameRuleManager) ChunkSnapshot(org.bukkit.ChunkSnapshot) BlockChangeDelegate(org.bukkit.BlockChangeDelegate) GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) MoonPhase(io.papermc.paper.world.MoonPhase) Biome(org.bukkit.block.Biome) WorldInitEvent(org.bukkit.event.world.WorldInitEvent) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) ChunkGenerator(org.bukkit.generator.ChunkGenerator) Block(org.bukkit.block.Block) Difficulty(org.bukkit.Difficulty) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage) NotImplementedException(org.apache.commons.lang.NotImplementedException) ToString(lombok.ToString) GlowBiome(net.glowstone.constants.GlowBiome) BlockPopulator(org.bukkit.generator.BlockPopulator) WorldStorageProvider(net.glowstone.io.WorldStorageProvider) ConcurrentSet(net.glowstone.util.collection.ConcurrentSet) GlowBiomeClimate(net.glowstone.constants.GlowBiomeClimate) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) Predicate(java.util.function.Predicate) GlowChunk(net.glowstone.chunk.GlowChunk) Collection(java.util.Collection) Sound(org.bukkit.Sound) UUID(java.util.UUID) EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) MetadataValue(org.bukkit.metadata.MetadataValue) Key(net.glowstone.chunk.GlowChunk.Key) NotNull(org.jetbrains.annotations.NotNull) FluidCollisionMode(org.bukkit.FluidCollisionMode) EmptySnapshot(net.glowstone.chunk.GlowChunkSnapshot.EmptySnapshot) Setter(lombok.Setter) ThunderChangeEvent(org.bukkit.event.weather.ThunderChangeEvent) CommandFunction(net.glowstone.data.CommandFunction) Getter(lombok.Getter) Item(org.bukkit.entity.Item) MessageDigest(java.security.MessageDigest) NonNls(org.jetbrains.annotations.NonNls) WorldLoadEvent(org.bukkit.event.world.WorldLoadEvent) CompletableFuture(java.util.concurrent.CompletableFuture) WorldCreator(org.bukkit.WorldCreator) WeatherChangeEvent(org.bukkit.event.weather.WeatherChangeEvent) Arrow(org.bukkit.entity.Arrow) Level(java.util.logging.Level) Consumer(org.bukkit.util.Consumer) HashSet(java.util.HashSet) ServerDifficultyMessage(net.glowstone.net.message.play.player.ServerDifficultyMessage) Effect(org.bukkit.Effect) LightningStrike(org.bukkit.entity.LightningStrike) RayUtil(net.glowstone.util.RayUtil) TickUtil(net.glowstone.util.TickUtil) WorldUnloadEvent(org.bukkit.event.world.WorldUnloadEvent) GlowItem(net.glowstone.entity.objects.GlowItem) SpawnReason(org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason) LinkedList(java.util.LinkedList) AbstractArrow(org.bukkit.entity.AbstractArrow) StandardMessenger(org.bukkit.plugin.messaging.StandardMessenger) NamespacedKey(org.bukkit.NamespacedKey) HeightmapType(com.destroystokyo.paper.HeightmapType) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) BlockState(org.bukkit.block.BlockState) GlowParticle(net.glowstone.constants.GlowParticle) GlowEntity(net.glowstone.entity.GlowEntity) WorldType(org.bukkit.WorldType) Particle(org.bukkit.Particle) RayTraceResult(org.bukkit.util.RayTraceResult) GlowTree(net.glowstone.constants.GlowTree) GlowSound(net.glowstone.constants.GlowSound) GlowLivingEntity(net.glowstone.entity.GlowLivingEntity) Collections(java.util.Collections) ChunkDataMessage(net.glowstone.net.message.play.game.ChunkDataMessage) Message(com.flowpowered.network.Message) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage) ServerDifficultyMessage(net.glowstone.net.message.play.player.ServerDifficultyMessage) LivingEntity(org.bukkit.entity.LivingEntity) GlowLivingEntity(net.glowstone.entity.GlowLivingEntity) Item(org.bukkit.entity.Item) GlowItem(net.glowstone.entity.objects.GlowItem) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) GlowEntity(net.glowstone.entity.GlowEntity) EntitySpawnEvent(org.bukkit.event.entity.EntitySpawnEvent)

Aggregations

GlowEntity (net.glowstone.entity.GlowEntity)19 Location (org.bukkit.Location)9 GlowPlayer (net.glowstone.entity.GlowPlayer)8 CompoundTag (net.glowstone.util.nbt.CompoundTag)8 Vector (org.bukkit.util.Vector)7 ArrayList (java.util.ArrayList)6 Entity (org.bukkit.entity.Entity)4 EntityType (org.bukkit.entity.EntityType)4 LivingEntity (org.bukkit.entity.LivingEntity)3 Message (com.flowpowered.network.Message)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 EventFactory (net.glowstone.EventFactory)2 BoundingBox (net.glowstone.entity.physics.BoundingBox)2 MojangsonParseException (net.glowstone.util.mojangson.ex.MojangsonParseException)2 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)2 ItemStack (org.bukkit.inventory.ItemStack)2