优化在使用papi情况下的性能
All checks were successful
Java CI-CD with Maven / build (push) Successful in 8m10s

This commit is contained in:
zhangyuheng 2024-07-05 14:57:54 +08:00
parent a007966d70
commit 3ffab50c9b
4 changed files with 18 additions and 12 deletions

View File

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

View File

@ -32,19 +32,10 @@ public class Expansion extends PlaceholderExpansion {
@Override
public String onPlaceholderRequest(Player bukkitPlayer, @NotNull String params) {
if (params.equalsIgnoreCase("player_title")) {
PlayerInfoDTO player = PlayerInfoDTO.get(bukkitPlayer);
if (player == null) {
TitleDTO t = MiniPlayerTitle.instance.getPlayerUsingTitle(bukkitPlayer.getUniqueId());
if (t == null) {
return "";
}
if (player.getUsingTitle().getId() == -1) {
return "";
}
PlayerTitleDTO title = PlayerTitleDTO.get(bukkitPlayer.getUniqueId(), player.getUsingTitle().getId());
if (title == null || title.isExpired()) {
player.setUsingTitle(null);
return "";
}
TitleDTO t = title.getTitle();
return ChatColor.translateAlternateColorCodes('&', t.getTitleColoredBukkit());
}

View File

@ -1,12 +1,16 @@
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.minecraftpluginutils.*;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import cn.lunadeer.miniplayertitle.utils.ConfigManager;
import cn.lunadeer.miniplayertitle.utils.DatabaseTables;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
public final class MiniPlayerTitle extends JavaPlugin {
@ -71,8 +75,17 @@ public final class MiniPlayerTitle extends JavaPlugin {
public static ConfigManager config;
public static DatabaseManager database;
private GiteaReleaseCheck giteaReleaseCheck;
private Map<UUID, TitleDTO> playerUsingTitle = new HashMap<>();
public static boolean usingPapi() {
return Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
}
public void setPlayerUsingTitle(UUID uuid, TitleDTO title) {
playerUsingTitle.put(uuid, title);
}
public TitleDTO getPlayerUsingTitle(UUID uuid) {
return playerUsingTitle.get(uuid);
}
}

View File

@ -1,6 +1,7 @@
package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
@ -24,6 +25,7 @@ public class Apis {
}
public static void updateName(Player player, @Nullable TitleDTO title) {
MiniPlayerTitle.instance.setPlayerUsingTitle(player.getUniqueId(), title);
if (usingPapi()) {
return;
}