mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-23 18:55:25 +01:00
Add faction tag to team prefix
This commit is contained in:
parent
51f1ceee14
commit
c049768e21
@ -4,6 +4,7 @@ import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.event.FactionRenameEvent;
|
||||
import com.massivecraft.factions.scoreboards.FScoreboard;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -73,6 +74,7 @@ public class CmdTag extends FCommand {
|
||||
faction.msg("<i>The faction %s<i> changed their name to %s.", fme.getColorTo(faction) + oldtag, myFaction.getTag(faction));
|
||||
}
|
||||
|
||||
FScoreboard.applyUpdates(myFaction);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.event.FactionRelationEvent;
|
||||
import com.massivecraft.factions.scoreboards.FScoreboard;
|
||||
@ -87,18 +86,7 @@ public abstract class FRelationCommand extends FCommand {
|
||||
myFaction.msg("<i>This will have no effect while your faction is peaceful.");
|
||||
}
|
||||
|
||||
for (FPlayer ourMember : myFaction.getFPlayers()) {
|
||||
if (!ourMember.isOnline()) {
|
||||
continue;
|
||||
}
|
||||
for (FPlayer theirMember : them.getFPlayers()) {
|
||||
if (!theirMember.isOnline()) {
|
||||
continue;
|
||||
}
|
||||
FScoreboard.get(ourMember).updateColor(theirMember);
|
||||
FScoreboard.get(theirMember).updateColor(ourMember);
|
||||
}
|
||||
}
|
||||
|
||||
FScoreboard.applyUpdates(myFaction);
|
||||
FScoreboard.applyUpdates(them);
|
||||
}
|
||||
}
|
||||
|
@ -526,13 +526,11 @@ public class FactionsPlayerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
final public void onFactionJoin(FPlayerJoinEvent event) {
|
||||
FScoreboard.updateColorToAllLater(event.getfPlayer());
|
||||
FScoreboard.updateColorsFromAllLater(event.getfPlayer());
|
||||
FScoreboard.applyUpdatesLater(event.getFaction());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onFactionLeave(FPlayerLeaveEvent event) {
|
||||
FScoreboard.updateColorToAllLater(event.getfPlayer());
|
||||
FScoreboard.updateColorsFromAllLater(event.getfPlayer());
|
||||
FScoreboard.applyUpdatesLater(event.getFaction());
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.massivecraft.factions.scoreboards;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
@ -20,16 +18,14 @@ public class FScoreboard {
|
||||
private final Scoreboard scoreboard;
|
||||
private final FPlayer fplayer;
|
||||
private final BufferedObjective bufferedObjective;
|
||||
private final Map<ChatColor, Team> colorTeams = new HashMap<ChatColor, Team>();
|
||||
private final Map<Faction, Team> factionTeams = new HashMap<Faction, Team>();
|
||||
private int factionTeamPtr;
|
||||
private FSidebarProvider defaultProvider;
|
||||
private FSidebarProvider temporaryProvider;
|
||||
private boolean removed = false;
|
||||
|
||||
public static void init(FPlayer fplayer) {
|
||||
fscoreboards.put(fplayer.getPlayer(), new FScoreboard(fplayer));
|
||||
|
||||
updateColorToAllLater(fplayer);
|
||||
updateColorsFromAllLater(fplayer);
|
||||
}
|
||||
|
||||
public static void remove(FPlayer fplayer) {
|
||||
@ -44,28 +40,19 @@ public class FScoreboard {
|
||||
return fscoreboards.get(player);
|
||||
}
|
||||
|
||||
public static void updateColorToAllLater(final FPlayer fplayer) {
|
||||
// We're delaying by a tick here to simplify logic in other areas
|
||||
// (e.g. for FPlayer{Join,Leave}Event handlers; CmdDisband)
|
||||
public static void applyUpdatesLater(final Faction faction) {
|
||||
Bukkit.getScheduler().runTask(P.p, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (FPlayer other : FPlayers.i.getOnline()) {
|
||||
get(other).updateColor(fplayer);
|
||||
}
|
||||
applyUpdates(faction);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void updateColorsFromAllLater(final FPlayer fplayer) {
|
||||
Bukkit.getScheduler().runTask(P.p, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (FPlayer other : FPlayers.i.getOnline()) {
|
||||
get(fplayer).updateColor(other);
|
||||
}
|
||||
}
|
||||
});
|
||||
public static void applyUpdates(Faction faction) {
|
||||
for (FScoreboard fscoreboard : fscoreboards.values()) {
|
||||
fscoreboard.updateFactionTeam(faction);
|
||||
}
|
||||
}
|
||||
|
||||
private FScoreboard(FPlayer fplayer) {
|
||||
@ -73,10 +60,8 @@ public class FScoreboard {
|
||||
this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||
this.bufferedObjective = new BufferedObjective(scoreboard);
|
||||
|
||||
for (ChatColor color : ChatColor.values()) {
|
||||
Team team = scoreboard.registerNewTeam(color.name());
|
||||
team.setPrefix(color.toString());
|
||||
colorTeams.put(color, team);
|
||||
for (Faction faction : Factions.i.get()) {
|
||||
updateFactionTeam(faction);
|
||||
}
|
||||
|
||||
fplayer.getPlayer().setScoreboard(scoreboard);
|
||||
@ -139,16 +124,44 @@ public class FScoreboard {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateColor(FPlayer other) {
|
||||
if (!other.isOnline()) {
|
||||
public void updateFactionTeam(Faction faction) {
|
||||
Team team = factionTeams.get(faction);
|
||||
|
||||
if (!Factions.i.get().contains(faction)) {
|
||||
// Faction was disbanded
|
||||
if (team != null) {
|
||||
factionTeams.remove(faction);
|
||||
team.unregister();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ChatColor newColor = fplayer.getRelationTo(other).getColor();
|
||||
Team team = colorTeams.get(newColor);
|
||||
if (team == null) {
|
||||
team = scoreboard.registerNewTeam("faction_" + (factionTeamPtr++));
|
||||
factionTeams.put(faction, team);
|
||||
}
|
||||
|
||||
if (!team.hasPlayer(other.getPlayer())) {
|
||||
team.addPlayer(other.getPlayer());
|
||||
for (OfflinePlayer player : team.getPlayers()) {
|
||||
if (!player.isOnline() || !faction.getFPlayers().contains(FPlayers.i.get(player.getPlayer()))) {
|
||||
// Player is offline or no longer in faction
|
||||
team.removePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
for (FPlayer fmember : faction.getFPlayers()) {
|
||||
if (!fmember.isOnline()) {
|
||||
continue;
|
||||
}
|
||||
if (!team.hasPlayer(fmember.getPlayer())) {
|
||||
// Scoreboard team doesn't have player; add him/her
|
||||
team.addPlayer(fmember.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
// Update faction prefix
|
||||
String prefix = faction.getTag().substring(0, Math.min(13, faction.getTag().length())) + " " + faction.getRelationTo(this.fplayer).getColor();
|
||||
if (team.getPrefix() == null || !team.getPrefix().equals(prefix)) {
|
||||
team.setPrefix(prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user