Search code examples
javabukkit

Best way to organize Players into Teams in MiniGames to also use make use of certain features available in org.bukkit.scoreboard.Team interface


I recently had an idea for a minecraft-minigame plugin.

Here, I need to organize Players into Teams. A few years back, I would have just made a new class Team, with add, remove methods etc.. However, I also want to implement features like friendly-fire, being able to see invisible teammates, setting name-tag visibility and make use of the sidebar-scoreboard. Those are all features available in the org.bukkit.scoreboard.Teaminterface Spigot-API 1.15.2 Team Interface Javadoc.

Is it possible to create my own class Team implements org.bukkit.scoreboard.Team, where I could make use of the Interface and also add own methods and features?

I am concerned this wouldn't work, because you normally get a org.bukkit.scoreboard.Team by calling

myScoreboard.registerNewTeam("TEAM_NAME");

and you cannot add an existing org.bukkit.scoreboard.Team-object to a scoreboard. This plugin should work in different versions of spigot (like 1.8+), and I don't know how each version handles Scoreboard Teams beside the interface.


Solution

  • You can not implement the team interface to use the functions, but you could make a wrapper class that can acces the function.

    An example wrapper class:

    class CustomTeam {
        private Team team;
    
        public CustomTeam(Team team) {
            this.team = team;
        }
    
        public customFunc() {
            //you can use the "team" here to do stuff.
        }
    }