Convert into constants

This commit is contained in:
Conclure 2021-03-15 21:18:40 +01:00
parent 9b60b20a0f
commit ae95b89641
8 changed files with 33 additions and 57 deletions

View File

@ -1,9 +1,11 @@
package io.github.simplexdev.simplexcore;
public class CoreState {
String message;
private final SimplexCorePlugin plugin;
private String message;
public CoreState() {
public CoreState(SimplexCorePlugin plugin) {
this.plugin = plugin;
switch (getState()) {
case ON:
message = "The Core is currently ON";
@ -25,7 +27,7 @@ public class CoreState {
return State.DEBUG;
}
if (SimplexCorePlugin.getInstance().isEnabled()) {
if (this.plugin.isEnabled()) {
return State.ON;
}

View File

@ -1,34 +1,25 @@
package io.github.simplexdev.simplexcore;
import io.github.simplexdev.simplexcore.command.CommandLoader;
import io.github.simplexdev.simplexcore.command.defaults.Command_info;
import io.github.simplexdev.simplexcore.config.Yaml;
import io.github.simplexdev.simplexcore.config.YamlFactory;
import io.github.simplexdev.simplexcore.plugin.AddonRegistry;
import io.github.simplexdev.simplexcore.plugin.DependencyManagement;
import io.github.simplexdev.simplexcore.task.Announcer;
import io.github.simplexdev.simplexcore.listener.DependencyListener;
import io.github.simplexdev.simplexcore.listener.SimplexListener;
import io.github.simplexdev.simplexcore.plugin.SimplexAddon;
import io.github.simplexdev.simplexcore.utils.TimeValues;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import java.io.File;
import java.util.logging.Logger;
public final class SimplexCorePlugin extends SimplexAddon<SimplexCorePlugin> {
protected static boolean debug = false;
protected static boolean suspended = false;
private static boolean debug = false;
private static boolean suspended = false;
private static SimplexCorePlugin instance;
private DependencyManagement dpm;
private Yaml config;
private TimeValues time;
private Yaml internals;
protected static SimplexCorePlugin instance;
public static SimplexCorePlugin getInstance() {
return instance;
} // I understand this could be an issue.
}
@Override
public SimplexCorePlugin getPlugin() {
@ -37,10 +28,9 @@ public final class SimplexCorePlugin extends SimplexAddon<SimplexCorePlugin> {
@Override
public void init() {
instance = this; // However, if the module is written correctly, this wont be an issue.
SimplexCorePlugin.instance = this;
this.dpm = new DependencyManagement();
this.config = new YamlFactory(this).setDefaultPathways();
this.time = new TimeValues();
this.internals = new YamlFactory(this).from("internals.yml", getParentFolder(), "internals.yml");
}
@ -59,7 +49,7 @@ public final class SimplexCorePlugin extends SimplexAddon<SimplexCorePlugin> {
// TODO: Write an output to a file with why it suspended.
}
CoreState state = new CoreState();
CoreState state = new CoreState(this);
getLogger().info(state.getMessage());
}
@ -84,10 +74,6 @@ public final class SimplexCorePlugin extends SimplexAddon<SimplexCorePlugin> {
return dpm;
}
public TimeValues getTimeValues() {
return time;
}
public Yaml getYamlConfig() {
return config;
}

View File

@ -5,6 +5,7 @@ import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import io.github.simplexdev.simplexcore.chat.Messages;
import io.github.simplexdev.simplexcore.config.Yaml;
import io.github.simplexdev.simplexcore.config.YamlFactory;
import io.github.simplexdev.simplexcore.utils.TickedTime;
import io.github.simplexdev.simplexcore.utils.Utilities;
import io.github.simplexdev.simplexcore.listener.SimplexListener;
import org.bukkit.command.CommandSender;
@ -37,7 +38,7 @@ public abstract class Ban implements IBan {
}
public Ban(Player player, CommandSender sender, BanType type) {
this(player, sender, type, SimplexCorePlugin.getInstance().getTimeValues().DAY());
this(player, sender, type, TickedTime.DAY);
}
public Ban(Player player, CommandSender sender, BanType type, long banDuration) {

View File

@ -5,6 +5,7 @@ import io.github.simplexdev.api.func.VoidSupplier;
import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import io.github.simplexdev.simplexcore.chat.Messages;
import io.github.simplexdev.simplexcore.config.Yaml;
import io.github.simplexdev.simplexcore.utils.TickedTime;
import io.github.simplexdev.simplexcore.utils.Utilities;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -126,11 +127,11 @@ public final class BanFactory {
private VoidSupplier assignBanDuration() {
return () -> {
if (type.equals(BanType.PERMANENT)) {
banDuration = SimplexCorePlugin.getInstance().getTimeValues().YEAR() * 99;
banDuration = TickedTime.YEAR * 99;
} else if (type.equals(BanType.TEMPORARY)) {
banDuration = SimplexCorePlugin.getInstance().getTimeValues().DAY();
banDuration = TickedTime.DAY;
} else {
banDuration = SimplexCorePlugin.getInstance().getTimeValues().MINUTE() * 5;
banDuration = TickedTime.MINUTE * 5;
}
};
}

View File

@ -1,6 +1,7 @@
package io.github.simplexdev.simplexcore.math;
import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import io.github.simplexdev.simplexcore.utils.TickedTime;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.scheduler.BukkitTask;
@ -44,6 +45,7 @@ public final class Cuboid {
};
SimplexCorePlugin.getInstance().getScheduler().runTaskLaterAsynchronously(SimplexCorePlugin.getInstance(), task, SimplexCorePlugin.getInstance().getTimeValues().SECOND());
SimplexCorePlugin.getInstance().getScheduler().runTaskLaterAsynchronously(SimplexCorePlugin.getInstance(), task,
TickedTime.SECOND);
}
}

View File

@ -3,6 +3,7 @@ package io.github.simplexdev.simplexcore.task;
import io.github.simplexdev.api.func.VoidSupplier;
import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import io.github.simplexdev.simplexcore.plugin.SimplexAddon;
import io.github.simplexdev.simplexcore.utils.TickedTime;
import org.bukkit.scheduler.BukkitTask;
import java.util.Date;
@ -28,8 +29,8 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
}
protected SimplexTask() {
DELAY = SimplexCorePlugin.getInstance().getTimeValues().SECOND() * 30; // 30 seconds until the task triggers for the first time.
INTERVAL = SimplexCorePlugin.getInstance().getTimeValues().MINUTE() * 5; // Task will run at 5 minute intervals once the first trigger has been called.
DELAY = TickedTime.SECOND * 30; // 30 seconds until the task triggers for the first time.
INTERVAL = TickedTime.MINUTE * 5; // Task will run at 5 minute intervals once the first trigger has been called.
}
public <T extends SimplexTask> void register(T task, SimplexAddon<?> plugin, boolean repeating, boolean delayed) {

View File

@ -0,0 +1,10 @@
package io.github.simplexdev.simplexcore.utils;
public final class TickedTime {
public static long SECOND = 20L;
public static long MINUTE = 1_200L;
public static long HOUR = 72_000L;
public static long DAY = 1_728_000L;
public static long MONTH = 51_840_000L;
public static long YEAR = 622_080_000L;
}

View File

@ -1,27 +0,0 @@
package io.github.simplexdev.simplexcore.utils;
public final class TimeValues {
public long SECOND() {
return 20L;
}
public long MINUTE() {
return 1200L;
}
public long HOUR() {
return 72000L;
}
public long DAY() {
return 1728000L;
}
public long MONTH() {
return 51840000L;
}
public long YEAR() {
return 622080000L;
}
}