Disable entity damage when gamemode equals survival

Discussion in 'Plugin Development' started by Verklickt, Jan 6, 2022.

  1. Offline


    So I tried to make a plugin which disables Entity Damage when you are in gamemode survival:

    import org.bukkit.Bukkit;
    import org.bukkit.GameMode;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    public class listeners implements Listener {
        public void disableDamage(EntityDamageEvent e) {
            if (Bukkit.getPlayer().getGameMode(equals(GameMode.SURVIVAL))) {
    However my Program says "Cannot resolve Method: getPlayer()"

    I'm a newbie in Bukkit Development so please help me out! :D
  2. Offline

    timtower Administrator Administrator Moderator

    @Verklickt Because you are not telling it what player.
    Try e.getEntity, check if it is a player, if so: cast to player, then do the gamemode check
  3. Offline


    try to first check if the entity is an instance of the player and if it isn't don't run the code but if it is then run it
    something like
    if (e.getEntity instanceof Player) then work forward from that

Share This Page