Merge remote-tracking branch 'origin/1.6.x' into 1.6.x

This commit is contained in:
DroppingAnvil 2020-06-25 13:24:13 -05:00
commit 677c609ec8
5 changed files with 117 additions and 81 deletions

View File

@ -489,7 +489,7 @@ public class FactionsPlayerListener implements Listener {
if (FactionsPlugin.instance.getConfig().getBoolean("scoreboard.default-enabled", false)) {
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());
}
@ -564,7 +564,7 @@ public class FactionsPlayerListener implements Listener {
CmdSeeChunk.seeChunkMap.remove(event.getPlayer().getName());
FScoreboard.remove(me);
FScoreboard.remove(me, event.getPlayer());
}
public String parseAllPlaceholders(String string, Faction faction, Player player) {

View File

@ -9,15 +9,27 @@ import org.bukkit.scoreboard.Team;
import java.lang.reflect.Method;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class BufferedObjective {
/**
* @author FactionsUUID Team
*/
private static final Method addEntryMethod;
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 {
// 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) {
this.scoreboard = scoreboard;
this.baseName = createBaseName();
@ -122,14 +123,75 @@ public class BufferedObjective {
Team team = scoreboard.registerNewTeam(getNextTeamName());
bufferTeams.add(team);
Iterator<String> split = Splitter.fixedLength(16).split(entry.getValue()).iterator();
String name, prefix = null, suffix = null;
team.setPrefix(split.next());
String name = split.next();
if (split.hasNext()) { // We only guarantee two splits
team.setSuffix(split.next());
String value = entry.getValue();
if (value.length() > 16) {
String[] arrImAPirate = new String[3];
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 {
addEntryMethod.invoke(team, name);
} catch (ReflectiveOperationException ignored) {

View File

@ -58,10 +58,13 @@ public class FScoreboard {
FTeamWrapper.track(fboard);
}
public static void remove(FPlayer fplayer) {
public static void remove(FPlayer fplayer, Player player) {
FScoreboard fboard = fscoreboards.remove(fplayer);
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;
FTeamWrapper.untrack(fboard);
}
@ -91,7 +94,7 @@ public class FScoreboard {
bufferedObjective.setDisplaySlot(visible ? DisplaySlot.SIDEBAR : null);
}
public void setDefaultSidebar(final FSidebarProvider provider, int updateInterval) {
public void setDefaultSidebar(final FSidebarProvider provider) {
if (!isSupportedByServer()) {
return;
}
@ -114,7 +117,7 @@ public class FScoreboard {
updateObjective();
}
}
}.runTaskTimer(FactionsPlugin.getInstance(), updateInterval, updateInterval);
}.runTaskTimer(FactionsPlugin.getInstance(), 20, 20);
}
public void setTemporarySidebar(final FSidebarProvider provider) {

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.scoreboards;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.tag.Tag;
import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TagUtil;
@ -20,16 +21,16 @@ public abstract class FSidebarProvider {
public abstract List<String> getLines(FPlayer fplayer);
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) {
// 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) {

View File

@ -19,8 +19,9 @@ public class FTeamWrapper {
private static final Map<Faction, FTeamWrapper> wrappers = new HashMap<>();
private static final List<FScoreboard> tracking = new ArrayList<>();
private static final Set<Faction> updating = new HashSet<>();
private static int factionTeamPtr;
private static final Set<Faction> updating = new HashSet<>();
private final Map<FScoreboard, Team> teams = new HashMap<>();
private final String teamName;
private final Faction faction;
@ -36,18 +37,11 @@ public class FTeamWrapper {
}
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;
}
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)) {
Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> {
@ -58,22 +52,17 @@ public class FTeamWrapper {
}
public static void applyUpdates(Faction faction) {
if (!FScoreboard.isSupportedByServer()) {
return;
}
if (!FScoreboard.isSupportedByServer()) return;
if (faction.isWilderness()) {
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.contains(faction)) {
// Faction will be updated soon.
if (!FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false)
|| FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members"))
return;
}
if (updating.contains(faction)) return;
FTeamWrapper wrapper = wrappers.get(faction);
Set<FPlayer> factionMembers = faction.getFPlayers();
@ -98,21 +87,16 @@ public class FTeamWrapper {
}
for (FPlayer fmember : factionMembers) {
if (!fmember.isOnline()) {
continue;
}
if (!fmember.isOnline()) continue;
// Scoreboard might not have player; add him/her
wrapper.addPlayer(fmember.getPlayer());
}
wrapper.updatePrefixes();
}
public static void updatePrefixes(Faction faction) {
if (!FScoreboard.isSupportedByServer()) {
return;
}
if (!FScoreboard.isSupportedByServer()) return;
if (!wrappers.containsKey(faction)) {
applyUpdates(faction);
@ -122,34 +106,22 @@ public class FTeamWrapper {
}
protected static void track(FScoreboard fboard) {
if (!FScoreboard.isSupportedByServer()) {
return;
}
if (!FScoreboard.isSupportedByServer()) return;
tracking.add(fboard);
for (FTeamWrapper wrapper : wrappers.values()) {
wrapper.add(fboard);
}
for (FTeamWrapper wrapper : wrappers.values()) wrapper.add(fboard);
}
protected static void untrack(FScoreboard fboard) {
if (!FScoreboard.isSupportedByServer()) {
return;
}
if (!FScoreboard.isSupportedByServer()) return;
tracking.remove(fboard);
for (FTeamWrapper wrapper : wrappers.values()) {
wrapper.remove(fboard);
}
for (FTeamWrapper wrapper : wrappers.values()) wrapper.remove(fboard);
}
private void add(FScoreboard fboard) {
Scoreboard board = fboard.getScoreboard();
Team team = board.registerNewTeam(teamName);
teams.put(fboard, team);
for (OfflinePlayer player : getPlayers()) {
team.addPlayer(player);
}
for (OfflinePlayer player : getPlayers()) team.addPlayer(player);
updatePrefix(fboard);
}
@ -159,9 +131,7 @@ public class FTeamWrapper {
private void updatePrefixes() {
if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false)) {
for (FScoreboard fboard : teams.keySet()) {
updatePrefix(fboard);
}
for (FScoreboard fboard : teams.keySet()) updatePrefix(fboard);
}
}