修复了在没有papi的情况下无法加载插件的bug
All checks were successful
Java CI-CD with Maven / build (push) Successful in 28m39s

This commit is contained in:
zhangyuheng 2024-06-27 16:24:57 +08:00
parent 706ea9a5a5
commit fc5f167587
6 changed files with 16 additions and 13 deletions

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId>
<artifactId>MiniPlayerTitle</artifactId>
<version>4.2.2</version>
<version>4.2.3</version>
<packaging>jar</packaging>
<name>MiniPlayerTitle</name>

View File

@ -10,7 +10,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import static cn.lunadeer.miniplayertitle.Expansion.isPapi;
import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
import static cn.lunadeer.miniplayertitle.commands.Apis.updateName;
public class Events implements Listener {
@ -39,7 +39,7 @@ public class Events implements Listener {
@EventHandler
public void onPlayerSendChat(AsyncChatEvent event) {
if (isPapi()) {
if (usingPapi()) {
return;
}
Component nameComponent = event.getPlayer().displayName();

View File

@ -5,12 +5,13 @@ import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
public class Expansion extends PlaceholderExpansion {
private final JavaPlugin plugin;
@ -19,7 +20,7 @@ public class Expansion extends PlaceholderExpansion {
public Expansion(JavaPlugin plugin) {
this.plugin = plugin;
if (isPapi()) {
if (usingPapi()) {
XLogger.info("PlaceholderAPI is enabled, registering expansion...");
this.register();
} else {
@ -65,8 +66,4 @@ public class Expansion extends PlaceholderExpansion {
public @NotNull String getVersion() {
return plugin.getPluginMeta().getVersion();
}
public static boolean isPapi() {
return Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
}
}

View File

@ -32,7 +32,9 @@ public final class MiniPlayerTitle extends JavaPlugin {
new VaultConnect(this);
}
new Expansion(this);
if (usingPapi()) {
new Expansion(this);
}
Bukkit.getPluginManager().registerEvents(new Events(), this);
Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setExecutor(new Commands());
@ -69,4 +71,8 @@ public final class MiniPlayerTitle extends JavaPlugin {
public static ConfigManager config;
public static DatabaseManager database;
private GiteaReleaseCheck giteaReleaseCheck;
public static boolean usingPapi() {
return Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
}
}

View File

@ -8,7 +8,8 @@ import org.bukkit.entity.Player;
import javax.annotation.Nullable;
import static cn.lunadeer.miniplayertitle.Expansion.isPapi;
import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
public class Apis {
public static boolean notOpOrConsole(CommandSender sender) {
@ -23,7 +24,7 @@ public class Apis {
}
public static void updateName(Player player, @Nullable TitleDTO title) {
if (isPapi()) {
if (usingPapi()) {
return;
}
if (title == null || title.getId() == -1) {

View File

@ -6,7 +6,6 @@ import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.HoverEvent;
import org.bukkit.ChatColor;
import java.sql.ResultSet;
import java.sql.SQLException;