T2CodeLib API 16.7 and new Config

This commit is contained in:
JaTiTV 2024-07-11 13:26:32 +02:00
parent 60cd82ef1f
commit 2aedb22959
17 changed files with 423 additions and 393 deletions

View File

@ -27,8 +27,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<configuration> <configuration>
<source>9</source> <source>11</source>
<target>9</target> <target>11</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -1,6 +1,10 @@
package net.t2code.automatedMessages; package net.t2code.automatedMessages;
import lombok.Getter; import lombok.Getter;
import net.t2code.t2codelib.util.T2C_Util;
import java.util.ArrayList;
import java.util.Arrays;
public class Util { public class Util {
@ -28,4 +32,10 @@ public class Util {
@Getter @Getter
private static String discord = "http://dc.t2code.net"; private static String discord = "http://dc.t2code.net";
public static String[] getConfigLogo() {
ArrayList<String> arrayList = new ArrayList<>(T2C_Util.getConfigT2CodeLogo());
arrayList.addAll(Arrays.asList("", "# Spigot: " + spigot));
return arrayList.toArray(new String[0]);
}
} }

View File

@ -2,8 +2,8 @@ package net.t2code.automatedMessages.command;
import net.t2code.automatedMessages.Util; import net.t2code.automatedMessages.Util;
import net.t2code.automatedMessages.config.Config; import net.t2code.automatedMessages.config.Config;
import net.t2code.automatedMessages.config.FileBuild; import net.t2code.automatedMessages.config.Languages;
import net.t2code.automatedMessages.config.messages.MessagesSelect; import net.t2code.automatedMessages.config.Messages;
import net.t2code.automatedMessages.messages.Management; import net.t2code.automatedMessages.messages.Management;
import net.t2code.automatedMessages.system.Main; import net.t2code.automatedMessages.system.Main;
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Send; import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Send;
@ -13,16 +13,17 @@ import org.bukkit.entity.Player;
public class Commands { public class Commands {
public static void reload(CommandSender sender) { public static void reload(CommandSender sender) {
T2C_Send.console(Config.msgReloadStart.valueString); T2C_Send.console(Languages.VALUES.msgReloadStart.getValue().toString());
if (sender instanceof Player) T2C_Send.sender(sender, Config.msgReloadStart.valueString); if (sender instanceof Player) T2C_Send.sender(sender, Languages.VALUES.msgReloadStart.getValue().toString());
Management.end(); Management.end();
FileBuild.selectConfig(); Config.set(true);
MessagesSelect.select(); Languages.set(true);
Messages.set(true);
Management.start(); Management.start();
if (sender instanceof Player) T2C_Send.sender(sender, Config.msgReloadEnd.valueString); if (sender instanceof Player) T2C_Send.sender(sender, Languages.VALUES.msgReloadEnd.getValue().toString());
T2C_Send.console(Config.msgReloadEnd.valueString); T2C_Send.console(Languages.VALUES.msgReloadEnd.getValue().toString());
} }
public static void info(CommandSender sender) { public static void info(CommandSender sender) {

View File

@ -1,41 +1,115 @@
package net.t2code.automatedMessages.config; package net.t2code.automatedMessages.config;
public enum Config { import net.t2code.automatedMessages.Util;
import net.t2code.automatedMessages.system.Main;
import net.t2code.t2codelib.SPIGOT.api.yaml.T2C_ConfigWriter;
import net.t2code.t2codelib.util.T2C_ConfigItem;
import net.t2code.t2codelib.util.T2C_LanguageEnum;
updateCheckOnJoin("plugin.updateCheck.onJoin", true, ConfigParam.BOOLEAN), import java.io.File;
updateCheckSeePreReleaseUpdates("plugin.updateCheck.seePreReleaseUpdates", true, ConfigParam.BOOLEAN), import java.util.HashMap;
updateCheckTimeInterval("plugin.updateCheck.timeInterval", 60, ConfigParam.INTEGER), import java.util.List;
prefix("plugin.prefix", "<dark_gray>[<dark_red>T2C</dark_red>-<color:#5cff5c>Automated</color><color:#69d2ff>Messages</color>]</dark_gray>", ConfigParam.STRING), public class Config {
sendConsole("plugin.broadcastInConsole", true, ConfigParam.BOOLEAN),
timeFormat("plugin.timeFormat", "HH:mm:ss yyyy/MM/dd", ConfigParam.STRING), public enum VALUES implements T2C_ConfigItem {
language("plugin.language", T2C_LanguageEnum.english, true,
new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
updateCheckOnJoin("plugin.updateCheck.onJoin", true, true,
new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
updateCheckSeePreReleaseUpdates("plugin.updateCheck.seePreReleaseUpdates", true, true,
new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
updateCheckTimeInterval("plugin.updateCheck.timeInterval", 60, true,
new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
msgReloadStart("plugin.messages.reloadStart", "[prefix] Reload starting...", ConfigParam.STRING), prefix("plugin.prefix", "<dark_gray>[<dark_red>T2C</dark_red>-<color:#5cff5c>Automated</color><color:#69d2ff>Messages</color>]</dark_gray>", true,
msgReloadEnd("plugin.messages.reloadEnd", "[prefix] Reload successful.", ConfigParam.STRING); new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
sendConsole("plugin.broadcastInConsole", true, true,
new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
timeFormat("plugin.timeFormat", "HH:mm:ss yyyy/MM/dd",true,
new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
msgReloadStart("plugin.messages.reloadStart", "[prefix] Reload starting...", true,
new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
msgReloadEnd("plugin.messages.reloadEnd", "[prefix] Reload successful.", true,
new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
public String path; ;
public String valueString;
public Boolean valueBoolean;
public Integer valueInteger;
public ConfigParam configParam;
Config(String path, String value, ConfigParam cEnum) { private final String path;
this.path = path; private Object value;
this.valueString = value; private final boolean forceSet;
this.configParam = cEnum; private final HashMap<T2C_LanguageEnum, List<String>> comments;
VALUES(String path, Object value, boolean forceSet, HashMap<T2C_LanguageEnum, List<String>> comments) {
this.path = path;
this.value = value;
this.forceSet = forceSet;
this.comments = comments;
}
@Override
public String getPath() {
return path;
}
@Override
public Object getValue() {
return value;
}
@Override
public boolean getForceSet() {
return forceSet;
}
@Override
public HashMap<T2C_LanguageEnum, List<String>> getComments() {
return comments;
}
@Override
public String getLanguagePath() {
return language.path;
}
@Override
public void setValue(Object newValue) {
value = newValue;
}
} }
Config(String path, Integer value, ConfigParam cEnum) { public static void set(boolean isReload) {
this.path = path; T2C_ConfigWriter.createConfig(Util.getPrefix(), new File(Main.getPath(), "config.yml"), VALUES.values(), isReload, Util.getConfigLogo());
this.valueInteger = value;
this.configParam = cEnum;
} }
Config(String path, Boolean value, ConfigParam cEnum) {
this.path = path;
this.valueBoolean = value;
this.configParam = cEnum;
}
} }

View File

@ -1,7 +0,0 @@
package net.t2code.automatedMessages.config;
public enum ConfigParam {
STRING,
INTEGER,
BOOLEAN
}

View File

@ -1,47 +0,0 @@
package net.t2code.automatedMessages.config;
import net.t2code.automatedMessages.Util;
import net.t2code.automatedMessages.system.Main;
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Replace;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
public class FileBuild {
public static void selectConfig() {
File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
for (Config value : Config.values()) {
switch (value.configParam) {
case STRING:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueString);
}
value.valueString = T2C_Replace.replace(Util.getPrefix(), Objects.requireNonNull(yamlConfiguration.getString(value.path)));
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.valueInteger);
}
value.valueInteger = yamlConfiguration.getInt(value.path);
break;
}
}
try {
yamlConfiguration.save(config);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,85 @@
// This class was created by JaTiTV.
package net.t2code.automatedMessages.config;
import net.t2code.automatedMessages.Util;
import net.t2code.automatedMessages.system.Main;
import net.t2code.t2codelib.SPIGOT.api.yaml.T2C_LanguageWriter;
import net.t2code.t2codelib.util.T2C_ConfigItemLanguages;
import net.t2code.t2codelib.util.T2C_LanguageEnum;
import java.util.HashMap;
import java.util.List;
public class Languages {
public enum VALUES implements T2C_ConfigItemLanguages {
otherLang("plugin", null, new HashMap<>() {{
put(T2C_LanguageEnum.german, null);
put(T2C_LanguageEnum.english, null);
}}, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of("Wenn du eine Eigene Sprache hinzufügen magst, dann kopiere einfach eine Sprachdatei und benenne sie in deine Sprache, dies kannst du dann in der config.yml einstellen.", ""));
put(T2C_LanguageEnum.english, List.of("If you want to add your own language, simply copy a language file and rename it to your language, you can then set this in config.yml.", ""));
}}),
msgReloadStart("plugin.reloadStart", null, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of("[prefix] Plugin wird neu geladen..."));
put(T2C_LanguageEnum.english, List.of("[prefix] Plugin is reloaded..."));
}}, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of("Wenn du eine Eigene Sprache hinzufügen magst, dann kopiere einfach eine Sprachdatei und benenne sie in deine Sprache, dies kannst du dann in der config.yml einstellen.", ""));
put(T2C_LanguageEnum.english, List.of("If you want to add your own language, simply copy a language file and rename it to your language, you can then set this in config.yml.", ""));
}}),
msgReloadEnd("plugin.reloadEnd", null, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
;
private final String path;
private Object value;
private final HashMap<T2C_LanguageEnum, List<String>> lang;
private final HashMap<T2C_LanguageEnum, List<String>> comments;
VALUES(String path, Object value, HashMap<T2C_LanguageEnum, List<String>> lang, HashMap<T2C_LanguageEnum, List<String>> comments) {
this.path = path;
this.value = value;
this.lang = lang;
this.comments = comments;
}
@Override
public String getPath() {
return path;
}
@Override
public Object getValue() {
if (value == null) {
return lang.get(T2C_LanguageEnum.english);
}
return value;
}
@Override
public HashMap<T2C_LanguageEnum, List<String>> getLanguage() {
return lang;
}
@Override
public HashMap<T2C_LanguageEnum, List<String>> getComments() {
return comments;
}
@Override
public void setValue(Object newValue) {
value = newValue;
}
}
public static void set(boolean isReload) {
T2C_LanguageWriter.createConfig(Util.getPrefix(), Main.getPath(), VALUES.values(), Config.VALUES.language.getValue().toString(), isReload, Util.getConfigLogo());
}
}

View File

@ -0,0 +1,201 @@
// This class was created by JaTiTV.
package net.t2code.automatedMessages.config;
import lombok.Getter;
import net.t2code.automatedMessages.Util;
import net.t2code.automatedMessages.objects.Message;
import net.t2code.automatedMessages.system.Main;
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2C_McVersion;
import net.t2code.t2codelib.SPIGOT.api.yaml.T2C_ConfigWriter;
import net.t2code.t2codelib.util.T2C_ConfigItem;
import net.t2code.t2codelib.util.T2C_LanguageEnum;
import org.bukkit.Sound;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
public class Messages {
@Getter
private static HashMap<String, Message> messageHashMap = new HashMap<>();
public enum VALUES implements T2C_ConfigItem {
enable("enable", false, true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
message("message", "", true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
soundEnable("sound.enable", true, true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
sound("sound.sound", sound(), true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
interval("permissionNeededToSeeMessage.enable", false, true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
permissionNeededToSeeMessage("permissionNeededToSeeMessage.permission", "", true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
permission("intervalInMin", 0, true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
exactTime("exactTime.enable", false, true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
timeMinute("exactTime.timeMinute", "*/5", true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
timeHour("exactTime.timeHour", "*", true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
timeDayOfMonth("exactTime.timeDayOfMonth", "*", true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
timeMonth("exactTime.timeMonth", "*", true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
timeDayOfWeek("exactTime.timeDayOfWeek", "*", true, new HashMap<>() {{
put(T2C_LanguageEnum.german, List.of());
put(T2C_LanguageEnum.english, List.of());
}}),
;
private final String path;
private Object value;
private final boolean forceSet;
private final HashMap<T2C_LanguageEnum, List<String>> comments;
VALUES(String path, Object value, boolean forceSet, HashMap<T2C_LanguageEnum, List<String>> comments) {
this.path = path;
this.value = value;
this.forceSet = forceSet;
this.comments = comments;
}
@Override
public String getPath() {
return path;
}
@Override
public Object getValue() {
return value;
}
@Override
public boolean getForceSet() {
return forceSet;
}
@Override
public HashMap<T2C_LanguageEnum, List<String>> getComments() {
return comments;
}
@Override
public String getLanguagePath() {
return Config.VALUES.language.getValue().toString();
}
@Override
public void setValue(Object newValue) {
value = newValue;
}
}
public static void set(boolean isReload) {
messageHashMap.clear();
File fo = new File(Main.getPath() + "/Messages/");
File f = new File(Main.getPath() + "/messages/");
if (!fo.exists()) {
try {
Files.move(Paths.get(fo.getAbsolutePath()), Paths.get(f.getAbsolutePath()));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (!f.exists()) {
createDefault("exampleTime.yml", "[prefix] <aqua>Es ist jetzt <yellow>[time]</yellow></aqua>", sound(), 0, "t2c.automatedmessages.messages.exampletime", true, "0/15/30/45");
createDefault("exampleDiscord.yml", "[prefix] <aqua>If you need help, just contact us on our <color:#ffcb2e><hover:show_text:''<red>dc.t2code.net</red>''><click:open_url:''https://discord.t2code.net''>T2Code Support Discord server</click></hover></color>.</aqua>", sound(), 20, "t2c.automatedmessages.messages.examplediscord", false, "*");
}
File[] fileArray = f.listFiles();
for (File file : fileArray) {
String sub = file.getName().substring(file.getName().length() - 4);
if (sub.equals(".yml")) {
String key = file.getName().replace(".yml", "");
T2C_ConfigWriter.createConfig(Util.getPrefix(), file, VALUES.values(), false, Util.getConfigLogo());
Boolean enable = (boolean) VALUES.enable.value;
String message = VALUES.message.value.toString();
Boolean soundEnable = (boolean) VALUES.soundEnable.value;
Sound sound;
try {
sound = Sound.valueOf(VALUES.sound.value.toString());
} catch (Exception e) {
sound = sound();
}
Integer interval = (int) VALUES.interval.value;
Boolean permissionNeededToSeeMessage = (boolean) VALUES.permissionNeededToSeeMessage.value;
String permission = VALUES.permission.value.toString();
Boolean exactTime = (boolean) VALUES.exactTime.value;
String timeMinute = VALUES.timeMinute.value.toString();
String timeHour = VALUES.timeHour.value.toString();
String timeDayOfMonth = VALUES.timeDayOfMonth.value.toString();
String timeMonth = VALUES.timeMonth.value.toString();
String timeDayOfWeek = VALUES.timeDayOfWeek.value.toString();
Message msg = new Message(key, enable, message, soundEnable, sound, permissionNeededToSeeMessage, permission, interval,
exactTime, timeMinute, timeHour, timeDayOfMonth, timeMonth, timeDayOfWeek);
messageHashMap.put(key, msg);
}
}
}
private static void createDefault(String fileName, String message, Sound sound, Integer interval, String permission, Boolean exactTime, String timeMinute) {
VALUES.enable.setValue(true);
VALUES.message.setValue(message);
VALUES.soundEnable.setValue(true);
VALUES.sound.setValue(sound.toString());
VALUES.interval.setValue(interval);
VALUES.permissionNeededToSeeMessage.setValue(false);
VALUES.permission.setValue(permission);
VALUES.exactTime.setValue(exactTime);
VALUES.timeMinute.setValue(timeMinute);
VALUES.timeHour.setValue("*");
VALUES.timeDayOfMonth.setValue("*");
VALUES.timeMonth.setValue("*");
VALUES.timeDayOfWeek.setValue("*");
T2C_ConfigWriter.createConfig(Util.getPrefix(), new File(Main.getPath() + "/Messages/" + fileName), VALUES.values(), false, Util.getConfigLogo());
}
private static Sound sound() {
if (T2C_McVersion.isMc1_8()) {
return Sound.valueOf("NOTE_PIANO");
} else if (T2C_McVersion.isMc1_9() || T2C_McVersion.isMc1_10() || T2C_McVersion.isMc1_11() || T2C_McVersion.isMc1_12()) {
return Sound.valueOf("BLOCK_NOTE_HARP");
} else return Sound.BLOCK_NOTE_BLOCK_HARP;
}
}

View File

@ -1,105 +0,0 @@
package net.t2code.automatedMessages.config.messages;
import org.bukkit.Sound;
public enum Messages {
message("enable", false,
"message", "",
"sound.enable", true,
"sound.sound", MessagesSelect.sound(),
"permissionNeededToSeeMessage.enable", false,
"permissionNeededToSeeMessage.permission", "",
"intervalInMin", 0,
"exactTime.enable", false,
"exactTime.timeMinute", "*/5",
"exactTime.timeHour", "*",
"exactTime.timeDayOfMonth", "*",
"exactTime.timeMonth", "*",
"exactTime.timeDayOfWeek", "*"
);
public String msgEnablePath;
public Boolean msgEnable;
public String msgMsgPath;
public String msgMsg;
public String soundEnablePath;
public Boolean soundEnable;
public String soundPath;
public Sound sound;
public String permissionNeededToSeeMessagePath;
public Boolean permissionNeededToSeeMessage;
public String permissionPath;
public String permission;
public String msgIntervalPath;
public Integer msgInterval;
public String exactTimePath;
public Boolean exactTime;
public String timeMinutePath;
public String timeMinute;
public String timeHourPath;
public String timeHour;
public String timeDayOfMonthPath;
public String timeDayOfMonth;
public String timeMonthPath;
public String timeMonth;
public String timeDayOfWeekPath;
public String timeDayOfWeek;
Messages(String msgEnablePath, Boolean msgEnable,
String msgMsgPath, String msgMsg,
String soundEnablePath, Boolean soundEnable,
String soundPath, Sound sound,
String permissionNeededToSeeMessagePath, Boolean permissionNeededToSeeMessage,
String permissionPath, String permission,
String msgIntervalPath, Integer msgInterval,
String exactTimePath, Boolean exactTime, String timeMinutePath, String timeMinute,
String timeHourPath, String timeHour,
String timeDayOfMonthPath, String timeDayOfMonth,
String timeMonthPath, String timeMonth,
String timeDayOfWeekPath, String timeDayOfWeek) {
this.msgEnablePath = msgEnablePath;
this.msgEnable = msgEnable;
this.msgMsgPath = msgMsgPath;
this.msgMsg = msgMsg;
this.soundEnablePath = soundEnablePath;
this.soundEnable = soundEnable;
this.soundPath = soundPath;
this.sound = sound;
this.permissionNeededToSeeMessagePath = permissionNeededToSeeMessagePath;
this.permissionNeededToSeeMessage = permissionNeededToSeeMessage;
this.permissionPath = permissionPath;
this.permission = permission;
this.msgIntervalPath = msgIntervalPath;
this.msgInterval = msgInterval;
this.exactTimePath = exactTimePath;
this.exactTime = exactTime;
this.timeMinutePath = timeMinutePath;
this.timeMinute = timeMinute;
this.timeHourPath = timeHourPath;
this.timeHour = timeHour;
this.timeDayOfMonthPath = timeDayOfMonthPath;
this.timeDayOfMonth = timeDayOfMonth;
this.timeMonthPath = timeMonthPath;
this.timeMonth = timeMonth;
this.timeDayOfWeekPath = timeDayOfWeekPath;
this.timeDayOfWeek = timeDayOfWeek;
}
}

View File

@ -1,92 +0,0 @@
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.T2C_McVersion;
import org.bukkit.Sound;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.HashMap;
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 (T2C_McVersion.isMc1_8()) {
return Sound.valueOf("NOTE_PIANO");
} else if (T2C_McVersion.isMc1_9() || T2C_McVersion.isMc1_10() || T2C_McVersion.isMc1_11() || T2C_McVersion.isMc1_12()) {
return Sound.valueOf("BLOCK_NOTE_HARP");
} else return Sound.BLOCK_NOTE_BLOCK_HARP;
}
}

View File

@ -1,7 +1,6 @@
package net.t2code.automatedMessages.messages; package net.t2code.automatedMessages.messages;
import net.t2code.automatedMessages.config.FileBuild; import net.t2code.automatedMessages.config.Messages;
import net.t2code.automatedMessages.config.messages.MessagesSelect;
import net.t2code.automatedMessages.objects.Message; import net.t2code.automatedMessages.objects.Message;
import java.util.ArrayList; import java.util.ArrayList;
@ -13,7 +12,7 @@ public class Management {
private static final List<CronJob> cronJobs = new ArrayList<>(); private static final List<CronJob> cronJobs = new ArrayList<>();
public static void start() { public static void start() {
for (Map.Entry<String, Message> value : MessagesSelect.getMessageHashMap().entrySet()) { for (Map.Entry<String, Message> value : Messages.getMessageHashMap().entrySet()) {
Message message = value.getValue(); Message message = value.getValue();
if (!message.enable) continue; if (!message.enable) continue;
if (message.exactTime) { if (message.exactTime) {

View File

@ -11,13 +11,13 @@ import java.util.*;
public class SendMessage { public class SendMessage {
public static void send(Message message) { public static void send(Message message) {
String timeStamp = new SimpleDateFormat(Config.timeFormat.valueString).format(Calendar.getInstance().getTime()); String timeStamp = new SimpleDateFormat(Config.VALUES.timeFormat.getValue().toString()).format(Calendar.getInstance().getTime());
if (Config.sendConsole.valueBoolean) { if ((boolean)Config.VALUES.sendConsole.getValue()) {
T2C_Send.console(replace(message.message, Map.entry("[time]", timeStamp), Map.entry("[prefix]", Config.prefix.valueString))); T2C_Send.console(replace(message.message, Map.entry("[time]", timeStamp), Map.entry("[prefix]", Config.VALUES.prefix.getValue().toString())));
} }
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
if (player.hasPermission(message.permission) || !message.permissionNeededToSeeMessage) { if (player.hasPermission(message.permission) || !message.permissionNeededToSeeMessage) {
T2C_Send.player(player, replace(message.message, Map.entry("[time]", timeStamp), Map.entry("[prefix]", Config.prefix.valueString), Map.entry("[player]", player.getName()))); T2C_Send.player(player, replace(message.message, Map.entry("[time]", timeStamp), Map.entry("[prefix]", Config.VALUES.prefix.getValue().toString()), Map.entry("[player]", player.getName())));
player.playSound(player.getLocation(), message.sound, 3, 1); player.playSound(player.getLocation(), message.sound, 3, 1);
} }
} }

View File

@ -9,7 +9,7 @@ public class Message {
public String key; public String key;
public Boolean enable; public Boolean enable;
public Object message; public String message;
public Boolean soundEnable; public Boolean soundEnable;
public Sound sound; public Sound sound;
@ -25,7 +25,7 @@ public class Message {
public Message(String key, public Message(String key,
Boolean enable, Boolean enable,
Object message, String message,
Boolean soundEnable, Boolean soundEnable,
Sound sound, Sound sound,
Boolean permissionNeededToSeeMessage, Boolean permissionNeededToSeeMessage,

View File

@ -3,8 +3,8 @@ package net.t2code.automatedMessages.system;
import net.t2code.automatedMessages.Util; import net.t2code.automatedMessages.Util;
import net.t2code.automatedMessages.command.CmdExecuter; import net.t2code.automatedMessages.command.CmdExecuter;
import net.t2code.automatedMessages.config.Config; import net.t2code.automatedMessages.config.Config;
import net.t2code.automatedMessages.config.FileBuild; import net.t2code.automatedMessages.config.Languages;
import net.t2code.automatedMessages.config.messages.MessagesSelect; import net.t2code.automatedMessages.config.Messages;
import net.t2code.automatedMessages.messages.Management; import net.t2code.automatedMessages.messages.Management;
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Template; import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Template;
import net.t2code.t2codelib.SPIGOT.api.update.T2C_UpdateAPI; import net.t2code.t2codelib.SPIGOT.api.update.T2C_UpdateAPI;
@ -17,13 +17,14 @@ public class Load {
long long_ = T2C_Template.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord()); long long_ = T2C_Template.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
plugin.getCommand("t2c-automatedmessages").setExecutor(new CmdExecuter()); plugin.getCommand("t2c-automatedmessages").setExecutor(new CmdExecuter());
FileBuild.selectConfig(); Config.set(false);
MessagesSelect.select(); Languages.set(false);
Messages.set(false);
Management.start(); Management.start();
T2C_UpdateAPI.onUpdateCheck(plugin, Util.getPrefix(), Util.getGit(), Util.getSpigotID(), Util.getDiscord(), Config.updateCheckOnJoin.valueBoolean, T2C_UpdateAPI.onUpdateCheck(plugin, Util.getPrefix(), Util.getGit(), Util.getSpigotID(), Util.getDiscord(), (boolean) Config.VALUES.updateCheckOnJoin.getValue(),
Config.updateCheckSeePreReleaseUpdates.valueBoolean, Config.updateCheckTimeInterval.valueInteger); (boolean) Config.VALUES.updateCheckSeePreReleaseUpdates.getValue(), (int) Config.VALUES.updateCheckTimeInterval.getValue());
Metrics.Bstats(plugin, Util.getBstatsID()); Metrics.Bstats(plugin, Util.getBstatsID());
T2C_Template.onLoadFooter(Util.getPrefix(), long_); T2C_Template.onLoadFooter(Util.getPrefix(), long_);

View File

@ -1,16 +0,0 @@
enable: true
message: "[prefix] <aqua>If you need help, just contact us on our <color:#ffcb2e><hover:show_text:''<red>dc.t2code.net</red>''><click:open_url:''https://discord.t2code.net''>T2Code Support Discord server</click></hover></color>.</aqua>"
sound:
enable: true
sound: BLOCK_NOTE_BLOCK_HARP
permissionNeededToSeeMessage:
enable: false
permission: t2c.automatedmessages.messages.examplediscord
intervalInMin: 20
exactTime:
enable: false
timeMinute: '*'
timeHour: '*'
timeDayOfMonth: '*'
timeMonth: '*'
timeDayOfWeek: '*'

View File

@ -1,16 +0,0 @@
enable: true
message: "[prefix] <aqua>Es ist jetzt <yellow>[time]</yellow></aqua>"
sound:
enable: true
sound: BLOCK_NOTE_BLOCK_HARP
permissionNeededToSeeMessage:
enable: false
permission: t2c.automatedmessages.messages.exampletime
intervalInMin: 0
exactTime:
enable: true
timeMinute: 0/15/30/45
timeHour: '*'
timeDayOfMonth: '*'
timeMonth: '*'
timeDayOfWeek: '*'

View File

@ -1,58 +0,0 @@
#####################################################
## To add another Function just create a new file. ##
#####################################################
# Here you can set whether the message should be activated or deactivated.
enable: false
# Specify here the message that the player should get.
#
# Placeholder:
# [player] = the player name of the recipient of the message.
# [time] = The current system time.
# [prefix] = The prefix set from config.yml.
#
# You can use Minecraft custom color codes: https://minecraft.fandom.com/de/wiki/Formatierungscodes
# You can use the hover module from T2Code:
# You can add a hover and/or clickable feature to all messages sent to players.
# Use /*/ to separate the message.
# Use [nl] to set a line break in a message or hover.
# Hover message: <message >/*/<hover>
# Message with hover and click function: <message >/*/<hover>/*/<action>/*/<actionValue>
# Message only with click function: <message >/*//*/<action>/*/<actionValue>
# Action:
# - OPEN_URL - Opens a URL under the path specified in ActionValue.
# - OPEN_FILE - Opens a file under the path specified by ActionValue.
# - RUN_COMMAND - Runs the command specified by ActionValue.
# - SUGGEST_COMMAND - Inserts the string specified in ActionValue into the player text box.
# - CHANGE_PAGE - Changes to the page number in a book specified by ActionValue.
# - COPY_TO_CLIPBOARD - Copies the string specified by ActionValue to the player's clipboard.
# You can also use MiniMessage:
# Wiki: https://docs.adventure.kyori.net/minimessage/format.html
# WebUI: https://webui.adventure.kyori.net
message: ''
sound:
# Here you can set whether a sound should be played with the message.
enable: true
# Here you can set which sound should be played.
sound: BLOCK_NOTE_BLOCK_HARP
permissionNeededToSeeMessage:
# Here you can set whether the players need a permission to receive the message.
enable: false
# Here you can set if the players need which permission to receive the message.
permission: t2c.automatedmessages.messages.exampletime
# Here you can set the time interval (in minutes) at which the message should be sent.
intervalInMin: 1
exactTime:
# Here you can set whether the message should be sent at certain times.
# If this option is used, then the intervalInMin option is disabled!
enable: false
# In these settings you can set at which minute, hour, day of the month, which month and on which day of the week the message should be sent.
# Time format examples:
# One: 5
# At several times: 5/10/15
# Every minute, hour, etc.: '*'
timeMinute: 0
timeHour: '*'
timeDayOfMonth: '*'
timeMonth: '*'
timeDayOfWeek: '*'