So I've ran into a problem. Adding potion effects won't work. I have this in my player respawn listener. //Strength Potion Effect (20 ticks = 10 seconds) p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 18000, 1)); I want players to spawn with Strength I effect for 15 minutes, but it won't work. WHY WON'T THIS WORK?
It has nothing to do with the listener, if I showed you the code it would basically be public void listenerName(Event event) { addPotionEffect(blabhahjvkhadksa); } I still need help with this.... EDIT by Moderator: merged posts, please use the edit button instead of double posting.
what is the problem? http://wiki.bukkit.org/Event_API_Reference http://jd.bukkit.org/dev/apidocs/or...dPotionEffect(org.bukkit.potion.PotionEffect)
I'm sorry, but are you blind? Please read what it says above, before posting links. I've already looked at the Bukkit API for potions, I'm not dumb.
public class listenerName implements Listener { @EventHandler public void onPlayerRespawn(PlayerRespawnEvent event) { Player p = event.getPlayer(); //Diamond Sword ItemStack diamondSword = new ItemStack(276, 1); //Iron Armor ItemStack ironHelmet = new ItemStack(Material.IRON_HELMET); ItemStack ironChestPlate = new ItemStack(Material.IRON_CHESTPLATE); ItemStack ironLeggings = new ItemStack(Material.IRON_LEGGINGS); ItemStack ironBoots = new ItemStack(Material.IRON_BOOTS); ItemStack mushroomSoup = new ItemStack(Material.MUSHROOM_SOUP); p.getInventory().setItem(0, diamondSword); p.getInventory().setHelmet(ironHelmet); p.getInventory().setChestplate(ironChestPlate); p.getInventory().setLeggings(ironLeggings); p.getInventory().setBoots(ironBoots); for(int i = 1; i <= 8; i++) { p.getInventory().setItem(i, mushroomSoup); } //Strength Potion Effect (20 ticks = 10 seconds) p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 18000, 2)); } } I still need help on this... EDIT by Moderator: merged posts, please use the edit button instead of double posting.
It is registered, and I'd know that because people spawn with armor and a diamond sword and mushroom soup already. Still need help with this.... EDIT by Moderator: merged posts, please use the edit button instead of double posting.
It doesnt work because it fires right away on respawn, so the potion effect can't be added, but you can create a delayed task like this: Code:java final Player player = event.getPlayer();plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() {public void run() {player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 18000, 2));}}, 20);[FONT=Consolas][/FONT] and the 20 at the end is the number of ticks to delay. Hopefully this works! Or you might have to use a "Sync" delayed task, im still new to the delayed task stuff, so im a little unsure.