I have an interface called Dog
, by default this "dog" is spawned for all players in the game i'm making, so I have extended this interface and created a new one called PerPlayerDog
that basically spawn different "dogs" depending on player, for this I have added a method called spawn(Player)
. I also have a registry class that stores all the dogs, so I iterate over all the spawned dogs
and i check if the dog is instanceof PerPlayerDog
and then I spawn this dog using my own logic, basically only for players that are nearby in a X radius all this in a repeated task that runs every second to check for the players to spawn the dog for, the problem is that using instance of
for more than "100+" spawned dogs and every second is expensive and not optimized, so I wanted to know a better option, also maybe it is better to rename the class to SubscribedDog
?, and have methods to subscribe to this dog for a player is this correct?, tell me your ideas or how i can improve the code, thanks.
interface Dog {
String getDogName();
UUID getUUID();
DogModel getDogModel();
}
interface PerPlayerDog extends Dog {
void spawn(Player player);
/** players that the dog has already been spawned for */
Iterable<Player> getReceipts();
}