diff --git a/pom.xml b/pom.xml index d020a31..7219d79 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ icu.nyat.Kusunoki NyatLib - 0.10.1-Beta.1 + 0.10.1-Beta.2 jar @@ -14,7 +14,7 @@ A Plugin Lib of Kusunoki - 1.8 + 21 UTF-8 1.22.0 Pre1 @@ -125,11 +125,6 @@ org.projectlombok lombok 1.18.28 - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - 2.15.2 compile @@ -162,11 +157,5 @@ 3.0.0 provided - - org.apache.httpcomponents.client5 - httpclient5-fluent - 5.2.1 - compile - diff --git a/src/main/java/icu/nyat/kusunoki/Action/NyatLibOnDisable.java b/src/main/java/icu/nyat/kusunoki/Action/NyatLibOnDisable.java new file mode 100644 index 0000000..5c3272d --- /dev/null +++ b/src/main/java/icu/nyat/kusunoki/Action/NyatLibOnDisable.java @@ -0,0 +1,14 @@ +package icu.nyat.kusunoki.Action; + +import icu.nyat.kusunoki.Utils.NyatLibLogger; + +import static icu.nyat.kusunoki.NyatLib.brandUpdater; + +public class NyatLibOnDisable { + public static void DisableStep(){ + if(brandUpdater != null){ + brandUpdater.stop(); + } + NyatLibLogger.logINFO("Goodbye!"); + } +} diff --git a/src/main/java/icu/nyat/kusunoki/NyatLibOnEnable.java b/src/main/java/icu/nyat/kusunoki/Action/NyatLibOnEnable.java similarity index 57% rename from src/main/java/icu/nyat/kusunoki/NyatLibOnEnable.java rename to src/main/java/icu/nyat/kusunoki/Action/NyatLibOnEnable.java index c4799aa..2ff831b 100644 --- a/src/main/java/icu/nyat/kusunoki/NyatLibOnEnable.java +++ b/src/main/java/icu/nyat/kusunoki/Action/NyatLibOnEnable.java @@ -1,14 +1,9 @@ -package icu.nyat.kusunoki; +package icu.nyat.kusunoki.Action; -import icu.nyat.kusunoki.utils.HttpUtil; -import icu.nyat.kusunoki.utils.NyatLibLogger; - -import java.io.InputStream; - -import static icu.nyat.kusunoki.utils.NyatLibYAMLPraser.getStringByInputStream; +import icu.nyat.kusunoki.NyatLib; +import icu.nyat.kusunoki.Utils.HttpUtil; +import icu.nyat.kusunoki.Utils.NyatLibLogger; import static org.bukkit.Bukkit.getServer; - -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.Plugin; public class NyatLibOnEnable { @@ -18,7 +13,7 @@ public class NyatLibOnEnable { public static String SubMCVersion; public boolean isProtocolLibInstalled; NyatLibLogger Logger = new NyatLibLogger(); - public void Fetch(){ + public void Check(){ Logger.logINFO("§3Powered By " + author); Logger.logINFO("§3Website: " + website); isProtocolLibInstalled = getServer().getPluginManager().isPluginEnabled("ProtocolLib"); @@ -30,21 +25,13 @@ public void Fetch(){ }else{ Logger.logWARN("You are using an untested ProtocolLib version!"); } - //InputStream subversion = plugin.getResource("subversion.yml"); - //String SubMCVersion = getStringByInputStream(subversion); - Logger.logINFO("Check for network access......"); - Thread FetchHitokoto = new Thread(() -> { - - String Hitokoto = new HttpUtil().get("https://v1.hitokoto.cn/?encode=text&charset=utf-8&max_length=20"); - if(Hitokoto == null){ - Logger.logWARN("Cannot connect to Internet, Please check your network connection!"); - }else{ - Logger.logINFO("Daily Saying from Hitokoto: " + Hitokoto); - } - }); - - Logger.logINFO("§3Current NyatWork Version is: " + NyatLib.BrandVersion + "§f"); + try{ + String Hitokoto = new HttpUtil().Fetch("https://v1.hitokoto.cn/?encode=text&charset=utf-8&max_length=20"); + Logger.logINFO("Daily Saying from Hitokoto: " + Hitokoto); + }catch (Exception ignored){ + Logger.logWARN("Cannot connect to Internet, Please check your network connection!"); + } }else{ plugin.onDisable(); diff --git a/src/main/java/icu/nyat/kusunoki/utils/ReloadCmd.java b/src/main/java/icu/nyat/kusunoki/Command/ReloadCmd.java similarity index 94% rename from src/main/java/icu/nyat/kusunoki/utils/ReloadCmd.java rename to src/main/java/icu/nyat/kusunoki/Command/ReloadCmd.java index 823eb0d..1459a25 100644 --- a/src/main/java/icu/nyat/kusunoki/utils/ReloadCmd.java +++ b/src/main/java/icu/nyat/kusunoki/Command/ReloadCmd.java @@ -1,4 +1,4 @@ -package icu.nyat.kusunoki.utils; +package icu.nyat.kusunoki.Command; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; diff --git a/src/main/java/icu/nyat/kusunoki/NyatLib.java b/src/main/java/icu/nyat/kusunoki/NyatLib.java index b9014db..b0c45ad 100644 --- a/src/main/java/icu/nyat/kusunoki/NyatLib.java +++ b/src/main/java/icu/nyat/kusunoki/NyatLib.java @@ -1,36 +1,37 @@ package icu.nyat.kusunoki; -import icu.nyat.kusunoki.utils.NyatLibLogger; -import icu.nyat.kusunoki.utils.ReloadCmd; -import icu.nyat.kusunoki.packet.*; +import icu.nyat.kusunoki.Action.NyatLibOnDisable; +import icu.nyat.kusunoki.Action.NyatLibOnEnable; +import icu.nyat.kusunoki.Utils.ConfigReader; +import icu.nyat.kusunoki.Utils.NyatLibLogger; +import icu.nyat.kusunoki.Command.ReloadCmd; +import icu.nyat.kusunoki.Packet.*; import icu.nyat.kusunoki.motd.PingEventPaper; import icu.nyat.kusunoki.motd.PingEventSpigot; import io.papermc.lib.PaperLib; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import java.util.ArrayList; import java.util.Collections; +import java.util.Objects; public final class NyatLib extends JavaPlugin { public static final String BRAND = "minecraft:brand"; private String PluginVersion = this.getDescription().getVersion(); - private NyatLibCore brandUpdater; + public static NyatLibCore brandUpdater; public static String BrandName; public static String BrandVersion; public static int BrandProtocolVersion; public static ArrayList ServerSupportedProtocolVersion; - public static boolean EnableBroadcast; + public static boolean isBroadcastEnabled; @Override public void onLoad(){ - NyatLibLogger Logger = new NyatLibLogger(); - NyatLibInit LibInit = new NyatLibInit(); try { - LibInit.initial(); - Logger.logLoader("NyatLib Version:" + PluginVersion); + initial(); + NyatLibLogger.logLoader("NyatLib Version:" + PluginVersion); }catch (Exception ex){ NyatLibLogger.logERROR(ex.toString()); } @@ -38,16 +39,11 @@ public void onLoad(){ @Override public void onEnable(){ - NyatLibLogger Logger = new NyatLibLogger(); - NyatLibOnEnable ResourceFetch = new NyatLibOnEnable(); - FileConfiguration config = getConfig(); - NyatLib.BrandName = config.getString("default.ServerName"); - NyatLib.BrandVersion = config.getString("default.ServerVersion"); - NyatLib.BrandProtocolVersion = (int)config.get("default.ServerProtocolVersion"); - NyatLib.ServerSupportedProtocolVersion = (ArrayList) config.get("default.ServerSupportedProtocolVersion"); - NyatLib.EnableBroadcast = config.getBoolean("default.EnableBroadcast"); + NyatLibOnEnable EnableStep = new NyatLibOnEnable(); + ConfigReader.Read(getConfig()); try { - ResourceFetch.Fetch(); + EnableStep.Check(); + NyatLibLogger.logINFO("§3Current NyatWork Version is: " + NyatLib.BrandVersion + "§f"); }catch(Exception e){ NyatLibLogger.logERROR(e.toString()); onDisable(); @@ -55,8 +51,7 @@ public void onEnable(){ ProtocolManager manager = ProtocolLibrary.getProtocolManager(); try{ - NyatLibLogger.logINFO(EnableBroadcast ? "true" : "false"); - if(EnableBroadcast){ + if(isBroadcastEnabled){ brandUpdater = new NyatLibCore(Collections.singletonList(BrandName + " " + BrandVersion + "§f"),100,manager); } } catch (Exception e) { @@ -68,10 +63,10 @@ public void onEnable(){ manager.addPacketListener(new PacketListener(this, brandUpdater)); try { - this.getCommand("nlreload").setExecutor(new ReloadCmd(this)); + Objects.requireNonNull(this.getCommand("nlreload")).setExecutor(new ReloadCmd(this)); }catch (Exception ignored){} - new PlayerListener(this, this.brandUpdater).register(); + new PlayerListener(this, brandUpdater).register(); if (brandUpdater.size() > 0) brandUpdater.broadcast(); if (brandUpdater.size() > 1) brandUpdater.start(); NyatLib plugin = NyatLib.getPlugin(NyatLib.class); @@ -88,9 +83,24 @@ public void onEnable(){ @Override public void onDisable() { // Plugin shutdown logic - if(brandUpdater != null){ - brandUpdater.stop(); - } NyatLibOnDisable.DisableStep(); } + public static void initial(){ + NyatLibLogger.logINFO("=========================================================================================="); + NyatLibLogger.logINFO(""); + NyatLibLogger.logINFO("@@@@@@^ @@@@^ =@@@@^ =@@@@^ @@@@@ =@@@@"); + NyatLibLogger.logINFO("@@@@@@@\\ @@@@^ =@@@@^ =@@@@^ =@@@@"); + NyatLibLogger.logINFO("@@@@@@@@\\ @@@@^.@@@@\\ @@@@/ O@@@@@@@@@` @@@@@@@@@@.=@@@@^ O@@@O =@@@@/@@@@@@`"); + NyatLibLogger.logINFO("@@@@^@@@@@.@@@@^ ,@@@@^ =@@@@. O@@[[[\\@@@@^ \\@@@@@@OOO.=@@@@^ O@@@O =@@@@@@@@@@@@`"); + NyatLibLogger.logINFO("@@@@^.@@@@@@@@@^ =@@@@`.@@@@^ .,]/@@@@@@@ =@@@@^ =@@@@^ O@@@O =@@@@ .@@@@^"); + NyatLibLogger.logINFO("@@@@^ \\@@@@@@@^ \\@@@@/@@@^ ,@@@@@@@@@@@@ =@@@@^ =@@@@^ O@@@O =@@@@ @@@@O"); + NyatLibLogger.logINFO("@@@@^ \\@@@@@@^ .@@@@@@@@ @@@@@ =@@@@ =@@@@^ =@@@@^ O@@@O =@@@@ ,@@@@^"); + NyatLibLogger.logINFO("@@@@^ =@@@@@^ ,@@@@@@. =@@@@@@@@@@@@ .@@@@@@@@.=@@@@@@@@@@@O O@@@O =@@@@@@@@@@@/"); + NyatLibLogger.logINFO("@@@@^ =@@@@^ =@@@@^ ,@@@@@/=@@@@ .\\@@@@@@.=@@@@@@@@@@@O O@@@O =@@@@\\@@@@/`"); + NyatLibLogger.logINFO(" ,@@@@/"); + NyatLibLogger.logINFO(" .@@@@@"); + NyatLibLogger.logINFO(""); + NyatLibLogger.logINFO("=========================================================================================="); + + } } diff --git a/src/main/java/icu/nyat/kusunoki/NyatLibCore.java b/src/main/java/icu/nyat/kusunoki/NyatLibCore.java index e67e326..9f7d565 100644 --- a/src/main/java/icu/nyat/kusunoki/NyatLibCore.java +++ b/src/main/java/icu/nyat/kusunoki/NyatLibCore.java @@ -5,7 +5,7 @@ import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.injector.netty.WirePacket; -import icu.nyat.kusunoki.utils.NyatLibLogger; +import icu.nyat.kusunoki.Utils.NyatLibLogger; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -45,13 +45,6 @@ public NyatLibCore(List brand, long period, ProtocolManager manager) thr this.brand = brand; this.period = period; this.manager = manager; - /*String serverVersion = String.valueOf(MinecraftVersion.getCurrentVersion()); - - NyatLibLogger.logINFO(serverVersion); - String[] versionParts = serverVersion.split(" ")[2].split("\\."); - int majorVersion = Integer.parseInt(versionParts[0]); - int minorVersion = Integer.parseInt(versionParts[1]); - int revision = Integer.parseInt(versionParts[2]);*/ this.pdscl = Class.forName("net.minecraft.network.PacketDataSerializer"); try{ Class class_PacketPlayOutCustomPayload = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutCustomPayload"); diff --git a/src/main/java/icu/nyat/kusunoki/NyatLibInit.java b/src/main/java/icu/nyat/kusunoki/NyatLibInit.java deleted file mode 100644 index d2da051..0000000 --- a/src/main/java/icu/nyat/kusunoki/NyatLibInit.java +++ /dev/null @@ -1,27 +0,0 @@ -package icu.nyat.kusunoki; - - -import icu.nyat.kusunoki.utils.NyatLibLogger; - -public class NyatLibInit { - public void initial(){ - NyatLibLogger.logINFO("=========================================================================================="); - NyatLibLogger.logINFO(""); - NyatLibLogger.logINFO("@@@@@@^ @@@@^ =@@@@^ =@@@@^ @@@@@ =@@@@"); - NyatLibLogger.logINFO("@@@@@@@\\ @@@@^ =@@@@^ =@@@@^ =@@@@"); - NyatLibLogger.logINFO("@@@@@@@@\\ @@@@^.@@@@\\ @@@@/ O@@@@@@@@@` @@@@@@@@@@.=@@@@^ O@@@O =@@@@/@@@@@@`"); - NyatLibLogger.logINFO("@@@@^@@@@@.@@@@^ ,@@@@^ =@@@@. O@@[[[\\@@@@^ \\@@@@@@OOO.=@@@@^ O@@@O =@@@@@@@@@@@@`"); - NyatLibLogger.logINFO("@@@@^.@@@@@@@@@^ =@@@@`.@@@@^ .,]/@@@@@@@ =@@@@^ =@@@@^ O@@@O =@@@@ .@@@@^"); - NyatLibLogger.logINFO("@@@@^ \\@@@@@@@^ \\@@@@/@@@^ ,@@@@@@@@@@@@ =@@@@^ =@@@@^ O@@@O =@@@@ @@@@O"); - NyatLibLogger.logINFO("@@@@^ \\@@@@@@^ .@@@@@@@@ @@@@@ =@@@@ =@@@@^ =@@@@^ O@@@O =@@@@ ,@@@@^"); - NyatLibLogger.logINFO("@@@@^ =@@@@@^ ,@@@@@@. =@@@@@@@@@@@@ .@@@@@@@@.=@@@@@@@@@@@O O@@@O =@@@@@@@@@@@/"); - NyatLibLogger.logINFO("@@@@^ =@@@@^ =@@@@^ ,@@@@@/=@@@@ .\\@@@@@@.=@@@@@@@@@@@O O@@@O =@@@@\\@@@@/`"); - NyatLibLogger.logINFO(" ,@@@@/"); - NyatLibLogger.logINFO(" .@@@@@"); - NyatLibLogger.logINFO(""); - NyatLibLogger.logINFO("=========================================================================================="); - - } - - -} diff --git a/src/main/java/icu/nyat/kusunoki/NyatLibOnDisable.java b/src/main/java/icu/nyat/kusunoki/NyatLibOnDisable.java deleted file mode 100644 index 62d56d3..0000000 --- a/src/main/java/icu/nyat/kusunoki/NyatLibOnDisable.java +++ /dev/null @@ -1,9 +0,0 @@ -package icu.nyat.kusunoki; - -import icu.nyat.kusunoki.utils.NyatLibLogger; - -public class NyatLibOnDisable { - public static void DisableStep(){ - NyatLibLogger.logINFO("Goodbye!"); - } -} diff --git a/src/main/java/icu/nyat/kusunoki/packet/PacketListener.java b/src/main/java/icu/nyat/kusunoki/Packet/PacketListener.java similarity index 95% rename from src/main/java/icu/nyat/kusunoki/packet/PacketListener.java rename to src/main/java/icu/nyat/kusunoki/Packet/PacketListener.java index 54c81fb..cfcfd25 100644 --- a/src/main/java/icu/nyat/kusunoki/packet/PacketListener.java +++ b/src/main/java/icu/nyat/kusunoki/Packet/PacketListener.java @@ -1,4 +1,4 @@ -package icu.nyat.kusunoki.packet; +package icu.nyat.kusunoki.Packet; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.ListenerPriority; @@ -9,7 +9,7 @@ import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.MinecraftKey; -import icu.nyat.kusunoki.utils.NyatLibLogger; +import icu.nyat.kusunoki.Utils.NyatLibLogger; import io.netty.buffer.ByteBuf; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/icu/nyat/kusunoki/packet/PlayerListener.java b/src/main/java/icu/nyat/kusunoki/Packet/PlayerListener.java similarity index 92% rename from src/main/java/icu/nyat/kusunoki/packet/PlayerListener.java rename to src/main/java/icu/nyat/kusunoki/Packet/PlayerListener.java index bfa370e..2714374 100644 --- a/src/main/java/icu/nyat/kusunoki/packet/PlayerListener.java +++ b/src/main/java/icu/nyat/kusunoki/Packet/PlayerListener.java @@ -1,8 +1,7 @@ -package icu.nyat.kusunoki.packet; +package icu.nyat.kusunoki.Packet; import icu.nyat.kusunoki.NyatLib; import icu.nyat.kusunoki.NyatLibCore; -import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; diff --git a/src/main/java/icu/nyat/kusunoki/Utils/ConfigReader.java b/src/main/java/icu/nyat/kusunoki/Utils/ConfigReader.java new file mode 100644 index 0000000..581fac9 --- /dev/null +++ b/src/main/java/icu/nyat/kusunoki/Utils/ConfigReader.java @@ -0,0 +1,16 @@ +package icu.nyat.kusunoki.Utils; + +import icu.nyat.kusunoki.NyatLib; +import org.bukkit.configuration.file.FileConfiguration; + +import java.util.ArrayList; + +public class ConfigReader { + public static void Read(FileConfiguration config){ + NyatLib.BrandName = config.getString("default.ServerName"); + NyatLib.BrandVersion = config.getString("default.ServerVersion"); + NyatLib.BrandProtocolVersion = (int)config.get("default.ServerProtocolVersion"); + NyatLib.ServerSupportedProtocolVersion = (ArrayList) config.get("default.ServerSupportedProtocolVersion"); + NyatLib.isBroadcastEnabled = config.getBoolean("default.EnableBroadcast"); + } +} diff --git a/src/main/java/icu/nyat/kusunoki/Utils/HttpUtil.java b/src/main/java/icu/nyat/kusunoki/Utils/HttpUtil.java new file mode 100644 index 0000000..c6923c0 --- /dev/null +++ b/src/main/java/icu/nyat/kusunoki/Utils/HttpUtil.java @@ -0,0 +1,25 @@ +package icu.nyat.kusunoki.Utils; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +public class HttpUtil { + public String Fetch(String urlString) throws Exception { + StringBuilder result = new StringBuilder(); + URL url = new URL(urlString); + HttpURLConnection HttpRequest = (HttpURLConnection) url.openConnection(); + HttpRequest.setRequestMethod("GET"); + HttpRequest.setConnectTimeout(2000); + HttpRequest.setReadTimeout(3000); + BufferedReader reader = new BufferedReader(new InputStreamReader(HttpRequest.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + result.append(line); + } + reader.close(); + return result.toString(); + } + +} \ No newline at end of file diff --git a/src/main/java/icu/nyat/kusunoki/utils/NyatLibLogger.java b/src/main/java/icu/nyat/kusunoki/Utils/NyatLibLogger.java similarity index 83% rename from src/main/java/icu/nyat/kusunoki/utils/NyatLibLogger.java rename to src/main/java/icu/nyat/kusunoki/Utils/NyatLibLogger.java index 2c8c3a8..5ca201d 100644 --- a/src/main/java/icu/nyat/kusunoki/utils/NyatLibLogger.java +++ b/src/main/java/icu/nyat/kusunoki/Utils/NyatLibLogger.java @@ -1,13 +1,8 @@ -package icu.nyat.kusunoki.utils; +package icu.nyat.kusunoki.Utils; import icu.nyat.kusunoki.NyatLib; -import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; - import java.util.logging.Level; - -import org.bukkit.ChatColor; -import org.bukkit.event.server.*; public class NyatLibLogger { //public Level.ERROR = new Level(""); public static final Plugin plugin = NyatLib.getPlugin(NyatLib.class); diff --git a/src/main/java/icu/nyat/kusunoki/motd/PingEventPaper.java b/src/main/java/icu/nyat/kusunoki/motd/PingEventPaper.java index 9194573..b61b4fd 100644 --- a/src/main/java/icu/nyat/kusunoki/motd/PingEventPaper.java +++ b/src/main/java/icu/nyat/kusunoki/motd/PingEventPaper.java @@ -19,6 +19,7 @@ @RequiredArgsConstructor public class PingEventPaper implements Listener, StatusPingListener { private final NyatLib plugin; + @EventHandler public void onPing(PaperServerListPingEvent event) { handle(wrap(event)); diff --git a/src/main/java/icu/nyat/kusunoki/motd/PingEventSpigot.java b/src/main/java/icu/nyat/kusunoki/motd/PingEventSpigot.java index 4d09eff..3dc8845 100644 --- a/src/main/java/icu/nyat/kusunoki/motd/PingEventSpigot.java +++ b/src/main/java/icu/nyat/kusunoki/motd/PingEventSpigot.java @@ -8,11 +8,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.server.ServerListPingEvent; -import org.bukkit.util.CachedServerIcon; - import java.net.InetSocketAddress; import java.util.Optional; -import java.util.UUID; @Getter @RequiredArgsConstructor diff --git a/src/main/java/icu/nyat/kusunoki/motd/shared/StatusPingListener.java b/src/main/java/icu/nyat/kusunoki/motd/shared/StatusPingListener.java index b77b4d4..7a349b7 100644 --- a/src/main/java/icu/nyat/kusunoki/motd/shared/StatusPingListener.java +++ b/src/main/java/icu/nyat/kusunoki/motd/shared/StatusPingListener.java @@ -1,16 +1,8 @@ package icu.nyat.kusunoki.motd.shared; import icu.nyat.kusunoki.NyatLib; - -import java.io.InputStream; -import java.net.InetSocketAddress; import java.util.*; -import java.util.stream.Collectors; - -import icu.nyat.kusunoki.utils.NyatLibLogger; -import static icu.nyat.kusunoki.utils.NyatLibYAMLPraser.getStringByInputStream; -import static org.bukkit.Bukkit.getServer; - +import icu.nyat.kusunoki.Utils.NyatLibLogger; import org.bukkit.plugin.Plugin; public interface StatusPingListener { @@ -19,7 +11,6 @@ public interface StatusPingListener { default void handle(StatusPing ping) { ping.setVersionName("Nyatwork " + NyatLib.BrandVersion); ping.setVersionProtocol(NyatLib.BrandProtocolVersion); - List supportedProtocols = new ArrayList<>(); try { NyatLib.ServerSupportedProtocolVersion.add(NyatLib.BrandProtocolVersion); diff --git a/src/main/java/icu/nyat/kusunoki/utils/HttpUtil.java b/src/main/java/icu/nyat/kusunoki/utils/HttpUtil.java deleted file mode 100644 index 575a3a0..0000000 --- a/src/main/java/icu/nyat/kusunoki/utils/HttpUtil.java +++ /dev/null @@ -1,38 +0,0 @@ -package icu.nyat.kusunoki.utils; - -import icu.nyat.kusunoki.utils.NyatLibLogger; - -import java.io.Closeable; -import java.io.IOException; -import java.util.concurrent.Future; - -import org.apache.hc.client5.http.fluent.Request; -import org.apache.hc.client5.http.fluent.Response; -import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; -import org.apache.hc.core5.concurrent.FutureCallback; -import org.apache.hc.core5.function.Supplier; -import org.apache.hc.core5.http.HttpHost; -import org.apache.hc.core5.http.nio.AsyncPushConsumer; -import org.apache.hc.core5.http.nio.AsyncRequestProducer; -import org.apache.hc.core5.http.nio.AsyncResponseConsumer; -import org.apache.hc.core5.http.nio.HandlerFactory; -import org.apache.hc.core5.http.protocol.HttpContext; -import org.apache.hc.core5.io.CloseMode; -import org.apache.hc.core5.reactor.IOReactorStatus; -import org.apache.hc.core5.util.TimeValue; -import org.apache.hc.core5.util.Timeout; - -public class HttpUtil { - NyatLibLogger Logger = new NyatLibLogger(); - public String get(String url) { - String result = null; - try { - Response response = Request.get(url).responseTimeout(Timeout.ofSeconds(3)).execute(); - result = response.returnContent().asString(); - } catch (Exception e) { - Logger.logERROR(e.toString()); - } - return result; - } - -} \ No newline at end of file diff --git a/src/main/java/icu/nyat/kusunoki/utils/NyatLibYAMLPraser.java b/src/main/java/icu/nyat/kusunoki/utils/NyatLibYAMLPraser.java deleted file mode 100644 index d0ce8aa..0000000 --- a/src/main/java/icu/nyat/kusunoki/utils/NyatLibYAMLPraser.java +++ /dev/null @@ -1,101 +0,0 @@ -package icu.nyat.kusunoki.utils; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.IOException; -import java.util.Map; -import java.util.HashMap; -public class NyatLibYAMLPraser { - public static String getStringByInputStream(InputStream inputStream){ - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); - try { - StringBuilder result = new StringBuilder(); - String line; - while ((line = bufferedReader.readLine()) != null) { - result.append(line); - } - return result.toString(); - } catch (Exception e) { - NyatLibLogger.logERROR(e.getMessage()); - try { - inputStream.close(); - bufferedReader.close(); - } catch (Exception e1) { - NyatLibLogger.logERROR(e1.getMessage()); - } - } - return null; - } - - public static String getYmlValue(String ymlPath,String cronName){ - ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); - InputStream input = null; - try { - input = new FileInputStream(ymlPath); - } catch (FileNotFoundException e) { - NyatLibLogger.logERROR(e.getMessage()); - return null; - } - Map map; - try { - map = objectMapper.readValue(input, Map.class); - } catch (IOException e) { - return null; - } - String[] split = cronName.split("\\."); - Map info = new HashMap(); - String cron = ""; - for (int i = 0; i < split.length; i++) { - if (i ==0) { - info = (Map) map.get(split[i]); - }else if(i==split.length-1){ - cron = (String) info.get(split[i]); - }else{ - info = (Map) info.get(split[i]); - } - if (info==null) { - return null; - } - - } - return cron; - } - public static String getPluginYmlValue(FileInputStream ymlPath,String cronName){ - ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); - /*try { - input = new FileInputStream(ymlPath); - } catch (FileNotFoundException e) { - NyatLibLogger.logERROR(e.getMessage()); - return null; - }*/ - Map map; - try { - map = objectMapper.readValue(ymlPath, Map.class); - } catch (IOException e) { - return null; - } - String[] split = cronName.split("\\."); - Map info = new HashMap(); - String cron = ""; - for (int i = 0; i < split.length; i++) { - if (i ==0) { - info = (Map) map.get(split[i]); - }else if(i==split.length-1){ - cron = (String) info.get(split[i]); - }else{ - info = (Map) info.get(split[i]); - } - if (info==null) { - return null; - } - - } - return cron; - } -}