Bourgeoise

This commit is contained in:
Paldiu 2021-02-08 17:09:15 -06:00
parent 6117c21231
commit 9fe9f8e2ae
16 changed files with 106 additions and 85 deletions

View File

@ -1,32 +1,8 @@
package io.github.paldiu.simplexcore; package io.github.paldiu.simplexcore;
import io.github.paldiu.simplexcore.utils.Constants; import io.github.paldiu.simplexcore.utils.Constants;
import org.bukkit.Bukkit;
public class CoreState { 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; String message;
public CoreState() { 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() { public String getMessage() {
return message; return message;
} }
enum State {
ON,
DEBUG,
SUSPENDED,
VOLATILE
}
} }

View File

@ -11,6 +11,18 @@ public final class SimplexCore extends SimplexAddon<SimplexCore> {
protected static boolean debug = false; protected static boolean debug = false;
protected static boolean suspended = 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 @Override
public SimplexCore getPlugin() { public SimplexCore getPlugin() {
return this; return this;
@ -36,16 +48,4 @@ public final class SimplexCore extends SimplexAddon<SimplexCore> {
public void stop() { public void stop() {
} }
public static void setDebug(boolean enable) {
debug = enable;
}
public static boolean isDebug() {
return debug;
}
public static boolean isSuspended() {
return suspended;
}
} }

View File

@ -7,12 +7,12 @@ public enum Messages {
KICK("You have been kicked by a moderator."), KICK("You have been kicked by a moderator."),
AFK_KICK("You were kicked to ensure space for active players."); AFK_KICK("You were kicked to ensure space for active players.");
String message;
Messages(String message) { Messages(String message) {
this.message = message; this.message = message;
} }
String message;
public String getMessage() { public String getMessage() {
return message; return message;
} }

View File

@ -1,7 +1,5 @@
package io.github.paldiu.simplexcore.command; package io.github.paldiu.simplexcore.command;
import org.bukkit.ChatColor;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;

View File

@ -18,8 +18,16 @@ import java.util.Map;
import java.util.MissingResourceException; import java.util.MissingResourceException;
public final class CommandLoader { public final class CommandLoader {
private static final CommandLoader instance = new CommandLoader();
private Reflections reflections; private Reflections reflections;
protected CommandLoader() {
}
public static CommandLoader getInstance() {
return instance;
}
public synchronized CommandLoader classpath(Class<?> clazz) { public synchronized CommandLoader classpath(Class<?> clazz) {
if (!clazz.isAnnotationPresent(CommandInfo.class)) { if (!clazz.isAnnotationPresent(CommandInfo.class)) {
throw new MissingResourceException("Cannot register this class as the main resource location!", clazz.getSimpleName(), "@CommandInfo"); 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;
}
} }

View File

@ -4,7 +4,6 @@ import io.github.paldiu.simplexcore.plugin.SimplexAddon;
import io.github.paldiu.simplexcore.utils.Trio; import io.github.paldiu.simplexcore.utils.Trio;
import java.io.File; import java.io.File;
import java.util.Map;
public final class JsonFactory { public final class JsonFactory {
private final SimplexAddon<?> plugin; private final SimplexAddon<?> plugin;

View File

@ -1,4 +1,4 @@
package io.github.paldiu.simplexcore.utils; package io.github.paldiu.simplexcore.functional;
@FunctionalInterface @FunctionalInterface
public interface Validate { public interface Validate {

View File

@ -11,17 +11,17 @@ import java.util.List;
public class Announcer extends SimplexTask { public class Announcer extends SimplexTask {
public Announcer() { private final List<String> stringList = new ArrayList<>() {{
super(20L);
register(this, Constants.getPlugin(), true, false);
}
private List<String> stringList = new ArrayList<>(){{
add("Join our discord!" + Messages.DISCORD.getMessage()); add("Join our discord!" + Messages.DISCORD.getMessage());
add("Thank you for using SimplexCore!"); add("Thank you for using SimplexCore!");
add("https://github.com/Paldiu/SimplexCore"); add("https://github.com/Paldiu/SimplexCore");
}}; }};
public Announcer() {
super(20L);
register(this, Constants.getPlugin(), true, false);
}
@Override @Override
public void accept(BukkitTask bukkitTask) { public void accept(BukkitTask bukkitTask) {
Bukkit.getServer().broadcastMessage(stringList.get(RandomUtils.nextInt(stringList.size()))); Bukkit.getServer().broadcastMessage(stringList.get(RandomUtils.nextInt(stringList.size())));

View File

@ -8,9 +8,9 @@ import java.util.Date;
import java.util.function.Consumer; import java.util.function.Consumer;
public abstract class SimplexTask implements Consumer<BukkitTask> { public abstract class SimplexTask implements Consumer<BukkitTask> {
protected Date lastRan = new Date();
protected final long DELAY; protected final long DELAY;
protected final long INTERVAL; protected final long INTERVAL;
protected Date lastRan = new Date();
protected SimplexTask(long initialDelay, long interval) { protected SimplexTask(long initialDelay, long interval) {
DELAY = initialDelay; DELAY = initialDelay;

View File

@ -1,17 +1,16 @@
package io.github.paldiu.simplexcore.listener; 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.Constants;
import io.github.paldiu.simplexcore.utils.Utilities;
import io.github.paldiu.simplexcore.utils.Validate;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.PluginEnableEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public final class ServerPluginListener extends SimplexListener { 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"); add("PlaceHolderAPI");
add("placeholderapi"); add("placeholderapi");
@ -20,26 +19,26 @@ public final class ServerPluginListener extends SimplexListener {
add("papi"); add("papi");
}}; }};
public List<String> PLIB_NAMES = new ArrayList<>(){{ public List<String> PLIB_NAMES = new ArrayList<>() {{
add("ProtocolLib"); add("ProtocolLib");
add("PLib"); add("PLib");
add("Protocollib"); add("Protocollib");
add("plib"); add("plib");
add("protocollib");
add("PROTOCOLLIB");
}}; }};
@EventHandler @EventHandler(priority = EventPriority.HIGHEST)
public void pluginRegister(PluginEnableEvent event) { public void pluginRegister(PluginEnableEvent event) {
Validate temp = () -> { Validate temp = () -> PLIB_NAMES.contains(event.getPlugin().getName());
if (PLIB_NAMES.contains(event.getPlugin().getName())) { Validate temp2 = () -> PAPI_NAMES.contains(event.getPlugin().getName());
return true;
}
return PAPI_NAMES.contains(event.getPlugin().getName());
};
if (temp.isValid()) { if (temp.isValid()) {
Constants.getDependencyManager().registerProtocolLib();
} }
if (temp2.isValid()) {
Constants.getDependencyManager().registerPAPI();
}
} }
} }

View File

@ -3,7 +3,8 @@ package io.github.paldiu.simplexcore.plugin;
import io.github.paldiu.simplexcore.utils.Constants; import io.github.paldiu.simplexcore.utils.Constants;
public final class AddonManager { public final class AddonManager {
public AddonManager() { } public AddonManager() {
}
public void disable(SimplexAddon<?> simplexAddon) { public void disable(SimplexAddon<?> simplexAddon) {
Constants.getManager().disablePlugin(simplexAddon); Constants.getManager().disablePlugin(simplexAddon);

View File

@ -4,8 +4,8 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
public final class AddonRegistry { public final class AddonRegistry {
private final Set<SimplexAddon<?>> components = new HashSet<>();
private static final AddonRegistry instance = new AddonRegistry(); private static final AddonRegistry instance = new AddonRegistry();
private final Set<SimplexAddon<?>> components = new HashSet<>();
protected AddonRegistry() { protected AddonRegistry() {
} }
@ -14,7 +14,7 @@ public final class AddonRegistry {
return instance; return instance;
} }
public <T extends SimplexAddon<T>>void register(T addon) { public <T extends SimplexAddon<T>> void register(T addon) {
getComponents().add(addon); getComponents().add(addon);
} }

View File

@ -1,7 +1,34 @@
package io.github.paldiu.simplexcore.plugin; package io.github.paldiu.simplexcore.plugin;
public class DependencyManagement { import com.comphenix.protocol.ProtocolLibrary;
public DependencyManagement() { 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;
} }
} }

View File

@ -1,6 +0,0 @@
package io.github.paldiu.simplexcore.utils;
@FunctionalInterface
public interface Complete<Void> {
void toComplete(Void complete);
}

View File

@ -3,6 +3,7 @@ package io.github.paldiu.simplexcore.utils;
import io.github.paldiu.simplexcore.SimplexCore; import io.github.paldiu.simplexcore.SimplexCore;
import io.github.paldiu.simplexcore.command.CommandLoader; import io.github.paldiu.simplexcore.command.CommandLoader;
import io.github.paldiu.simplexcore.plugin.AddonRegistry; import io.github.paldiu.simplexcore.plugin.AddonRegistry;
import io.github.paldiu.simplexcore.plugin.DependencyManagement;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -16,6 +17,7 @@ public final class Constants {
private static final Logger logger = plugin.getLogger(); private static final Logger logger = plugin.getLogger();
private static final PluginManager manager = server.getPluginManager(); private static final PluginManager manager = server.getPluginManager();
private static final BukkitScheduler scheduler = server.getScheduler(); private static final BukkitScheduler scheduler = server.getScheduler();
private static final DependencyManagement dpm = new DependencyManagement();
public static SimplexCore getPlugin() { public static SimplexCore getPlugin() {
return plugin; return plugin;
@ -45,6 +47,10 @@ public final class Constants {
return CommandLoader.getInstance(); return CommandLoader.getInstance();
} }
public static DependencyManagement getDependencyManager() {
return dpm;
}
public static TimeValues getTimeValues() { public static TimeValues getTimeValues() {
return new TimeValues(); return new TimeValues();
} }

View File

@ -1,7 +1,6 @@
package io.github.paldiu.simplexcore.utils; package io.github.paldiu.simplexcore.utils;
import io.github.paldiu.simplexcore.listener.SimplexListener; import io.github.paldiu.simplexcore.functional.Validate;
import io.github.paldiu.simplexcore.plugin.SimplexAddon;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;