T2CodeLib/src/main/java/net/t2code/t2codelib/SPIGOT/api/yaml/T2Cconfig.java

169 lines
6.7 KiB
Java

package net.t2code.t2codelib.SPIGOT.api.yaml;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
import org.bukkit.Sound;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
public class T2Cconfig {
public static void set(String path, String value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value);
}
}
public static void set(String path, Object value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value);
}
}
public static void set(String path, YamlConfiguration YamlConfiguration) {
YamlConfiguration.set(path, null);
}
public static void set(String path, Integer value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value);
}
}
public static void set(String path, Double value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value);
}
}
public static void set(String path, Boolean value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value);
}
}
public static void set(String path, List<String> value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value);
}
}
public static void set(String path, ItemStack value, YamlConfiguration YamlConfiguration) {
if (!YamlConfiguration.contains(path)) {
YamlConfiguration.set(path, value);
}
}
public static void setSound(String soundName, String sound1_8, String sound1_9, String sound1_13, YamlConfiguration yamlConfiguration) {
set("Sound." + soundName + ".Enable", true, yamlConfiguration);
String sound;
if (T2CmcVersion.isMc1_8()) {
sound = sound1_8.toString();
} else if (T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12()) {
sound = sound1_9.toString();
} else sound = sound1_13.toString();
set("Sound." + soundName + ".Sound", sound, yamlConfiguration);
}
public static void setSound(String soundName, String sound1_8, String sound1_13, YamlConfiguration yamlConfiguration) {
set("Sound." + soundName + ".Enable", true, yamlConfiguration);
String sound;
if (T2CmcVersion.isMc1_8()) {
sound = sound1_8.toString();
} else sound = sound1_13.toString();
set("Sound." + soundName + ".Sound", sound, yamlConfiguration);
}
public static void setSound(String soundName, String sound, YamlConfiguration yamlConfiguration) {
set("Sound." + soundName + ".Enable", true, yamlConfiguration);
set("Sound." + soundName + ".Sound", sound.toString(), yamlConfiguration);
}
public static boolean selectSoundEnable(String soundName, YamlConfiguration yamlConfiguration) {
return selectBoolean("Sound." + soundName + ".Enable", yamlConfiguration);
}
public static String selectSound(String prefix, String soundName, YamlConfiguration yamlConfiguration) {
return select(prefix, "Sound." + soundName + ".Sound", yamlConfiguration);
}
public static Sound checkSound(String sound1_8, String sound1_9, String sound1_13, String selectSoundFromConfig, String prefix) {
String SOUND;
if (T2CmcVersion.isMc1_8()) {
SOUND = sound1_8;
} else if (T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12()) {
SOUND = sound1_9;
} else SOUND = sound1_13;
return checkSound(SOUND, selectSoundFromConfig, prefix);
}
public static Sound checkSound(String sound1_8, String sound1_13, String selectSoundFromConfig, String prefix) {
String SOUND;
if (T2CmcVersion.isMc1_8()) {
SOUND = sound1_8;
} else SOUND = sound1_13;
return checkSound(SOUND, selectSoundFromConfig, prefix);
}
public static Sound checkSound(String sound, String selectSoundFromConfig, String prefix) {
try {
return Sound.valueOf(selectSoundFromConfig);
} catch (Exception e) {
T2Csend.console("§4\n§4\n§4\n" + SelectLibMsg.soundNotFound.replace("[prefix]", prefix)
.replace("[sound]", "§8Buy: §6" + selectSoundFromConfig) + "§4\n§4\n§4\n");
return Sound.valueOf(sound);
}
}
public static String select(String prefix, String path, YamlConfiguration yamlConfiguration) {
return T2Creplace.replace(prefix, yamlConfiguration.getString(path));
}
public static Object selectObject(String prefix, String path, YamlConfiguration yamlConfiguration) {
return T2Creplace.replaceObject(prefix, yamlConfiguration.get(path));
}
public static Integer selectInt(String path, YamlConfiguration yamlConfiguration) {
return (yamlConfiguration.getInt(path));
}
public static Boolean selectBoolean(String path, YamlConfiguration yamlConfiguration) {
return (yamlConfiguration.getBoolean(path));
}
public static Double selectDouble(String path, YamlConfiguration yamlConfiguration) {
return (yamlConfiguration.getDouble(path));
}
public static List<String> selectList(String path, YamlConfiguration yamlConfiguration) {
return (yamlConfiguration.getStringList(path));
}
public static ItemStack selectItemStack(String path, YamlConfiguration yamlConfiguration) {
return (yamlConfiguration.getItemStack(path));
}
public static List<String> selectList(String prefix, String path, YamlConfiguration yamlConfiguration) {
List<String> output = new ArrayList<>();
List<String> input = yamlConfiguration.getStringList(path);
for (String st : input) {
output.add(T2Creplace.replace(prefix, st));
}
return output;
}
public static void select(String prefix, List<String> value, String path, YamlConfiguration yamlConfiguration) {
List<String> output = new ArrayList<>();
List<String> input = yamlConfiguration.getStringList(path);
for (String st : input) {
output.add(T2Creplace.replace(prefix, st));
}
value = output;
}
}