Solved Add#Potion#Effect not working

Discussion in 'Spigot Plugin Development' started by Ohwnead, Jul 2, 2018.

  1. Hi, I try to apply a potion on respawn to avoid respawning in lava with this code :

    Code (Java):
    e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE.createEffect(15*20, 1)));
    this code says it's a map.
    ""incompatible types: PotionEffect cannot be converted to Map<String,Object>""

    and with this code nothing append :
    Code (Text):
    Wrong Code!
    Full class here :
    Code (Text):
    public class Respawn implements Listener
    {
        public FileConfiguration PlayerCFG;
        public File PlayerFile;

        public FileConfiguration IslandCFG;
        public File IslandFile;

        @EventHandler
        public void onPlayerSpawn(PlayerRespawnEvent e)
        {
            Main plugin = Main.getPlugin(Main.class);
            PlayerFile = new File(plugin.getDataFolder(), e.getPlayer().getUniqueId().toString() + ".yml");
            IslandFile = new File(plugin.getDataFolder(), "_Island.yml");

            if (PlayerFile.exists() && IslandFile.exists())
            {
                PlayerCFG = YamlConfiguration.loadConfiguration(PlayerFile);

                Location loc = e.getRespawnLocation();

                if (PlayerCFG.getBoolean("Info.Player.HasIle") == true)
                {
                    IslandCFG = YamlConfiguration.loadConfiguration(IslandFile);
                    int xIle = PlayerCFG.getInt("Info.Player.IleNumX");
                    int zIle = PlayerCFG.getInt("Info.Player.IleNumZ");

                    loc = (Location) IslandCFG.get(xIle + " " + zIle + ".location");
                }
                else
                {
                    loc.setX(0.5);
                    loc.setZ(0.5);
                    loc.setY(100.5);
                    loc.setYaw(0);
                    loc.setPitch(0);
                    loc.setWorld(Bukkit.getWorld("Spawn"));
                }

                e.setRespawnLocation(loc);
                e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 15 * 20, 1));
            }
        }

    }
     
    thanks for help.
     
    #1 Ohwnead, Jul 2, 2018
    Last edited: Jul 2, 2018
  2. Try delaying it by a tick or two. I'm unsure if the player has actually respawned and in the world when this event is fired.
     
  3. Oh yeah, same problem append some time with teleportation after respawning, I forgot this ^^, thanks, i'll try
     
  4. Working, thanks, 1 ticks of delay work like for teleportation.
    New code :
    Code (Java):
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
                {
                    public void run()
                    {
                        e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 15 * 20, 1));
                    }

                }, (1));
    Closed