Compare commits

..

No commits in common. "main" and "cronJob" have entirely different histories.

17 changed files with 277 additions and 625 deletions

26
pom.xml
View File

@ -5,11 +5,8 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>AutomatedMessages</artifactId> <artifactId>T2C-AutomatedMessages</artifactId>
<version>1.3_dev</version> <version>1.0-SNAPSHOT</version>
<!--version>VERSION_snapshot-0</version-->
<!--version>VERSION_beta-0</version-->
<!--version>VERSION_dev-0</version-->
<packaging>jar</packaging> <packaging>jar</packaging>
<name>T2C-AutomatedMessages</name> <name>T2C-AutomatedMessages</name>
@ -20,15 +17,15 @@
</properties> </properties>
<build> <build>
<finalName>${project.name}_${project.version}</finalName> <finalName>${project.artifactId}_${project.version}</finalName>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<configuration> <configuration>
<source>11</source> <source>${java.version}</source>
<target>11</target> <target>${java.version}</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
@ -77,23 +74,28 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.21-R0.1-SNAPSHOT</version> <version>1.19.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- t2code --> <!-- t2code -->
<dependency> <dependency>
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId> <artifactId>T2CodeLib</artifactId>
<version>16.7</version> <version>13.4</version>
<classifier>dev-24</classifier>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.30</version> <version>1.18.24</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.2</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,10 +1,6 @@
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 {
@ -12,13 +8,13 @@ public class Util {
private static String infoText = ""; private static String infoText = "";
@Getter @Getter
private static String requiredT2CodeLibVersion = "16.7"; private static String requiredT2CodeLibVersion = "13.4";
@Getter @Getter
private static String prefix = "<dark_gray>[<dark_red>T2C</dark_red>-<color:#5cff5c>Automated</color><color:#69d2ff>Messages</color>]</dark_gray>"; private static String prefix = "<dark_gray>[<dark_red>T2C</dark_red>-<color:#5cff5c>Automated</color><color:#69d2ff>Messages</color>]</dark_gray>";
@Getter @Getter
private static Integer spigotID = 110801; private static Integer spigotID = 0000; //todo
@Getter @Getter
private static String git = "JaTiTV/T2C-AutomatedMessages"; private static String git = "JaTiTV/T2C-AutomatedMessages";
@ -32,10 +28,4 @@ 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,7 @@
package net.t2code.automatedMessages.command; package net.t2code.automatedMessages.command;
import net.t2code.automatedMessages.Util; import net.t2code.t2codelib.SPIGOT.api.commands.T2Ctab;
import net.t2code.t2codelib.SPIGOT.api.commands.T2C_Tab;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -17,10 +16,6 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!sender.hasPermission("t2c.automatedmessages.admin")) {
sender.sendMessage(Util.getPrefix() + "§cYou do not have permission for OPSecurity! §7<t2c.automatedmessages.admin>");
return false;
}
if (args.length == 0) { if (args.length == 0) {
Commands.reload(sender); Commands.reload(sender);
} else { } else {
@ -49,7 +44,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String s, String[] args) { public List<String> onTabComplete(CommandSender sender, Command cmd, String s, String[] args) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
T2C_Tab.tab(list,sender,0,args,arg1); T2Ctab.tab(list,sender,0,args,arg1);
return list; return list;
} }
} }

View File

@ -2,31 +2,36 @@ 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.Languages; import net.t2code.automatedMessages.config.FileBuild;
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.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Template; import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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(Languages.VALUES.msgReloadStart.getValue().toString()); if (!sender.hasPermission("t2c.automatedmessages.admin")) {
if (sender instanceof Player) T2C_Send.sender(sender, Languages.VALUES.msgReloadStart.getValue().toString()); sender.sendMessage(Util.getPrefix() + "§cYou do not have permission for OPSecurity! §7<t2c.automatedmessages.admin>");
return;
}
T2Csend.console(Config.msgReloadStart.valueString);
if (sender instanceof Player) T2Csend.sender(sender, Config.msgReloadStart.valueString);
Management.end(); Management.end();
Config.set(true); FileBuild.selectConfig();
Languages.set(true);
Messages.set(true);
Management.start(); Management.start();
if (sender instanceof Player) T2C_Send.sender(sender, Languages.VALUES.msgReloadEnd.getValue().toString()); if (sender instanceof Player) T2Csend.sender(sender, Config.msgReloadEnd.valueString);
T2C_Send.console(Languages.VALUES.msgReloadEnd.getValue().toString()); T2Csend.console(Config.msgReloadEnd.valueString);
} }
public static void info(CommandSender sender) { public static void info(CommandSender sender) {
T2C_Template.sendInfo(sender, Main.getPlugin(), Util.getSpigotID(), Util.getDiscord(), Util.getInfoText()); if (!sender.hasPermission("t2c.automatedmessages.admin")) {
sender.sendMessage(Util.getPrefix() + "§cYou do not have permission for OPSecurity! §7<t2c.automatedmessages.admin>");
return;
}
T2Ctemplate.sendInfo(sender, Main.getPlugin(), Util.getSpigotID(), Util.getDiscord(), Util.getInfoText());
} }
} }

View File

@ -1,115 +1,81 @@
package net.t2code.automatedMessages.config; package net.t2code.automatedMessages.config;
import net.t2code.automatedMessages.Util; public enum Config {
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;
import java.io.File; updateCheckOnJoin("plugin.updateCheck.onJoin", true, ConfigParam.BOOLEAN),
import java.util.HashMap; updateCheckSeePreReleaseUpdates("plugin.updateCheck.seePreReleaseUpdates", true, ConfigParam.BOOLEAN),
import java.util.List; updateCheckTimeInterval("plugin.updateCheck.timeInterval", 60, ConfigParam.INTEGER),
public class Config { prefix("plugin.prefix", "", ConfigParam.STRING),
public enum VALUES implements T2C_ConfigItem { msgReloadStart("plugin.messages.reloadStart", "Reload start", ConfigParam.STRING),
language("plugin.language", T2C_LanguageEnum.english, true, msgReloadEnd("plugin.messages.reloadEnd", "Reload end", ConfigParam.STRING),
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());
}}),
prefix("plugin.prefix", "<dark_gray>[<dark_red>T2C</dark_red>-<color:#5cff5c>Automated</color><color:#69d2ff>Messages</color>]</dark_gray>", true, message("messages",
new HashMap<>() {{ "messages.KEY.enable", false,
put(T2C_LanguageEnum.german, List.of()); "messages.KEY.message", "",
put(T2C_LanguageEnum.english, List.of()); "messages.KEY.intervalInMin", 0,
}}), "messages.KEY.useCronJob.enable", false,
sendConsole("plugin.broadcastInConsole", true, true, "messages.KEY.useCronJob.value", "",
new HashMap<>() {{ ConfigParam.MESSAGE
put(T2C_LanguageEnum.german, List.of()); );
put(T2C_LanguageEnum.english, List.of());
}}),
timeFormat("plugin.timeFormat", "HH:mm:ss yyyy/MM/dd",true, public String path;
new HashMap<>() {{ public String valueString;
put(T2C_LanguageEnum.german, List.of()); public Boolean valueBoolean;
put(T2C_LanguageEnum.english, List.of()); public Integer valueInteger;
}}),
msgReloadStart("plugin.messages.reloadStart", "[prefix] Reload starting...", true, public String msgPath;
new HashMap<>() {{ public String msgEnablePath;
put(T2C_LanguageEnum.german, List.of()); public Boolean msgEnable;
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 msgMsgPath;
public String msgMsg;
public String msgIntervalPath;
public Integer msgInterval;
public String msgCronJobPath;
public Boolean msgCronJob;
public String msgCronJobStringPath;
public String msgCronJobString;
; public ConfigParam configParam;
private final String path; Config(String path, String value, ConfigParam cEnum) {
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.path = path;
this.value = value; this.valueString = value;
this.forceSet = forceSet; this.configParam = cEnum;
this.comments = comments;
} }
@Override Config(String path, Integer value, ConfigParam cEnum) {
public String getPath() { this.path = path;
return path; this.valueInteger = value;
this.configParam = cEnum;
} }
@Override Config(String path, Boolean value, ConfigParam cEnum) {
public Object getValue() { this.path = path;
return value; this.valueBoolean = value;
this.configParam = cEnum;
} }
@Override Config(String msgPath,
public boolean getForceSet() { String msgEnablePath, Boolean msgEnable,
return forceSet; String msgMsgPath, String msgMsg,
} String msgIntervalPath, Integer msgInterval,
String msgCronJobPath, Boolean msgCronJob,
@Override String msgCronJobStringPath, String msgCronJobString,
public HashMap<T2C_LanguageEnum, List<String>> getComments() { ConfigParam configParam) {
return comments; this.msgPath = msgPath;
} this.msgEnablePath = msgEnablePath;
this.msgEnable = msgEnable;
@Override this.msgMsgPath = msgMsgPath;
public String getLanguagePath() { this.msgMsg = msgMsg;
return language.path; this.msgIntervalPath = msgIntervalPath;
} this.msgInterval = msgInterval;
this.msgCronJobPath = msgCronJobPath;
@Override this.msgCronJob = msgCronJob;
public void setValue(Object newValue) { this.msgCronJobStringPath = msgCronJobStringPath;
value = newValue; this.msgCronJobString = msgCronJobString;
this.configParam = configParam;
} }
} }
public static void set(boolean isReload) {
T2C_ConfigWriter.createConfig(Util.getPrefix(), new File(Main.getPath(), "config.yml"), VALUES.values(), isReload, Util.getConfigLogo());
}
}

View File

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

View File

@ -0,0 +1,87 @@
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.messages.T2Creplace;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
public class FileBuild {
@Getter
private static HashMap<String, Message> messageHashMap = new HashMap<>();
public static void selectConfig() {
File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
messageHashMap.clear();
for (Config value : Config.values()) {
switch (value.configParam) {
case STRING:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueString);
}
value.valueString = T2Creplace.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;
case MESSAGE:
if (!yamlConfiguration.contains(value.msgPath)) {
setExample("exampleDiscord", true,
"[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>",
20, false, "0 0/5 * ? * * *", yamlConfiguration);
setExample("exampleTime", true,
"[prefix] <aqua>Es ist jetzt <yellow>[time]</yellow></aqua>",
0, true, "0 0/20 * ? * * *", yamlConfiguration);
}
for (String key : yamlConfiguration.getConfigurationSection(value.msgPath).getKeys(false)) {
Boolean enable = yamlConfiguration.getBoolean(value.msgEnablePath.replace("KEY", key));
String message = yamlConfiguration.getString(value.msgMsgPath.replace("KEY", key));
Integer interval = yamlConfiguration.getInt(value.msgIntervalPath.replace("KEY", key));
Boolean cronJob = yamlConfiguration.getBoolean(value.msgCronJobPath.replace("KEY", key));
String cronJobString = yamlConfiguration.getString(value.msgCronJobStringPath.replace("KEY", key));
Message msg = new Message(key, enable, message, interval, cronJob, cronJobString);
T2Csend.debugmsg(Main.getPlugin(),key);
T2Csend.debugmsg(Main.getPlugin(), String.valueOf(cronJob));
T2Csend.debugmsg(Main.getPlugin(),cronJobString);
messageHashMap.put(key, msg);
}
break;
}
}
try {
yamlConfiguration.save(config);
} catch (IOException e) {
e.printStackTrace();
}
}
private static void setExample(String key, Boolean enable, String msg, Integer interval, Boolean useCronJobEnable, String useCronJobValue,YamlConfiguration yamlConfiguration) {
yamlConfiguration.set("messages." + key + ".enable", enable);
yamlConfiguration.set("messages." + key + ".message", msg);
yamlConfiguration.set("messages." + key + ".intervalInMin", interval);
yamlConfiguration.set("messages." + key + ".useCronJob.enable", useCronJobEnable);
yamlConfiguration.set("messages." + key + ".useCronJob.value", useCronJobValue);
}
}

View File

@ -1,85 +0,0 @@
// 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

@ -1,201 +0,0 @@
// 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,85 +1,18 @@
package net.t2code.automatedMessages.messages; package net.t2code.automatedMessages.messages;
import net.t2code.automatedMessages.objects.Message; import net.t2code.automatedMessages.objects.Message;
import net.t2code.automatedMessages.system.Main; import org.quartz.Job;
import org.bukkit.Bukkit; import org.quartz.JobExecutionContext;
import org.jetbrains.annotations.NotNull; import org.quartz.JobExecutionException;
import java.time.LocalDateTime; public class CronJob implements Job {
public Message message;
public class CronJob { public CronJob(Message message) {
private Message message;
private Boolean shutdown = false;
public CronJob(@NotNull Message message) {
this.message=message; this.message=message;
String minuteString = message.timeMinute;
String hourString = message.timeHour;
if (minuteString.contains("*/")) {
timer(Integer.valueOf(minuteString.replace("*/", "")), 60);
return;
}
if (hourString.contains("*/")) {
timer(Integer.valueOf(hourString.replace("*/", "")), 60 * 60);
return;
}
job();
} }
private void job() { public void execute(JobExecutionContext context) throws JobExecutionException {
Bukkit.getScheduler().runTaskTimerAsynchronously(Main.getPlugin(), new Runnable() { SendMessage.send(message.message);
@Override
public void run() {
if (shutdown) return;
executeJob();
}
}, 0, 60 * 20L);
}
private void executeJob() {
LocalDateTime dateTime = LocalDateTime.now();
if (check(message.timeMinute, dateTime.getMinute(), "minute")) return;
if (check(message.timeHour, dateTime.getHour(), "h")) return;
if (check(message.timeDayOfMonth, dateTime.getDayOfMonth(), "dom")) return;
if (check(message.timeMonth, dateTime.getMonth().getValue(), "mon")) return;
if (check(message.timeDayOfWeek, dateTime.getDayOfWeek().getValue(), "dow")) return;
SendMessage.send(message);
}
private boolean check(@NotNull String check, Integer value, String v) {
if (check.equals("*")) return false;
if (check.contains("/")) {
String[] strings = check.split("/");
for (String string : strings) {
if (string.equals("*")) return false;
if (Integer.parseInt(string) == value) return false;
}
return true;
}
try {
if (Integer.parseInt(check) == value) return false;
} catch (Exception ignored) {
}
return true;
}
public void timer(Integer period, Integer value) {
Bukkit.getScheduler().scheduleAsyncRepeatingTask(Main.getPlugin(), new Runnable() {
@Override
public void run() {
if (shutdown) return;
SendMessage.send(message);
}
}, 0, 20L * value * period);
}
public void shutdown() {
this.shutdown = true;
} }
} }

View File

@ -1,23 +1,33 @@
package net.t2code.automatedMessages.messages; package net.t2code.automatedMessages.messages;
import net.t2code.automatedMessages.config.Messages; import net.t2code.automatedMessages.config.FileBuild;
import net.t2code.automatedMessages.objects.Message; import net.t2code.automatedMessages.objects.Message;
import net.t2code.automatedMessages.system.Main;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class Management { public class Management {
private static List<Scheduler> jobList = new ArrayList<>();
public static HashMap<JobDetail, Scheduler> hashMap = new HashMap<>();
private static final List<Timer> timerJobList = new ArrayList<>(); private static final List<Timer> timerJobList = new ArrayList<>();
private static final List<CronJob> cronJobs = new ArrayList<>();
public static void start() { public static void start() {
for (Map.Entry<String, Message> value : Messages.getMessageHashMap().entrySet()) { for (Map.Entry<String, Message> value : FileBuild.getMessageHashMap().entrySet()) {
Message message = value.getValue(); Message message = value.getValue();
if (!message.enable) continue; if (!message.enable) continue;
if (message.exactTime) { if (message.cronJob) {
CronJob cronJob = new CronJob(message); startCronJob(message);
cronJobs.add(cronJob);
} else { } else {
Timer job = new Timer(message); Timer job = new Timer(message);
timerJobList.add(job); timerJobList.add(job);
@ -25,12 +35,37 @@ public class Management {
} }
} }
public static void startCronJob(Message message) {
try {
CronJob cronJob = new CronJob(message);
JobDetail job = JobBuilder.newJob(cronJob.getClass())
.withIdentity(message.key, message.key).build();
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(message.key, message.key)
.withSchedule(CronScheduleBuilder.cronSchedule(message.cronJobString))
//.withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
.build();
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.start();
scheduler.scheduleJob(job, trigger);
jobList.add(scheduler);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void end() { public static void end() {
for (Timer job : timerJobList) { for (Timer job : timerJobList) {
job.disable = true; job.disable = true;
} }
for (CronJob cronJob : cronJobs) { for (Scheduler scheduler : jobList) {
cronJob.shutdown(); try {
scheduler.shutdown();
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
} }
} }
} }

View File

@ -1,50 +1,15 @@
package net.t2code.automatedMessages.messages; package net.t2code.automatedMessages.messages;
import net.t2code.automatedMessages.config.Config; import net.t2code.automatedMessages.system.Main;
import net.t2code.automatedMessages.objects.Message; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Send;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.text.SimpleDateFormat;
import java.util.*;
public class SendMessage { public class SendMessage {
public static void send(Message message) { public static void send(String msg){
String timeStamp = new SimpleDateFormat(Config.VALUES.timeFormat.getValue().toString()).format(Calendar.getInstance().getTime()); T2Csend.debugmsg(Main.getPlugin(),msg);
if ((boolean)Config.VALUES.sendConsole.getValue()) {
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) { T2Csend.player(player, msg);
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);
} }
} }
} }
@SafeVarargs
private static Object replace(Object object, Map.Entry<String, String>... map) {
Object o = null;
if (object instanceof List) {
ArrayList<String> res = (ArrayList<String>) object;
ArrayList<String> out = new ArrayList<>();
for (String s : res) {
String re = s;
for (Map.Entry<String, String> placeholder : map) {
re = re.replace(placeholder.getKey(), placeholder.getValue());
}
out.add(re);
}
o = out;
}
if (object instanceof String) {
String res = (String) object;
for (Map.Entry<String, String> placeholder : map) {
res = res.replace(placeholder.getKey(), placeholder.getValue());
}
o = res;
}
return o;
}
}

View File

@ -1,21 +1,20 @@
package net.t2code.automatedMessages.messages; package net.t2code.automatedMessages.messages;
import net.t2code.automatedMessages.messages.SendMessage;
import net.t2code.automatedMessages.objects.Message; import net.t2code.automatedMessages.objects.Message;
import net.t2code.automatedMessages.system.Main; import net.t2code.automatedMessages.system.Main;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
public class Timer { public class Timer {
public Timer(@NotNull Message message) { public Timer(Message message) {
Bukkit.getScheduler().scheduleAsyncRepeatingTask(Main.getPlugin(), new Runnable() { Bukkit.getScheduler().scheduleAsyncRepeatingTask(Main.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
if (disable) return; if (disable) return;
SendMessage.send(message); SendMessage.send(message.message);
} }
}, 0, 20L * 60 * message.interval); }, 0, 20L * 60 * message.interval);
} }
public Boolean disable = false; public Boolean disable = false;
} }

View File

@ -1,8 +1,5 @@
package net.t2code.automatedMessages.objects; package net.t2code.automatedMessages.objects;
import org.bukkit.Sound;
import javax.sound.midi.Soundbank;
import java.util.List; import java.util.List;
public class Message { public class Message {
@ -10,49 +7,21 @@ public class Message {
public String key; public String key;
public Boolean enable; public Boolean enable;
public String message; public String message;
public Boolean soundEnable;
public Sound sound;
public Boolean permissionNeededToSeeMessage;
public String permission;
public Integer interval; public Integer interval;
public Boolean exactTime; public Boolean cronJob;
public String timeMinute; public String cronJobString;
public String timeHour;
public String timeDayOfMonth;
public String timeMonth;
public String timeDayOfWeek;
public Message(String key, public Message(String key,
Boolean enable, Boolean enable,
String message, String message,
Boolean soundEnable,
Sound sound,
Boolean permissionNeededToSeeMessage,
String permission,
Integer interval, Integer interval,
Boolean cronJob,
Boolean exactTime, String cronJobString) {
String timeMinute,
String timeHour,
String timeDayOfMonth,
String timeMonth,
String timeDayOfWeek) {
this.key = key; this.key = key;
this.enable = enable; this.enable = enable;
this.message = message; this.message = message;
this.soundEnable = soundEnable;
this.sound = sound;
this.permissionNeededToSeeMessage = permissionNeededToSeeMessage;
this.permission = permission;
this.interval = interval; this.interval = interval;
this.exactTime = exactTime; this.cronJob = cronJob;
this.timeMinute = timeMinute; this.cronJobString=cronJobString;
this.timeHour = timeHour;
this.timeDayOfMonth = timeDayOfMonth;
this.timeMonth = timeMonth;
this.timeDayOfWeek = timeDayOfWeek;
} }
} }

View File

@ -3,30 +3,26 @@ 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.Languages; import net.t2code.automatedMessages.config.FileBuild;
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.T2Ctemplate;
import net.t2code.t2codelib.SPIGOT.api.update.T2C_UpdateAPI; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
public class Load { public class Load {
public static void onLoad(@NotNull Main plugin, List<String> autor, String version) { public static void onLoad(Main plugin, List<String> autor, String version) {
long long_ = T2C_Template.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord()); long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
plugin.getCommand("t2c-automatedmessages").setExecutor(new CmdExecuter()); plugin.getCommand("t2c-automatedmessages").setExecutor(new CmdExecuter());
Config.set(false); FileBuild.selectConfig();
Languages.set(false);
Messages.set(false);
Management.start(); Management.start();
T2C_UpdateAPI.onUpdateCheck(plugin, Util.getPrefix(), Util.getGit(), Util.getSpigotID(), Util.getDiscord(), (boolean) Config.VALUES.updateCheckOnJoin.getValue(), T2CupdateAPI.onUpdateCheck(plugin, Util.getPrefix(),Util.getGit(),Util.getSpigotID(),Util.getDiscord(), Config.updateCheckOnJoin.valueBoolean,
(boolean) Config.VALUES.updateCheckSeePreReleaseUpdates.getValue(), (int) Config.VALUES.updateCheckTimeInterval.getValue()); Config.updateCheckSeePreReleaseUpdates.valueBoolean, Config.updateCheckTimeInterval.valueInteger);
Metrics.Bstats(plugin, Util.getBstatsID()); Metrics.Bstats(plugin, Util.getBstatsID());
T2C_Template.onLoadFooter(Util.getPrefix(), long_); T2Ctemplate.onLoadFooter(Util.getPrefix(), long_);
} }
} }

View File

@ -2,12 +2,9 @@ package net.t2code.automatedMessages.system;
import lombok.Getter; import lombok.Getter;
import net.t2code.automatedMessages.Util; import net.t2code.automatedMessages.Util;
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Send; import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Template;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
@ -15,8 +12,7 @@ import java.util.logging.Level;
public final class Main extends JavaPlugin { public final class Main extends JavaPlugin {
@Contract(pure = true) public static File getPath() {
public static @NotNull File getPath() {
return plugin.getDataFolder(); return plugin.getDataFolder();
} }
@ -43,10 +39,10 @@ public final class Main extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
// Plugin shutdown logic // Plugin shutdown logic
if (t2codeLib) T2C_Template.onDisable(Util.getPrefix(),plugin); if (t2codeLib) T2Ctemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
} }
private static @NotNull Boolean pluginNotFound(String pl, Integer spigotID, String ver) { private static Boolean pluginNotFound(String pl, Integer spigotID, String ver) {
if (Bukkit.getPluginManager().getPlugin(pl) == null) { if (Bukkit.getPluginManager().getPlugin(pl) == null) {
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!"); plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4could not be found. Please download it here: " Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4could not be found. Please download it here: "
@ -78,7 +74,4 @@ public final class Main extends JavaPlugin {
return false; return false;
} }
} }
public static void sendTryCatch(Class c, StackTraceElement line) {
T2C_Send.error(plugin,c.getName() + " Line: " + line.getLineNumber());
}
} }

View File

@ -1,18 +1,13 @@
name: '${project.name}' name: '${project.artifactId}'
version: '${project.version}' version: '${project.version}'
prefix: "[T2C-AutomatedMessages]" prefix: "[T2C-AutomatedMessages]"
main: net.t2code.automatedMessages.system.Main main: net.t2code.automatedMessages.system.Main
api-version: 1.13 api-version: 1.13
softdepend: [ T2CodeLib ] softdepend: [ T2CodeLib ]
authors: [ JaTiTV ] authors: [ JaTiTV ]
website: https://www.spigotmc.org/resources/110801/
commands: commands:
t2c-automatedmessages: t2c-automatedmessages:
description: T2C-AutomatedMessages Main Command. description: T2C-AutomatedMessages Main Command.
aliases: aliases:
- automatedmessages - automatedmessages
- amsg - amsg
permissions:
t2c.automatedmessages.admin:
default: op