forked from Upstream/CitizensCMD
Remove async data management
This commit is contained in:
parent
f13a6de519
commit
50c4fc9ee1
@ -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("&3Citizens&cCMD &8&o" + getDescription().getVersion())));
|
||||||
console.sendMessage(TAG.append(LEGACY.deserialize("&8by &3Mateus Moreira &c@LichtHund &8& Maintained by &3HexedHero")));
|
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
|
||||||
settings = SettingsManagerBuilder
|
settings = SettingsManagerBuilder
|
||||||
.withYamlFile(Paths.get(getDataFolder().getPath(), "config.yml"))
|
.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)));
|
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
|
||||||
api = new CitizensCMDAPI(dataHandler);
|
api = new CitizensCMDAPI(dataHandler);
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ import me.mattstudios.citizenscmd.utility.Util;
|
|||||||
public class CooldownHandler {
|
public class CooldownHandler {
|
||||||
|
|
||||||
private final CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
|
|
||||||
private File cooldownsFile;
|
private File cooldownsFile;
|
||||||
private File dir;
|
private File dir;
|
||||||
|
|
||||||
private FileConfiguration cooldownsConfigurator;
|
private FileConfiguration cooldownsConfigurator;
|
||||||
|
|
||||||
private final Map<String, Long> cooldownData = new ConcurrentHashMap<>();
|
private final Map<String, Long> cooldownData = new ConcurrentHashMap<>();
|
||||||
|
@ -30,7 +30,6 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@ -45,10 +44,10 @@ import net.kyori.adventure.audience.Audience;
|
|||||||
public class DataHandler {
|
public class DataHandler {
|
||||||
|
|
||||||
private final CitizensCMD plugin;
|
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<>();
|
private final Map<String, Object> data = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@ -90,7 +89,6 @@ public class DataHandler {
|
|||||||
* Caches the data from the file
|
* Caches the data from the file
|
||||||
*/
|
*/
|
||||||
private void cacheData() {
|
private void cacheData() {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
try {
|
try {
|
||||||
dataConfigurator.load(savesFile);
|
dataConfigurator.load(savesFile);
|
||||||
|
|
||||||
@ -125,8 +123,6 @@ public class DataHandler {
|
|||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,7 +135,6 @@ public class DataHandler {
|
|||||||
* @param left If the command should be added to the left or right click
|
* @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) {
|
public void addCommand(int npc, String permission, String command, Audience sender, boolean left) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
dataConfigurator.load(savesFile);
|
dataConfigurator.load(savesFile);
|
||||||
@ -185,7 +180,6 @@ public class DataHandler {
|
|||||||
sender.sendMessage(HEADER);
|
sender.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_ADD_FAIL));
|
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
|
* @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) {
|
public void addCommand(int npc, String permission, String command, boolean left) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
dataConfigurator.load(savesFile);
|
dataConfigurator.load(savesFile);
|
||||||
@ -238,7 +231,6 @@ public class DataHandler {
|
|||||||
dataConfigurator.save(savesFile);
|
dataConfigurator.save(savesFile);
|
||||||
} catch (IOException | InvalidConfigurationException ignored) {
|
} catch (IOException | InvalidConfigurationException ignored) {
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -249,7 +241,6 @@ public class DataHandler {
|
|||||||
* @param sender The player who run the command
|
* @param sender The player who run the command
|
||||||
*/
|
*/
|
||||||
public void setCooldown(int npc, int cooldown, Audience sender) {
|
public void setCooldown(int npc, int cooldown, Audience sender) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
dataConfigurator.load(savesFile);
|
dataConfigurator.load(savesFile);
|
||||||
@ -266,7 +257,6 @@ public class DataHandler {
|
|||||||
sender.sendMessage(HEADER);
|
sender.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_COOLDOWN_SET_ERROR));
|
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
|
* @param sender The player who run the command
|
||||||
*/
|
*/
|
||||||
public void setPrice(int npc, double price, Audience sender) {
|
public void setPrice(int npc, double price, Audience sender) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
dataConfigurator.load(savesFile);
|
dataConfigurator.load(savesFile);
|
||||||
@ -293,7 +282,6 @@ public class DataHandler {
|
|||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -304,7 +292,6 @@ public class DataHandler {
|
|||||||
* @param sender The player who run the command
|
* @param sender The player who run the command
|
||||||
*/
|
*/
|
||||||
public void setCustomPermission(int npc, String permission, Audience sender) {
|
public void setCustomPermission(int npc, String permission, Audience sender) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
dataConfigurator.load(savesFile);
|
dataConfigurator.load(savesFile);
|
||||||
@ -320,7 +307,6 @@ public class DataHandler {
|
|||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -330,7 +316,6 @@ public class DataHandler {
|
|||||||
* @param sender The player who run the command
|
* @param sender The player who run the command
|
||||||
*/
|
*/
|
||||||
public void removeCustomPermission(int npc, Audience sender) {
|
public void removeCustomPermission(int npc, Audience sender) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
dataConfigurator.load(savesFile);
|
dataConfigurator.load(savesFile);
|
||||||
@ -348,7 +333,6 @@ public class DataHandler {
|
|||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCustomPermission(int npc) {
|
public String getCustomPermission(int npc) {
|
||||||
@ -445,7 +429,6 @@ public class DataHandler {
|
|||||||
* @param sender The player to send the message to
|
* @param sender The player to send the message to
|
||||||
*/
|
*/
|
||||||
public void removeCommand(int npc, int commandID, EnumTypes.ClickType click, Audience sender) {
|
public void removeCommand(int npc, int commandID, EnumTypes.ClickType click, Audience sender) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
dataConfigurator.load(savesFile);
|
dataConfigurator.load(savesFile);
|
||||||
@ -465,7 +448,6 @@ public class DataHandler {
|
|||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -479,7 +461,6 @@ public class DataHandler {
|
|||||||
* @param sender The player to send messages
|
* @param sender The player to send messages
|
||||||
*/
|
*/
|
||||||
public void edit(int npc, int commandID, EnumTypes.ClickType click, EnumTypes.EditType type, String newValue, Audience sender) {
|
public void edit(int npc, int commandID, EnumTypes.ClickType click, EnumTypes.EditType type, String newValue, Audience sender) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
dataConfigurator.load(savesFile);
|
dataConfigurator.load(savesFile);
|
||||||
@ -515,7 +496,6 @@ public class DataHandler {
|
|||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -524,7 +504,6 @@ public class DataHandler {
|
|||||||
* @param npc the NPC id
|
* @param npc the NPC id
|
||||||
*/
|
*/
|
||||||
public void removeNPCData(int npc) {
|
public void removeNPCData(int npc) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
dataConfigurator.load(savesFile);
|
dataConfigurator.load(savesFile);
|
||||||
@ -539,7 +518,6 @@ public class DataHandler {
|
|||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -549,7 +527,6 @@ public class DataHandler {
|
|||||||
* @param npcClone The ID of the new NPC.
|
* @param npcClone The ID of the new NPC.
|
||||||
*/
|
*/
|
||||||
public void cloneData(int npc, int npcClone) {
|
public void cloneData(int npc, int npcClone) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
dataConfigurator.load(savesFile);
|
dataConfigurator.load(savesFile);
|
||||||
@ -569,7 +546,6 @@ public class DataHandler {
|
|||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user