diff --git a/.gitignore b/.gitignore index e0fd5d8..30c4fde 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ *.log # Idea files -*.idea +.idea/* # BlueJ files *.ctxt diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3c666e8..8e63824 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,16 @@ - + + + + + + + + + + @@ -162,20 +97,20 @@ @@ -377,11 +312,11 @@ - + - + @@ -458,7 +393,8 @@ - + + @@ -492,13 +428,6 @@ - - - - - - - @@ -544,107 +473,119 @@ - + + + + - - + + - - - - + + + + + + + + + - - + + + + + + - + - - + + + + - + - + + + - + - + - + - + + + + - + - - + + - - + + - + + - + - - - - - + + - + - - - - - + + - - + + - - - - - - - - - + + + + + + + diff --git a/src/main/java/nycuro/SimpleMessagesAPI.java b/src/main/java/nycuro/SimpleMessagesAPI.java index 9f65c83..a0340e9 100644 --- a/src/main/java/nycuro/SimpleMessagesAPI.java +++ b/src/main/java/nycuro/SimpleMessagesAPI.java @@ -1,5 +1,7 @@ package nycuro; +import nycuro.utils.Settings; + /** * author: NycuRO * SimpleMessages-Nemisys Project @@ -9,7 +11,11 @@ public class SimpleMessagesAPI { public static SimpleMessagesMain mainAPI; + public static Settings settingsAPI; + public static SimpleMessagesMain getMainAPI() { return mainAPI; } + + public static Settings getSettingsAPI() { return settingsAPI; } } diff --git a/src/main/java/nycuro/SimpleMessagesMain.java b/src/main/java/nycuro/SimpleMessagesMain.java index f2f2310..d99748c 100644 --- a/src/main/java/nycuro/SimpleMessagesMain.java +++ b/src/main/java/nycuro/SimpleMessagesMain.java @@ -2,7 +2,6 @@ import nycuro.tasks.MessagesTask; import nycuro.utils.Settings; -import nycuro.utils.objects.Mechanic; import org.itxtech.nemisys.plugin.PluginBase; @@ -35,22 +34,22 @@ public void onDisable() { private void registerAPI() { SimpleMessagesAPI.mainAPI = this; + SimpleMessagesAPI.settingsAPI = new Settings(); } private void registerTasks() { - Mechanic mechanic = new Mechanic(); // synapse have 100 tps, not 20 like nukkit - this.getServer().getScheduler().scheduleRepeatingTask(new MessagesTask(), mechanic.getPeriod() * 100, mechanic.isAsync()); + this.getServer().getScheduler().scheduleRepeatingTask(new MessagesTask(), + SimpleMessagesAPI.getSettingsAPI().mechanic.getPeriod() * 100, SimpleMessagesAPI.getSettingsAPI().mechanic.isAsync()); } private void createConfig() { this.getLogger().info(String.valueOf(this.getDataFolder().mkdirs())); - Settings.init(); + SimpleMessagesAPI.getSettingsAPI().init(); } - public static String time() { - Mechanic mechanic = new Mechanic(); - String timeString = String.valueOf(mechanic.getCountry()); + public String time() { + String timeString = String.valueOf(SimpleMessagesAPI.getSettingsAPI().mechanic.getCountry()); TimeZone timeZone = TimeZone.getTimeZone(timeString); Calendar calendar = new GregorianCalendar(); calendar.setTimeZone(timeZone); diff --git a/src/main/java/nycuro/tasks/MessagesTask.java b/src/main/java/nycuro/tasks/MessagesTask.java index e650700..5d320e8 100644 --- a/src/main/java/nycuro/tasks/MessagesTask.java +++ b/src/main/java/nycuro/tasks/MessagesTask.java @@ -6,9 +6,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import nycuro.SimpleMessagesAPI; -import nycuro.SimpleMessagesMain; import nycuro.utils.objects.Mechanic; -import nycuro.utils.objects.Message; import org.itxtech.nemisys.Player; import org.itxtech.nemisys.scheduler.Task; @@ -53,7 +51,7 @@ public class MessagesTask extends Task { placeHolders.put("%tps_averange", String.valueOf((int) SimpleMessagesAPI.getMainAPI().getServer().getTickUsageAverage())); placeHolders.put("%server_uptime", String.valueOf(SimpleMessagesAPI.getMainAPI().getServer().uptime)); placeHolders.put("&", "ยง"); - placeHolders.put("%time", SimpleMessagesMain.time()); + placeHolders.put("%time", SimpleMessagesAPI.getMainAPI().time()); placeHolders.put("%year", String.valueOf(year)); placeHolders.put("%month", String.valueOf(month)); placeHolders.put("%hour", String.valueOf(hour)); @@ -71,10 +69,10 @@ public class MessagesTask extends Task { @Override public void onRun(int i) { - Message configMessage = new Message(); - //List messages = configMessage.getBroadcast(); - System.out.println(configMessage.getBroadcast().toString()); - /*int lenght = messages.toArray().length; + List messages = SimpleMessagesAPI.getSettingsAPI().message.getBroadcast(); + System.out.println("Broadcast from MessagesTask: " + messages + "\n\n"); + System.out.println(messages.size()); + int lenght = messages.size(); for (Player player : SimpleMessagesAPI.getMainAPI().getServer().getOnlinePlayers().values()) { Integer playerTime = timers.getInt(player.getName()); if (playerTime <= (lenght - 1)) { @@ -83,7 +81,6 @@ public void onRun(int i) { "%time", "%year", "%month", "%hour", "%minute", "%second", "%dayOfYear", "%dayOfMonth", "%dayOfWeek", "%dayOfWeekInMonth", "%weekOfMonth", "%weekOfYear", "%zoneOffset", "%milliseconds" )) { - System.out.println(message); if (message.contains(string)) { message = message.replace(string, placeHolders.get(string)); } @@ -95,6 +92,6 @@ public void onRun(int i) { timers.remove(player.getName()); timers.put(player.getName(), 0); } - }*/ + } } } diff --git a/src/main/java/nycuro/utils/Settings.java b/src/main/java/nycuro/utils/Settings.java index 4149cb6..b0eef89 100644 --- a/src/main/java/nycuro/utils/Settings.java +++ b/src/main/java/nycuro/utils/Settings.java @@ -19,7 +19,10 @@ */ public class Settings { - public static void init() { + public Message message = new Message(); + public Mechanic mechanic = new Mechanic(); + + public void init() { try { File file = new File(SimpleMessagesAPI.getMainAPI().getDataFolder(), "config.json"); if (!file.exists()) { @@ -32,37 +35,31 @@ public static void init() { JsonNode jsonNodeMessages = settings.get("messages").get("broadcast"); JsonNode jsonNodeMechanic = settings.get("mechanic"); - Mechanic mechanic = new Mechanic(); mechanic.setPeriod(Integer.valueOf(jsonNodeMechanic.get("period").toString())); mechanic.setAsync(Boolean.getBoolean(jsonNodeMechanic.get("async").toString())); mechanic.setCountry(jsonNodeMechanic.get("country").toString()); + List strings = new ArrayList<>(); if (jsonNodeMessages.isArray()) { for (final JsonNode objNode : jsonNodeMessages) { - List strings = new ArrayList<>(); strings.add(objNode.toString()); - Message message = new Message(); - message.setBroadcast(strings); - System.out.println("Finished"); - System.out.println(message.toString()); } } + message.setBroadcast(strings); } } catch (IOException e) { e.fillInStackTrace(); } } - private static String serializeData() throws JsonProcessingException { + private String serializeData() throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); JsonObject json = new JsonObject(); - Mechanic mechanic = new Mechanic(); mechanic.setAsync(true); mechanic.setCountry("Europe/Bucharest"); mechanic.setPeriod(5); - Message message = new Message(); List messages = Arrays.asList( "&7Hello players! Now is %server_online players!", "&eNow is %time", diff --git a/src/main/java/nycuro/utils/objects/JsonObject.java b/src/main/java/nycuro/utils/objects/JsonObject.java index dcc7540..69347ac 100644 --- a/src/main/java/nycuro/utils/objects/JsonObject.java +++ b/src/main/java/nycuro/utils/objects/JsonObject.java @@ -4,6 +4,6 @@ @Data public class JsonObject { - private Mechanic mechanic; - private Message messages; + public Mechanic mechanic; + public Message messages; } diff --git a/src/main/java/nycuro/utils/objects/MatchedGroup.java b/src/main/java/nycuro/utils/objects/MatchedGroup.java deleted file mode 100644 index a3d5e47..0000000 --- a/src/main/java/nycuro/utils/objects/MatchedGroup.java +++ /dev/null @@ -1,17 +0,0 @@ -package nycuro.utils.objects; - -import lombok.Data; - -@Data -public class MatchedGroup { - - public String value; - public int start; - public int end; - - public MatchedGroup(String value, int start, int end) { - this.value = value; - this.start = start; - this.end = end; - } -} diff --git a/src/main/java/nycuro/utils/objects/Mechanic.java b/src/main/java/nycuro/utils/objects/Mechanic.java index 58b3756..d1b1328 100644 --- a/src/main/java/nycuro/utils/objects/Mechanic.java +++ b/src/main/java/nycuro/utils/objects/Mechanic.java @@ -4,7 +4,7 @@ @Data public class Mechanic { - private int period; - private boolean async; - private String country; + public int period; + public boolean async; + public String country; } diff --git a/src/main/java/nycuro/utils/objects/Message.java b/src/main/java/nycuro/utils/objects/Message.java index a0e5176..eca3281 100644 --- a/src/main/java/nycuro/utils/objects/Message.java +++ b/src/main/java/nycuro/utils/objects/Message.java @@ -6,5 +6,5 @@ @Data public class Message { - private List broadcast; + public List broadcast; }