Remove async data management

This commit is contained in:
HexedHero 2022-06-21 03:23:21 +01:00
parent f13a6de519
commit 50c4fc9ee1
3 changed files with 242 additions and 265 deletions

View File

@ -114,6 +114,12 @@ public final class CitizensCMD extends JavaPlugin {
console.sendMessage(TAG.append(LEGACY.deserialize("&3Citizens&cCMD &8&o" + getDescription().getVersion())));
console.sendMessage(TAG.append(LEGACY.deserialize("&8by &3Mateus Moreira &c@LichtHund &8& Maintained by &3HexedHero")));
// Data
dataHandler = new DataHandler(this);
cooldownHandler = new CooldownHandler(this);
dataHandler.initialize();
cooldownHandler.initialize();
// Settings
settings = SettingsManagerBuilder
.withYamlFile(Paths.get(getDataFolder().getPath(), "config.yml"))
@ -157,11 +163,6 @@ public final class CitizensCMD extends JavaPlugin {
console.sendMessage(TAG.append(lang.getMessage(Messages.VAULT_AVAILABLE)));
}
// Data
dataHandler = new DataHandler(this);
cooldownHandler = new CooldownHandler(this);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> { dataHandler.initialize(); cooldownHandler.initialize(); }, 1L);
// API
api = new CitizensCMDAPI(dataHandler);

View File

@ -36,9 +36,9 @@ import me.mattstudios.citizenscmd.utility.Util;
public class CooldownHandler {
private final CitizensCMD plugin;
private File cooldownsFile;
private File dir;
private FileConfiguration cooldownsConfigurator;
private final Map<String, Long> cooldownData = new ConcurrentHashMap<>();

View File

@ -30,7 +30,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -45,10 +44,10 @@ import net.kyori.adventure.audience.Audience;
public class DataHandler {
private final CitizensCMD plugin;
private static File savesFile;
private static File dir;
private static FileConfiguration dataConfigurator;
private File savesFile;
private File dir;
private FileConfiguration dataConfigurator;
private final Map<String, Object> data = new ConcurrentHashMap<>();
@ -90,7 +89,6 @@ public class DataHandler {
* Caches the data from the file
*/
private void cacheData() {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
dataConfigurator.load(savesFile);
@ -125,8 +123,6 @@ public class DataHandler {
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
});
}
/**
@ -139,7 +135,6 @@ public class DataHandler {
* @param left If the command should be added to the left or right click
*/
public void addCommand(int npc, String permission, String command, Audience sender, boolean left) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
createBasics();
dataConfigurator.load(savesFile);
@ -185,7 +180,6 @@ public class DataHandler {
sender.sendMessage(HEADER);
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_ADD_FAIL));
}
});
}
/**
@ -197,7 +191,6 @@ public class DataHandler {
* @param left If the command should be added to the left or right click
*/
public void addCommand(int npc, String permission, String command, boolean left) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
createBasics();
dataConfigurator.load(savesFile);
@ -238,7 +231,6 @@ public class DataHandler {
dataConfigurator.save(savesFile);
} catch (IOException | InvalidConfigurationException ignored) {
}
});
}
/**
@ -249,7 +241,6 @@ public class DataHandler {
* @param sender The player who run the command
*/
public void setCooldown(int npc, int cooldown, Audience sender) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
createBasics();
dataConfigurator.load(savesFile);
@ -266,7 +257,6 @@ public class DataHandler {
sender.sendMessage(HEADER);
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_COOLDOWN_SET_ERROR));
}
});
}
/**
@ -277,7 +267,6 @@ public class DataHandler {
* @param sender The player who run the command
*/
public void setPrice(int npc, double price, Audience sender) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
createBasics();
dataConfigurator.load(savesFile);
@ -293,7 +282,6 @@ public class DataHandler {
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
});
}
/**
@ -304,7 +292,6 @@ public class DataHandler {
* @param sender The player who run the command
*/
public void setCustomPermission(int npc, String permission, Audience sender) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
createBasics();
dataConfigurator.load(savesFile);
@ -320,7 +307,6 @@ public class DataHandler {
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
});
}
/**
@ -330,7 +316,6 @@ public class DataHandler {
* @param sender The player who run the command
*/
public void removeCustomPermission(int npc, Audience sender) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
createBasics();
dataConfigurator.load(savesFile);
@ -348,7 +333,6 @@ public class DataHandler {
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
});
}
public String getCustomPermission(int npc) {
@ -445,7 +429,6 @@ public class DataHandler {
* @param sender The player to send the message to
*/
public void removeCommand(int npc, int commandID, EnumTypes.ClickType click, Audience sender) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
createBasics();
dataConfigurator.load(savesFile);
@ -465,7 +448,6 @@ public class DataHandler {
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
});
}
/**
@ -479,7 +461,6 @@ public class DataHandler {
* @param sender The player to send messages
*/
public void edit(int npc, int commandID, EnumTypes.ClickType click, EnumTypes.EditType type, String newValue, Audience sender) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
createBasics();
dataConfigurator.load(savesFile);
@ -515,7 +496,6 @@ public class DataHandler {
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
});
}
/**
@ -524,7 +504,6 @@ public class DataHandler {
* @param npc the NPC id
*/
public void removeNPCData(int npc) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
createBasics();
dataConfigurator.load(savesFile);
@ -539,7 +518,6 @@ public class DataHandler {
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
});
}
/**
@ -549,7 +527,6 @@ public class DataHandler {
* @param npcClone The ID of the new NPC.
*/
public void cloneData(int npc, int npcClone) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
createBasics();
dataConfigurator.load(savesFile);
@ -569,7 +546,6 @@ public class DataHandler {
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
});
}
/**