Skip to content

Commit

Permalink
saving sync consistency fix and find_blocks ceil call
Browse files Browse the repository at this point in the history
Find_blocks is NOT stable for short ranges and should not be used for such, but this change makes it a little more consistent at least
  • Loading branch information
mcmonkey4eva committed Jun 4, 2022
1 parent a853c23 commit a9e43dc
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions plugin/src/main/java/com/denizenscript/denizen/Denizen.java
Expand Up @@ -487,7 +487,7 @@ public void onDisable() {
getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " disabled.");
Bukkit.getServer().getScheduler().cancelTasks(this);
HandlerList.unregisterAll(this);
saveSaves(false);
saveSaves(true);
worldFlags.shutdown();
}

Expand Down Expand Up @@ -536,9 +536,9 @@ public FileConfiguration getScoreboards() {

/**
* Immediately saves all non-core save data.
* @param canSleep 'true' if the system should sleep and lock the thread until saves are complete. 'false' is saves can happen in the future.
* @param lockUntilDone 'true' if the system should sleep and lock the thread until saves are complete. 'false' is saves can happen in the future.
*/
public void saveSaves(boolean canSleep) {
public void saveSaves(boolean lockUntilDone) {
// Save scoreboards to scoreboards.yml
ScoreboardHelper._saveScoreboards();
// Save maps to maps.yml
Expand All @@ -550,9 +550,9 @@ public void saveSaves(boolean canSleep) {
catch (IOException ex) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save to " + scoreboardsConfigFile, ex);
}
PlayerFlagHandler.saveAllNow(canSleep);
PlayerFlagHandler.saveAllNow(lockUntilDone);
worldFlags.saveAll();
RunLaterCommand.saveToFile(!canSleep);
RunLaterCommand.saveToFile(!lockUntilDone);
}

@Override
Expand Down
Expand Up @@ -2655,7 +2655,7 @@ else if (yaw < 315) {
int index = 0;
Location tstart = object.getBlockLocation();
double tstartY = tstart.getY();
int radiusInt = (int) radius;
int radiusInt = (int) Math.ceil(radius);
fullloop:
for (int y = -radiusInt; y <= radiusInt; y++) {
double newY = y + tstartY;
Expand Down Expand Up @@ -2699,7 +2699,7 @@ else if (yaw < 315) {
int index = 0;
Location tstart = object.getBlockLocation();
double tstartY = tstart.getY();
int radiusInt = (int) radius;
int radiusInt = (int) Math.ceil(radius);
fullloop:
for (int y = -radiusInt; y <= radiusInt; y++) {
double newY = y + tstartY;
Expand Down
Expand Up @@ -2625,7 +2625,7 @@ public static void adjustServer(Mechanism mechanism) {
// -->
if (mechanism.matches("save")) {
DenizenCore.saveAll();
Denizen.getInstance().saveSaves(true);
Denizen.getInstance().saveSaves(false);
}

// <--[mechanism]
Expand Down
Expand Up @@ -137,7 +137,7 @@ public void run() {
}
}.runTaskLater(Denizen.getInstance(), 3);
}
Denizen.getInstance().saveSaves(true);
Denizen.getInstance().saveSaves(false);
Debug.log("==== Done updating legacy saves (except NPCs) ====");
}

Expand Down
Expand Up @@ -274,7 +274,7 @@ public void version(CommandContext args, CommandSender sender) throws CommandExc
min = 1, max = 3, permission = "denizen.basic")
public void save(CommandContext args, CommandSender sender) throws CommandException {
DenizenCore.saveAll();
Denizen.getInstance().saveSaves(true);
Denizen.getInstance().saveSaves(false);
Messaging.send(sender, "Denizen save data saved to disk from memory.");
}

Expand Down
Expand Up @@ -254,11 +254,11 @@ public void run() {
}
}

public static void saveAllNow(boolean canSleep) {
public static void saveAllNow(boolean lockUntilDone) {
for (Map.Entry<UUID, CachedPlayerFlag> entry : playerFlagTrackerCache.entrySet()) {
CachedPlayerFlag flags = entry.getValue();
if (flags.tracker.modified) {
if (!canSleep && flags.savingNow.get() || flags.loadingNow.get()) {
if (!lockUntilDone && flags.savingNow.get() || flags.loadingNow.get()) {
continue;
}
while (flags.savingNow.get() || flags.loadingNow.get()) {
Expand Down

0 comments on commit a9e43dc

Please sign in to comment.