mirror of
https://github.com/SimplexDevelopment/SimplexCore.git
synced 2024-12-22 08:37:37 +00:00
Slowly adding more shit
This commit is contained in:
parent
4fd134f86b
commit
d8b8bedc98
@ -1,6 +1,8 @@
|
||||
package io.github.paldiu.simplexcore;
|
||||
|
||||
import io.github.paldiu.simplexcore.command.defaults.Command_info;
|
||||
import io.github.paldiu.simplexcore.listener.ServerPluginListener;
|
||||
import io.github.paldiu.simplexcore.listener.SimplexListener;
|
||||
import io.github.paldiu.simplexcore.plugin.SimplexAddon;
|
||||
import io.github.paldiu.simplexcore.utils.Constants;
|
||||
|
||||
@ -14,6 +16,7 @@ public final class SimplexCore extends SimplexAddon<SimplexCore> {
|
||||
public void start() {
|
||||
Constants.getRegistry().register(this);
|
||||
Constants.getCommandLoader().classpath(Command_info.class).load();
|
||||
SimplexListener.register(new ServerPluginListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,33 @@
|
||||
package io.github.paldiu.simplexcore.config;
|
||||
|
||||
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;
|
||||
private String resourcePath;
|
||||
private File directory;
|
||||
private String fileName;
|
||||
|
||||
public JsonFactory(SimplexAddon<?> plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public JsonFactory setPathways(String resourcePath, File directory, String fileName) {
|
||||
this.resourcePath = resourcePath;
|
||||
this.directory = directory;
|
||||
this.fileName = fileName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JsonFactory setDefaultPathways() {
|
||||
return setPathways("config.yml", plugin.getDataFolder(), "config.yml");
|
||||
}
|
||||
|
||||
public Trio<String, File, String> getPathways() {
|
||||
return new Trio<>(resourcePath, directory, fileName);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package io.github.paldiu.simplexcore.config;
|
||||
|
||||
import io.github.paldiu.simplexcore.plugin.SimplexAddon;
|
||||
import io.github.paldiu.simplexcore.utils.Trio;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public final class YamlFactory {
|
||||
private final SimplexAddon<?> plugin;
|
||||
private String resourcePath;
|
||||
private File directory;
|
||||
private String fileName;
|
||||
|
||||
public YamlFactory(SimplexAddon<?> plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public YamlFactory setPathways(String resourcePath, File directory, String fileName) {
|
||||
this.resourcePath = resourcePath;
|
||||
this.directory = directory;
|
||||
this.fileName = fileName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public YamlFactory setDefaultPathways() {
|
||||
return setPathways("config.yml", plugin.getDataFolder(), "config.yml");
|
||||
}
|
||||
|
||||
public Trio<String, File, String> getPathways() {
|
||||
return new Trio<>(resourcePath, directory, fileName);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package io.github.paldiu.simplexcore.listener;
|
||||
|
||||
import io.github.paldiu.simplexcore.plugin.SimplexAddon;
|
||||
import io.github.paldiu.simplexcore.utils.Constants;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
|
||||
public class ServerPluginListener extends SimplexListener {
|
||||
@EventHandler
|
||||
public void pluginRegister(PluginEnableEvent event) {
|
||||
if (SimplexAddon.class.isAssignableFrom(event.getPlugin().getClass())) {
|
||||
if (!Constants.getRegistry().getComponents().contains(event.getPlugin())) {
|
||||
Constants.getRegistry().getComponents().add((SimplexAddon<?>) event.getPlugin());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package io.github.paldiu.simplexcore.listener;
|
||||
|
||||
import io.github.paldiu.simplexcore.plugin.SimplexAddon;
|
||||
import io.github.paldiu.simplexcore.utils.Constants;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public abstract class SimplexListener implements Listener {
|
||||
/**
|
||||
* This will register your listener by its class. This requires your class to have a single constructor which takes no parameters.
|
||||
* This also requires the class in question to extend SimplexListener.
|
||||
*
|
||||
* @param cls The class to register.
|
||||
*/
|
||||
public static void registerFromClass(Class<? extends SimplexListener> cls, SimplexAddon<?> plugin) {
|
||||
if (!SimplexListener.class.isAssignableFrom(cls)) {
|
||||
Constants.getLogger().severe("You can only register subclasses of SimplexListener with this method.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Constructor<? extends SimplexListener> constr = cls.getDeclaredConstructor();
|
||||
register(constr.newInstance(), plugin);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
||||
Constants.getLogger().severe("Could not register this listener!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers your listener with the server plugin manager.
|
||||
*
|
||||
* @param listener The listener instance
|
||||
* @param plugin Your plugin instance
|
||||
* @param <T> Type of which extends SimplexListener.
|
||||
*/
|
||||
public static <T extends SimplexListener> void register(T listener, SimplexAddon<?> plugin) {
|
||||
Constants.getManager().registerEvents(listener, plugin);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package io.github.paldiu.simplexcore.listeners;
|
||||
|
||||
import io.github.paldiu.simplexcore.plugin.SimplexAddon;
|
||||
import io.github.paldiu.simplexcore.utils.Constants;
|
||||
import io.github.paldiu.simplexcore.utils.Utilities;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
|
||||
public abstract class SimplexListener implements Listener {
|
||||
@EventHandler
|
||||
public void pluginRegister(PluginEnableEvent event) {
|
||||
if (SimplexAddon.class.isAssignableFrom(event.getPlugin().getClass())) {
|
||||
if (!Constants.getRegistry().getComponents().contains(event.getPlugin())) {
|
||||
Constants.getRegistry().getComponents().add((SimplexAddon<?>) event.getPlugin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends SimplexListener> void registerAll(T[] sl, SimplexAddon<?> plugin) {
|
||||
Utilities.primitiveFE(sl, action -> {
|
||||
SimplexListener.register(action, plugin);
|
||||
});
|
||||
}
|
||||
|
||||
public static <T extends SimplexListener> void register(T listener, SimplexAddon<?> plugin) {
|
||||
Constants.getManager().registerEvents(listener, plugin);
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package io.github.paldiu.simplexcore.utils;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
public class Trio<A, B, C> {
|
||||
private final A primary;
|
||||
private final B secondary;
|
||||
@ -22,4 +25,38 @@ public class Trio<A, B, C> {
|
||||
public C getTertiary() {
|
||||
return tertiary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder().append(getPrimary())
|
||||
.append(getSecondary())
|
||||
.append(getTertiary())
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Trio<?, ?, ?>)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj.equals(this)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Trio<?, ?, ?> trio = (Trio<?, ?, ?>) obj;
|
||||
return new EqualsBuilder().append(getPrimary(), trio.getPrimary())
|
||||
.append(getSecondary(), trio.getSecondary())
|
||||
.append(getTertiary(), trio.getTertiary())
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getPrimary().toString() +
|
||||
"\n" +
|
||||
getSecondary().toString() +
|
||||
"\n" +
|
||||
getTertiary().toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package io.github.paldiu.simplexcore.utils;
|
||||
|
||||
import io.github.paldiu.simplexcore.listener.SimplexListener;
|
||||
import io.github.paldiu.simplexcore.plugin.SimplexAddon;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
Loading…
Reference in New Issue
Block a user