Skip to content

Commit

Permalink
Ver 0.10.1-Beta.2: Removed unused dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiroiame-Kusu committed Jul 2, 2024
1 parent 8dc456c commit c852767
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 270 deletions.
15 changes: 2 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

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

<packaging>jar</packaging>

<name>NyatLib</name>

<description>A Plugin Lib of Kusunoki</description>
<properties>
<java.version>1.8</java.version>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mc.subversion>1.22.0 Pre1</mc.subversion>
</properties>
Expand Down Expand Up @@ -125,11 +125,6 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.15.2</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -162,11 +157,5 @@
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5-fluent</artifactId>
<version>5.2.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
14 changes: 14 additions & 0 deletions src/main/java/icu/nyat/kusunoki/Action/NyatLibOnDisable.java
Original file line number Diff line number Diff line change
@@ -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!");
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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");
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package icu.nyat.kusunoki.utils;
package icu.nyat.kusunoki.Command;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand Down
62 changes: 36 additions & 26 deletions src/main/java/icu/nyat/kusunoki/NyatLib.java
Original file line number Diff line number Diff line change
@@ -1,62 +1,57 @@
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<Integer> 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());
}
}

@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<Integer>) 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();
}
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) {
Expand All @@ -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);
Expand All @@ -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("==========================================================================================");

}
}
9 changes: 1 addition & 8 deletions src/main/java/icu/nyat/kusunoki/NyatLibCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -45,13 +45,6 @@ public NyatLibCore(List<String> 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");
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/icu/nyat/kusunoki/NyatLibInit.java

This file was deleted.

9 changes: 0 additions & 9 deletions src/main/java/icu/nyat/kusunoki/NyatLibOnDisable.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/icu/nyat/kusunoki/Utils/ConfigReader.java
Original file line number Diff line number Diff line change
@@ -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<Integer>) config.get("default.ServerSupportedProtocolVersion");
NyatLib.isBroadcastEnabled = config.getBoolean("default.EnableBroadcast");
}
}
25 changes: 25 additions & 0 deletions src/main/java/icu/nyat/kusunoki/Utils/HttpUtil.java
Original file line number Diff line number Diff line change
@@ -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();
}

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

@EventHandler
public void onPing(PaperServerListPingEvent event) {
handle(wrap(event));
Expand Down
Loading

0 comments on commit c852767

Please sign in to comment.