Hello, ive had alot of trouble trying to figure out how to test when a player splash's a speed potion
1. Interact event 2. Check if left click (throw) 3. Check if item in hand is potion 4. Check if potion is speedpotion 5. Your code
Can anyone give me some example code of potion splash so like when a PLAYEr splashes a Speed pot it will either cancel the event or remove the effect
well you're strait up asking for a spoonfeed public void onPotionSplash(PotionSplashEvent e){ if(e.getPotionEffect().equals(speed)){ yada yada } } The code was written on the browser and is untested and if you paste this into eclipse I can pretty much guarantee it wont work
Code (Text): @EventHandler public void onPotionSplash(PotionSplashEvent e) { Bukkit.broadcastMessage("splas"); if(e.getPotion().equals(PotionEffectType.SPEED)) { Bukkit.broadcastMessage("speed"); When I throw a potion it says splash, when I throw a speed it doesnt say Speed though. Any ideas why? (Debugging btw)
wait you know your shit I thought you didnt know what to do since it seemed like you needed a spoonfeed ok uhh try this: { @EventHandler public void onPotionSplash(PotionSplashEvent e) { Bukkit.broadcastMessage("splas"); if(e.getPotion().getEffects().contains(PotionEffectType.SPEED)) { Bukkit.broadcastMessage("speed"); }}}
Incorrect. I've produced this code: Code (Text): @EventHandler public void onPotionSplash(PotionSplashEvent event) { if (event.getEntity().getShooter() instanceof Player) { Player player = (Player) event.getEntity().getShooter(); for (PotionEffect potionEffect : event.getPotion().getEffects()) { if (potionEffect.getType().equals(PotionEffectType.SPEED)) { player.sendMessage(ChatColor.GREEN + "You just threw a splash potion of Speed."); } } } }
I know by the way, I didn't test it but according to all laws of code and my knowledge, it should work but then I could be stupid
Also if a player splashes another player what would i use to say message the player who was affected?
I've created an example of the two requests that you were asking for: Code (Text): @EventHandler public void onPotionSplash(PotionSplashEvent event) { if (event.getEntity().getShooter() instanceof Player) { Player player = (Player) event.getEntity().getShooter(); for (PotionEffect potionEffect : event.getPotion().getEffects()) { if (potionEffect.getType().equals(PotionEffectType.SPEED)) { player.sendMessage(ChatColor.GREEN + "You just threw a splash potion of Speed."); for (LivingEntity livingEntities : event.getAffectedEntities()) { if (livingEntities instanceof Player) { Player targetPlayer = (Player) livingEntities; if (targetPlayer != player) { targetPlayer.sendMessage(ChatColor.RED + "You were affected by " + player.getName() + "'s splash potion of speed."); } } } } } } if (event.getEntity().getShooter() instanceof BlockProjectileSource) { BlockProjectileSource bps = (BlockProjectileSource) event.getEntity().getShooter(); if (bps.getBlock().getType() == Material.DISPENSER) { for (PotionEffect potionEffect : event.getPotion().getEffects()) { Bukkit.broadcastMessage(ChatColor.GREEN + "A splash potion of " + potionEffect.getType().getName().toLowerCase() + " was released from a dispenser."); } } } }