mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 06:38:56 +00:00
Tweaked performance of data save and campfire check
This commit is contained in:
@@ -26,7 +26,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class BCauldron {
|
public class BCauldron {
|
||||||
public static final byte EMPTY = 0, SOME = 1, FULL = 2;
|
public static final byte EMPTY = 0, SOME = 1, FULL = 2;
|
||||||
private static Set<UUID> plInteracted = new HashSet<>();
|
private static Set<UUID> plInteracted = new HashSet<>(); // Interact Event helper
|
||||||
public static Map<Block, BCauldron> bcauldrons = new HashMap<>(); // All active cauldrons. Mapped to their block for fast retrieve
|
public static Map<Block, BCauldron> bcauldrons = new HashMap<>(); // All active cauldrons. Mapped to their block for fast retrieve
|
||||||
|
|
||||||
private BIngredients ingredients = new BIngredients();
|
private BIngredients ingredients = new BIngredients();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.dre.brewery.utility.LegacyUtil;
|
|||||||
import org.apache.commons.lang.math.NumberUtils;
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@@ -315,6 +316,11 @@ public class P extends JavaPlugin {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
if (use1_14) {
|
||||||
|
// Campfires are weird
|
||||||
|
// Initialize once now so it doesn't lag later when we check for campfires under Cauldrons
|
||||||
|
getServer().createBlockData(Material.CAMPFIRE);
|
||||||
|
}
|
||||||
|
|
||||||
// load the Config
|
// load the Config
|
||||||
try {
|
try {
|
||||||
@@ -575,17 +581,32 @@ public class P extends JavaPlugin {
|
|||||||
public class BreweryRunnable implements Runnable {
|
public class BreweryRunnable implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
//long t1 = System.nanoTime();
|
||||||
BConfig.reloader = null;
|
BConfig.reloader = null;
|
||||||
for (BCauldron cauldron : BCauldron.bcauldrons.values()) {
|
for (BCauldron cauldron : BCauldron.bcauldrons.values()) {
|
||||||
cauldron.onUpdate();// runs every min to update cooking time
|
cauldron.onUpdate();// runs every min to update cooking time
|
||||||
}
|
}
|
||||||
|
//long t2 = System.nanoTime();
|
||||||
Barrel.onUpdate();// runs every min to check and update ageing time
|
Barrel.onUpdate();// runs every min to check and update ageing time
|
||||||
|
//long t3 = System.nanoTime();
|
||||||
if (use1_14) MCBarrel.onUpdate();
|
if (use1_14) MCBarrel.onUpdate();
|
||||||
|
//long t4 = System.nanoTime();
|
||||||
BPlayer.onUpdate();// updates players drunkeness
|
BPlayer.onUpdate();// updates players drunkeness
|
||||||
|
//long t5 = System.nanoTime();
|
||||||
|
|
||||||
debugLog("Update");
|
debugLog("Update");
|
||||||
|
|
||||||
|
//long t6 = System.nanoTime();
|
||||||
DataSave.autoSave();
|
DataSave.autoSave();
|
||||||
|
//long t7 = System.nanoTime();
|
||||||
|
|
||||||
|
/*P.p.log("BreweryRunnable: " +
|
||||||
|
"t1: " + (t2 - t1) / 1000000.0 + "ms" +
|
||||||
|
" | t2: " + (t3 - t2) / 1000000.0 + "ms" +
|
||||||
|
" | t3: " + (t4 - t3) / 1000000.0 + "ms" +
|
||||||
|
" | t4: " + (t5 - t4) / 1000000.0 + "ms" +
|
||||||
|
" | t5: " + (t6 - t5) / 1000000.0 + "ms" +
|
||||||
|
" | t6: " + (t7 - t6) / 1000000.0 + "ms" );*/
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,18 @@ public class BData {
|
|||||||
File file = new File(P.p.getDataFolder(), "data.yml");
|
File file = new File(P.p.getDataFolder(), "data.yml");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
|
|
||||||
|
long t1 = System.currentTimeMillis();
|
||||||
|
|
||||||
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||||
|
|
||||||
|
long t2 = System.currentTimeMillis();
|
||||||
|
|
||||||
|
if (t2 - t1 > 5000) {
|
||||||
|
// Spigot is very slow at loading inventories from yml. Notify Admin that loading Data took long
|
||||||
|
P.p.log("Bukkit took " + (t2 - t1) / 1000.0 + "s to load the Data File,");
|
||||||
|
P.p.log("consider switching to Paper, or have less items in Barrels");
|
||||||
|
}
|
||||||
|
|
||||||
Brew.installTime = data.getLong("installTime", System.currentTimeMillis());
|
Brew.installTime = data.getLong("installTime", System.currentTimeMillis());
|
||||||
MCBarrel.mcBarrelTime = data.getLong("MCBarrelTime", 0);
|
MCBarrel.mcBarrelTime = data.getLong("MCBarrelTime", 0);
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
package com.dre.brewery.filedata;
|
package com.dre.brewery.filedata;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import com.dre.brewery.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import com.dre.brewery.MCBarrel;
|
|
||||||
import com.dre.brewery.utility.BUtil;
|
import com.dre.brewery.utility.BUtil;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@@ -14,12 +9,8 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import com.dre.brewery.BCauldron;
|
import java.util.ArrayList;
|
||||||
import com.dre.brewery.BPlayer;
|
import java.util.List;
|
||||||
import com.dre.brewery.Barrel;
|
|
||||||
import com.dre.brewery.Brew;
|
|
||||||
import com.dre.brewery.P;
|
|
||||||
import com.dre.brewery.Wakeup;
|
|
||||||
|
|
||||||
public class DataSave extends BukkitRunnable {
|
public class DataSave extends BukkitRunnable {
|
||||||
|
|
||||||
@@ -42,6 +33,7 @@ public class DataSave extends BukkitRunnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
long saveTime = System.nanoTime();
|
||||||
FileConfiguration oldData;
|
FileConfiguration oldData;
|
||||||
if (read != null) {
|
if (read != null) {
|
||||||
if (!read.done) {
|
if (!read.done) {
|
||||||
@@ -103,6 +95,9 @@ public class DataSave extends BukkitRunnable {
|
|||||||
configFile.set("Version", dataVersion);
|
configFile.set("Version", dataVersion);
|
||||||
|
|
||||||
collected = true;
|
collected = true;
|
||||||
|
|
||||||
|
P.p.debugLog("saving: " + ((System.nanoTime() - saveTime) / 1000000.0) + "ms");
|
||||||
|
|
||||||
if (P.p.isEnabled()) {
|
if (P.p.isEnabled()) {
|
||||||
P.p.getServer().getScheduler().runTaskAsynchronously(P.p, new WriteData(configFile));
|
P.p.getServer().getScheduler().runTaskAsynchronously(P.p, new WriteData(configFile));
|
||||||
} else {
|
} else {
|
||||||
@@ -126,7 +121,6 @@ public class DataSave extends BukkitRunnable {
|
|||||||
|
|
||||||
// Save all data. Takes a boolean whether all data should be collected in instantly
|
// Save all data. Takes a boolean whether all data should be collected in instantly
|
||||||
public static void save(boolean collectInstant) {
|
public static void save(boolean collectInstant) {
|
||||||
long time = System.nanoTime();
|
|
||||||
if (running != null) {
|
if (running != null) {
|
||||||
P.p.log("Another Save was started while a Save was in Progress");
|
P.p.log("Another Save was started while a Save was in Progress");
|
||||||
if (collectInstant) {
|
if (collectInstant) {
|
||||||
@@ -134,24 +128,17 @@ public class DataSave extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File datafile = new File(P.p.getDataFolder(), "data.yml");
|
|
||||||
|
|
||||||
if (datafile.exists()) {
|
ReadOldData read = new ReadOldData();
|
||||||
ReadOldData read = new ReadOldData();
|
if (collectInstant) {
|
||||||
if (collectInstant) {
|
read.run();
|
||||||
read.run();
|
running = new DataSave(read);
|
||||||
running = new DataSave(read);
|
|
||||||
running.run();
|
|
||||||
} else {
|
|
||||||
read.runTaskAsynchronously(P.p);
|
|
||||||
running = new DataSave(read);
|
|
||||||
running.runTaskTimer(P.p, 1, 2);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
running = new DataSave(null);
|
|
||||||
running.run();
|
running.run();
|
||||||
|
} else {
|
||||||
|
read.runTaskAsynchronously(P.p);
|
||||||
|
running = new DataSave(read);
|
||||||
|
running.runTaskTimer(P.p, 1, 2);
|
||||||
}
|
}
|
||||||
P.p.debugLog("saving: " + ((System.nanoTime() - time) / 1000000.0) + "ms");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void autoSave() {
|
public static void autoSave() {
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ public class ReadOldData extends BukkitRunnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
File datafile = new File(P.p.getDataFolder(), "data.yml");
|
File datafile = new File(P.p.getDataFolder(), "data.yml");
|
||||||
|
if (!datafile.exists()) {
|
||||||
|
data = new YamlConfiguration();
|
||||||
|
done = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
data = YamlConfiguration.loadConfiguration(datafile);
|
data = YamlConfiguration.loadConfiguration(datafile);
|
||||||
|
|
||||||
if (DataSave.lastBackup > 10) {
|
if (DataSave.lastBackup > 10) {
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
|
|
||||||
import com.dre.brewery.P;
|
import com.dre.brewery.P;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the collected Data to file in Async Thread
|
||||||
|
*/
|
||||||
public class WriteData implements Runnable {
|
public class WriteData implements Runnable {
|
||||||
|
|
||||||
private FileConfiguration data;
|
private FileConfiguration data;
|
||||||
|
|||||||
Reference in New Issue
Block a user