9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2026-01-06 15:42:00 +00:00
This commit is contained in:
XiaoMoMi
2025-07-19 23:48:06 +08:00
parent 2ebb781721
commit df5a1faa19
3 changed files with 76 additions and 5 deletions

View File

@@ -53,6 +53,14 @@ public class BukkitRequirementManager extends AbstractRequirementManager {
this.registerBedrock();
this.registerDisguise();
this.registerPassenger();
this.registerTeammates();
}
private void registerTeammates() {
this.registerRequirement((args, interval) -> {
boolean is = (boolean) args;
return new TeammatesRequirement(interval, is);
}, "teammates");
}
private void registerPassenger() {

View File

@@ -0,0 +1,63 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.bukkit.requirement.builtin;
import net.momirealms.customnameplates.api.CNPlayer;
import net.momirealms.customnameplates.backend.requirement.AbstractRequirement;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Team;
public class TeammatesRequirement extends AbstractRequirement {
private final boolean is;
public TeammatesRequirement(int refreshInterval, boolean is) {
super(refreshInterval);
this.is = is;
}
@Override
public boolean isSatisfied(CNPlayer p1, CNPlayer p2) {
Player player1 = (Player) p1.player();
Player player2 = (Player) p2.player();
Team team1 = Bukkit.getScoreboardManager().getMainScoreboard().getEntityTeam(player1);
Team team2 = Bukkit.getScoreboardManager().getMainScoreboard().getEntityTeam(player2);
if (this.is) {
return team1 != null && team1.equals(team2);
} else {
return team1 == null || !team1.equals(team2);
}
}
@Override
public String type() {
return "teammates";
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TeammatesRequirement that = (TeammatesRequirement) o;
return that.is == this.is;
}
@Override
public int hashCode() {
return this.is ? 17 : 3;
}
}