Skip to content

Commit

Permalink
Attempt to fix new 1.4 scoreboards format conversion from old config
Browse files Browse the repository at this point in the history
  • Loading branch information
joserodpt committed Apr 8, 2024
1 parent 48a6f19 commit 9f505eb
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>joserodpt.realscoreboard</groupId>
<artifactId>realscoreboard-parent</artifactId>
<version>1.4</version>
<version>1.4.1</version>
<packaging>pom</packaging>

<name>RealScoreboard-Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion realscoreboard-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>joserodpt.realscoreboard</groupId>
<artifactId>realscoreboard-parent</artifactId>
<version>1.4</version>
<version>1.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void setup(JavaPlugin javaPlugin) {
GeneralSettings.builder().setUseDefaults(false).build(),
LoaderSettings.builder().setAutoUpdate(true).build(),
DumperSettings.DEFAULT,
UpdaterSettings.builder().setVersioning(new BasicVersioning("Version")).addIgnoredRoute("1", "Scoreboards", '.').build());
UpdaterSettings.builder().setVersioning(new BasicVersioning("Version")).addIgnoredRoute("2", "Scoreboards", '.').build());
} catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "Couldn't setup config files!");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package joserodpt.realscoreboard.api.managers;

import joserodpt.realscoreboard.api.scoreboard.RScoreboard;
import org.bukkit.World;
import org.bukkit.entity.Player;

import java.util.List;
Expand All @@ -15,5 +14,4 @@ public interface AbstractScoreboardManager {
List<RScoreboard> getScoreboards();
RScoreboard getScoreboardForPlayer(Player p);
RScoreboard getScoreboard(String name);
RScoreboard getDefaultScoreboard(World w);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class RScoreboardBoards extends RScoreboard {

protected List<RBoard> boards = new ArrayList<>();
protected final int boardLoopDelay;
protected int boardIndex;
protected int boardIndex = 0;
private BukkitTask boardsLooperTask;

//loading from normal config scoreboards.yml
Expand Down Expand Up @@ -61,15 +61,14 @@ public void init() {
//init board tasks
this.boards.forEach(RBoard::init);

boardIndex = 0;
if (boards.size() > 1) {
this.boardsLooperTask = new BukkitRunnable() {
@Override
public void run() {
if (boardIndex == boards.size() - 1) {
if (boardIndex >= boards.size() - 1) {
boardIndex = 0;
} else {
++boardIndex;
boardIndex++;
}
}
}.runTaskTimerAsynchronously(RealScoreboardAPI.getInstance().getPlugin(), 0L, boardLoopDelay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ public class RScoreboardSingle extends RScoreboard {

private final RBoard board;


//old data version
public RScoreboardSingle(final String name, final String permission, final String defaultWord, final List<String> title, final List<String> lines,
final int titleRefresh, final int titleLoopDelay, final int globalScoreboardRefresh) {
super(name, "&7" + name, permission, defaultWord, titleRefresh, titleLoopDelay, globalScoreboardRefresh, false);
final int titleRefresh, final int titleLoopDelay, final int globalScoreboardRefresh, final boolean defaultSB, boolean save) {
super(name, "&7" + name, permission, defaultWord, titleRefresh, titleLoopDelay, globalScoreboardRefresh, defaultSB);
this.board = new RBoard(this, title, lines);

//save in new format
this.saveScoreboard();
if (save) this.saveScoreboard();
}

//new data version
Expand Down
4 changes: 2 additions & 2 deletions realscoreboard-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>joserodpt.realscoreboard</groupId>
<artifactId>realscoreboard-parent</artifactId>
<version>1.4</version>
<version>1.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -108,7 +108,7 @@
<dependency>
<groupId>me.mattstudios.utils</groupId>
<artifactId>matt-framework</artifactId>
<version>1.4</version>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import joserodpt.realscoreboard.api.scoreboard.RScoreboard;
import joserodpt.realscoreboard.api.scoreboard.RScoreboardBoards;
import joserodpt.realscoreboard.api.scoreboard.RScoreboardSingle;
import org.bukkit.World;
import org.bukkit.entity.Player;

import java.util.ArrayList;
Expand All @@ -42,9 +41,8 @@ public void loadScoreboards() {
//starting from version 1.4, scoreboards are stored in the scoreboards.yml file and have a new structure,
//this next part of the code is responsible for the conversion of those old scoreboards in the config.yml
if (RSBConfig.file().contains("Config.Scoreboard")) {
rsa.getLogger().warning("Starting scoreboard conversion to scoreboards.yml...");
rsa.getLogger().warning("Starting scoreboard conversion to the new scoreboards.yml file...");
convertOldScoreboardsV1dot4();
return;
}

if (!RSBScoreboards.file().contains("Scoreboards") || RSBScoreboards.file().getSection("Scoreboards") == null) {
Expand All @@ -53,6 +51,11 @@ public void loadScoreboards() {
}

for (String scoreboardName : RSBScoreboards.file().getSection("Scoreboards").getRoutesAsStrings(false)) {
//verify that this scoreboard is not loaded
if (this.scoreboards.containsKey(scoreboardName)) {
continue;
}

String key = "Scoreboards." + scoreboardName + ".";
String w = RSBScoreboards.file().getString(key + "Default-World");

Expand Down Expand Up @@ -103,27 +106,29 @@ private void convertOldScoreboardsV1dot4() {

for (String world : RSBConfig.file().getSection("Config.Scoreboard").getRoutesAsStrings(false)) {
for (String permNode : RSBConfig.file().getSection("Config.Scoreboard." + world).getRoutesAsStrings(false)) {
String scoreboardEntry = "Config.Scoreboard." + world + "." + permNode + ".";
RSBScoreboards.file().remove("Scoreboards." + permNode);
String oldScoreboardEntry = "Config.Scoreboard." + world + "." + permNode + ".";
String newPermission = permNode.equalsIgnoreCase("default") ? "none" : ("realscoreboard.scoreboard" + permNode);

if (RSBConfig.file().getSection(scoreboardEntry + "Boards").getRoutesAsStrings(false).size() == 1) {
for (String boardName : RSBConfig.file().getSection(scoreboardEntry + "Boards").getRoutesAsStrings(false)) {
String boardEntry = scoreboardEntry + "Boards." + boardName;
if (RSBConfig.file().getSection(oldScoreboardEntry + "Boards").getRoutesAsStrings(false).size() == 1) {
for (String boardName : RSBConfig.file().getSection(oldScoreboardEntry + "Boards").getRoutesAsStrings(false)) {
String boardEntry = oldScoreboardEntry + "Boards." + boardName;

List<String> title = RSBConfig.file().getStringList(boardEntry + ".Title");
List<String> lines = RSBConfig.file().getStringList(boardEntry + ".Lines");

this.scoreboards.put(permNode, new RScoreboardSingle(permNode, permNode.equalsIgnoreCase("default") ? "none" : ("realscoreboard.scoreboard" + permNode), world, title, lines,
20, 20, 20));
this.scoreboards.put(permNode, new RScoreboardSingle(permNode, newPermission, world, title, lines,
20, 20, 20, permNode.equalsIgnoreCase("default"), true));
++counter;
}
} else {
List<RBoard> boards = new ArrayList<>();

RScoreboardBoards rsbb = new RScoreboardBoards(permNode, permNode.equalsIgnoreCase("default") ? "none" : ("realscoreboard.scoreboard" + permNode), world,
20, 20, 20 , RSBConfig.file().getInt(scoreboardEntry + "Switch-Timer"), permNode.equalsIgnoreCase("default")); ++counter;
RScoreboardBoards rsbb = new RScoreboardBoards(permNode, newPermission, world,
20, 20, 20, RSBConfig.file().getInt(oldScoreboardEntry + "Switch-Timer"), permNode.equalsIgnoreCase("default")); ++counter;

for (String boardName : RSBConfig.file().getSection(scoreboardEntry + "Boards").getRoutesAsStrings(false)) {
String boardEntry = scoreboardEntry + "Boards." + boardName;
for (String boardName : RSBConfig.file().getSection(oldScoreboardEntry + "Boards").getRoutesAsStrings(false)) {
String boardEntry = oldScoreboardEntry + "Boards." + boardName;

List<String> title = RSBConfig.file().getStringList(boardEntry + ".Title");
List<String> lines = RSBConfig.file().getStringList(boardEntry + ".Lines");
Expand All @@ -136,7 +141,6 @@ private void convertOldScoreboardsV1dot4() {
this.scoreboards.put(permNode, rsbb);
}

RSBConfig.file().remove("Config.Scoreboard." + world + "." + permNode);
rsa.getLogger().warning("Converted Scoreboard " + permNode);
}
}
Expand Down Expand Up @@ -188,9 +192,4 @@ public RScoreboard getScoreboardForPlayer(Player p) {
public RScoreboard getScoreboard(String name) {
return this.getScoreboardMap().get(name);
}

@Override
public RScoreboard getDefaultScoreboard(World w) {
return this.getScoreboards().stream().filter(rScoreboard -> rScoreboard.getDefaultWord().equals(w.getName()) && rScoreboard.isDefault()).findFirst().orElse(null);
}
}
16 changes: 8 additions & 8 deletions realscoreboard-plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#✦------------------------------------------------------✦
#| Main Config |
#| Main Config |
#✦------------------------------------------------------✦
#RealScoreboard created by joserodpt and maintained by Neziw
# RealScoreboard created by joserodpt and maintained by Neziw
#
#Useful links:
#SpigotMC - https://www.spigotmc.org/resources/22928/
#Discord Server - https://discord.gg/t7gfnYZKy8
#bStats - https://bstats.org/plugin/bukkit/RealScoreboard/10080
#HEX Color Formats: https://github.com/Iridium-Development/IridiumColorAPI
#API for Developers: https://github.com/joserodpt/RealScoreboard/blob/master/api.md
# Useful links:
# SpigotMC - https://www.spigotmc.org/resources/22928/
# Discord Server - https://discord.gg/t7gfnYZKy8
# bStats - https://bstats.org/plugin/bukkit/RealScoreboard/10080
# HEX Color Formats: https://github.com/Iridium-Development/IridiumColorAPI
# API for Developers: https://github.com/joserodpt/RealScoreboard/blob/master/api.md
Debug: false
Config:
Prefix: '&fReal&dScoreboard &7| &r'
Expand Down
14 changes: 13 additions & 1 deletion realscoreboard-plugin/src/main/resources/scoreboards.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
Version: 1
#✦------------------------------------------------------✦
#| Scoreboard Config |
#✦------------------------------------------------------✦
# RealScoreboard created by joserodpt and maintained by Neziw
# Parameter explanation:
# - Default: if the scoreboard is the default one, doesn't require a permission
# - Default-World: the default world where the scoreboard appears
# - Display-Name: used for GUI and other purposes.
# - Refresh-Scoreboard: the main refresh delay for the whole scoreboard
# - Refresh-Title: refresh delay only for the scoreboard title
# - Title-Loop-Delay: loop delay for the title animation task
# - Board-Loop-Delay: loop delay for the bards switching task (if the scoreboard has multiple boards)
Version: 2
Scoreboards:
default:
Default: true
Expand Down

0 comments on commit 9f505eb

Please sign in to comment.