Merge remote-tracking branch 'origin/1.6.x' into 1.6.x
This commit is contained in:
commit
677c609ec8
@ -489,7 +489,7 @@ public class FactionsPlayerListener implements Listener {
|
|||||||
|
|
||||||
if (FactionsPlugin.instance.getConfig().getBoolean("scoreboard.default-enabled", false)) {
|
if (FactionsPlugin.instance.getConfig().getBoolean("scoreboard.default-enabled", false)) {
|
||||||
FScoreboard.init(me);
|
FScoreboard.init(me);
|
||||||
FScoreboard.get(me).setDefaultSidebar(new FDefaultSidebar(), FactionsPlugin.instance.getConfig().getInt("scoreboard.default-update-interval", 20));
|
FScoreboard.get(me).setDefaultSidebar(new FDefaultSidebar());
|
||||||
FScoreboard.get(me).setSidebarVisibility(me.showScoreboard());
|
FScoreboard.get(me).setSidebarVisibility(me.showScoreboard());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,7 +564,7 @@ public class FactionsPlayerListener implements Listener {
|
|||||||
|
|
||||||
CmdSeeChunk.seeChunkMap.remove(event.getPlayer().getName());
|
CmdSeeChunk.seeChunkMap.remove(event.getPlayer().getName());
|
||||||
|
|
||||||
FScoreboard.remove(me);
|
FScoreboard.remove(me, event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String parseAllPlaceholders(String string, Faction faction, Player player) {
|
public String parseAllPlaceholders(String string, Faction faction, Player player) {
|
||||||
|
@ -9,15 +9,27 @@ import org.bukkit.scoreboard.Team;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class BufferedObjective {
|
public class BufferedObjective {
|
||||||
|
|
||||||
/**
|
|
||||||
* @author FactionsUUID Team
|
|
||||||
*/
|
|
||||||
|
|
||||||
private static final Method addEntryMethod;
|
private static final Method addEntryMethod;
|
||||||
private static final int MAX_LINE_LENGTH;
|
private static final int MAX_LINE_LENGTH;
|
||||||
|
private static final Pattern PATTERN = Pattern.compile("(\u00A7[0-9a-fk-r])|(.)");
|
||||||
|
|
||||||
|
private final Scoreboard scoreboard;
|
||||||
|
private final String baseName;
|
||||||
|
|
||||||
|
private Objective current;
|
||||||
|
private List<Team> currentTeams = new ArrayList<>();
|
||||||
|
private String title;
|
||||||
|
private DisplaySlot displaySlot;
|
||||||
|
|
||||||
|
private int objPtr;
|
||||||
|
private int teamPtr;
|
||||||
|
private boolean requiresUpdate = false;
|
||||||
|
|
||||||
|
private final Map<Integer, String> contents = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Check for long line support.
|
// Check for long line support.
|
||||||
@ -39,17 +51,6 @@ public class BufferedObjective {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Scoreboard scoreboard;
|
|
||||||
private final String baseName;
|
|
||||||
private final Map<Integer, String> contents = new HashMap<>();
|
|
||||||
private Objective current;
|
|
||||||
private List<Team> currentTeams = new ArrayList<>();
|
|
||||||
private String title;
|
|
||||||
private DisplaySlot displaySlot;
|
|
||||||
private int objPtr;
|
|
||||||
private int teamPtr;
|
|
||||||
private boolean requiresUpdate = false;
|
|
||||||
|
|
||||||
public BufferedObjective(Scoreboard scoreboard) {
|
public BufferedObjective(Scoreboard scoreboard) {
|
||||||
this.scoreboard = scoreboard;
|
this.scoreboard = scoreboard;
|
||||||
this.baseName = createBaseName();
|
this.baseName = createBaseName();
|
||||||
@ -122,14 +123,75 @@ public class BufferedObjective {
|
|||||||
Team team = scoreboard.registerNewTeam(getNextTeamName());
|
Team team = scoreboard.registerNewTeam(getNextTeamName());
|
||||||
bufferTeams.add(team);
|
bufferTeams.add(team);
|
||||||
|
|
||||||
Iterator<String> split = Splitter.fixedLength(16).split(entry.getValue()).iterator();
|
String name, prefix = null, suffix = null;
|
||||||
|
|
||||||
team.setPrefix(split.next());
|
String value = entry.getValue();
|
||||||
String name = split.next();
|
if (value.length() > 16) {
|
||||||
if (split.hasNext()) { // We only guarantee two splits
|
String[] arrImAPirate = new String[3];
|
||||||
team.setSuffix(split.next());
|
Matcher matcherrr = PATTERN.matcher(value);
|
||||||
|
StringBuilder builderrr = new StringBuilder();
|
||||||
|
int sCURvy = 0;
|
||||||
|
char currrentColorrr = 'r';
|
||||||
|
char currrentFormat = 'r';
|
||||||
|
while (sCURvy < 3 && matcherrr.find()) {
|
||||||
|
String tharSheBlows = matcherrr.group();
|
||||||
|
boolean hoist = false;
|
||||||
|
if (tharSheBlows.length() == 1) {
|
||||||
|
builderrr.append(tharSheBlows);
|
||||||
|
if (builderrr.length() == 16) {
|
||||||
|
hoist = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
char c = tharSheBlows.charAt(1);
|
||||||
|
if (c >= 'k' && c <= 'r') { // format!
|
||||||
|
currrentFormat = c;
|
||||||
|
if (c == 'r') {
|
||||||
|
currrentColorrr = 'r';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currrentColorrr = c;
|
||||||
|
currrentFormat = 'r';
|
||||||
|
}
|
||||||
|
if (builderrr.length() < 14) {
|
||||||
|
builderrr.append(tharSheBlows);
|
||||||
|
} else {
|
||||||
|
hoist = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hoist) {
|
||||||
|
arrImAPirate[sCURvy++] = builderrr.toString();
|
||||||
|
builderrr = new StringBuilder();
|
||||||
|
if (currrentColorrr != 'r') {
|
||||||
|
builderrr.append('\u00A7').append(currrentColorrr);
|
||||||
|
}
|
||||||
|
if (currrentFormat != 'r') {
|
||||||
|
builderrr.append('\u00A7').append(currrentFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sCURvy < 3 && builderrr.length() > 0) {
|
||||||
|
arrImAPirate[sCURvy] = builderrr.toString();
|
||||||
|
}
|
||||||
|
if (arrImAPirate[2] == null) {
|
||||||
|
name = arrImAPirate[0];
|
||||||
|
suffix = arrImAPirate[1];
|
||||||
|
} else {
|
||||||
|
prefix = arrImAPirate[0];
|
||||||
|
name = arrImAPirate[1];
|
||||||
|
suffix = arrImAPirate[2];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
name = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prefix != null) {
|
||||||
|
team.setPrefix(prefix);
|
||||||
|
}
|
||||||
|
if (suffix != null) {
|
||||||
|
team.setSuffix(suffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addEntryMethod.invoke(team, name);
|
addEntryMethod.invoke(team, name);
|
||||||
} catch (ReflectiveOperationException ignored) {
|
} catch (ReflectiveOperationException ignored) {
|
||||||
|
@ -58,10 +58,13 @@ public class FScoreboard {
|
|||||||
FTeamWrapper.track(fboard);
|
FTeamWrapper.track(fboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void remove(FPlayer fplayer) {
|
public static void remove(FPlayer fplayer, Player player) {
|
||||||
FScoreboard fboard = fscoreboards.remove(fplayer);
|
FScoreboard fboard = fscoreboards.remove(fplayer);
|
||||||
|
|
||||||
if (fboard != null) {
|
if (fboard != null) {
|
||||||
|
if (fboard.scoreboard == player.getScoreboard()) { // No equals method implemented, so may as well skip a nullcheck
|
||||||
|
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||||
|
}
|
||||||
fboard.removed = true;
|
fboard.removed = true;
|
||||||
FTeamWrapper.untrack(fboard);
|
FTeamWrapper.untrack(fboard);
|
||||||
}
|
}
|
||||||
@ -91,7 +94,7 @@ public class FScoreboard {
|
|||||||
bufferedObjective.setDisplaySlot(visible ? DisplaySlot.SIDEBAR : null);
|
bufferedObjective.setDisplaySlot(visible ? DisplaySlot.SIDEBAR : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultSidebar(final FSidebarProvider provider, int updateInterval) {
|
public void setDefaultSidebar(final FSidebarProvider provider) {
|
||||||
if (!isSupportedByServer()) {
|
if (!isSupportedByServer()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -114,7 +117,7 @@ public class FScoreboard {
|
|||||||
updateObjective();
|
updateObjective();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskTimer(FactionsPlugin.getInstance(), updateInterval, updateInterval);
|
}.runTaskTimer(FactionsPlugin.getInstance(), 20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTemporarySidebar(final FSidebarProvider provider) {
|
public void setTemporarySidebar(final FSidebarProvider provider) {
|
||||||
|
@ -3,6 +3,7 @@ package com.massivecraft.factions.scoreboards;
|
|||||||
import com.massivecraft.factions.FPlayer;
|
import com.massivecraft.factions.FPlayer;
|
||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
import com.massivecraft.factions.FactionsPlugin;
|
import com.massivecraft.factions.FactionsPlugin;
|
||||||
|
import com.massivecraft.factions.tag.Tag;
|
||||||
import com.massivecraft.factions.zcore.util.TL;
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
import com.massivecraft.factions.zcore.util.TagUtil;
|
import com.massivecraft.factions.zcore.util.TagUtil;
|
||||||
|
|
||||||
@ -20,16 +21,16 @@ public abstract class FSidebarProvider {
|
|||||||
public abstract List<String> getLines(FPlayer fplayer);
|
public abstract List<String> getLines(FPlayer fplayer);
|
||||||
|
|
||||||
public String replaceTags(FPlayer fPlayer, String s) {
|
public String replaceTags(FPlayer fPlayer, String s) {
|
||||||
s = TagUtil.parsePlaceholders(fPlayer.getPlayer(), s);
|
s = Tag.parsePlaceholders(fPlayer.getPlayer(), s);
|
||||||
|
|
||||||
return qualityAssure(TagUtil.parsePlain(fPlayer, s));
|
return qualityAssure(Tag.parsePlain(fPlayer, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String replaceTags(Faction faction, FPlayer fPlayer, String s) {
|
public String replaceTags(Faction faction, FPlayer fPlayer, String s) {
|
||||||
// Run through Placeholder API first
|
// Run through Placeholder API first
|
||||||
s = TagUtil.parsePlaceholders(fPlayer.getPlayer(), s);
|
s = Tag.parsePlaceholders(fPlayer.getPlayer(), s);
|
||||||
|
|
||||||
return qualityAssure(Objects.requireNonNull(TagUtil.parsePlain(faction, fPlayer, s)));
|
return qualityAssure(Tag.parsePlain(faction, fPlayer, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String qualityAssure(String line) {
|
private String qualityAssure(String line) {
|
||||||
|
@ -19,8 +19,9 @@ public class FTeamWrapper {
|
|||||||
|
|
||||||
private static final Map<Faction, FTeamWrapper> wrappers = new HashMap<>();
|
private static final Map<Faction, FTeamWrapper> wrappers = new HashMap<>();
|
||||||
private static final List<FScoreboard> tracking = new ArrayList<>();
|
private static final List<FScoreboard> tracking = new ArrayList<>();
|
||||||
private static final Set<Faction> updating = new HashSet<>();
|
|
||||||
private static int factionTeamPtr;
|
private static int factionTeamPtr;
|
||||||
|
private static final Set<Faction> updating = new HashSet<>();
|
||||||
|
|
||||||
private final Map<FScoreboard, Team> teams = new HashMap<>();
|
private final Map<FScoreboard, Team> teams = new HashMap<>();
|
||||||
private final String teamName;
|
private final String teamName;
|
||||||
private final Faction faction;
|
private final Faction faction;
|
||||||
@ -36,18 +37,11 @@ public class FTeamWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void applyUpdatesLater(final Faction faction) {
|
public static void applyUpdatesLater(final Faction faction) {
|
||||||
if (!FScoreboard.isSupportedByServer()) {
|
if (!FScoreboard.isSupportedByServer()) return;
|
||||||
|
if (faction.isWilderness()) return;
|
||||||
|
if (!FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false)
|
||||||
|
|| FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members"))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (faction.isWilderness()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false) || FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (updating.add(faction)) {
|
if (updating.add(faction)) {
|
||||||
Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> {
|
||||||
@ -58,22 +52,17 @@ public class FTeamWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void applyUpdates(Faction faction) {
|
public static void applyUpdates(Faction faction) {
|
||||||
if (!FScoreboard.isSupportedByServer()) {
|
if (!FScoreboard.isSupportedByServer()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (faction.isWilderness()) {
|
if (faction.isWilderness()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false) || FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updating.contains(faction)) {
|
if (!FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false)
|
||||||
// Faction will be updated soon.
|
|| FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members"))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
|
if (updating.contains(faction)) return;
|
||||||
|
|
||||||
FTeamWrapper wrapper = wrappers.get(faction);
|
FTeamWrapper wrapper = wrappers.get(faction);
|
||||||
Set<FPlayer> factionMembers = faction.getFPlayers();
|
Set<FPlayer> factionMembers = faction.getFPlayers();
|
||||||
@ -98,21 +87,16 @@ public class FTeamWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (FPlayer fmember : factionMembers) {
|
for (FPlayer fmember : factionMembers) {
|
||||||
if (!fmember.isOnline()) {
|
if (!fmember.isOnline()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scoreboard might not have player; add him/her
|
// Scoreboard might not have player; add him/her
|
||||||
wrapper.addPlayer(fmember.getPlayer());
|
wrapper.addPlayer(fmember.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper.updatePrefixes();
|
wrapper.updatePrefixes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updatePrefixes(Faction faction) {
|
public static void updatePrefixes(Faction faction) {
|
||||||
if (!FScoreboard.isSupportedByServer()) {
|
if (!FScoreboard.isSupportedByServer()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!wrappers.containsKey(faction)) {
|
if (!wrappers.containsKey(faction)) {
|
||||||
applyUpdates(faction);
|
applyUpdates(faction);
|
||||||
@ -122,34 +106,22 @@ public class FTeamWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static void track(FScoreboard fboard) {
|
protected static void track(FScoreboard fboard) {
|
||||||
if (!FScoreboard.isSupportedByServer()) {
|
if (!FScoreboard.isSupportedByServer()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
tracking.add(fboard);
|
tracking.add(fboard);
|
||||||
for (FTeamWrapper wrapper : wrappers.values()) {
|
for (FTeamWrapper wrapper : wrappers.values()) wrapper.add(fboard);
|
||||||
wrapper.add(fboard);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void untrack(FScoreboard fboard) {
|
protected static void untrack(FScoreboard fboard) {
|
||||||
if (!FScoreboard.isSupportedByServer()) {
|
if (!FScoreboard.isSupportedByServer()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
tracking.remove(fboard);
|
tracking.remove(fboard);
|
||||||
for (FTeamWrapper wrapper : wrappers.values()) {
|
for (FTeamWrapper wrapper : wrappers.values()) wrapper.remove(fboard);
|
||||||
wrapper.remove(fboard);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void add(FScoreboard fboard) {
|
private void add(FScoreboard fboard) {
|
||||||
Scoreboard board = fboard.getScoreboard();
|
Scoreboard board = fboard.getScoreboard();
|
||||||
Team team = board.registerNewTeam(teamName);
|
Team team = board.registerNewTeam(teamName);
|
||||||
teams.put(fboard, team);
|
teams.put(fboard, team);
|
||||||
|
for (OfflinePlayer player : getPlayers()) team.addPlayer(player);
|
||||||
for (OfflinePlayer player : getPlayers()) {
|
|
||||||
team.addPlayer(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePrefix(fboard);
|
updatePrefix(fboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,9 +131,7 @@ public class FTeamWrapper {
|
|||||||
|
|
||||||
private void updatePrefixes() {
|
private void updatePrefixes() {
|
||||||
if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false)) {
|
if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false)) {
|
||||||
for (FScoreboard fboard : teams.keySet()) {
|
for (FScoreboard fboard : teams.keySet()) updatePrefix(fboard);
|
||||||
updatePrefix(fboard);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user