-2

I'm making plugins requested by a server for the game Minecraft using the api Spigot

In this API there's a class named Player. For the purposes of these plugins (and because it's easier) I like to make my "own player class".

So there are the Plugin1, the Plugin2 and the Plugin3. I'll name them API, Faction and Scoreboard.

The API plugins contains my own player class which has methods that refers to some other classes of Faction and Scoreboard. SO API has Scoreboard and Faction in it's projects dependencies.
BUT as I also need to to use my custom player class in Scoreboard and Faction they both have a project dependency to API.

Basically Scoreboard -> API <- Faction BUT Faction <- API and Scoreboard <- API

So I have here a cycling problem. And I have no idea on how to solve it as I want to have some clear and separated projects.
I don't find it as a big issue as everything looks stable but I did some researches and found that it's a problem though.

I hope to have been clear enough. Thanks any kind of help.

Jules
  • 346
  • 1
  • 3
  • 15

1 Answers1

0

It's a good practice to separate the common components used across multiple projects into a shared library. This way the library can be imported into the projects wherever necessary and you avoid circular dependencies.

I'd say extract all the POJOs like your custom Player into a lib and use it across all those projects. Create a new class in any of the projects for the part of the code that leverages other classes like the Scoreboard or Faction. Or use interfaces and implement them in your projects.

Aditya Vikas Devarapalli
  • 3,186
  • 2
  • 36
  • 54
  • By POJO you mean Plain Old Java Object ? Which is mostly a class with only getter and setter right ? And I don't understand how using interfaces would solve this problem... – Jules Jan 09 '19 at 18:53