I have tried randomizing potion effects every time a player eats something. I used this code, but nothing happened:
package de.jobebe.randomizer;
import java.util.concurrent.ThreadLocalRandom;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class Main extends JavaPlugin {
@Override
public void onEnable() {
}
@Override
public void onDisable() {
}
@EventHandler
public void onChowDown(PlayerItemConsumeEvent e) {
int rnd = ThreadLocalRandom.current().nextInt(PotionEffectType.values().length);
e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.values()[rnd], 200, 1));
}
}
I researched a bit, but everything I found was that I have to register an event in the onEnable Method. But if I try this like that
getServer().getPluginManager().registerEvents(this, this);
it throws an error in Eclipse because the Method needs a Listener. Can I register this event differently?