Skip to content

Commit

Permalink
Ver 0.8.1-Beta.2: Hey, What's wrong with you?
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiroiame-Kusu committed Feb 26, 2024
1 parent 6daefd8 commit e02aa46
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 40 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>icu.nyat.Kusunoki</groupId>
<artifactId>NyatLib</artifactId>
<version>0.7.0-Beta.1</version>
<version>0.8.1-Beta.2</version>

<packaging>jar</packaging>

Expand Down Expand Up @@ -141,7 +141,7 @@
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.0.0</version>
<version>5.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
36 changes: 24 additions & 12 deletions src/main/java/icu/nyat/kusunoki/NyatLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,64 @@
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;

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);
Expand All @@ -71,7 +81,9 @@ public void onEnable(){
@Override
public void onDisable() {
// Plugin shutdown logic
brandUpdater.stop();
if(brandUpdater != null){
brandUpdater.stop();
}
NyatLibOnDisable.DisableStep();
}
}
4 changes: 1 addition & 3 deletions src/main/java/icu/nyat/kusunoki/NyatLibCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.netty.buffer.Unpooled;



import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
Expand Down Expand Up @@ -47,8 +46,7 @@ public NyatLibCore(NyatLib plugin, List<String> 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);

Expand Down
46 changes: 27 additions & 19 deletions src/main/java/icu/nyat/kusunoki/NyatLibOnEnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
1 change: 0 additions & 1 deletion src/main/java/icu/nyat/kusunoki/motd/PingEventPaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
@RequiredArgsConstructor
public class PingEventPaper implements Listener, StatusPingListener {
private final NyatLib plugin;

@EventHandler
public void onPing(PaperServerListPingEvent event) {
handle(wrap(event));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public interface StatusPingListener {

default void handle(StatusPing ping) {
Set<UUID> 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<String> supportedProtocols = new ArrayList<>();
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
default:
ServerName: "§bNyatwork"
ServerVersion: "§d1.21.0-Pre1"
ServerProtocolVersion: -1
1 change: 0 additions & 1 deletion src/main/resources/subversion.yml

This file was deleted.

0 comments on commit e02aa46

Please sign in to comment.