183 lines
7.2 KiB
Java
183 lines
7.2 KiB
Java
package net.t2code.lib.Spigot.Lib.yamlConfiguration;
|
|
|
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
|
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
|
|
import net.t2code.lib.Spigot.Lib.replace.Replace;
|
|
import net.t2code.lib.Spigot.system.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 Config {
|
|
public static void set(String path, String 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 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) {
|
|
Config.set("Sound." + soundName + ".Enable", true, yamlConfiguration);
|
|
String sound;
|
|
if (MCVersion.minecraft1_8) {
|
|
sound = sound1_8.toString();
|
|
} else if (MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) {
|
|
sound = sound1_9.toString();
|
|
} else sound = sound1_13.toString();
|
|
Config.set("Sound." + soundName + ".Sound", sound, yamlConfiguration);
|
|
}
|
|
|
|
public static void setSound(String soundName, String sound1_8, String sound1_13, YamlConfiguration yamlConfiguration) {
|
|
Config.set("Sound." + soundName + ".Enable", true, yamlConfiguration);
|
|
String sound;
|
|
if (MCVersion.minecraft1_8) {
|
|
sound = sound1_8.toString();
|
|
} else sound = sound1_13.toString();
|
|
Config.set("Sound." + soundName + ".Sound", sound, yamlConfiguration);
|
|
}
|
|
|
|
public static void setSound(String soundName, String sound, YamlConfiguration yamlConfiguration) {
|
|
Config.set("Sound." + soundName + ".Enable", true, yamlConfiguration);
|
|
Config.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 (MCVersion.minecraft1_8) {
|
|
SOUND = sound1_8;
|
|
} else if (MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) {
|
|
SOUND = sound1_9;
|
|
} else SOUND = sound1_13;
|
|
|
|
try {
|
|
Sound sound_Buy = Sound.valueOf(selectSoundFromConfig);
|
|
if (sound_Buy != null) {
|
|
return sound_Buy;
|
|
} else return null;
|
|
} catch (Exception e) {
|
|
send.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 Sound checkSound(String sound1_8, String sound1_13, String selectSoundFromConfig, String prefix) {
|
|
String SOUND;
|
|
if (MCVersion.minecraft1_8) {
|
|
SOUND = sound1_8;
|
|
} else SOUND = sound1_13;
|
|
|
|
try {
|
|
Sound sound_Buy = Sound.valueOf(selectSoundFromConfig);
|
|
if (sound_Buy != null) {
|
|
return sound_Buy;
|
|
} else return null;
|
|
} catch (Exception e) {
|
|
send.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 Sound checkSound(String sound, String selectSoundFromConfig, String prefix) {
|
|
try {
|
|
Sound sound_Buy = Sound.valueOf(selectSoundFromConfig);
|
|
if (sound_Buy != null) {
|
|
return sound_Buy;
|
|
} else return null;
|
|
} catch (Exception e) {
|
|
send.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 Replace.replace(prefix, yamlConfiguration.getString(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 selectList(String path, YamlConfiguration yamlConfiguration) {
|
|
return (yamlConfiguration.getList(path));
|
|
}
|
|
|
|
public static ItemStack selectItemStack(String path, YamlConfiguration yamlConfiguration) {
|
|
return (yamlConfiguration.getItemStack(path));
|
|
}
|
|
|
|
|
|
public static List selectList(String prefix, String path, YamlConfiguration yamlConfiguration) {
|
|
List<String> output = new ArrayList<>();
|
|
List<String> input = yamlConfiguration.getStringList(path);
|
|
for (String st : input) {
|
|
output.add(Replace.replace(prefix, st));
|
|
}
|
|
return output;
|
|
}
|
|
|
|
public static void select(String prefix, List value, String path, YamlConfiguration yamlConfiguration) {
|
|
List<String> output = new ArrayList<>();
|
|
List<String> input = yamlConfiguration.getStringList(path);
|
|
for (String st : input) {
|
|
output.add(Replace.replace(prefix, st));
|
|
}
|
|
value = output;
|
|
}
|
|
}
|