How can i get the potion the player is trowing (Check if is Splash Potion and get Type) and cancel if is specific type?
I trying this but i cannot know how to get the potion, and dont know if this the correct event too
@Subscribe
public void onPotionSplash(LaunchProjectileEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getCause().first(SplashPotionData.class).isPresent()){
...
You’ll want to call event.getTargetEntity()
and check if it is an instanceof ThrownPotion
Uh, i forgot to use TrownPotion.
TargetType is the target, in case, not the potion right?
Maybe using this i can get the potion:
if (event.getCause().first(ThrownPotion.class).isPresent()){
ThrownPotion potion = event.getCause().first(ThrownPotion.class).get();
...
But i didnt find a way to get the potion type.
Thanks.
If I’m not mistaken, it should look like this:
@Listener
public void onPotionThrow(LaunchProjectileEvent event) {
if(event.getTargetEntity() instanceof ThrownPotion) {
ThrownPotion potion = (ThrownPotion) event.getTargetEntity();
Optional<List<PotionEffect>> listOptional = potion.get(Keys.POTION_EFFECTS);
if(listOptional.isPresent()) {
List<PotionEffect> effects = listOptional.get();
//Do stuff with the effects
}
}
}
However, as far as I know, LaunchProjectileEvent is still unimplemented.
1 Like
Did this ever work? I’ve tried using the LaunchProjectileEvent
in a basic listener, but it doesn’t work.
@Listener
public void onPotionThrow(LaunchProjectileEvent event) {
event.setCancelled(true);
}