SilkyFalcon

Generation

code to explanationWed, 23 Nov 2022

package dev.inventex.queuesystem; import com.google.inject.Inject; import com.moandjiezana.toml.Toml; import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.command.CommandMeta; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.ProxyServer; import dev.inventex.queuesystem.modules.QueueCommand; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; @Plugin(id = "queuesystem", name = "QueueSystem", version = "1.0-SNAPSHOT", url = "inventex.dev", authors = {"SilkyFalcon"}) public class QueueSystem { private static Logger logger; private static ProxyServer server; private static Path path; private static Toml toml; @Inject public QueueSystem(@NotNull Logger logger, ProxyServer server, @DataDirectory Path path) { QueueSystem.logger = logger; QueueSystem.server = server; QueueSystem.path = path; logger.info("[VelocityQueue] Started!"); } @Subscribe public void onProxyInitialization(ProxyInitializeEvent event) { toml = new Toml().read(loadTomlFile()); CommandManager commandManager = server.getCommandManager(); CommandMeta commandMeta = commandManager.metaBuilder("queue").build(); commandManager.register(commandMeta, new QueueCommand()); } public @Nullable File loadTomlFile() { final File file = new File(path.toFile() + "/config.toml"); if (path.toFile().exists()) return file; path.toFile().mkdirs(); if (file.exists()) return file; try (InputStream inputStream = getClass().getResourceAsStream("/" + file.getName())) { if (inputStream == null) return null; Files.copy(inputStream, file.toPath()); } catch (IOException e) { e.printStackTrace(); } return file; } public static Toml getToml() { return toml; } public static ProxyServer getServer() { return server; } public static Logger getLogger() { return logger; } }

package dev.inventex.queuesystem; import com.google.inject.Inject; import com.moandjiezana.toml.Toml; import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.command.CommandMeta; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.ProxyServer; import dev.inventex.queuesystem.modules.QueueCommand; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files;

Questions about programming?Chat with your personal AI assistant