diff --git a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java index d9f6441..57fddc6 100644 --- a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java +++ b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java @@ -1,6 +1,7 @@ package io.github.paldiu.simplexcore; import io.github.paldiu.simplexcore.command.defaults.Command_info; +import io.github.paldiu.simplexcore.future.Announcer; import io.github.paldiu.simplexcore.listener.ServerPluginListener; import io.github.paldiu.simplexcore.listener.SimplexListener; import io.github.paldiu.simplexcore.plugin.SimplexAddon; @@ -21,6 +22,7 @@ public final class SimplexCore extends SimplexAddon { Constants.getRegistry().register(this); Constants.getCommandLoader().classpath(Command_info.class).load(); SimplexListener.register(new ServerPluginListener(), this); + new Announcer(); } catch (Exception ex) { suspended = true; // TODO: Write an output to a file with why it suspended. diff --git a/src/main/java/io/github/paldiu/simplexcore/chat/ChatUtils.java b/src/main/java/io/github/paldiu/simplexcore/chat/ChatUtils.java index 3f65167..4be0dfe 100644 --- a/src/main/java/io/github/paldiu/simplexcore/chat/ChatUtils.java +++ b/src/main/java/io/github/paldiu/simplexcore/chat/ChatUtils.java @@ -1,30 +1,29 @@ package io.github.paldiu.simplexcore.chat; import io.github.paldiu.simplexcore.utils.Bean; -import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.command.CommandSender; public final class ChatUtils { protected final Bean target; protected final TextComponentFactory factory = new TextComponentFactory(); - + private ChatUtils(Bean target) { this.target = target; } - + public static ChatUtils target(T target) { return new ChatUtils(new Bean<>(target)); } - + public void msg(String message) { target.get().sendMessage(message); } - + public void msg(TextComponent component) { target.get().sendMessage(component); } - + public void err(Messages message) { target.get().sendMessage(message.getMessage()); } diff --git a/src/main/java/io/github/paldiu/simplexcore/command/defaults/DefaultCommand.java b/src/main/java/io/github/paldiu/simplexcore/command/defaults/DefaultCommand.java index 2dd6f6e..cb6c32c 100644 --- a/src/main/java/io/github/paldiu/simplexcore/command/defaults/DefaultCommand.java +++ b/src/main/java/io/github/paldiu/simplexcore/command/defaults/DefaultCommand.java @@ -6,7 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; -@CommandInfo(name = "defaultcommand", usage = "/", description = "Default plugin command.") +@CommandInfo(name = "default", usage = "/", description = "Default plugin command.") public final class DefaultCommand extends SimplexCommand { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { diff --git a/src/main/java/io/github/paldiu/simplexcore/future/Announcer.java b/src/main/java/io/github/paldiu/simplexcore/future/Announcer.java new file mode 100644 index 0000000..a497072 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/future/Announcer.java @@ -0,0 +1,29 @@ +package io.github.paldiu.simplexcore.future; + +import io.github.paldiu.simplexcore.chat.Messages; +import io.github.paldiu.simplexcore.utils.Constants; +import org.apache.commons.lang.math.RandomUtils; +import org.bukkit.Bukkit; +import org.bukkit.scheduler.BukkitTask; + +import java.util.ArrayList; +import java.util.List; + +public class Announcer extends SimplexTask { + + public Announcer() { + super(20L); + register(this, Constants.getPlugin(), true, false); + } + + private List stringList = new ArrayList<>(){{ + add("Join our discord!" + Messages.DISCORD.getMessage()); + add("Thank you for using SimplexCore!"); + add("https://github.com/Paldiu/SimplexCore"); + }}; + + @Override + public void accept(BukkitTask bukkitTask) { + Bukkit.getServer().broadcastMessage(stringList.get(RandomUtils.nextInt(stringList.size()))); + } +} diff --git a/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java b/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java index 4086910..ddbba27 100644 --- a/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java +++ b/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java @@ -17,6 +17,11 @@ public abstract class SimplexTask implements Consumer { INTERVAL = interval; } + protected SimplexTask(long interval) { + DELAY = 0L; + INTERVAL = interval; + } + protected SimplexTask() { DELAY = Constants.getTimeValues().SECOND() * 30; // 30 seconds until the task triggers for the first time. INTERVAL = Constants.getTimeValues().MINUTE() * 5; // Task will run at 5 minute intervals once the first trigger has been called.