perf: 优化代码
This commit is contained in:
@@ -40,7 +40,7 @@ subprojects {
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = 'UTF-8'
|
||||
options.setEncoding("UTF-8")
|
||||
}
|
||||
|
||||
tasks.withType(Jar) {
|
||||
@@ -50,7 +50,7 @@ subprojects {
|
||||
|
||||
javadoc {
|
||||
options.quiet()
|
||||
options.encoding = 'UTF-8'
|
||||
options.setEncoding("UTF-8")
|
||||
options.jFlags("-Dfile.encoding=utf8")
|
||||
options.addStringOption('Xdoclint:none', '-quiet')
|
||||
options.links = [
|
||||
|
@@ -8,6 +8,7 @@ dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT'
|
||||
|
||||
compileOnly "cn.hamster3.mc.plugin.core:bukkit:${hamster_core_version}"
|
||||
apiShade("me.clip:placeholderapi:2.11.2") { transitive = false }
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package cn.hamster3.mc.plugin.ball.bukkit;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.bukkit.api.BallBukkitAPI;
|
||||
import cn.hamster3.mc.plugin.ball.bukkit.hook.PlaceholderHook;
|
||||
import cn.hamster3.mc.plugin.ball.bukkit.listener.BallBukkitListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -39,6 +40,14 @@ public class HamsterBallPlugin extends JavaPlugin {
|
||||
Bukkit.getPluginManager().registerEvents(BallBukkitListener.INSTANCE, this);
|
||||
logger.info("已注册 BallBukkitListener.");
|
||||
logger.info("HamsterBall 已启动.");
|
||||
sync(() -> {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
PlaceholderHook.INSTANCE.register();
|
||||
logger.info("已挂载 PlaceholderAPI 变量!");
|
||||
} else {
|
||||
logger.warning("服务器未安装 PlaceholderAPI, 取消挂载变量!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -0,0 +1,55 @@
|
||||
package cn.hamster3.mc.plugin.ball.bukkit.hook;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PlaceholderHook extends PlaceholderExpansion {
|
||||
public static final PlaceholderHook INSTANCE = new PlaceholderHook();
|
||||
|
||||
private PlaceholderHook() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "hamster_ball";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "MiniDay";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
switch (params) {
|
||||
case "local_server_id": {
|
||||
return BallAPI.getInstance().getLocalServerInfo().getId();
|
||||
}
|
||||
case "local_server_name": {
|
||||
return BallAPI.getInstance().getLocalServerInfo().getName();
|
||||
}
|
||||
case "proxy_id": {
|
||||
return BallAPI.getInstance().getPlayerInfo(player.getUniqueId()).getProxyServer();
|
||||
}
|
||||
case "proxy_name": {
|
||||
String id = BallAPI.getInstance().getPlayerInfo(player.getUniqueId()).getProxyServer();
|
||||
return BallAPI.getInstance().getServerInfo(id).getName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String onPlaceholderRequest(Player player, @NotNull String params) {
|
||||
return onRequest(player, params);
|
||||
}
|
||||
}
|
@@ -7,5 +7,10 @@ author: MiniDay
|
||||
website: https://github.com/MiniDay/hamster-ball
|
||||
description: 仓鼠球:一个基于 Netty 的 Minecraft 服务端通用消息中间件(原HamsterService)
|
||||
|
||||
load: STARTUP
|
||||
|
||||
depend:
|
||||
- HamsterCore
|
||||
|
||||
softdepend:
|
||||
- PlaceholderAPI
|
||||
|
@@ -5,7 +5,7 @@ dependencies {
|
||||
//noinspection GradlePackageUpdate
|
||||
compileOnly 'com.google.code.gson:gson:2.8.0'
|
||||
// https://mvnrepository.com/artifact/io.netty/netty-all
|
||||
compileOnly 'io.netty:netty-all:4.1.84.Final'
|
||||
compileOnly 'io.netty:netty-all:4.1.82.Final'
|
||||
|
||||
compileOnly "cn.hamster3.mc.plugin.core:common:${hamster_core_version}"
|
||||
|
||||
|
@@ -14,7 +14,7 @@ dependencies {
|
||||
shade 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'
|
||||
|
||||
// https://mvnrepository.com/artifact/io.netty/netty-all
|
||||
implementationShade 'io.netty:netty-all:4.1.84.Final'
|
||||
implementationShade 'io.netty:netty-all:4.1.82.Final'
|
||||
// https://mvnrepository.com/artifact/org.yaml/snakeyaml
|
||||
implementationShade 'org.yaml:snakeyaml:1.33'
|
||||
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
||||
|
Reference in New Issue
Block a user