2022-11-03 01:29:26 +00:00
|
|
|
package net.t2code.opsecurity.config;
|
|
|
|
|
|
|
|
import net.t2code.opsecurity.Util;
|
|
|
|
import net.t2code.opsecurity.config.config.Config;
|
|
|
|
import net.t2code.opsecurity.config.language.Language;
|
|
|
|
import net.t2code.opsecurity.config.opWhitelist.OPWhitelist;
|
2022-11-03 18:15:07 +00:00
|
|
|
import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist;
|
2022-11-03 01:29:26 +00:00
|
|
|
import net.t2code.opsecurity.objects.PlayerCash;
|
|
|
|
import net.t2code.opsecurity.objects.PlayerObject;
|
|
|
|
import net.t2code.opsecurity.system.Main;
|
2022-11-03 18:15:07 +00:00
|
|
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace;
|
2022-11-03 01:29:26 +00:00
|
|
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
|
|
|
import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
|
2022-11-09 22:20:25 +00:00
|
|
|
import org.bukkit.GameMode;
|
2022-11-03 18:15:07 +00:00
|
|
|
import org.bukkit.Sound;
|
2022-11-03 01:29:26 +00:00
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
public class FileSelect {
|
|
|
|
public static void selectConfig() {
|
|
|
|
File config = new File(Main.getPath(), "config.yml");
|
|
|
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
|
|
|
for (Config value : Config.values()) {
|
2022-11-17 20:07:15 +00:00
|
|
|
switch (value.configParam) {
|
2022-11-03 01:29:26 +00:00
|
|
|
case STRING:
|
|
|
|
if (!yamlConfiguration.contains(value.path)) {
|
|
|
|
yamlConfiguration.set(value.path, value.valueString);
|
|
|
|
}
|
2022-11-17 20:07:15 +00:00
|
|
|
value.valueString = T2Creplace.replace(Util.getPrefix(), Objects.requireNonNull(yamlConfiguration.getString(value.path)));
|
2022-11-03 01:29:26 +00:00
|
|
|
break;
|
|
|
|
case SOUND:
|
|
|
|
if (!yamlConfiguration.contains(value.path)) {
|
2022-11-03 18:15:07 +00:00
|
|
|
yamlConfiguration.set(value.path, value.sound.toString());
|
2022-11-03 01:29:26 +00:00
|
|
|
}
|
|
|
|
try {
|
2022-11-03 18:15:07 +00:00
|
|
|
value.sound = Sound.valueOf(yamlConfiguration.getString(value.path));
|
2022-11-03 01:29:26 +00:00
|
|
|
} catch (Exception ex) {
|
|
|
|
T2Csend.console("§4\n§4\n§4\n" + SelectLibMsg.soundNotFound.replace("[prefix]", Util.getPrefix())
|
|
|
|
.replace("[sound]", "§8" + value.path + ": §6" + yamlConfiguration.getString(value.path)) + "§4\n§4\n§4\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BOOLEAN:
|
|
|
|
if (!yamlConfiguration.contains(value.path)) {
|
|
|
|
yamlConfiguration.set(value.path, value.valueBoolean);
|
|
|
|
}
|
|
|
|
value.valueBoolean = yamlConfiguration.getBoolean(value.path);
|
|
|
|
break;
|
|
|
|
case INTEGER:
|
|
|
|
if (!yamlConfiguration.contains(value.path)) {
|
|
|
|
yamlConfiguration.set(value.path, value.valueInt);
|
|
|
|
}
|
2022-11-03 18:15:07 +00:00
|
|
|
|
2022-11-03 01:29:26 +00:00
|
|
|
value.valueInt = yamlConfiguration.getInt(value.path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
yamlConfiguration.save(config);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ArrayList<String> defaultLanguages = new ArrayList<>(Arrays.asList("german", "english"));
|
|
|
|
|
|
|
|
public static void selectLanguage() {
|
|
|
|
long long_ = System.currentTimeMillis();
|
2022-11-03 18:15:07 +00:00
|
|
|
|
|
|
|
for (String language : defaultLanguages) {
|
|
|
|
File config = new File(Main.getPath(), "languages/" + language + ".yml");
|
|
|
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
|
|
|
for (Language value : Language.values()) {
|
|
|
|
if (!yamlConfiguration.contains(value.path)) {
|
|
|
|
switch (language) {
|
|
|
|
case "german":
|
|
|
|
yamlConfiguration.set(value.path, value.german);
|
|
|
|
break;
|
|
|
|
case "english":
|
|
|
|
yamlConfiguration.set(value.path, value.english);
|
|
|
|
break;
|
2022-11-03 01:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-03 18:15:07 +00:00
|
|
|
}
|
|
|
|
T2Csend.debug(Main.getPlugin(), "save: " + language);
|
|
|
|
try {
|
|
|
|
yamlConfiguration.save(config);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2022-11-03 01:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String selectMSG;
|
2022-11-03 18:15:07 +00:00
|
|
|
File config = new File(Main.getPath(), "languages/" + Config.language.valueString + ".yml");
|
|
|
|
T2Csend.debug(Main.getPlugin(), config.getAbsolutePath());
|
2022-11-03 01:29:26 +00:00
|
|
|
if (!config.isFile()) {
|
|
|
|
T2Csend.console(Util.getPrefix());
|
|
|
|
T2Csend.console(Util.getPrefix() + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
|
|
T2Csend.console(Util.getPrefix() + " §4The selected §c" + Config.language.valueString + " §4language file was not found.");
|
|
|
|
T2Csend.console(Util.getPrefix() + " §6The default language §eEnglish §6is used!");
|
|
|
|
T2Csend.console(Util.getPrefix() + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
|
|
T2Csend.console(Util.getPrefix());
|
2022-11-03 18:15:07 +00:00
|
|
|
config = new File(Main.getPath(), "languages/" + "english.yml");
|
2022-11-03 01:29:26 +00:00
|
|
|
selectMSG = "english";
|
|
|
|
} else selectMSG = Config.language.valueString;
|
|
|
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
|
|
|
|
|
|
|
for (Language value : Language.values()) {
|
2022-11-03 18:15:07 +00:00
|
|
|
T2Csend.debug(Main.getPlugin(), "Select: File: " + config.getName() + " Path: " + value.path);
|
|
|
|
value.value = T2Creplace.replace(Util.getPrefix(), yamlConfiguration.getString(value.path));
|
2022-11-03 01:29:26 +00:00
|
|
|
}
|
|
|
|
T2Csend.console(Util.getPrefix() + " §2Language successfully selected to: §6" + selectMSG + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void selectOpWhitelist() {
|
2022-11-09 22:20:25 +00:00
|
|
|
PlayerCash.getOpHashMap().clear();
|
2022-11-03 01:29:26 +00:00
|
|
|
File config = new File(Main.getPath(), "opWhitelist.yml");
|
|
|
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
|
|
|
for (OPWhitelist value : OPWhitelist.values()) {
|
|
|
|
switch (value.cEnum) {
|
|
|
|
case BOOLEAN:
|
|
|
|
if (!yamlConfiguration.contains(value.path)) {
|
|
|
|
yamlConfiguration.set(value.path, value.valueBoolean);
|
|
|
|
}
|
|
|
|
value.valueBoolean = yamlConfiguration.getBoolean(value.path);
|
|
|
|
break;
|
|
|
|
case STRINGLIST:
|
|
|
|
if (!yamlConfiguration.contains(value.path)) {
|
2022-11-19 02:12:53 +00:00
|
|
|
yamlConfiguration.set(value.path, value.valueStringList);
|
2022-11-03 01:29:26 +00:00
|
|
|
}
|
2022-11-03 18:15:07 +00:00
|
|
|
value.valueStringList = T2Creplace.replace(Util.getPrefix(), yamlConfiguration.getStringList(value.path));
|
2022-11-03 01:29:26 +00:00
|
|
|
break;
|
|
|
|
case PLAYERLIST:
|
|
|
|
if (!yamlConfiguration.contains(value.pathPlayerListPath)) {
|
|
|
|
yamlConfiguration.set(value.pathPlayerName.replace("KEY", "player1"), value.valuePlayerName);
|
|
|
|
yamlConfiguration.set(value.pathPlayerUuid.replace("KEY", "player1"), value.valuePlayerUuid);
|
|
|
|
yamlConfiguration.set(value.pathPlayerName.replace("KEY", "player2"), value.valuePlayerName);
|
|
|
|
yamlConfiguration.set(value.pathPlayerUuid.replace("KEY", "player2"), value.valuePlayerUuid);
|
|
|
|
}
|
|
|
|
for (String key : yamlConfiguration.getConfigurationSection(value.pathPlayerListPath).getKeys(false)) {
|
2022-11-09 22:20:25 +00:00
|
|
|
String name = yamlConfiguration.getString(value.pathPlayerName.replace("KEY", key));
|
2022-11-03 01:29:26 +00:00
|
|
|
PlayerObject playerObject = new PlayerObject(
|
2022-11-09 22:20:25 +00:00
|
|
|
name,
|
2022-11-17 20:07:15 +00:00
|
|
|
yamlConfiguration.getString(value.pathPlayerUuid.replace("KEY", key)).replace("-", ""));
|
2022-11-09 22:20:25 +00:00
|
|
|
PlayerCash.getOpHashMap().put(name, playerObject);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GAMEMODE:
|
|
|
|
if (!yamlConfiguration.contains(value.path)) {
|
|
|
|
yamlConfiguration.set(value.path, value.valueGameMode.toString());
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
value.valueGameMode = GameMode.valueOf(yamlConfiguration.getString(value.path).toUpperCase());
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
value.valueGameMode = GameMode.SURVIVAL;
|
2022-11-03 01:29:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
yamlConfiguration.save(config);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void selectPermissionWhitelist() {
|
2022-11-09 22:20:25 +00:00
|
|
|
PlayerCash.getPermissionHashMap().clear();
|
2022-11-03 01:29:26 +00:00
|
|
|
File config = new File(Main.getPath(), "permissionWhitelist.yml");
|
|
|
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
2022-11-03 18:15:07 +00:00
|
|
|
for (PermissionWhitelist value : PermissionWhitelist.values()) {
|
2022-11-03 01:29:26 +00:00
|
|
|
switch (value.cEnum) {
|
|
|
|
case BOOLEAN:
|
|
|
|
if (!yamlConfiguration.contains(value.path)) {
|
|
|
|
yamlConfiguration.set(value.path, value.valueBoolean);
|
|
|
|
}
|
|
|
|
value.valueBoolean = yamlConfiguration.getBoolean(value.path);
|
|
|
|
break;
|
|
|
|
case STRINGLIST:
|
|
|
|
if (!yamlConfiguration.contains(value.path)) {
|
2022-11-13 14:54:47 +00:00
|
|
|
yamlConfiguration.set(value.path, value.valueStringList);
|
2022-11-03 01:29:26 +00:00
|
|
|
}
|
2022-11-03 18:15:07 +00:00
|
|
|
value.valueStringList = T2Creplace.replace(Util.getPrefix(), yamlConfiguration.getStringList(value.path));
|
2022-11-03 01:29:26 +00:00
|
|
|
break;
|
|
|
|
case PLAYERLIST:
|
|
|
|
if (!yamlConfiguration.contains(value.pathPlayerListPath)) {
|
|
|
|
yamlConfiguration.set(value.pathPlayerName.replace("KEY", "player1"), value.valuePlayerName);
|
|
|
|
yamlConfiguration.set(value.pathPlayerUuid.replace("KEY", "player1"), value.valuePlayerUuid);
|
|
|
|
yamlConfiguration.set(value.pathPlayerName.replace("KEY", "player2"), value.valuePlayerName);
|
|
|
|
yamlConfiguration.set(value.pathPlayerUuid.replace("KEY", "player2"), value.valuePlayerUuid);
|
|
|
|
}
|
|
|
|
for (String key : yamlConfiguration.getConfigurationSection(value.pathPlayerListPath).getKeys(false)) {
|
2022-11-09 22:20:25 +00:00
|
|
|
String name = yamlConfiguration.getString(value.pathPlayerName.replace("KEY", key));
|
2022-11-03 01:29:26 +00:00
|
|
|
PlayerObject playerObject = new PlayerObject(
|
2022-11-09 22:20:25 +00:00
|
|
|
name,
|
2022-11-20 19:17:55 +00:00
|
|
|
yamlConfiguration.getString(value.pathPlayerUuid.replace("KEY", key)).replace("-", ""));
|
2022-11-09 22:20:25 +00:00
|
|
|
PlayerCash.getPermissionHashMap().put(name, playerObject);
|
2022-11-03 01:29:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
yamlConfiguration.save(config);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|