Hello! I made a plugin and it worked fine. I wanted to make another one, an event listener. I managed to do it until I entered the event in my Main class. I wrote: new EntityDamageEvent(this); and i got an error! It wrote: java: no suitable constructor found for EntityDamageEvent(survival.survival.Survival) What should I do? I am attaching the whole code. Thank you very much in advance for your help.
Hello! I made a plugin and it worked fine. I wanted to make another one, an event listener. I managed to do it until I entered the event in my Main class. I wrote: new EntityDamageEvent(this); and i got an error! It wrote: java: no suitable constructor found for EntityDamageEvent(survival.survival.Survival) What should I do? I am attaching the whole code. Thank you very much in advance for your help.
Hello! I made a plugin and it worked fine. I wanted to make another one, an event listener. I managed to do it until I entered the event in my Main class. I wrote: new EntityDamageEvent(this); and i got an error! It wrote: java: no suitable constructor found for EntityDamageEvent(survival.survival.Survival) What should I do? I am attaching the whole code. Thank you very much in advance for your help.
package survival.survival.Handlers;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
public class EntityDamageEvent implements Listener {
public EntityDamageEvent(Plugin plugin)
{
Bukkit.getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onEntityDamage(org.bukkit.event.entity.EntityDamageEvent event)
{
Entity entity = event.getEntity();
if ((entity instanceof Player)) {
event.setCancelled(true);
}
}
}
Ok, I've corrected your code, but next time just look for what you're doing wrong or see some tutorials. These are the basics, so you shouldn't have any problem finding a good tutorial.
First of all before you cast you must be sure that the object you want to cast is similar or the same object to which you want to cast, e.g. In this case, you wanted to cast the entity to the player without first checking whether the entity is a player. (you checked if entity is a player after casting)
Second, the class name should not be the same as in the event method. (idk, my IDE gives me many warnings)
Third, some things in this code could be a lot more readable and better.
Fourth, the name of package: survival.survival is at least strange, usually something like this is used: com.example.project
You have a lot to learn, so instead of making more posts, I recommend to fiddle around with code before posting your next question, or you can go step by step in guides, over time you should learn something.
That's it, please take my answer seriously. Check if it works, though it works for me, but you know you'll never know.
package survival.survival.Handlers;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
public class EntityDamageEvent implements Listener {
public EntityDamageEvent(Plugin plugin)
{
Bukkit.getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onEntityDamage(org.bukkit.event.entity.EntityDamageEvent event)
{
Entity entity = event.getEntity();
if ((entity instanceof Player)) {
event.setCancelled(true);
}
}
}
Ok, I've corrected your code, but next time just look for what you're doing wrong or see some tutorials. These are the basics, so you shouldn't have any problem finding a good tutorial.
First of all before you cast you must be sure that the object you want to cast is similar or the same object to which you want to cast, e.g. In this case, you wanted to cast the entity to the player without first checking whether the entity is a player. (you checked if entity is a player after casting)
Second, the class name should not be the same as in the event method. (idk, my IDE gives me many warnings)
Third, some things in this code could be a lot more readable and better.
Fourth, the name of package: survival.survival is at least strange, usually something like this is used: com.example.project
You have a lot to learn, so instead of making more posts, I recommend to fiddle around with code before posting your next question, or you can go step by step in guides, over time you should learn something.
That's it, please take my answer seriously. Check if it works, though it works for me, but you know you'll never know.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.