diff --git a/pom.xml b/pom.xml index a43c55a..fa31035 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ icu.nyat.Kusunoki NyatLib - 0.7.0-Beta.1 + 0.8.1-Beta.2 jar @@ -141,7 +141,7 @@ com.comphenix.protocol ProtocolLib - 5.0.0 + 5.2.0-SNAPSHOT provided diff --git a/src/main/java/icu/nyat/kusunoki/NyatLib.java b/src/main/java/icu/nyat/kusunoki/NyatLib.java index 6df9a27..e439858 100644 --- a/src/main/java/icu/nyat/kusunoki/NyatLib.java +++ b/src/main/java/icu/nyat/kusunoki/NyatLib.java @@ -7,6 +7,8 @@ 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.Plugin; import org.bukkit.plugin.java.JavaPlugin; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; @@ -14,47 +16,55 @@ import java.util.Collections; public final class NyatLib extends JavaPlugin { - private static NyatLib Main; - private String version = this.getDescription().getVersion().toString(); + + + private String PluginVersion = this.getDescription().getVersion(); private NyatLibCore brandUpdater; + public static String BrandName; + public static String BrandVersion; + public static String BrandSubVersion; + @Override public void onLoad(){ NyatLibLogger Logger = new NyatLibLogger(); NyatLibInit LibInit = new NyatLibInit(); try { LibInit.initial(); - Logger.logLoader("NyatLib Version:" + version); + Logger.logLoader("NyatLib Version:" + PluginVersion); }catch (Exception ex){ NyatLibLogger.logERROR(ex.toString()); } - - } @Override public void onEnable(){ NyatLibLogger Logger = new NyatLibLogger(); - Main = this; NyatLibOnEnable ResourceFetch = new NyatLibOnEnable(); + FileConfiguration config = getConfig(); + NyatLib.BrandName = config.getString("default.ServerName"); + NyatLib.BrandVersion = config.getString("default.ServerVersion"); + NyatLib.BrandSubVersion = config.getString("default.ServerProtocolVersion"); try { ResourceFetch.Fetch(); }catch(Exception e){ - Logger.logERROR(e.toString()); + NyatLibLogger.logERROR(e.toString()); onDisable(); } ProtocolManager manager = ProtocolLibrary.getProtocolManager(); try{ - brandUpdater = new NyatLibCore(this, Collections.singletonList("§bNyatwork §d" + ResourceFetch.SubMCVersion + "§f"),100,manager); - } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) { + brandUpdater = new NyatLibCore(this, Collections.singletonList(BrandName + " " + BrandVersion + "§f"),100,manager); + } catch (Exception e) { NyatLibLogger.logERROR(e.getMessage()); + NyatLibLogger.logERROR(e.toString()); onDisable(); - return; } manager.addPacketListener(new PacketListener(this, brandUpdater)); - this.getCommand("nlreload").setExecutor(new ReloadCmd(this)); + try { + this.getCommand("nlreload").setExecutor(new ReloadCmd(this)); + }catch (Exception ignored){} new PlayerListener(this, this.brandUpdater).register(); NyatLib plugin = NyatLib.getPlugin(NyatLib.class); @@ -71,7 +81,9 @@ public void onEnable(){ @Override public void onDisable() { // Plugin shutdown logic - brandUpdater.stop(); + if(brandUpdater != null){ + brandUpdater.stop(); + } NyatLibOnDisable.DisableStep(); } } diff --git a/src/main/java/icu/nyat/kusunoki/NyatLibCore.java b/src/main/java/icu/nyat/kusunoki/NyatLibCore.java index c048ac9..54afd7c 100644 --- a/src/main/java/icu/nyat/kusunoki/NyatLibCore.java +++ b/src/main/java/icu/nyat/kusunoki/NyatLibCore.java @@ -10,7 +10,6 @@ import io.netty.buffer.Unpooled; - import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -47,8 +46,7 @@ public NyatLibCore(NyatLib plugin, List brand, long period, ProtocolMana this.manager = manager; this.class_PacketDataSerializer = Class.forName("net.minecraft.network.PacketDataSerializer"); - Class class_PacketPlayOutCustomPayload = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutCustomPayload"); - + Class class_PacketPlayOutCustomPayload = Class.forName("net.minecraft.network.packet.PacketPlayOutCustomPayload"); this.constructor_PacketPlayOutCustomPayload = class_PacketPlayOutCustomPayload.getConstructors()[0]; this.instance_MinecraftKey_Brand = class_PacketPlayOutCustomPayload.getField("a").get(null); diff --git a/src/main/java/icu/nyat/kusunoki/NyatLibOnEnable.java b/src/main/java/icu/nyat/kusunoki/NyatLibOnEnable.java index 79de010..ba3a53e 100644 --- a/src/main/java/icu/nyat/kusunoki/NyatLibOnEnable.java +++ b/src/main/java/icu/nyat/kusunoki/NyatLibOnEnable.java @@ -8,12 +8,13 @@ import static icu.nyat.kusunoki.utils.NyatLibYAMLPraser.getStringByInputStream; import static org.bukkit.Bukkit.getServer; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.Plugin; public class NyatLibOnEnable { public static final Plugin plugin = NyatLib.getPlugin(NyatLib.class); - private String author = plugin.getDescription().getVersion(); - private String website = plugin.getDescription().getWebsite(); + private final String author = plugin.getDescription().getVersion(); + private final String website = plugin.getDescription().getWebsite(); public static String SubMCVersion; public boolean isProtocolLibInstalled; @@ -22,25 +23,32 @@ public void Fetch(){ Logger.logINFO("§3Powered By " + author); Logger.logINFO("§3Website: " + website); isProtocolLibInstalled = getServer().getPluginManager().isPluginEnabled("ProtocolLib"); - String ProtocolLibVersionDescription = getServer().getPluginManager().getPlugin("ProtocolLib").toString(); - String ProtocolLibVersion = ProtocolLibVersionDescription.substring(ProtocolLibVersionDescription.length() - 5); - if(ProtocolLibVersion.equals("5.1.0")){ - Logger.logINFO("Seems that you have installed correct ProtocolLib version, continue..."); - }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!"); + if(isProtocolLibInstalled){ + String ProtocolLibVersionDescription = getServer().getPluginManager().getPlugin("ProtocolLib").toString(); + String ProtocolLibVersion = ProtocolLibVersionDescription.substring(ProtocolLibVersionDescription.length() - 5); + if(ProtocolLibVersion.equals("5.2.0")){ + Logger.logINFO("Seems that you have installed correct ProtocolLib version, continue..."); }else{ - Logger.logINFO("Daily Saying from Hitokoto: " + Hitokoto); + 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.BrandSubVersion); + + }else{ + plugin.onDisable(); + } - Logger.logINFO("§3Current NyatWork Version is: " + SubMCVersion); } } diff --git a/src/main/java/icu/nyat/kusunoki/motd/PingEventPaper.java b/src/main/java/icu/nyat/kusunoki/motd/PingEventPaper.java index b61b4fd..9194573 100644 --- a/src/main/java/icu/nyat/kusunoki/motd/PingEventPaper.java +++ b/src/main/java/icu/nyat/kusunoki/motd/PingEventPaper.java @@ -19,7 +19,6 @@ @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/shared/StatusPingListener.java b/src/main/java/icu/nyat/kusunoki/motd/shared/StatusPingListener.java index ddafb55..bfca15a 100644 --- a/src/main/java/icu/nyat/kusunoki/motd/shared/StatusPingListener.java +++ b/src/main/java/icu/nyat/kusunoki/motd/shared/StatusPingListener.java @@ -20,8 +20,7 @@ public interface StatusPingListener { default void handle(StatusPing ping) { Set vanished = new HashSet<>(); - InputStream subversion = plugin.getResource("subversion.yml"); - String SubMCVersion = getStringByInputStream(subversion); + String SubMCVersion = NyatLib.BrandSubVersion; ping.setVersionName("Nyatwork " + SubMCVersion); ping.setVersionProtocol(-1); List supportedProtocols = new ArrayList<>(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..0f17913 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,4 @@ +default: + ServerName: "§bNyatwork" + ServerVersion: "§d1.21.0-Pre1" + ServerProtocolVersion: -1 \ No newline at end of file diff --git a/src/main/resources/subversion.yml b/src/main/resources/subversion.yml deleted file mode 100644 index 751f8d1..0000000 --- a/src/main/resources/subversion.yml +++ /dev/null @@ -1 +0,0 @@ -${mc.subversion} \ No newline at end of file