9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-29 11:49:14 +00:00

2.2.0.7.1

This commit is contained in:
Xiao-MoMi
2023-05-14 18:16:54 +08:00
parent 167f74c3b8
commit 35d8e3ca6f
12 changed files with 114 additions and 38 deletions

View File

@@ -69,6 +69,7 @@ public final class CustomNameplates extends JavaPlugin {
protocolManager = ProtocolLibrary.getProtocolManager();
AdventureUtils.consoleMessage("[CustomNameplates] Running on <white>" + Bukkit.getVersion());
this.fix();
this.versionHelper = new VersionHelper(this);
this.configManager = new ConfigManager();
this.messageManager = new MessageManager();
this.teamManager = new TeamManager(this);
@@ -82,7 +83,6 @@ public final class CustomNameplates extends JavaPlugin {
this.fontManager = new FontManager(this);
this.imageManager = new ImageManager(this);
this.chatBubblesManager = new ChatBubblesManager(this);
this.versionHelper = new VersionHelper(this);
this.customNameplatesAPI = new CustomNameplatesAPI(this);
this.customNameplatesAPI.init();
this.registerCommands();
@@ -111,6 +111,7 @@ public final class CustomNameplates extends JavaPlugin {
TimeZone timeZone = TimeZone.getDefault();
String libRepo = timeZone.getID().startsWith("Asia") ? "https://maven.aliyun.com/repository/public/" : "https://repo.maven.apache.org/maven2/";
LibraryLoader.load("commons-io","commons-io","2.11.0", libRepo);
LibraryLoader.load("org.apache.commons","commons-lang3","3.12.0", libRepo);
LibraryLoader.load("com.zaxxer","HikariCP","5.0.1", libRepo);
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3", libRepo);
LibraryLoader.load("org.mariadb.jdbc","mariadb-java-client","3.1.2", libRepo);

View File

@@ -28,7 +28,6 @@ package net.momirealms.customnameplates.helper;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import net.momirealms.customnameplates.CustomNameplates;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.InputStream;
@@ -96,13 +95,13 @@ public final class LibraryLoader {
}
if (!saveLocation.exists()) {
throw new RuntimeException("Unable to download dependency: " + d.toString());
throw new RuntimeException("Unable to download dependency: " + d);
}
try {
URL_INJECTOR.get().addURL(saveLocation.toURI().toURL());
} catch (Exception e) {
throw new RuntimeException("Unable to load dependency: " + saveLocation.toString(), e);
throw new RuntimeException("Unable to load dependency: " + saveLocation, e);
}
}
@@ -111,7 +110,7 @@ public final class LibraryLoader {
File serverDir = pluginDataFolder.getParentFile().getParentFile();
File helperDir = new File(serverDir, "libraries");
String[] split = StringUtils.split(dependency.getGroupId(), ".");
String[] split = dependency.getGroupId().split("\\.");
File jarDir;
StringJoiner stringJoiner = new StringJoiner(File.separator);
for (String str : split) {

View File

@@ -32,6 +32,7 @@ import java.net.URLConnection;
public class VersionHelper {
private boolean isNewerThan1_19_R2;
private boolean isNewerThan1_19;
private String serverVersion;
private final CustomNameplates plugin;
private final String pluginVersion;
@@ -41,11 +42,11 @@ public class VersionHelper {
public VersionHelper(CustomNameplates plugin) {
this.plugin = plugin;
this.pluginVersion = plugin.getDescription().getVersion();
this.isVersionNewerThan1_19_R2();
this.initialize();
this.pack_format = getPack_format(serverVersion);
}
public boolean isVersionNewerThan1_19_R2() {
public void initialize() {
if (serverVersion == null) {
this.serverVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
String[] split = serverVersion.split("_");
@@ -53,10 +54,18 @@ public class VersionHelper {
if (main_ver >= 20) isNewerThan1_19_R2 = true;
else if (main_ver == 19) isNewerThan1_19_R2 = Integer.parseInt(split[2].substring(1)) >= 2;
else isNewerThan1_19_R2 = false;
isNewerThan1_19 = main_ver >= 19;
}
}
public boolean isVersionNewerThan1_19_R2() {
return isNewerThan1_19_R2;
}
public boolean isVersionNewerThan1_19() {
return isNewerThan1_19;
}
public void checkUpdate() {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
@@ -170,4 +179,5 @@ public class VersionHelper {
public int getPack_format() {
return pack_format;
}
}

View File

@@ -29,7 +29,7 @@ public class ActionBarListener extends PacketAdapter {
private final ActionBarManager actionBarManager;
public ActionBarListener(ActionBarManager actionBarManager) {
super(CustomNameplates.getInstance(), ListenerPriority.HIGHEST, PacketType.Play.Server.SET_ACTION_BAR_TEXT);
super(CustomNameplates.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.SET_ACTION_BAR_TEXT);
this.actionBarManager = actionBarManager;
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.listener.packet;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.manager.ActionBarManager;
public class ChatMessageListener extends PacketAdapter {
private final ActionBarManager actionBarManager;
public ChatMessageListener(ActionBarManager actionBarManager) {
super(CustomNameplates.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.CHAT);
this.actionBarManager = actionBarManager;
}
public void onPacketSending(PacketEvent event) {
actionBarManager.onReceiveChatMessagePacket(event);
}
}

View File

@@ -29,7 +29,7 @@ public class SystemChatListener extends PacketAdapter {
private final ActionBarManager actionBarManager;
public SystemChatListener(ActionBarManager actionBarManager) {
super(CustomNameplates.getInstance(), ListenerPriority.HIGHEST, PacketType.Play.Server.SYSTEM_CHAT);
super(CustomNameplates.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.SYSTEM_CHAT);
this.actionBarManager = actionBarManager;
}

View File

@@ -17,15 +17,22 @@
package net.momirealms.customnameplates.manager;
import com.comphenix.protocol.events.InternalStructure;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ScoreComponent;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.listener.JoinQuitListener;
import net.momirealms.customnameplates.listener.packet.ActionBarListener;
import net.momirealms.customnameplates.listener.packet.ChatMessageListener;
import net.momirealms.customnameplates.listener.packet.SystemChatListener;
import net.momirealms.customnameplates.object.Function;
import net.momirealms.customnameplates.object.actionbar.ActionBarConfig;
@@ -49,7 +56,8 @@ public class ActionBarManager extends Function {
private final LinkedHashMap<String, ActionBarConfig> actionBarConfigMap;
private final ConcurrentHashMap<UUID, ActionBarTask> actionBarTaskMap;
private final ActionBarListener actionBarListener;
private final SystemChatListener systemChatListener;
private SystemChatListener systemChatListener;
private ChatMessageListener chatMessageListener;
private final JoinQuitListener joinQuitListener;
private final CustomNameplates plugin;
@@ -59,7 +67,11 @@ public class ActionBarManager extends Function {
this.actionBarTaskMap = new ConcurrentHashMap<>();
this.joinQuitListener = new JoinQuitListener(this);
this.actionBarListener = new ActionBarListener(this);
this.systemChatListener = new SystemChatListener(this);
if (plugin.getVersionHelper().isVersionNewerThan1_19()) {
this.systemChatListener = new SystemChatListener(this);
} else {
this.chatMessageListener = new ChatMessageListener(this);
}
}
@Override
@@ -67,8 +79,9 @@ public class ActionBarManager extends Function {
if (!ConfigManager.enableActionBar) return;
this.loadConfig();
Bukkit.getPluginManager().registerEvents(joinQuitListener, plugin);
CustomNameplates.getProtocolManager().addPacketListener(actionBarListener);
CustomNameplates.getProtocolManager().addPacketListener(systemChatListener);
if (actionBarListener != null) CustomNameplates.getProtocolManager().addPacketListener(actionBarListener);
if (systemChatListener != null) CustomNameplates.getProtocolManager().addPacketListener(systemChatListener);
if (chatMessageListener != null) CustomNameplates.getProtocolManager().addPacketListener(chatMessageListener);
for (Player player : Bukkit.getOnlinePlayers()) {
onJoin(player);
}
@@ -80,8 +93,9 @@ public class ActionBarManager extends Function {
actionBarTask.stop();
}
actionBarConfigMap.clear();
CustomNameplates.getProtocolManager().removePacketListener(actionBarListener);
CustomNameplates.getProtocolManager().removePacketListener(systemChatListener);
if (actionBarListener != null) CustomNameplates.getProtocolManager().removePacketListener(actionBarListener);
if (systemChatListener != null) CustomNameplates.getProtocolManager().removePacketListener(systemChatListener);
if (chatMessageListener != null) CustomNameplates.getProtocolManager().removePacketListener(chatMessageListener);
HandlerList.unregisterAll(joinQuitListener);
}
@@ -135,27 +149,42 @@ public class ActionBarManager extends Function {
}
}
// 1.19+
public void onReceiveSystemChatPacket(PacketEvent event) {
PacketContainer packet = event.getPacket();
// 1.19+
Boolean overlay = packet.getBooleans().readSafely(0);
// lower version
Integer position = packet.getIntegers().readSafely(0);
if ((overlay != null && overlay || position != null && position == 2)) {
if (overlay != null && overlay) {
ActionBarTask actionBarTask = getActionBarTask(event.getPlayer().getUniqueId());
if (actionBarTask != null) {
String json = packet.getStrings().read(0);
event.setCancelled(true);
String json = packet.getStrings().readSafely(0);
if (json != null && !json.equals("")) {
Component component = GsonComponentSerializer.gson().deserialize(json);
if (component instanceof ScoreComponent scoreComponent) {
if (scoreComponent.name().equals("nameplates") && scoreComponent.objective().equals("actionbar")) {
return;
}
if (component instanceof TranslatableComponent) {
return;
}
event.setCancelled(true);
actionBarTask.setOtherText(AdventureUtils.getMiniMessageFormat(component), System.currentTimeMillis());
} else {
}
}
}
}
// lower version
public void onReceiveChatMessagePacket(PacketEvent event) {
PacketContainer packet = event.getPacket();
EnumWrappers.ChatType type = packet.getChatTypes().readSafely(0);
if (type == EnumWrappers.ChatType.GAME_INFO) {
ActionBarTask actionBarTask = getActionBarTask(event.getPlayer().getUniqueId());
if (actionBarTask != null) {
WrappedChatComponent wrappedChatComponent = packet.getChatComponents().read(0);
if (wrappedChatComponent != null) {
event.setCancelled(true);
String json = wrappedChatComponent.getJson();
Component component = GsonComponentSerializer.gson().deserialize(json);
if (component instanceof TranslatableComponent) {
return;
}
actionBarTask.setOtherText(AdventureUtils.getMiniMessageFormat(component), System.currentTimeMillis());
}
}
}

View File

@@ -21,6 +21,7 @@ import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.data.*;
import net.momirealms.customnameplates.listener.JoinQuitListener;
import net.momirealms.customnameplates.object.Function;
import net.momirealms.customnameplates.object.nameplate.mode.DisplayMode;
import net.momirealms.customnameplates.utils.ConfigUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -82,7 +83,7 @@ public class DataManager extends Function {
}
else {
playerDataMap.put(uuid, playerData);
if (!ConfigManager.enableNameplates) return;
if (!ConfigManager.enableNameplates || plugin.getNameplateManager().getMode() == DisplayMode.DISABLE) return;
plugin.getTeamManager().getTeamNameInterface().onJoin(player);
plugin.getTeamManager().createTeam(uuid);
}

View File

@@ -28,7 +28,6 @@ import net.momirealms.customnameplates.object.font.OffsetFont;
import net.momirealms.customnameplates.object.nameplate.NameplateConfig;
import net.momirealms.customnameplates.utils.AdventureUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import java.io.*;
@@ -90,7 +89,7 @@ public class ResourceManager {
jo_np.add("file", new JsonPrimitive(ConfigManager.namespace + ":" + ConfigManager.images_folder_path.replaceAll("\\\\", "/") + simpleChar.getFile()));
addCharToArray(jsonArray, simpleChar, jo_np);
try {
FileUtils.copyFile(new File(plugin.getDataFolder(), "contents" + File.separator + "images" + File.separator + simpleChar.getFile()), new File(textures_file.getPath() + File.separatorChar + StringUtils.replace(ConfigManager.images_folder_path, "\\", File.separator) + simpleChar.getFile()));
FileUtils.copyFile(new File(plugin.getDataFolder(), "contents" + File.separator + "images" + File.separator + simpleChar.getFile()), new File(textures_file.getPath() + File.separatorChar + ConfigManager.images_folder_path.replace("\\", File.separator) + simpleChar.getFile()));
} catch (IOException e) {
AdventureUtils.consoleMessage("<red>[CustomNameplates] Error! Failed to copy images to resource pack.</red>");
}
@@ -106,7 +105,7 @@ public class ResourceManager {
jo_np.add("file", new JsonPrimitive(ConfigManager.namespace + ":" + ConfigManager.nameplates_folder_path.replaceAll("\\\\", "/") + simpleChar.getFile()));
addCharToArray(jsonArray, simpleChar, jo_np);
try {
FileUtils.copyFile(new File(plugin.getDataFolder(), "contents" + File.separator + "nameplates" + File.separator + simpleChar.getFile()), new File(textures_file.getPath() + File.separatorChar + StringUtils.replace(ConfigManager.nameplates_folder_path, "\\", File.separator) + simpleChar.getFile()));
FileUtils.copyFile(new File(plugin.getDataFolder(), "contents" + File.separator + "nameplates" + File.separator + simpleChar.getFile()), new File(textures_file.getPath() + File.separatorChar + ConfigManager.nameplates_folder_path.replace("\\", File.separator) + simpleChar.getFile()));
} catch (IOException e) {
AdventureUtils.consoleMessage("<red>[CustomNameplates] Error! Failed to copy nameplates to resource pack.</red>");
}
@@ -124,7 +123,7 @@ public class ResourceManager {
jo_bb.add("file", new JsonPrimitive(ConfigManager.namespace + ":" + ConfigManager.bubbles_folder_path.replaceAll("\\\\","/") + simpleChar.getFile()));
addCharToArray(jsonArray, simpleChar, jo_bb);
try {
FileUtils.copyFile(new File(plugin.getDataFolder(),"contents" + File.separator + "bubbles" + File.separator + simpleChar.getFile()), new File(textures_file.getPath() + File.separator + StringUtils.replace(ConfigManager.bubbles_folder_path, "\\", File.separator) + simpleChar.getFile()));
FileUtils.copyFile(new File(plugin.getDataFolder(),"contents" + File.separator + "bubbles" + File.separator + simpleChar.getFile()), new File(textures_file.getPath() + File.separator + ConfigManager.bubbles_folder_path.replace("\\", File.separator) + simpleChar.getFile()));
}
catch (IOException e){
AdventureUtils.consoleMessage("<red>[CustomNameplates] Error! Failed to copy bubbles to resource pack.</red>");
@@ -147,7 +146,7 @@ public class ResourceManager {
jo_bg.add("file", new JsonPrimitive(ConfigManager.namespace + ":" + ConfigManager.backgrounds_folder_path.replaceAll("\\\\","/") + simpleChar.getFile()));
addCharToArray(jsonArray, simpleChar, jo_bg);
try {
FileUtils.copyFile(new File(plugin.getDataFolder(), "contents" + File.separator + "backgrounds" + File.separator + simpleChar.getFile()), new File(textures_file.getPath() + File.separatorChar + StringUtils.replace(ConfigManager.backgrounds_folder_path, "\\", File.separator) + simpleChar.getFile()));
FileUtils.copyFile(new File(plugin.getDataFolder(), "contents" + File.separator + "backgrounds" + File.separator + simpleChar.getFile()), new File(textures_file.getPath() + File.separatorChar + ConfigManager.backgrounds_folder_path.replace("\\", File.separator) + simpleChar.getFile()));
}
catch (IOException e){
AdventureUtils.consoleMessage("<red>[CustomNameplates] Error! Failed to copy backgrounds to resource pack.</red>");
@@ -295,7 +294,7 @@ public class ResourceManager {
private void saveSplit(String texture_folder_path) {
try {
plugin.saveResource("space_split.png", false);
FileUtils.copyFile(new File(plugin.getDataFolder(),"space_split.png"), new File(texture_folder_path + File.separator + StringUtils.replace(ConfigManager.space_split_folder_path, "\\", File.separator) + "space_split.png"));
FileUtils.copyFile(new File(plugin.getDataFolder(),"space_split.png"), new File(texture_folder_path + File.separator + ConfigManager.space_split_folder_path.replace("\\", File.separator) + "space_split.png"));
File file = new File(plugin.getDataFolder(),"space_split.png");
if (file.exists()) {
file.delete();

View File

@@ -17,7 +17,6 @@
package net.momirealms.customnameplates.object.requirements;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.entity.Player;
import java.util.List;
@@ -28,7 +27,7 @@ public record TimeImpl(List<String> times) implements Requirement{
public boolean isConditionMet(Player player) {
long time = player.getWorld().getTime();
for (String range : times) {
String[] timeMinMax = StringUtils.split(range, "~");
String[] timeMinMax = range.split("~");
if (time > Long.parseLong(timeMinMax[0]) && time < Long.parseLong(timeMinMax[1])) {
return true;
}

View File

@@ -17,7 +17,6 @@
package net.momirealms.customnameplates.object.requirements;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.entity.Player;
import java.util.List;
@@ -28,7 +27,7 @@ public record YPosImpl(List<String> yPos) implements Requirement {
public boolean isConditionMet(Player player) {
int y = (int) player.getLocation().getY();
for (String range : yPos) {
String[] yMinMax = StringUtils.split(range, "~");
String[] yMinMax = range.split("~");
if (y > Integer.parseInt(yMinMax[0]) && y < Integer.parseInt(yMinMax[1])) {
return true;
}