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

huangapple go评论70阅读模式
英文:

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

问题

我最近想到了一个关于Minecraft小游戏插件的想法。

在这里,我需要将玩家组织成团队。几年前,我可能只会创建一个新的类Team,其中包含添加、删除等方法。然而,我还想实现诸如友好火焰、能够看到隐形队友、设置名牌可见性以及使用侧边栏记分板等功能。
这些功能在org.bukkit.scoreboard.Team接口中都是可用的Spigot-API 1.15.2 Team Interface Javadoc

我是否可以创建自己的类Team,实现org.bukkit.scoreboard.Team接口,在其中既可以利用接口,又可以添加自己的方法和功能?

我担心这样做可能行不通,因为通常你会通过调用以下方法来获得org.bukkit.scoreboard.Team

myScoreboard.registerNewTeam("TEAM_NAME");

而且你不能将现有的org.bukkit.scoreboard.Team对象添加到记分板中。
该插件应该在不同版本的Spigot中运行(例如1.8+),我不知道每个版本在接口之外如何处理记分板团队。

英文:

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.

答案1

得分: 1

不能实现团队接口以使用这些函数,但您可以创建一个包装类,该类可以访问这些函数。

一个示例包装类:

class CustomTeam {
    private Team team;

    public CustomTeam(Team team) {
        this.team = team;
    }

    public void customFunc() {
        // 在这里可以使用 "team" 来执行操作。
    }
}
英文:

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.
    }
}

huangapple
  • 本文由 发表于 2020年4月9日 22:37:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/61123671.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定