2024-07-01 19:50:19 +02:00

125 lines
4.9 KiB
Java

// This class was created by JaTiTV.
package net.t2code.t2codelib.VELOCITY.system;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import lombok.Getter;
import net.t2code.t2codelib.Util;
import net.t2code.t2codelib.VELOCITY.api.pluginMessaging.T2CVplmsgCmd;
import net.t2code.t2codelib.VELOCITY.api.pluginMessaging.autoResponse.T2CVapiAutoResponse;
import net.t2code.t2codelib.VELOCITY.api.pluginMessaging.commandgui.T2CVapiCGUI;
import net.t2code.t2codelib.VELOCITY.api.pluginMessaging.opSecurity.T2CVapiOpSecurity;
import net.t2code.t2codelib.VELOCITY.api.proxyPlayers.T2CVPlayers;
import net.t2code.t2codelib.VELOCITY.api.update.T2CVupdateAPI;
import net.t2code.t2codelib.VELOCITY.system.bstats.Metrics;
import net.t2code.t2codelib.VELOCITY.system.config.T2CVlibConfig;
import org.slf4j.Logger;
import java.io.IOException;
import java.nio.file.Path;
public class T2CodeVMain {
@Getter
private static ProxyServer server;
@Getter
private static Logger logger;
@Getter
private PluginContainer plugin;
@Getter
private final long starttime;
@Getter
private static Path dataDirectory;
private final Metrics.Factory metricsFactory;
public static final MinecraftChannelIdentifier bcmd = MinecraftChannelIdentifier.from("t2c:bcmd");
public static final MinecraftChannelIdentifier bonlp = MinecraftChannelIdentifier.from("t2c:bonlp");
public static final MinecraftChannelIdentifier cguiopl = MinecraftChannelIdentifier.from("t2c:cguiopl");
public static final MinecraftChannelIdentifier aresp = MinecraftChannelIdentifier.from("t2c:aresp");
public static final MinecraftChannelIdentifier opsec = MinecraftChannelIdentifier.from("t2c:opsec");
@Inject
public T2CodeVMain(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory, Metrics.Factory metricsFactory) {
starttime = System.currentTimeMillis();
T2CodeVMain.server = server;
T2CodeVMain.logger = logger;
T2CodeVMain.dataDirectory = dataDirectory;
this.metricsFactory = metricsFactory;
}
@Subscribe
public void onLoad(ProxyInitializeEvent e) {
new pl(this, server);
logger.info("╔════════════════════════════════════");
// logger.info("║");
for (String s : Util.getLoadLogo()) {
logger.info("║ {}", s);
}
logger.info("");
// Thread.sleep(5000);
logger.info("║ Author: {}", String.valueOf(plugin.getDescription().getAuthors()).replace("[", "").replace("]", ""));
logger.info("║ Version: {}", plugin.getDescription().getVersion().orElse("unknown"));
logger.info("║ Spigot: {}", Util.getSpigot());
logger.info("║ Discord: {}", Util.getDiscord());
try {
T2CVlibConfig.set(dataDirectory, logger);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
// new T2CVcmd(server, logger);
// server.getEventManager().register(this, new T2CVpluginMessagingCmd(server, logger));
//API
server.getEventManager().register(this, new T2CVplmsgCmd(server, logger));
server.getChannelRegistrar().register(T2CodeVMain.bonlp);
T2CVPlayers.sendToSpigotDeleteAll();
if ((boolean) T2CVlibConfig.VALUES.apiCommandGUIEnable.getValue()) {
server.getEventManager().register(this, new T2CVapiCGUI(server, logger));
T2CVapiCGUI.sendToSpigotDeleteAll();
}
if ((boolean) T2CVlibConfig.VALUES.apiAutoResponse.getValue()) {
server.getEventManager().register(this, new T2CVapiAutoResponse(server, logger));
}
if ((boolean) T2CVlibConfig.VALUES.apiOpSecurity.getValue()) {
server.getEventManager().register(this, new T2CVapiOpSecurity(server, logger));
}
Metrics.bStats(this, Util.getBstatsID(), metricsFactory);
T2CVupdateAPI.onUpdateCheckTimer(logger, plugin, server, Util.getVPrefix(), Util.getDiscord(), Util.getSpigotID(), Util.getGit());
logger.info("");
logger.info("║ Plugin loaded successfully - {}ms", System.currentTimeMillis() - starttime);
logger.info("╚════════════════════════════════════");
}
public class pl {
public pl(Object pl, ProxyServer server) {
plugin = server.getPluginManager().fromInstance(pl)
.orElseThrow(() -> new IllegalArgumentException("The provided instance is not a plugin"));
}
}
}