#How to make this smarter...

1 messages · Page 1 of 1 (latest)

rare hemlock
#

@dusk magnet good idea

dusk magnet
#

Okay, so you want to create an interface class to represent all boss behaviour.

rare hemlock
#

yeah I have BossUtils as my main event listener

dusk magnet
#
public interface Boss{
    void death();

    void attack();
}
#

For example like that.

rare hemlock
#

and I would like to just pass data to the sub classes

#

so BossNature.death()

#

BossIce.death()
etc

dusk magnet
#

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.

rare hemlock
#
            listener.attack(data1, data2, data2);
        }
dusk magnet
#

Not like that.

rare hemlock
#

yeah so I don't know how to setup that map, what the object types are

dusk magnet
#
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.
rare hemlock
#

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()?

dusk magnet
#

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.

rare hemlock
#

is there an example on github you can link me to?

dusk magnet
#

I don't think there is. I just made that up on discord

rare hemlock
#

event.getEntity().getUniqueId() is very nice! don't have to store the whole entity

dusk magnet
#

I don't know how to explain it more better but yeah

rare hemlock
#

yeah i see now

#

so I need to simply store the bosses in a hashmap, then call the methods on each boss directly

somber carbon
rare hemlock
#

ok got it, thanks!

#

i appreciate the help

#

oli! yes please give me feedback

dusk magnet
#

Yeah, assuming that you can spawn multiple bosses with the same type.

rare hemlock
#

only 1 boss per type

somber carbon
#

Name your classes something usefuk

#

like

rare hemlock
#

but multiple types at once perhaps

somber carbon
#

"BossDeathListener"

#

Utils classes are annoying and mis-represents what it is

rare hemlock
#

fair point, my code could be cleaner

#

but also I dislike too much breaking up of files

dusk magnet
#

How do you create and spawn your bosses?

rare hemlock
#

i read a sign that's pasted in via world edit

somber carbon
rare hemlock
#

hahaha well yes and no. methods yes. files, not really

dusk magnet
#

jeff is my code example there acceptable?

somber carbon
#

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

dusk magnet
#

implementing entity?

somber carbon
#

yeah

#

org.bukkit.entity.Entity

dusk magnet
#

I don't think I implemented Entity on the code example

somber carbon
#

thats what i mean

somber carbon
#

if you dont implement Entity

#

that is the best way

dusk magnet
#

oh smh

#

also can you give me an example of wrapper class?

somber carbon
#

myeah

#

let me open an IDE

rare hemlock
#

thanks for the help! i'll be back with some code examples once i have it working

#

public class vs interface...

somber carbon
#

something like this maybe

#

an instanceof check is needed in that damage cast

dusk magnet
#

Why the SpiderBossManager class an interface?

#

Why not just normal class

somber carbon
#

eh its up to you really

#

they could just be static methods on a class yes

#

prefer it like that tho

dusk magnet
#

ah okay

#

kinda similiar like my code example

somber carbon
#

Yep

#

i just built on the spider Entity

#

to make it wrap the entity more

rare hemlock
#

Now I have a static problem...

dusk magnet
#

thank you for the example jeff

dusk magnet
somber carbon
#

yeah just yeet the manager

#

if you want

rare hemlock
#

Is it bad to use static for things? I am kinda stuck there and it's hard to get out

somber carbon
#

It is not bad

#

as long as it is used correctly

rare hemlock
somber carbon
#

@graceful latch

#

you wanna offer some insight

dusk magnet
graceful latch
#

whats needed?

rare hemlock
#

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()