Some tweaks

This commit is contained in:
Paldiu 2021-02-04 10:51:18 -06:00
parent 6c18f25820
commit 952bbd72d5
5 changed files with 42 additions and 7 deletions

View File

@ -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<SimplexCore> {
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.

View File

@ -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<? extends CommandSender> target;
protected final TextComponentFactory factory = new TextComponentFactory();
private ChatUtils(Bean<? extends CommandSender> target) {
this.target = target;
}
public static <T extends CommandSender> 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());
}

View File

@ -6,7 +6,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@CommandInfo(name = "defaultcommand", usage = "/<command>", description = "Default plugin command.")
@CommandInfo(name = "default", usage = "/<command>", 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) {

View File

@ -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<String> 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())));
}
}

View File

@ -17,6 +17,11 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
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.