#Can anyone tell me whats wrong with my code?

1 messages · Page 1 of 1 (latest)

rustic patrol
#

import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Warden;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class Regen implements Listener {
    @EventHandler
    public void onDamage(EntityDamageEvent e){
        if (e.getEntity().getType() == EntityType.WARDEN){
            if (e.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK){
                PotionEffect effect = new PotionEffect(PotionEffectType.REGENERATION, 10, 2);
                effect.apply((LivingEntity) Warden);

            }



        }
    }
}```
#

It says Expression expected

#

on line 19

#

which is the EntityType.WARDEN

mortal lintel
#

can you use ?paste

#

?paste

#

dang bot dont work in threads

rustic patrol
#

how do I do that

worthy marlin
#

xd

icy mica
#

isnt there an Entity#addPotionEffect?

#

or apply

mortal lintel
icy mica
mortal lintel
#

its actually on LivingEntity

icy mica
#

i guess ide is old and doesnt like multi line expressions :/

rustic patrol
#

What do I do in ? paste

icy mica
#

what ide are you using actually?

mortal lintel
worthy marlin
rustic patrol
mortal lintel
#

yeah

#

so

rustic patrol
mortal lintel
#

your applaying a Entity as a potion effect

#

wait

#

tf

#

ahh

#

Warden

#

is not valid

#

you need its actual instance

#

not its class name

icy mica
#

e.getEntity()

mortal lintel
#

^

icy mica
#

my lazy ass was reading over it

mortal lintel
#

i do that a lot too

#

especially with weird things i see like that xD

rustic patrol
#

do I replace Warden with e.getEntity?

mortal lintel
#

yessir

#

Warden is its type/class name, and not an actual entity thats loaded into the world

#

e.getEntity() is a real entity in the world

rustic patrol
#

ok

#

can you tell me how are you good at spigot

mortal lintel
#

im sure anyone in this thread is more than capable to answer a question if im not :))

worthy marlin
#

gud

#

i saw ur github and its good

#

so ye

#

he is good

mortal lintel
mortal lintel
worthy marlin
#

:d for the pathfinder its good its bad if u want to have a more complicated but its good

mortal lintel
#

nah it just follows basic survival rules

#

eg dont fall down more than 4 blocks

#

and it avoids water/lava

#

all it rly needs atm

worthy marlin
#

then its good to me the function is the first then the pretty code i never judge a code for it look to me the first is the function

#

not the look

#

i need to go! gl for this thread!

rustic patrol
#

does anyone here know how to check for if the health is below 100?

icy mica
#

Entity::getHealth?

#

check docs

rustic patrol
rustic patrol
#

yes

mortal lintel
#

okay 2 things

icy mica
#

uhh learn java

mortal lintel
#

your instanceof check can be better with newer java syntax's and lets you not need to cast

if (e.getEntity() instanceof LivingEntity theEntity) {
    ((Damagable) theEntity).getMaxHealth();
}
#

2nd

#

use Damagable

#

it extends LivingEntity so you can cast it

#

in fact if you only need Damagable

#

just instanceof Damageable on e.getEntity()

rustic patrol
#

ok thanks

mortal lintel
#

oh one more thing

rustic patrol
#

it flags Damagable

mortal lintel
#

theres 2 types of Damagable one for entity one for inventory

mortal lintel
#

but for current health you use damageable

rustic patrol
#

ok

#

it also flags theEntity

rustic patrol
icy mica
#

put your java version higher

rustic patrol
#

ok