94 lines
4.0 KiB
Java
94 lines
4.0 KiB
Java
package net.t2code.automatedMessages.config.messages;
|
|
|
|
import lombok.Getter;
|
|
import net.t2code.automatedMessages.objects.Message;
|
|
import net.t2code.automatedMessages.system.Main;
|
|
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
|
|
import org.bukkit.Sound;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import java.io.File;
|
|
import java.util.HashMap;
|
|
import java.util.Objects;
|
|
|
|
public class MessagesSelect {
|
|
|
|
@Getter
|
|
private static HashMap<String, Message> messageHashMap = new HashMap<>();
|
|
|
|
public static void select() {
|
|
messageHashMap.clear();
|
|
|
|
File f = new File(Main.getPath() + "/Messages/");
|
|
if (!f.exists()){
|
|
try {
|
|
Main.getPlugin().saveResource("Messages/exampleDiscord.yml", false);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
try {
|
|
Main.getPlugin().saveResource("Messages/exampleTime.yml", false);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
try {
|
|
Main.getPlugin().saveResource("Messages/xx_messagesDeclaration_xx.yml", true);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
File[] fileArray = f.listFiles();
|
|
for (File config : fileArray) {
|
|
try {
|
|
if (config.getName().equals("xx_messagesDeclaration_xx.yml")) continue;
|
|
String sub = config.getName().substring(config.getName().length() - 4);
|
|
if (sub.equals(".yml")) {
|
|
String key = config.getName().replace(".yml", "");
|
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
|
|
|
for (Messages value : Messages.values()) {
|
|
Boolean enable = yamlConfiguration.getBoolean(value.msgEnablePath);
|
|
Object message = yamlConfiguration.get(value.msgMsgPath);
|
|
Boolean soundEnable = yamlConfiguration.getBoolean(value.soundEnablePath);
|
|
|
|
Sound sound;
|
|
try {
|
|
sound = Sound.valueOf(yamlConfiguration.getString(value.soundPath));
|
|
} catch (Exception e) {
|
|
sound = sound();
|
|
}
|
|
|
|
Integer interval = yamlConfiguration.getInt(value.msgIntervalPath);
|
|
|
|
Boolean permissionNeededToSeeMessage = yamlConfiguration.getBoolean(value.permissionNeededToSeeMessagePath);
|
|
String permission = yamlConfiguration.getString(value.permissionPath);
|
|
|
|
Boolean exactTime = yamlConfiguration.getBoolean(value.exactTimePath);
|
|
String timeMinute = yamlConfiguration.getString(value.timeMinutePath);
|
|
String timeHour = yamlConfiguration.getString(value.timeHourPath);
|
|
String timeDayOfMonth = yamlConfiguration.getString(value.timeDayOfMonthPath);
|
|
String timeMonth = yamlConfiguration.getString(value.timeMonthPath);
|
|
String timeDayOfWeek = yamlConfiguration.getString(value.timeDayOfWeekPath);
|
|
Message msg = new Message(key, enable, message, soundEnable, sound, permissionNeededToSeeMessage, permission, interval,
|
|
exactTime, timeMinute, timeHour, timeDayOfMonth, timeMonth, timeDayOfWeek);
|
|
messageHashMap.put(key, msg);
|
|
|
|
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
Main.sendTryCatch(MessagesSelect.class, e.getStackTrace()[0]);
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
static Sound sound() {
|
|
if (T2CmcVersion.isMc1_8()) {
|
|
return Sound.valueOf("NOTE_PIANO");
|
|
} else if (T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12()) {
|
|
return Sound.valueOf("BLOCK_NOTE_HARP");
|
|
} else return Sound.BLOCK_NOTE_BLOCK_HARP;
|
|
}
|
|
}
|