mirror of
https://github.com/SimplexDevelopment/SimplexCore.git
synced 2024-12-22 08:37:37 +00:00
Bourgeoise
This commit is contained in:
parent
6117c21231
commit
9fe9f8e2ae
@ -1,32 +1,8 @@
|
||||
package io.github.paldiu.simplexcore;
|
||||
|
||||
import io.github.paldiu.simplexcore.utils.Constants;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class CoreState {
|
||||
enum State {
|
||||
ON,
|
||||
DEBUG,
|
||||
SUSPENDED,
|
||||
VOLATILE
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
if (SimplexCore.isDebug()) {
|
||||
return State.DEBUG;
|
||||
}
|
||||
|
||||
if (Constants.getPlugin().isEnabled()) {
|
||||
return State.ON;
|
||||
}
|
||||
|
||||
if (SimplexCore.isSuspended()) {
|
||||
return State.SUSPENDED;
|
||||
}
|
||||
|
||||
return State.VOLATILE;
|
||||
}
|
||||
|
||||
String message;
|
||||
|
||||
public CoreState() {
|
||||
@ -46,7 +22,30 @@ public class CoreState {
|
||||
}
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
if (SimplexCore.isDebug()) {
|
||||
return State.DEBUG;
|
||||
}
|
||||
|
||||
if (Constants.getPlugin().isEnabled()) {
|
||||
return State.ON;
|
||||
}
|
||||
|
||||
if (SimplexCore.isSuspended()) {
|
||||
return State.SUSPENDED;
|
||||
}
|
||||
|
||||
return State.VOLATILE;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
enum State {
|
||||
ON,
|
||||
DEBUG,
|
||||
SUSPENDED,
|
||||
VOLATILE
|
||||
}
|
||||
}
|
@ -11,6 +11,18 @@ public final class SimplexCore extends SimplexAddon<SimplexCore> {
|
||||
protected static boolean debug = false;
|
||||
protected static boolean suspended = false;
|
||||
|
||||
public static boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public static void setDebug(boolean enable) {
|
||||
debug = enable;
|
||||
}
|
||||
|
||||
public static boolean isSuspended() {
|
||||
return suspended;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimplexCore getPlugin() {
|
||||
return this;
|
||||
@ -36,16 +48,4 @@ public final class SimplexCore extends SimplexAddon<SimplexCore> {
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
|
||||
public static void setDebug(boolean enable) {
|
||||
debug = enable;
|
||||
}
|
||||
|
||||
public static boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public static boolean isSuspended() {
|
||||
return suspended;
|
||||
}
|
||||
}
|
@ -7,12 +7,12 @@ public enum Messages {
|
||||
KICK("You have been kicked by a moderator."),
|
||||
AFK_KICK("You were kicked to ensure space for active players.");
|
||||
|
||||
String message;
|
||||
|
||||
Messages(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
String message;
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package io.github.paldiu.simplexcore.command;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
|
@ -18,8 +18,16 @@ import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
public final class CommandLoader {
|
||||
private static final CommandLoader instance = new CommandLoader();
|
||||
private Reflections reflections;
|
||||
|
||||
protected CommandLoader() {
|
||||
}
|
||||
|
||||
public static CommandLoader getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public synchronized CommandLoader classpath(Class<?> clazz) {
|
||||
if (!clazz.isAnnotationPresent(CommandInfo.class)) {
|
||||
throw new MissingResourceException("Cannot register this class as the main resource location!", clazz.getSimpleName(), "@CommandInfo");
|
||||
@ -150,13 +158,4 @@ public final class CommandLoader {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final CommandLoader instance = new CommandLoader();
|
||||
|
||||
protected CommandLoader() {
|
||||
}
|
||||
|
||||
public static CommandLoader getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import io.github.paldiu.simplexcore.plugin.SimplexAddon;
|
||||
import io.github.paldiu.simplexcore.utils.Trio;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public final class JsonFactory {
|
||||
private final SimplexAddon<?> plugin;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.paldiu.simplexcore.utils;
|
||||
package io.github.paldiu.simplexcore.functional;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Validate {
|
@ -11,17 +11,17 @@ 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<>(){{
|
||||
private final List<String> stringList = new ArrayList<>() {{
|
||||
add("Join our discord!" + Messages.DISCORD.getMessage());
|
||||
add("Thank you for using SimplexCore!");
|
||||
add("https://github.com/Paldiu/SimplexCore");
|
||||
}};
|
||||
|
||||
public Announcer() {
|
||||
super(20L);
|
||||
register(this, Constants.getPlugin(), true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(BukkitTask bukkitTask) {
|
||||
Bukkit.getServer().broadcastMessage(stringList.get(RandomUtils.nextInt(stringList.size())));
|
||||
|
@ -8,9 +8,9 @@ import java.util.Date;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class SimplexTask implements Consumer<BukkitTask> {
|
||||
protected Date lastRan = new Date();
|
||||
protected final long DELAY;
|
||||
protected final long INTERVAL;
|
||||
protected Date lastRan = new Date();
|
||||
|
||||
protected SimplexTask(long initialDelay, long interval) {
|
||||
DELAY = initialDelay;
|
||||
|
@ -1,17 +1,16 @@
|
||||
package io.github.paldiu.simplexcore.listener;
|
||||
|
||||
import io.github.paldiu.simplexcore.plugin.SimplexAddon;
|
||||
import io.github.paldiu.simplexcore.functional.Validate;
|
||||
import io.github.paldiu.simplexcore.utils.Constants;
|
||||
import io.github.paldiu.simplexcore.utils.Utilities;
|
||||
import io.github.paldiu.simplexcore.utils.Validate;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class ServerPluginListener extends SimplexListener {
|
||||
public List<String> PAPI_NAMES = new ArrayList<>(){{
|
||||
public List<String> PAPI_NAMES = new ArrayList<>() {{
|
||||
add("PlaceholderAPI");
|
||||
add("PlaceHolderAPI");
|
||||
add("placeholderapi");
|
||||
@ -20,26 +19,26 @@ public final class ServerPluginListener extends SimplexListener {
|
||||
add("papi");
|
||||
}};
|
||||
|
||||
public List<String> PLIB_NAMES = new ArrayList<>(){{
|
||||
public List<String> PLIB_NAMES = new ArrayList<>() {{
|
||||
add("ProtocolLib");
|
||||
add("PLib");
|
||||
add("Protocollib");
|
||||
add("plib");
|
||||
add("protocollib");
|
||||
add("PROTOCOLLIB");
|
||||
}};
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void pluginRegister(PluginEnableEvent event) {
|
||||
Validate temp = () -> {
|
||||
if (PLIB_NAMES.contains(event.getPlugin().getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return PAPI_NAMES.contains(event.getPlugin().getName());
|
||||
};
|
||||
Validate temp = () -> PLIB_NAMES.contains(event.getPlugin().getName());
|
||||
Validate temp2 = () -> PAPI_NAMES.contains(event.getPlugin().getName());
|
||||
|
||||
if (temp.isValid()) {
|
||||
|
||||
Constants.getDependencyManager().registerProtocolLib();
|
||||
}
|
||||
|
||||
if (temp2.isValid()) {
|
||||
Constants.getDependencyManager().registerPAPI();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,8 @@ package io.github.paldiu.simplexcore.plugin;
|
||||
import io.github.paldiu.simplexcore.utils.Constants;
|
||||
|
||||
public final class AddonManager {
|
||||
public AddonManager() { }
|
||||
public AddonManager() {
|
||||
}
|
||||
|
||||
public void disable(SimplexAddon<?> simplexAddon) {
|
||||
Constants.getManager().disablePlugin(simplexAddon);
|
||||
|
@ -4,8 +4,8 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public final class AddonRegistry {
|
||||
private final Set<SimplexAddon<?>> components = new HashSet<>();
|
||||
private static final AddonRegistry instance = new AddonRegistry();
|
||||
private final Set<SimplexAddon<?>> components = new HashSet<>();
|
||||
|
||||
protected AddonRegistry() {
|
||||
}
|
||||
@ -14,7 +14,7 @@ public final class AddonRegistry {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public <T extends SimplexAddon<T>>void register(T addon) {
|
||||
public <T extends SimplexAddon<T>> void register(T addon) {
|
||||
getComponents().add(addon);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,34 @@
|
||||
package io.github.paldiu.simplexcore.plugin;
|
||||
|
||||
public class DependencyManagement {
|
||||
public DependencyManagement() {
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DependencyManagement {
|
||||
private ProtocolManager manager;
|
||||
private PlaceholderAPIPlugin papi;
|
||||
|
||||
public DependencyManagement() {
|
||||
manager = null;
|
||||
papi = null;
|
||||
}
|
||||
|
||||
public void registerProtocolLib() {
|
||||
manager = ProtocolLibrary.getProtocolManager();
|
||||
}
|
||||
|
||||
public void registerPAPI() {
|
||||
papi = PlaceholderAPIPlugin.getInstance();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PlaceholderAPIPlugin getPAPI() {
|
||||
return papi;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ProtocolManager getProtocolManager() {
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
package io.github.paldiu.simplexcore.utils;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Complete<Void> {
|
||||
void toComplete(Void complete);
|
||||
}
|
@ -3,6 +3,7 @@ package io.github.paldiu.simplexcore.utils;
|
||||
import io.github.paldiu.simplexcore.SimplexCore;
|
||||
import io.github.paldiu.simplexcore.command.CommandLoader;
|
||||
import io.github.paldiu.simplexcore.plugin.AddonRegistry;
|
||||
import io.github.paldiu.simplexcore.plugin.DependencyManagement;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -16,6 +17,7 @@ public final class Constants {
|
||||
private static final Logger logger = plugin.getLogger();
|
||||
private static final PluginManager manager = server.getPluginManager();
|
||||
private static final BukkitScheduler scheduler = server.getScheduler();
|
||||
private static final DependencyManagement dpm = new DependencyManagement();
|
||||
|
||||
public static SimplexCore getPlugin() {
|
||||
return plugin;
|
||||
@ -45,6 +47,10 @@ public final class Constants {
|
||||
return CommandLoader.getInstance();
|
||||
}
|
||||
|
||||
public static DependencyManagement getDependencyManager() {
|
||||
return dpm;
|
||||
}
|
||||
|
||||
public static TimeValues getTimeValues() {
|
||||
return new TimeValues();
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.github.paldiu.simplexcore.utils;
|
||||
|
||||
import io.github.paldiu.simplexcore.listener.SimplexListener;
|
||||
import io.github.paldiu.simplexcore.plugin.SimplexAddon;
|
||||
import io.github.paldiu.simplexcore.functional.Validate;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
Loading…
Reference in New Issue
Block a user