#How to make this smarter...
1 messages · Page 1 of 1 (latest)
Okay, so you want to create an interface class to represent all boss behaviour.
yeah I have BossUtils as my main event listener
and I would like to just pass data to the sub classes
so BossNature.death()
BossIce.death()
etc
And you want to create the actual boss class
public class SpiderBoss implements Boss{
@Override
public void death(){
// something
}
@Override
public void attack(){
// something
}
}
And then when you spawn the boss, you need to keep track of the boss by putting them on a Map or a Set, depends on your preference.
listener.attack(data1, data2, data2);
}
Not like that.
yeah so I don't know how to setup that map, what the object types are
public class SpiderBossManager{
// The UUID is the boss entity uuid
private final Map<UUID, Boss> bossMap = new HashMap<>();
@EventHandler
public void onBossDeath(EntityDeathEvent event){
// If the entity UUID is not a boss, just return
if(!bossMap.containsKey(event.getEntity().getUniqueId()){
return;
}
// So after make sure the entity is a boss, we get the value from the map and call the death method.
bossMap.get(event.getEntity().getUniqueId()).death();
// After boss dead, we remove them from the map
bossMap.remove(event.getEntity().getUniqueId());
}
```That's it.
on SpiderBoss.create() I push the attack() method into some hashmap of bossname and method, then on event listen I check bossname and send event to bossX.attack()?
Also I need more information about your code right now.
So everytime you spawn a boss, put them on a map, and play around with the map for the listeners.
And you can do the same thing for the damage event, etc.
You just need to set the behaviour on the boss class.
is there an example on github you can link me to?
I don't think there is. I just made that up on discord
event.getEntity().getUniqueId() is very nice! don't have to store the whole entity
I don't know how to explain it more better but yeah
yeah i see now
so I need to simply store the bosses in a hashmap, then call the methods on each boss directly
i dont like this naming
Yeah, assuming that you can spawn multiple bosses with the same type.
only 1 boss per type
but multiple types at once perhaps
fair point, my code could be cleaner
but also I dislike too much breaking up of files
How do you create and spawn your bosses?
i read a sign that's pasted in via world edit
Which is the whole point of oop 😜
hahaha well yes and no. methods yes. files, not really
jeff is my code example there acceptable?
i mean
without implementing Entity & Boss, that is the best way afaik
just having a wrapper class
and implementing entity is not a good idea
cause of all the methods you have to override lol
implementing entity?
I don't think I implemented Entity on the code example
thats what i mean
.
if you dont implement Entity
that is the best way
thanks for the help! i'll be back with some code examples once i have it working
public class vs interface...
eh its up to you really
they could just be static methods on a class yes
prefer it like that tho
Now I have a static problem...
thank you for the example jeff
my example doesnt use static at all
Is it bad to use static for things? I am kinda stuck there and it's hard to get out
You don't want to make that method static.
I think I've figure it all out, basically I need to move all my bosses to be object based, so I can call bossObject.attack() instead of BossClassnameFile.attack()