Setting adventure mode does not work

Discussion in 'Plugin Development' started by AlpacaKyle, Jun 18, 2020.

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

    AlpacaKyle

    So whenever a player join my server, my code is supposed to set their game mode to adventure, clear their inventory, and teleport them to spawn. All the code works properly, but the player does not spawn in adventure mode like they are supposed to.
    Heres my code:
    Code:
        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            p.setGameMode(GameMode.ADVENTURE);
            p.getInventory().clear();
            p.teleport(p.getWorld().getSpawnLocation());
            for (PotionEffect effect : p.getActivePotionEffects())
                p.removePotionEffect(effect.getType());
            p.addPotionEffect((new PotionEffect(PotionEffectType.SPEED, 999999999, 1)));
            p.addPotionEffect((new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 999999999, 1)));
            p.addPotionEffect((new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 999999999, 9)));
        }
     
  2. Offline

    bowlerguy66

    Maybe it's something with the worlds default GameMode? Have you tried changing the player's GameMode with a delay (like 1 tick or something)?
     
Thread Status:
Not open for further replies.

Share This Page