Solved Entities die immediately after they spawn?

Discussion in 'Spigot Plugin Development' started by Vengine, Feb 11, 2021.

Thread Status:
Not open for further replies.
  1. Vengine

    Vengine Previously SkillCode

    Hi, I have a problem for days and just can not get ahead. I want to spawn a creeper in the JoinListener for testing, but it is immediately dead. But if I spawn him via a command, everything works. Thank you in advance for your answers!

    Version: PaperSpigot 1.8.8

    Code (Java):
    @EventHandler
        public void onJoin(@NotNull final PlayerJoinEvent event) {
            final Player player = event.getPlayer();

            final Creeper creeper = (Creeper) LocationProvider.SPAWN.getWorld().spawnEntity(
                    LocationProvider.SPAWN, EntityType.CREEPER
            );

            if (creeper.isDead()) System.out.println("CREEPER IS DEAD :c");

            player.teleport(LocationProvider.SPAWN);
        }
    Code (Java):
     @Override
        public boolean onCommand(final CommandSender commandSender, final Command command, final String s, final String[] strings) {
            final Creeper creeper = (Creeper) LocationProvider.SPAWN.getWorld().spawnEntity(
                    LocationProvider.SPAWN, EntityType.CREEPER
            );

            if (creeper.isDead()) System.out.println("CREEPER IS DEAD :c");
            return false;
        }
    Code (Text):
    [11.02 13:23:46.726] INFO: [Lobby-1] [13:23:46 INFO]: CREEPER IS DEAD :c
    [11.02 13:23:46.830] INFO: [Lobby-1] [13:23:46 INFO]: SkillCode[/192.168.178.51:65431] logged in with entity id 57 at ([world]1.5, 36.0, 17.5)
    [11.02 13:23:47.867] INFO: [Lobby-1] [13:23:47 INFO]: [NoteBlockAPI] New update available!
    [11.02 13:23:50.946] INFO: [Lobby-1] [13:23:50 INFO]: SkillCode issued server command: /test
    [11.02 13:23:54.287] INFO: The identity b71e5129-7216-4d79-b79f-2e3893a6befa:SkillCode on the proxy Proxy-1 has left the network
    [11.02 13:23:54.330] INFO: [Lobby-1] [13:23:54 INFO]: SkillCode lost connection: Disconnected

    EDIT: I put a delay in the JoinListener and now it works, but in the onEnable it still doesn't work
     
    #1 Vengine, Feb 11, 2021
    Last edited: Feb 11, 2021
  2. Vengine

    Vengine Previously SkillCode

    I finally solved it! I had to load the chunk manually.
     
Thread Status:
Not open for further replies.