🚧 Fix scoreboard

This commit is contained in:
Maxlego08 2022-02-28 11:22:28 +01:00
parent f7e88b3741
commit 2b5f8c7e31
6 changed files with 58 additions and 41 deletions

View File

@ -1,7 +1,7 @@
name: zKoth name: zKoth
author: Maxlego08 author: Maxlego08
main: fr.maxlego08.zkoth.ZKothPlugin main: fr.maxlego08.zkoth.ZKothPlugin
version: 2.0.3.4 version: 2.1.0.0
softdepend: [PlaceholderAPI, Guilds, Factions, FactionsX, SuperiorSkyblock2, LegacyFactions, FeatherBoard, TAB, TitleManager, UltimateFactions] softdepend: [PlaceholderAPI, Guilds, Factions, FactionsX, SuperiorSkyblock2, LegacyFactions, FeatherBoard, TAB, TitleManager, UltimateFactions]
commands: commands:
api-version: 1.13 api-version: 1.13

View File

@ -47,25 +47,27 @@ public class KothExpension extends PlaceholderExpansion {
if (koths.size() >= 1) { if (koths.size() >= 1) {
Koth koth = koths.get(0); Koth koth = koths.get(0);
if (params.equals("name")) if (params.equals("name")) {
return koth.getName(); return koth.getName();
else if (params.equals("capture")) } else if (params.equals("capture")) {
return String.valueOf(koth.getCurrentSecond()); return String.valueOf(koth.getCurrentSecond());
else if (params.equals("x")) } else if (params.equals("x")) {
return String.valueOf(koth.getCenter().getBlockX()); return String.valueOf(koth.getCenter().getBlockX());
else if (params.equals("y")) } else if (params.equals("y")) {
return String.valueOf(koth.getCenter().getBlockY()); return String.valueOf(koth.getCenter().getBlockY());
else if (params.equals("z")) } else if (params.equals("z")) {
return String.valueOf(koth.getCenter().getBlockZ()); return String.valueOf(koth.getCenter().getBlockZ());
else if (params.equals("faction")) } else if (params.equals("faction")) {
return String.valueOf(koth.getCurrentFaction()); return String.valueOf(koth.getCurrentFaction());
else if (params.equals("player")) } else if (params.equals("player")) {
return koth.getCurrentPlayer(); return koth.getCurrentPlayer();
}
} }
if (!params.contains("_")) if (!params.contains("_")) {
return null; return null;
}
String[] args = params.split("_"); String[] args = params.split("_");

View File

@ -487,12 +487,13 @@ public class ZKoth extends ZUtils implements Koth {
@Override @Override
public CollectionConsumer<Player> onScoreboard() { public CollectionConsumer<Player> onScoreboard() {
if (isCooldown) if (this.isCooldown) {
return p -> Config.scoreboardCooldown.stream().map(e -> papi(replaceMessage(e), p)) return p -> Config.scoreboardCooldown.stream().map(e -> papi(replaceMessage(e), p))
.collect(Collectors.toList()); .collect(Collectors.toList());
else } else {
return p -> Config.scoreboard.stream().map(e -> papi(replaceMessage(e), p)).collect(Collectors.toList()); return p -> Config.scoreboard.stream().map(e -> papi(replaceMessage(e), p)).collect(Collectors.toList());
} }
}
@Override @Override
public void addCommand(String command) { public void addCommand(String command) {

View File

@ -174,8 +174,9 @@ public class CommandManager extends ZUtils implements CommandExecutor, TabComple
} }
CommandType returnType = command.prePerform(main, sender, strings); CommandType returnType = command.prePerform(main, sender, strings);
if (returnType == CommandType.SYNTAX_ERROR) if (returnType == CommandType.SYNTAX_ERROR) {
message(sender, Message.COMMAND_SYNTAXE_ERROR, command.getSyntaxe()); message(sender, Message.COMMAND_SYNTAXE_ERROR, command.getSyntaxe());
}
return returnType; return returnType;
} }
message(sender, Message.COMMAND_NO_PERMISSION); message(sender, Message.COMMAND_NO_PERMISSION);

View File

@ -48,6 +48,7 @@ public class Config implements Saveable {
* static Singleton instance. * static Singleton instance.
*/ */
private static volatile Config instance; private static volatile Config instance;
public static boolean enableDebug;
/** /**
* Private constructor for singleton. * Private constructor for singleton.

View File

@ -1,7 +1,7 @@
package fr.maxlego08.zkoth.scoreboard; package fr.maxlego08.zkoth.scoreboard;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -47,11 +47,15 @@ public class ScoreBoardManager extends ZUtils {
return; return;
} }
Collection<String> lines = this.lines.accept(null); Iterator<FastBoard> iterator = this.boards.values().iterator();
boards.forEach((player, board) -> { while (iterator.hasNext()) {
if (player.isOnline()) FastBoard b = iterator.next();
board.updateLines(lines); if (b.isDeleted() || !b.getPlayer().isOnline()) {
}); this.boards.remove(b.getPlayer());
}
}
this.boards.forEach((player, board) -> board.updateLines(this.lines.accept(player)));
}); });
} }
@ -65,16 +69,18 @@ public class ScoreBoardManager extends ZUtils {
*/ */
public FastBoard createBoard(Player player, String title) { public FastBoard createBoard(Player player, String title) {
if (hasBoard(player)) if (this.hasBoard(player)) {
return getBoard(player); return this.getBoard(player);
}
FastBoard board = new FastBoard(player); FastBoard board = new FastBoard(player);
board.updateTitle(title); board.updateTitle(title);
if (lines != null) if (this.lines != null) {
board.updateLines(lines.accept(player)); board.updateLines(this.lines.accept(player));
}
boards.put(player, board); this.boards.put(player, board);
this.scoreboard.hide(player, create(board, player, title)); this.scoreboard.hide(player, create(board, player, title));
return board; return board;
@ -92,15 +98,16 @@ public class ScoreBoardManager extends ZUtils {
if (current != null) if (current != null)
current.delete(); current.delete();
boards.remove(player); this.boards.remove(player);
FastBoard board = new FastBoard(player); FastBoard board = new FastBoard(player);
board.updateTitle(title); board.updateTitle(title);
if (lines != null) if (this.lines != null) {
board.updateLines(lines.accept(player)); board.updateLines(this.lines.accept(player));
}
boards.put(player, board); this.boards.put(player, board);
}; };
} }
@ -112,11 +119,14 @@ public class ScoreBoardManager extends ZUtils {
*/ */
public boolean delete(Player player) { public boolean delete(Player player) {
if (!hasBoard(player)) if (!this.hasBoard(player)) {
return false; return false;
}
FastBoard board = getBoard(player); FastBoard board = getBoard(player);
if (!board.isDeleted()) {
board.delete(); board.delete();
}
this.scoreboard.toggle(player, p -> { this.scoreboard.toggle(player, p -> {
@ -132,8 +142,9 @@ public class ScoreBoardManager extends ZUtils {
* @return * @return
*/ */
public boolean updateTitle(Player player, String title) { public boolean updateTitle(Player player, String title) {
if (!hasBoard(player)) if (!this.hasBoard(player)) {
return false; return false;
}
FastBoard board = getBoard(player); FastBoard board = getBoard(player);
board.updateTitle(title); board.updateTitle(title);
return true; return true;
@ -153,8 +164,9 @@ public class ScoreBoardManager extends ZUtils {
* @return * @return
*/ */
public boolean updateLine(Player player, int line, String string) { public boolean updateLine(Player player, int line, String string) {
if (!hasBoard(player)) if (!this.hasBoard(player)) {
return false; return false;
}
FastBoard board = getBoard(player); FastBoard board = getBoard(player);
board.updateLine(line, string); board.updateLine(line, string);
return true; return true;
@ -166,7 +178,7 @@ public class ScoreBoardManager extends ZUtils {
* @return {@link Boolean} * @return {@link Boolean}
*/ */
public boolean hasBoard(Player player) { public boolean hasBoard(Player player) {
return boards.containsKey(player); return this.boards.containsKey(player);
} }
/** /**
@ -175,28 +187,28 @@ public class ScoreBoardManager extends ZUtils {
* @return {@link FastBoard} * @return {@link FastBoard}
*/ */
public FastBoard getBoard(Player player) { public FastBoard getBoard(Player player) {
return boards.getOrDefault(player, null); return this.boards.getOrDefault(player, null);
} }
/** /**
* @return the boards * @return the boards
*/ */
public Map<Player, FastBoard> getBoards() { public Map<Player, FastBoard> getBoards() {
return boards; return this.boards;
} }
/** /**
* @return the isRunning * @return the isRunning
*/ */
public boolean isRunning() { public boolean isRunning() {
return isRunning; return this.isRunning;
} }
/** /**
* @return the lines * @return the lines
*/ */
public CollectionConsumer<Player> getLines() { public CollectionConsumer<Player> getLines() {
return lines; return this.lines;
} }
/** /**