mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-26 02:19:28 +00:00
2.0-PRE-3
This commit is contained in:
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'net.momirealms'
|
||||
version = '2.0-PRE-1'
|
||||
version = '2.0-PRE-3'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
@@ -17,34 +17,33 @@
|
||||
|
||||
package net.momirealms.customnameplates;
|
||||
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.momirealms.customnameplates.bossbar.BossBarConfig;
|
||||
import net.momirealms.customnameplates.bossbar.Overlay;
|
||||
import net.momirealms.customnameplates.objects.BackGround;
|
||||
import net.momirealms.customnameplates.bossbar.adventure.BossBarConfigA;
|
||||
import net.momirealms.customnameplates.bossbar.protocollib.BossBarConfigP;
|
||||
import net.momirealms.customnameplates.bossbar.protocollib.Overlay;
|
||||
import net.momirealms.customnameplates.font.FontWidthNormal;
|
||||
import net.momirealms.customnameplates.font.FontWidthThin;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import net.momirealms.customnameplates.objects.BGInfo;
|
||||
import net.momirealms.customnameplates.objects.NPInfo;
|
||||
import net.momirealms.customnameplates.objects.BackGroundText;
|
||||
import net.momirealms.customnameplates.objects.NameplateText;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
public static TreeMap<String, BackGround> backgrounds = new TreeMap<>();
|
||||
public static TreeMap<String, BossBarConfigA> bossbarsA = new TreeMap<>();
|
||||
public static TreeMap<String, BossBarConfigP> bossbarsP = new TreeMap<>();
|
||||
public static HashMap<String, BGInfo> papiBG = new HashMap<>();
|
||||
public static HashMap<String, NPInfo> papiNP = new HashMap<>();
|
||||
public static TreeMap<String, BossBarConfig> bossBars = new TreeMap<>();
|
||||
public static HashMap<String, BackGroundText> papiBG = new HashMap<>();
|
||||
public static HashMap<String, NameplateText> papiNP = new HashMap<>();
|
||||
public static HashMap<Character, Integer> fontWidth = new HashMap<>();
|
||||
|
||||
/**
|
||||
@@ -63,41 +62,49 @@ public class ConfigManager {
|
||||
/**
|
||||
* 载入模块
|
||||
*/
|
||||
public static boolean nameplate;
|
||||
public static boolean background;
|
||||
public static boolean bossbar;
|
||||
public static boolean actionbar;
|
||||
public static boolean useAdventure;
|
||||
public static void loadModule(){
|
||||
YamlConfiguration module = getConfig("MODULES.yml");
|
||||
nameplate = module.getBoolean("nameplate", true);
|
||||
background = module.getBoolean("background", true);
|
||||
bossbar = module.getBoolean("bossbar", true);
|
||||
actionbar = module.getBoolean("actionbar", true);
|
||||
public static class Module{
|
||||
|
||||
public static boolean nameplate;
|
||||
public static boolean background;
|
||||
public static boolean bossBar;
|
||||
public static boolean actionbar;
|
||||
|
||||
public static void loadModule(){
|
||||
YamlConfiguration module = getConfig("MODULES.yml");
|
||||
nameplate = module.getBoolean("nameplate", true);
|
||||
background = module.getBoolean("background", true);
|
||||
bossBar = module.getBoolean("bossbar", true);
|
||||
actionbar = module.getBoolean("actionbar", true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 载入主配置
|
||||
*/
|
||||
public static class MainConfig{
|
||||
public static class Main {
|
||||
|
||||
public static String namespace;
|
||||
public static String fontName;
|
||||
public static String start_char;
|
||||
public static char start;
|
||||
public static String lang;
|
||||
public static String version;
|
||||
|
||||
public static String folder_path;
|
||||
public static String bg_folder_path;
|
||||
public static String ss_folder_path;
|
||||
public static String font;
|
||||
public static List<Integer> offsets;
|
||||
public static Key key;
|
||||
|
||||
public static boolean itemsAdder;
|
||||
public static boolean placeholderAPI;
|
||||
public static String lang;
|
||||
|
||||
public static boolean thin_font;
|
||||
public static boolean tab;
|
||||
public static boolean oraxen;
|
||||
public static boolean extract;
|
||||
public static String version;
|
||||
public static List<Integer> offsets;
|
||||
public static char start;
|
||||
public static Key key;
|
||||
|
||||
|
||||
public static void reload(){
|
||||
|
||||
@@ -114,7 +121,6 @@ public class ConfigManager {
|
||||
folder_path = config.getString("config.nameplate-folder-path","font\\nameplates\\");
|
||||
bg_folder_path = config.getString("config.background-folder-path","font\\backgrounds\\");
|
||||
ss_folder_path = config.getString("config.space-split-folder-path","font\\");
|
||||
|
||||
key = Key.key(fontName);
|
||||
thin_font = config.getBoolean("config.use-thin-font",false);
|
||||
itemsAdder = config.getBoolean("config.integrations.ItemsAdder",false);
|
||||
@@ -151,40 +157,47 @@ public class ConfigManager {
|
||||
public static String default_nameplate;
|
||||
public static String player_prefix;
|
||||
public static String player_suffix;
|
||||
public static boolean mode_team;
|
||||
public static long preview;
|
||||
public static boolean update;
|
||||
public static int refresh;
|
||||
public static String mode;
|
||||
public static boolean hidePrefix;
|
||||
public static boolean hideSuffix;
|
||||
public static boolean show_after;
|
||||
public static boolean tryHook;
|
||||
public static boolean removeTag;
|
||||
public static boolean smallSize;
|
||||
public static List<String> texts;
|
||||
public static HashMap<String, Double> textMap = new HashMap<>();
|
||||
|
||||
public static void reload() {
|
||||
|
||||
YamlConfiguration config = getConfig("nameplate.yml");
|
||||
default_nameplate = config.getString("nameplate.default-nameplate");
|
||||
preview = config.getLong("nameplate.preview-duration");
|
||||
show_after = config.getBoolean("nameplate.show-after-load-resourcepack");
|
||||
mode_team = config.getString("nameplate.mode","team").equalsIgnoreCase("team");
|
||||
update = config.getBoolean("nameplate.update.enable",false);
|
||||
mode = config.getString("nameplate.mode","team");
|
||||
update = config.getBoolean("nameplate.update.enable",true);
|
||||
refresh = config.getInt("nameplate.update.ticks",20);
|
||||
|
||||
if (mode_team) {
|
||||
player_prefix = config.getString("nameplate.team.prefix","");
|
||||
player_suffix = config.getString("nameplate.team.suffix","");
|
||||
hidePrefix = config.getBoolean("nameplate.team.hide-prefix-when-equipped",false);
|
||||
hideSuffix = config.getBoolean("nameplate.team.hide-suffix-when-equipped",false);
|
||||
player_prefix = config.getString("nameplate.prefix","");
|
||||
player_suffix = config.getString("nameplate.suffix","");
|
||||
hidePrefix = config.getBoolean("nameplate.team.hide-prefix-when-equipped",true);
|
||||
hideSuffix = config.getBoolean("nameplate.team.hide-suffix-when-equipped",true);
|
||||
if (mode.equalsIgnoreCase("team")) removeTag = false;
|
||||
else if (mode.equalsIgnoreCase("riding")) {
|
||||
tryHook = config.getBoolean("nameplate.riding.try-to-hook-cosmetics-plugin", false);
|
||||
List<String> texts = config.getStringList("nameplate.riding.text");
|
||||
textMap.clear();
|
||||
for (String text : texts) {
|
||||
textMap.put(text, -0.1);
|
||||
}
|
||||
smallSize = config.getBoolean("nameplate.riding.small-size", true);
|
||||
removeTag = config.getBoolean("nameplate.riding.remove-nametag");
|
||||
}
|
||||
else {
|
||||
player_prefix = "";
|
||||
player_suffix = "";
|
||||
removeTag = config.getBoolean("nameplate.entity.remove-nametag");
|
||||
tryHook = config.getBoolean("nameplate.entity.try-to-hook-cosmetics-plugin");
|
||||
texts = config.getStringList("nameplate.entity.text");
|
||||
smallSize = config.getBoolean("nameplate.entity.small-size", true);
|
||||
else if (mode.equalsIgnoreCase("teleporting")) {
|
||||
removeTag = config.getBoolean("nameplate.teleporting.remove-nametag");
|
||||
smallSize = config.getBoolean("nameplate.teleporting.small-size", true);
|
||||
textMap.clear();
|
||||
config.getConfigurationSection("nameplate.teleporting.text").getKeys(false).forEach(key -> {
|
||||
textMap.put(config.getString("nameplate.teleporting.text." + key + ".content"), config.getDouble("nameplate.teleporting.text." + key + ".offset"));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,36 +212,36 @@ public class ConfigManager {
|
||||
public static String lackArgs;
|
||||
public static String reload;
|
||||
public static String equip;
|
||||
public static String unequip;
|
||||
public static String unEquip;
|
||||
public static String force_equip;
|
||||
public static String force_unequip;
|
||||
public static String force_unEquip;
|
||||
public static String not_exist;
|
||||
public static String not_online;
|
||||
public static String no_console;
|
||||
public static String notAvailable;
|
||||
public static String available;
|
||||
public static String cooldown;
|
||||
public static String coolDown;
|
||||
public static String preview;
|
||||
public static String generate;
|
||||
public static String noNameplate;
|
||||
|
||||
public static void reload(){
|
||||
|
||||
YamlConfiguration messagesConfig = getConfig("messages/messages_" + MainConfig.lang +".yml");
|
||||
YamlConfiguration messagesConfig = getConfig("messages/messages_" + Main.lang +".yml");
|
||||
noPerm = messagesConfig.getString("messages.no-perm");
|
||||
prefix = messagesConfig.getString("messages.prefix");
|
||||
lackArgs = messagesConfig.getString("messages.lack-args");
|
||||
reload = messagesConfig.getString("messages.reload");
|
||||
equip = messagesConfig.getString("messages.equip");
|
||||
unequip = messagesConfig.getString("messages.unequip");
|
||||
unEquip = messagesConfig.getString("messages.unequip");
|
||||
force_equip = messagesConfig.getString("messages.force-equip");
|
||||
force_unequip = messagesConfig.getString("messages.force-unequip");
|
||||
force_unEquip = messagesConfig.getString("messages.force-unequip");
|
||||
not_exist = messagesConfig.getString("messages.not-exist");
|
||||
not_online = messagesConfig.getString("messages.not-online");
|
||||
no_console = messagesConfig.getString("messages.no-console");
|
||||
notAvailable = messagesConfig.getString("messages.not-available");
|
||||
available = messagesConfig.getString("messages.available");
|
||||
cooldown = messagesConfig.getString("messages.cooldown");
|
||||
coolDown = messagesConfig.getString("messages.cooldown");
|
||||
preview = messagesConfig.getString("messages.preview");
|
||||
generate = messagesConfig.getString("messages.generate");
|
||||
noNameplate = messagesConfig.getString("messages.no-nameplate","messages.no-nameplate is missing");
|
||||
@@ -249,48 +262,27 @@ public class ConfigManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 载入bossbar配置
|
||||
* 载入BossBar配置
|
||||
*/
|
||||
public static void loadBossBar() {
|
||||
YamlConfiguration config = getConfig("bossbar.yml");
|
||||
useAdventure = config.getString("mode").equalsIgnoreCase("Adventure");
|
||||
if (useAdventure){
|
||||
config.getConfigurationSection("bossbar").getKeys(false).forEach(key -> {
|
||||
BossBarConfigA bossbarConfig = ConfigManager.bossbarsA.get(key);
|
||||
if (bossbarConfig != null) {
|
||||
bossbarConfig.setColor(BossBar.Color.valueOf(config.getString("bossbar." + key + ".color").toUpperCase()));
|
||||
bossbarConfig.setOverlay(BossBar.Overlay.valueOf(config.getString("bossbar." + key + ".overlay").toUpperCase()));
|
||||
bossbarConfig.setRate(config.getInt("bossbar." + key + ".refresh-rate") - 1);
|
||||
bossbarConfig.setText(config.getString("bossbar." + key + ".text"));
|
||||
}
|
||||
else {
|
||||
bossbarsA.put(key, new BossBarConfigA(
|
||||
config.getString("bossbar." + key + ".text"),
|
||||
BossBar.Overlay.valueOf(config.getString("bossbar." + key + ".overlay").toUpperCase()),
|
||||
BossBar.Color.valueOf(config.getString("bossbar." + key + ".color").toUpperCase()),
|
||||
config.getInt("bossbar." + key + ".refresh-rate") - 1
|
||||
));
|
||||
}
|
||||
});
|
||||
}else {
|
||||
config.getConfigurationSection("bossbar").getKeys(false).forEach(key -> {
|
||||
BossBarConfigP bossbarConfig = ConfigManager.bossbarsP.get(key);
|
||||
if (bossbarConfig != null) {
|
||||
bossbarConfig.setColor(BarColor.valueOf(config.getString("bossbar."+key+".color").toUpperCase()));
|
||||
bossbarConfig.setRate(config.getInt("bossbar." + key + ".refresh-rate") - 1);
|
||||
bossbarConfig.setText(config.getString("bossbar." + key + ".text"));
|
||||
bossbarConfig.setOverlay(Overlay.valueOf(config.getString("bossbar."+key+".overlay").toUpperCase()));
|
||||
}
|
||||
else {
|
||||
bossbarsP.put(key, new BossBarConfigP(
|
||||
config.getString("bossbar." + key + ".text"),
|
||||
Overlay.valueOf(config.getString("bossbar."+key+".overlay").toUpperCase()),
|
||||
BarColor.valueOf(config.getString("bossbar."+key+".color").toUpperCase()),
|
||||
config.getInt("bossbar." + key + ".refresh-rate") - 1
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
Objects.requireNonNull(config.getConfigurationSection("bossbar")).getKeys(false).forEach(key -> {
|
||||
BossBarConfig bossbarConfig = ConfigManager.bossBars.get(key);
|
||||
if (bossbarConfig != null) {
|
||||
bossbarConfig.setColor(BarColor.valueOf(config.getString("bossbar."+key+".color").toUpperCase()));
|
||||
bossbarConfig.setRate(config.getInt("bossbar." + key + ".refresh-rate") - 1);
|
||||
bossbarConfig.setText(config.getString("bossbar." + key + ".text"));
|
||||
bossbarConfig.setOverlay(Overlay.valueOf(config.getString("bossbar."+key+".overlay").toUpperCase()));
|
||||
}
|
||||
else {
|
||||
bossBars.put(key, new BossBarConfig(
|
||||
config.getString("bossbar." + key + ".text"),
|
||||
Overlay.valueOf(config.getString("bossbar."+key+".overlay").toUpperCase()),
|
||||
BarColor.valueOf(config.getString("bossbar."+key+".color").toUpperCase()),
|
||||
config.getInt("bossbar." + key + ".refresh-rate") - 1
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,9 +294,9 @@ public class ConfigManager {
|
||||
YamlConfiguration papiInfo = getConfig("custom-papi.yml");
|
||||
papiInfo.getConfigurationSection("papi").getKeys(false).forEach(key -> {
|
||||
if (papiInfo.contains("papi." + key + ".background"))
|
||||
papiBG.put(key, new BGInfo(papiInfo.getString("papi."+key+".text"), papiInfo.getString("papi." + key + ".background")));
|
||||
papiBG.put(key, new BackGroundText(papiInfo.getString("papi."+key+".text"), papiInfo.getString("papi." + key + ".background")));
|
||||
if (papiInfo.contains("papi." + key + ".nameplate"))
|
||||
papiNP.put(key, new NPInfo(papiInfo.getString("papi."+key+".text"), papiInfo.getString("papi." + key + ".nameplate")));
|
||||
papiNP.put(key, new NameplateText(papiInfo.getString("papi."+key+".text"), papiInfo.getString("papi." + key + ".nameplate")));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -329,7 +321,7 @@ public class ConfigManager {
|
||||
YamlConfiguration config = getConfig("char-width.yml");
|
||||
config.getConfigurationSection("").getKeys(false).forEach(key -> fontWidth.put(key.charAt(0), config.getInt(key)));
|
||||
AdventureUtil.consoleMessage("[CustomNameplates] Loaded <green>" + fontWidth.size() + " <gray>custom char-width");
|
||||
if (MainConfig.thin_font)
|
||||
if (Main.thin_font)
|
||||
for (int i = 0; i < FontWidthThin.values().length; i++)
|
||||
fontWidth.put(FontWidthThin.values()[i].getCharacter(), FontWidthThin.values()[i].getLength());
|
||||
else
|
||||
@@ -355,17 +347,17 @@ public class ConfigManager {
|
||||
public static int maximum_lifetime;
|
||||
public static int idle_timeout;
|
||||
|
||||
public static void LoadConfig(){
|
||||
public static void reload(){
|
||||
|
||||
YamlConfiguration databaseConfig = getConfig("database.yml");
|
||||
String storage_mode = databaseConfig.getString("settings.storage-mode");
|
||||
String storage_mode = databaseConfig.getString("settings.storage-mode","SQLite");
|
||||
async = !databaseConfig.getBoolean("settings.disable-async", true);
|
||||
if(storage_mode.equals("SQLite")){
|
||||
if(storage_mode.equalsIgnoreCase("SQLite")){
|
||||
enable_pool = false;
|
||||
use_mysql = false;
|
||||
tableName = "nameplates";
|
||||
}
|
||||
else if(storage_mode.equals("MYSQL")){
|
||||
else if(storage_mode.equalsIgnoreCase("MYSQL")){
|
||||
use_mysql = true;
|
||||
ENCODING = databaseConfig.getString("MySQL.property.encoding");
|
||||
tableName = databaseConfig.getString("MySQL.table-name");
|
||||
|
||||
@@ -20,21 +20,28 @@ package net.momirealms.customnameplates;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.momirealms.customnameplates.actionbar.Timer;
|
||||
import net.momirealms.customnameplates.bossbar.adventure.QuitAndJoinA;
|
||||
import net.momirealms.customnameplates.bossbar.protocollib.QuitAndJoinP;
|
||||
import net.momirealms.customnameplates.actionbar.ActionBarManager;
|
||||
import net.momirealms.customnameplates.bossbar.BossBarManager;
|
||||
import net.momirealms.customnameplates.commands.Execute;
|
||||
import net.momirealms.customnameplates.commands.TabComplete;
|
||||
import net.momirealms.customnameplates.data.DataManager;
|
||||
import net.momirealms.customnameplates.data.SqlHandler;
|
||||
import net.momirealms.customnameplates.helper.LibraryLoader;
|
||||
import net.momirealms.customnameplates.hook.Placeholders;
|
||||
import net.momirealms.customnameplates.listener.*;
|
||||
import net.momirealms.customnameplates.hook.PlaceholderManager;
|
||||
import net.momirealms.customnameplates.nameplates.TeamPacketManager;
|
||||
import net.momirealms.customnameplates.nameplates.mode.NameplateManager;
|
||||
import net.momirealms.customnameplates.nameplates.mode.rd.RidingTag;
|
||||
import net.momirealms.customnameplates.nameplates.mode.tm.TeamTag;
|
||||
import net.momirealms.customnameplates.nameplates.mode.tmpackets.TeamPacketA;
|
||||
import net.momirealms.customnameplates.nameplates.mode.tmpackets.TeamPacketB;
|
||||
import net.momirealms.customnameplates.nameplates.mode.tmpackets.TeamPacketC;
|
||||
import net.momirealms.customnameplates.nameplates.mode.tp.TeleportingTag;
|
||||
import net.momirealms.customnameplates.resource.ResourceManager;
|
||||
import net.momirealms.customnameplates.scoreboard.ScoreBoardManager;
|
||||
import net.momirealms.customnameplates.nameplates.TeamManager;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import net.momirealms.customnameplates.utils.ConfigUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -44,15 +51,15 @@ public final class CustomNameplates extends JavaPlugin {
|
||||
public static CustomNameplates instance;
|
||||
public static BukkitAudiences adventure;
|
||||
public static ProtocolManager protocolManager;
|
||||
public static Placeholders placeholders;
|
||||
|
||||
private ResourceManager resourceManager;
|
||||
private DataManager dataManager;
|
||||
private ScoreBoardManager scoreBoardManager;
|
||||
private Timer timer;
|
||||
private PlayerPacketsListener playerPackets;
|
||||
private MountPacketListener mountPackets;
|
||||
private EntityDestroyListener entityDestroy;
|
||||
private TeamManager teamManager;
|
||||
private TeamPacketManager teamPacketManager;
|
||||
private BossBarManager bossBarManager;
|
||||
private ActionBarManager actionBarManager;
|
||||
private PlaceholderManager placeholderManager;
|
||||
private NameplateManager nameplateManager;
|
||||
|
||||
@Override
|
||||
public void onLoad(){
|
||||
@@ -74,10 +81,11 @@ public final class CustomNameplates extends JavaPlugin {
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("customnameplates")).setTabCompleter(new TabComplete());
|
||||
|
||||
loadConfig();
|
||||
|
||||
this.resourceManager = new ResourceManager();
|
||||
this.resourceManager.generateResourcePack();
|
||||
|
||||
if (Objects.equals(ConfigManager.MainConfig.version, "2")){
|
||||
if (!Objects.equals(ConfigManager.Main.version, "3")){
|
||||
ConfigUtil.update();
|
||||
}
|
||||
|
||||
@@ -86,85 +94,130 @@ public final class CustomNameplates extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (ConfigManager.nameplate){
|
||||
if (ConfigManager.Module.nameplate){
|
||||
SqlHandler.saveAll();
|
||||
SqlHandler.close();
|
||||
}
|
||||
if (timer != null){
|
||||
timer.stopTimer(timer.getTaskID());
|
||||
if (actionBarManager != null){
|
||||
actionBarManager.unload();
|
||||
}
|
||||
if (adventure != null) {
|
||||
adventure.close();
|
||||
}
|
||||
if (protocolManager != null){
|
||||
if (playerPackets != null) {
|
||||
protocolManager.removePacketListener(this.playerPackets);
|
||||
}
|
||||
if (mountPackets != null) {
|
||||
protocolManager.removePacketListener(this.mountPackets);
|
||||
}
|
||||
if (entityDestroy != null) {
|
||||
protocolManager.removePacketListener(this.entityDestroy);
|
||||
}
|
||||
}
|
||||
if (placeholders != null){
|
||||
placeholders.unregister();
|
||||
}
|
||||
if (resourceManager != null){
|
||||
resourceManager = null;
|
||||
}
|
||||
if (scoreBoardManager != null){
|
||||
scoreBoardManager = null;
|
||||
if (teamManager != null){
|
||||
teamManager = null;
|
||||
}
|
||||
if (dataManager != null){
|
||||
dataManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
ConfigManager.loadModule();
|
||||
ConfigManager.MainConfig.reload();
|
||||
public void loadConfig() {
|
||||
|
||||
ConfigManager.Module.loadModule();
|
||||
ConfigManager.Main.reload();
|
||||
ConfigManager.Message.reload();
|
||||
ConfigManager.loadWidth();
|
||||
|
||||
if (ConfigManager.bossbar){
|
||||
if (ConfigManager.Module.bossBar){
|
||||
ConfigManager.loadBossBar();
|
||||
if (ConfigManager.useAdventure) Bukkit.getPluginManager().registerEvents(new QuitAndJoinA(),this);
|
||||
else Bukkit.getPluginManager().registerEvents(new QuitAndJoinP(),this);
|
||||
if (this.bossBarManager != null) {
|
||||
this.bossBarManager.unload();
|
||||
this.bossBarManager.load();
|
||||
}
|
||||
else {
|
||||
this.bossBarManager = new BossBarManager("BossBar");
|
||||
this.bossBarManager.load();
|
||||
}
|
||||
}
|
||||
if (ConfigManager.actionbar){
|
||||
else if (this.bossBarManager != null) {
|
||||
this.bossBarManager.unload();
|
||||
this.bossBarManager = null;
|
||||
}
|
||||
|
||||
if (ConfigManager.Module.actionbar){
|
||||
ConfigManager.ActionbarConfig.load();
|
||||
timer = new Timer();
|
||||
if (actionBarManager != null) {
|
||||
this.actionBarManager.unload();
|
||||
this.actionBarManager.load();
|
||||
}
|
||||
else {
|
||||
this.actionBarManager = new ActionBarManager("ActionBar");
|
||||
this.actionBarManager.load();
|
||||
}
|
||||
}
|
||||
if (ConfigManager.background){
|
||||
else if (this.actionBarManager != null) {
|
||||
this.actionBarManager.unload();
|
||||
this.actionBarManager = null;
|
||||
}
|
||||
|
||||
if (ConfigManager.Module.background){
|
||||
ConfigManager.loadBGConfig();
|
||||
}
|
||||
if (ConfigManager.nameplate){
|
||||
|
||||
if (ConfigManager.Module.nameplate){
|
||||
ConfigManager.Nameplate.reload();
|
||||
ConfigManager.DatabaseConfig.LoadConfig();
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerListener(),this);
|
||||
this.scoreBoardManager = new ScoreBoardManager();
|
||||
this.dataManager = new DataManager();
|
||||
if (!dataManager.create()) {
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Error! Failed to enable Data Manager! Disabling plugin...</red>");
|
||||
return;
|
||||
ConfigManager.DatabaseConfig.reload();
|
||||
if (this.dataManager == null) {
|
||||
this.dataManager = new DataManager();
|
||||
if (!dataManager.create()) {
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Error! Failed to enable Data Manager!</red>");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!ConfigManager.Nameplate.mode_team) {
|
||||
playerPackets = new PlayerPacketsListener(this);
|
||||
protocolManager.addPacketListener(playerPackets);
|
||||
entityDestroy = new EntityDestroyListener(this);
|
||||
protocolManager.addPacketListener(entityDestroy);
|
||||
if (ConfigManager.Nameplate.tryHook) {
|
||||
mountPackets = new MountPacketListener(this);
|
||||
protocolManager.addPacketListener(mountPackets);
|
||||
if (this.teamManager == null) {
|
||||
this.teamManager = new TeamManager();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
CustomNameplates.instance.getDataManager().loadData(player);
|
||||
}
|
||||
}
|
||||
if (this.nameplateManager != null) {
|
||||
this.nameplateManager.unload();
|
||||
this.nameplateManager = null;
|
||||
}
|
||||
if (ConfigManager.Nameplate.mode.equalsIgnoreCase("team")) {
|
||||
this.teamPacketManager = new TeamPacketA();
|
||||
this.nameplateManager = new TeamTag("TEAM");
|
||||
this.nameplateManager.load();
|
||||
}
|
||||
else {
|
||||
this.teamPacketManager = new TeamPacketB();
|
||||
if (ConfigManager.Nameplate.mode.equalsIgnoreCase("riding")) {
|
||||
this.nameplateManager = new RidingTag("RIDING");
|
||||
this.nameplateManager.load();
|
||||
}else if (ConfigManager.Nameplate.mode.equalsIgnoreCase("teleporting")){
|
||||
this.nameplateManager = new TeleportingTag("TELEPORTING");
|
||||
this.nameplateManager.load();
|
||||
}else {
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Unknown nameplate mode!");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ConfigManager.MainConfig.placeholderAPI){
|
||||
placeholders = new Placeholders();
|
||||
placeholders.register();
|
||||
else {
|
||||
if (this.nameplateManager != null) {
|
||||
TeamPacketC.clearTeamInfo();
|
||||
this.nameplateManager.unload();
|
||||
this.nameplateManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigManager.Main.placeholderAPI){
|
||||
ConfigManager.loadPapi();
|
||||
Bukkit.getPluginManager().registerEvents(new PapiReload(), this);
|
||||
if (this.placeholderManager != null) {
|
||||
this.placeholderManager.unload();
|
||||
this.placeholderManager.load();
|
||||
}
|
||||
else {
|
||||
this.placeholderManager = new PlaceholderManager("PAPI");
|
||||
this.placeholderManager.load();
|
||||
}
|
||||
}
|
||||
else if (this.placeholderManager != null) {
|
||||
this.placeholderManager.unload();
|
||||
this.placeholderManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +229,27 @@ public final class CustomNameplates extends JavaPlugin {
|
||||
return this.dataManager;
|
||||
}
|
||||
|
||||
public ScoreBoardManager getScoreBoardManager() {
|
||||
return this.scoreBoardManager;
|
||||
public TeamManager getTeamManager() {
|
||||
return this.teamManager;
|
||||
}
|
||||
|
||||
public TeamPacketManager getTeamPacketManager() {
|
||||
return teamPacketManager;
|
||||
}
|
||||
|
||||
public PlaceholderManager getPlaceholderManager() {
|
||||
return placeholderManager;
|
||||
}
|
||||
|
||||
public BossBarManager getBossBarManager() {
|
||||
return bossBarManager;
|
||||
}
|
||||
|
||||
public ActionBarManager getActionBarManager() {
|
||||
return actionBarManager;
|
||||
}
|
||||
|
||||
public NameplateManager getNameplateManager() {
|
||||
return nameplateManager;
|
||||
}
|
||||
}
|
||||
|
||||
19
src/main/java/net/momirealms/customnameplates/Function.java
Normal file
19
src/main/java/net/momirealms/customnameplates/Function.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package net.momirealms.customnameplates;
|
||||
|
||||
public abstract class Function {
|
||||
|
||||
private final String name;
|
||||
|
||||
protected Function(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
//
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
//
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package net.momirealms.customnameplates.actionbar;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.Function;
|
||||
import net.momirealms.customnameplates.hook.PlaceholderManager;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class ActionBarManager extends Function {
|
||||
|
||||
private BukkitTask bukkitTask;
|
||||
|
||||
private int timer;
|
||||
|
||||
public ActionBarManager(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
|
||||
PlaceholderManager placeholderManager = CustomNameplates.instance.getPlaceholderManager();
|
||||
|
||||
this.bukkitTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (timer < ConfigManager.ActionbarConfig.rate){
|
||||
timer++;
|
||||
}
|
||||
else {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> AdventureUtil.playerActionbar(player, ConfigManager.Main.placeholderAPI ? placeholderManager.parsePlaceholders(player, ConfigManager.ActionbarConfig.text) : ConfigManager.ActionbarConfig.text));
|
||||
timer = 0;
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(CustomNameplates.instance, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
this.bukkitTask.cancel();
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* 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.actionbar;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class ActionbarSender extends BukkitRunnable {
|
||||
|
||||
private int timer;
|
||||
|
||||
public ActionbarSender(){
|
||||
this.timer = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (timer < ConfigManager.ActionbarConfig.rate){
|
||||
timer++;
|
||||
}else {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
if (ConfigManager.MainConfig.placeholderAPI){
|
||||
AdventureUtil.playerActionbar(player, PlaceholderAPI.setPlaceholders(player, ConfigManager.ActionbarConfig.text));
|
||||
}else {
|
||||
AdventureUtil.playerActionbar(player, ConfigManager.ActionbarConfig.text);
|
||||
}
|
||||
});
|
||||
timer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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.actionbar;
|
||||
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class Timer {
|
||||
|
||||
private final int taskID;
|
||||
|
||||
public void stopTimer(int ID) {
|
||||
Bukkit.getScheduler().cancelTask(ID);
|
||||
}
|
||||
|
||||
public Timer() {
|
||||
ActionbarSender actionbarSender = new ActionbarSender();
|
||||
BukkitTask task = actionbarSender.runTaskTimerAsynchronously(CustomNameplates.instance, 1,1);
|
||||
this.taskID = task.getTaskId();
|
||||
}
|
||||
|
||||
public int getTaskID() {
|
||||
return this.taskID;
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,50 @@
|
||||
package net.momirealms.customnameplates.bossbar.protocollib;
|
||||
package net.momirealms.customnameplates.bossbar;
|
||||
|
||||
import org.bukkit.boss.BarColor;
|
||||
|
||||
public class BossBarConfigP {
|
||||
public class BossBarConfig {
|
||||
|
||||
private String text;
|
||||
private Overlay overlay;
|
||||
private BarColor color;
|
||||
private int rate;
|
||||
|
||||
public BossBarConfigP(String text, Overlay overlay, BarColor color, int rate){
|
||||
public BossBarConfig(String text, Overlay overlay, BarColor color, int rate) {
|
||||
this.text = text;
|
||||
this.overlay = overlay;
|
||||
this.color = color;
|
||||
this.rate = rate;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void setRate(int rate) {
|
||||
this.rate = rate;
|
||||
}
|
||||
|
||||
public void setOverlay(Overlay overlay) {
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
public void setColor(BarColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public int getRate() {
|
||||
return rate;
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Overlay getOverlay() {
|
||||
return overlay;
|
||||
}
|
||||
|
||||
public void setOverlay(Overlay overlay) {
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
public BarColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public Overlay getOverlay() {
|
||||
return overlay;
|
||||
public void setColor(BarColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getRate() {
|
||||
return rate;
|
||||
}
|
||||
|
||||
public void setRate(int rate) {
|
||||
this.rate = rate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.momirealms.customnameplates.bossbar;
|
||||
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.Function;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class BossBarManager extends Function {
|
||||
|
||||
private final SimpleListener simpleListener;
|
||||
|
||||
private final HashMap<Player, TimerTaskP> taskCache = new HashMap<>();
|
||||
|
||||
public BossBarManager(String name) {
|
||||
super(name);
|
||||
this.simpleListener = new SimpleListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
taskCache.put(player, new TimerTaskP(player));
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(simpleListener, CustomNameplates.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
HandlerList.unregisterAll(simpleListener);
|
||||
for (TimerTaskP timerTask : taskCache.values()) {
|
||||
timerTask.stopTimer();
|
||||
}
|
||||
taskCache.clear();
|
||||
}
|
||||
|
||||
public void onJoin(Player player) {
|
||||
taskCache.put(player, new TimerTaskP(player));
|
||||
}
|
||||
|
||||
public void onQuit(Player player) {
|
||||
TimerTaskP timerTask = taskCache.remove(player);
|
||||
if (timerTask != null){
|
||||
timerTask.stopTimer();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.momirealms.customnameplates.bossbar.protocollib;
|
||||
package net.momirealms.customnameplates.bossbar;
|
||||
|
||||
public enum Overlay {
|
||||
NOTCHED_6,
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.momirealms.customnameplates.bossbar;
|
||||
|
||||
public class PacketPlayOutBoss {
|
||||
|
||||
public enum Action {
|
||||
ADD,
|
||||
REMOVE,
|
||||
UPDATE_PCT,
|
||||
UPDATE_NAME,
|
||||
UPDATE_STYLE,
|
||||
UPDATE_PROPERTIES
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package net.momirealms.customnameplates.bossbar;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.InternalStructure;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.objects.TextCache;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Sender {
|
||||
|
||||
private final Player player;
|
||||
private int timer;
|
||||
private final TextCache text;
|
||||
private final BukkitTask bukkitTask;
|
||||
private final UUID uuid;
|
||||
|
||||
public Sender(Player player, BossBarConfig config){
|
||||
|
||||
this.player = player;
|
||||
this.text = new TextCache(player, config.getText());
|
||||
this.timer = 0;
|
||||
this.uuid = UUID.randomUUID();
|
||||
|
||||
show(config);
|
||||
|
||||
this.bukkitTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (timer < config.getRate()){
|
||||
timer++;
|
||||
}
|
||||
else {
|
||||
timer = 0;
|
||||
if (text.update()) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS);
|
||||
packet.getModifier().write(0, uuid);
|
||||
InternalStructure internalStructure = packet.getStructures().read(1);
|
||||
internalStructure.getChatComponents().write(0, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(text.getLatestValue()))));
|
||||
internalStructure.getFloat().write(0,1F);
|
||||
internalStructure.getEnumModifier(BarColor.class, 2).write(0, config.getColor());
|
||||
internalStructure.getEnumModifier(Overlay.class, 3).write(0, config.getOverlay());
|
||||
internalStructure.getModifier().write(5, false);
|
||||
internalStructure.getModifier().write(6, false);
|
||||
internalStructure.getModifier().write(4, false);
|
||||
try{
|
||||
CustomNameplates.protocolManager.sendServerPacket(player, packet);
|
||||
}catch (InvocationTargetException e){
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Failed to display bossbar for " + player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(CustomNameplates.instance,1,1);
|
||||
|
||||
}
|
||||
|
||||
private void show(BossBarConfig config){
|
||||
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS);
|
||||
|
||||
packet.getModifier().write(0, uuid);
|
||||
|
||||
InternalStructure internalStructure = packet.getStructures().read(1);
|
||||
internalStructure.getChatComponents().write(0, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(text.getLatestValue()))));
|
||||
internalStructure.getFloat().write(0,1F);
|
||||
internalStructure.getEnumModifier(BarColor.class, 2).write(0, config.getColor());
|
||||
internalStructure.getEnumModifier(Overlay.class, 3).write(0, config.getOverlay());
|
||||
internalStructure.getModifier().write(5, false);
|
||||
internalStructure.getModifier().write(6, false);
|
||||
internalStructure.getModifier().write(4, false);
|
||||
try{
|
||||
CustomNameplates.protocolManager.sendServerPacket(player, packet);
|
||||
}catch (InvocationTargetException e){
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Failed to display bossbar for " + player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
remove();
|
||||
bukkitTask.cancel();
|
||||
}
|
||||
|
||||
private void remove() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.momirealms.customnameplates.bossbar;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public record SimpleListener(BossBarManager function) implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
function.onJoin(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
function.onQuit(event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.momirealms.customnameplates.bossbar;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class TimerTaskP {
|
||||
|
||||
private final HashSet<Sender> bossBarCache = new HashSet<>();
|
||||
|
||||
public TimerTaskP(Player player){
|
||||
for (BossBarConfig config : ConfigManager.bossBars.values()) {
|
||||
Sender sender = new Sender(player, config);
|
||||
bossBarCache.add(sender);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopTimer(){
|
||||
bossBarCache.forEach(Sender::hide);
|
||||
bossBarCache.clear();
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* 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.bossbar.adventure;
|
||||
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
|
||||
public class BossBarConfigA {
|
||||
|
||||
private String text;
|
||||
private BossBar.Overlay overlay;
|
||||
private BossBar.Color color;
|
||||
private int rate;
|
||||
|
||||
public BossBarConfigA(String text, BossBar.Overlay overlay,
|
||||
BossBar.Color color, int rate){
|
||||
this.text = text;
|
||||
this.rate = rate;
|
||||
this.overlay = overlay;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public BossBar.Color getColor() {
|
||||
return color;
|
||||
}
|
||||
public int getRate() {
|
||||
return rate;
|
||||
}
|
||||
public BossBar.Overlay getOverlay() {
|
||||
return overlay;
|
||||
}
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setColor(BossBar.Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public void setOverlay(BossBar.Overlay overlay) {
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
public void setRate(int rate) {
|
||||
this.rate = rate;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* 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.bossbar.adventure;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class BossBarSenderA extends BukkitRunnable {
|
||||
|
||||
private final Player player;
|
||||
private final Audience audience;
|
||||
private BossBar bossBar;
|
||||
private int timer;
|
||||
private final BossBarConfigA bossbarConfig;
|
||||
|
||||
public BossBarSenderA(Player player, BossBarConfigA bossbarConfig){
|
||||
this.player = player;
|
||||
this.bossbarConfig = bossbarConfig;
|
||||
audience = CustomNameplates.adventure.player(player);
|
||||
this.timer = 0;
|
||||
}
|
||||
|
||||
public void hideBossbar(){
|
||||
audience.hideBossBar(bossBar);
|
||||
}
|
||||
|
||||
public void showBossbar(){
|
||||
if (ConfigManager.MainConfig.placeholderAPI){
|
||||
String s = PlaceholderAPI.setPlaceholders(player, bossbarConfig.getText());
|
||||
Component component = MiniMessage.miniMessage().deserialize(s);
|
||||
bossBar = BossBar.bossBar(component,1,bossbarConfig.getColor(),bossbarConfig.getOverlay());
|
||||
audience.showBossBar(bossBar);
|
||||
}else {
|
||||
Component component = MiniMessage.miniMessage().deserialize(bossbarConfig.getText());
|
||||
bossBar = BossBar.bossBar(component,1,bossbarConfig.getColor(),bossbarConfig.getOverlay());
|
||||
audience.showBossBar(bossBar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (timer < bossbarConfig.getRate()){
|
||||
timer++;
|
||||
}else {
|
||||
if (ConfigManager.MainConfig.placeholderAPI){
|
||||
bossBar.name(MiniMessage.miniMessage().deserialize(PlaceholderAPI.setPlaceholders(player, bossbarConfig.getText())));
|
||||
}else {
|
||||
bossBar.name(MiniMessage.miniMessage().deserialize(bossbarConfig.getText()));
|
||||
}
|
||||
bossBar.color(bossbarConfig.getColor());
|
||||
bossBar.overlay(bossbarConfig.getOverlay());
|
||||
timer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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.bossbar.adventure;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class QuitAndJoinA implements Listener {
|
||||
|
||||
public static HashMap<Player, TimerTaskA> cache = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event){
|
||||
Player player = event.getPlayer();
|
||||
TimerTaskA timerTask = new TimerTaskA(player);
|
||||
cache.put(player, timerTask);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event){
|
||||
Player player = event.getPlayer();
|
||||
TimerTaskA timerTask = cache.get(player);
|
||||
if (timerTask != null){
|
||||
timerTask.stopTimer();
|
||||
}
|
||||
cache.remove(player);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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.bossbar.adventure;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TimerTaskA {
|
||||
|
||||
private HashMap<Integer, BossBarSenderA> bossbarCache = new HashMap<>();
|
||||
|
||||
public TimerTaskA(Player player){
|
||||
ConfigManager.bossbarsA.forEach((key, bossbarConfig) -> {
|
||||
BossBarSenderA bossbar = new BossBarSenderA(player, bossbarConfig);
|
||||
bossbar.showBossbar();
|
||||
BukkitTask task = bossbar.runTaskTimerAsynchronously(CustomNameplates.instance, 1,1);
|
||||
bossbarCache.put(task.getTaskId(), bossbar);
|
||||
});
|
||||
}
|
||||
|
||||
public void stopTimer(){
|
||||
bossbarCache.forEach((key,value)-> {
|
||||
value.hideBossbar();
|
||||
Bukkit.getScheduler().cancelTask(key);
|
||||
});
|
||||
bossbarCache = null;
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package net.momirealms.customnameplates.bossbar.protocollib;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.InternalStructure;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BossBarSenderP extends BukkitRunnable {
|
||||
|
||||
private final Player player;
|
||||
private PacketContainer packet;
|
||||
private int timer;
|
||||
private final BossBarConfigP bossbarConfig;
|
||||
private String text;
|
||||
private Overlay overlay;
|
||||
private BarColor barColor;
|
||||
|
||||
public BossBarSenderP(Player player, BossBarConfigP bossbarConfig){
|
||||
this.player = player;
|
||||
this.bossbarConfig = bossbarConfig;
|
||||
this.timer = 0;
|
||||
}
|
||||
|
||||
public void showBossbar(){
|
||||
this.packet = new PacketContainer(PacketType.Play.Server.BOSS);
|
||||
this.overlay = bossbarConfig.getOverlay();
|
||||
this.barColor = bossbarConfig.getColor();
|
||||
packet.getModifier().write(0, UUID.randomUUID());
|
||||
InternalStructure internalStructure = packet.getStructures().read(1);
|
||||
if (ConfigManager.MainConfig.placeholderAPI){
|
||||
this.text = PlaceholderAPI.setPlaceholders(player, bossbarConfig.getText());
|
||||
}else {
|
||||
this.text = bossbarConfig.getText();
|
||||
}
|
||||
internalStructure.getChatComponents().write(0, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(text))));
|
||||
internalStructure.getFloat().write(0,1F);
|
||||
internalStructure.getEnumModifier(BarColor.class, 2).write(0, barColor);
|
||||
internalStructure.getEnumModifier(Overlay.class, 3).write(0, overlay);
|
||||
internalStructure.getModifier().write(5, false);
|
||||
internalStructure.getModifier().write(6, false);
|
||||
internalStructure.getModifier().write(4, false);
|
||||
try{
|
||||
CustomNameplates.protocolManager.sendServerPacket(player, packet);
|
||||
}catch (InvocationTargetException e){
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Failed to display bossbar for "+player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (timer < bossbarConfig.getRate()){
|
||||
timer++;
|
||||
}else {
|
||||
timer = 0;
|
||||
String newText;
|
||||
Label_out: {
|
||||
if (ConfigManager.MainConfig.placeholderAPI){
|
||||
newText = PlaceholderAPI.setPlaceholders(player, bossbarConfig.getText());
|
||||
}else {
|
||||
newText = bossbarConfig.getText();
|
||||
}
|
||||
if (!Objects.equals(newText, text) || !Objects.equals(bossbarConfig.getColor(), barColor) || !Objects.equals(bossbarConfig.getOverlay(), overlay)){
|
||||
text = newText;
|
||||
barColor = bossbarConfig.getColor();
|
||||
overlay = bossbarConfig.getOverlay();
|
||||
break Label_out;
|
||||
}
|
||||
return;
|
||||
}
|
||||
InternalStructure internalStructure = packet.getStructures().read(1);
|
||||
internalStructure.getChatComponents().write(0, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(text))));
|
||||
internalStructure.getEnumModifier(BarColor.class, 2).write(0, barColor);
|
||||
internalStructure.getEnumModifier(Overlay.class, 3).write(0, overlay);
|
||||
internalStructure.getModifier().write(5, false);
|
||||
internalStructure.getModifier().write(6, false);
|
||||
internalStructure.getModifier().write(4, false);
|
||||
try{
|
||||
CustomNameplates.protocolManager.sendServerPacket(player, packet);
|
||||
}catch (InvocationTargetException e){
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Failed to display bossbar for " + player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package net.momirealms.customnameplates.bossbar.protocollib;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class QuitAndJoinP implements Listener {
|
||||
|
||||
public static HashMap<Player, TimerTaskP> cache = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event){
|
||||
Player player = event.getPlayer();
|
||||
TimerTaskP timerTask = new TimerTaskP(player);
|
||||
cache.put(player, timerTask);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event){
|
||||
Player player = event.getPlayer();
|
||||
TimerTaskP timerTask = cache.get(player);
|
||||
if (timerTask != null){
|
||||
timerTask.stopTimer();
|
||||
}
|
||||
cache.remove(player);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package net.momirealms.customnameplates.bossbar.protocollib;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TimerTaskP {
|
||||
|
||||
private HashMap<Integer, BossBarSenderP> bossbarCache = new HashMap<>();
|
||||
|
||||
public TimerTaskP(Player player){
|
||||
ConfigManager.bossbarsP.forEach((key, bossbarConfig) -> {
|
||||
BossBarSenderP bossbar = new BossBarSenderP(player, bossbarConfig);
|
||||
bossbar.showBossbar();
|
||||
BukkitTask task = bossbar.runTaskTimerAsynchronously(CustomNameplates.instance, 1,1);
|
||||
bossbarCache.put(task.getTaskId(), bossbar);
|
||||
});
|
||||
}
|
||||
|
||||
public void stopTimer(){
|
||||
bossbarCache.forEach((key,value)-> {
|
||||
Bukkit.getScheduler().cancelTask(key);
|
||||
});
|
||||
bossbarCache = null;
|
||||
}
|
||||
}
|
||||
@@ -22,18 +22,14 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.resource.ResourceManager;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.data.DataManager;
|
||||
import net.momirealms.customnameplates.nameplates.NameplateInstance;
|
||||
import net.momirealms.customnameplates.hook.PapiHook;
|
||||
import net.momirealms.customnameplates.hook.TABHook;
|
||||
import net.momirealms.customnameplates.nameplates.NameplateUtil;
|
||||
import net.momirealms.customnameplates.scoreboard.NameplatesTeam;
|
||||
import net.momirealms.customnameplates.scoreboard.ScoreBoardManager;
|
||||
import net.momirealms.customnameplates.utils.ArmorStandPacketUtil;
|
||||
import net.momirealms.customnameplates.nameplates.NameplatesTeam;
|
||||
import net.momirealms.customnameplates.nameplates.TeamManager;
|
||||
import net.momirealms.customnameplates.utils.HoloUtil;
|
||||
import net.momirealms.customnameplates.utils.TeamPacketUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -53,24 +49,20 @@ public class Execute implements CommandExecutor {
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (args.length < 1){
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender,ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args[0]) {
|
||||
//重载
|
||||
case "reload" -> {
|
||||
|
||||
if (sender.hasPermission("nameplates.reload") || sender.isOp()) {
|
||||
|
||||
ConfigManager.MainConfig.reload();
|
||||
ConfigManager.Message.reload();
|
||||
ConfigManager.loadWidth();
|
||||
|
||||
if (ConfigManager.actionbar) ConfigManager.ActionbarConfig.load();
|
||||
if (ConfigManager.bossbar) ConfigManager.loadBossBar();
|
||||
if (ConfigManager.background) ConfigManager.loadBGConfig();
|
||||
if (ConfigManager.MainConfig.placeholderAPI) ConfigManager.loadPapi();
|
||||
if (ConfigManager.nameplate) ConfigManager.Nameplate.reload();
|
||||
CustomNameplates.instance.loadConfig();
|
||||
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.reload);
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.reload);
|
||||
@@ -78,9 +70,10 @@ public class Execute implements CommandExecutor {
|
||||
else AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.noPerm);
|
||||
return true;
|
||||
}
|
||||
//生成资源包
|
||||
case "generate" -> {
|
||||
if (sender.hasPermission("nameplates.generate") || sender.isOp()) {
|
||||
ConfigManager.MainConfig.reload();
|
||||
ConfigManager.Main.reload();
|
||||
CustomNameplates.instance.getResourceManager().generateResourcePack();
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.generate);
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.generate);
|
||||
@@ -88,138 +81,149 @@ public class Execute implements CommandExecutor {
|
||||
else AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.noPerm);
|
||||
return true;
|
||||
}
|
||||
//佩戴铭牌
|
||||
case "equip" -> {
|
||||
if (sender instanceof Player player) {
|
||||
|
||||
if (args.length < 2) {
|
||||
AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.hasPermission("nameplates.equip." + args[1]) || sender.isOp()) {
|
||||
|
||||
if (CustomNameplates.instance.getResourceManager().getNameplateInstance(args[1]) == null) {
|
||||
AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.not_exist);
|
||||
return true;
|
||||
}
|
||||
DataManager.cache.get(player.getUniqueId()).equipNameplate(args[1]);
|
||||
CustomNameplates.instance.getDataManager().getCache().get(player.getUniqueId()).equipNameplate(args[1]);
|
||||
CustomNameplates.instance.getDataManager().savePlayer(player.getUniqueId());
|
||||
String teamName = player.getName();
|
||||
if (ConfigManager.MainConfig.tab) teamName = TABHook.getTABTeam(teamName);
|
||||
ScoreBoardManager.teams.get(teamName).updateNameplates();
|
||||
if (ConfigManager.Nameplate.mode_team) {
|
||||
TeamPacketUtil.sendUpdateToAll(player);
|
||||
}
|
||||
CustomNameplates.instance.getTeamManager().getTeams().get(TeamManager.getTeamName(player)).updateNameplates();
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToAll(player);
|
||||
AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.equip.replace("{Nameplate}", CustomNameplates.instance.getResourceManager().getNameplateInstance(args[1]).getConfig().getName()));
|
||||
|
||||
}
|
||||
else AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.notAvailable);
|
||||
}
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.no_console);
|
||||
|
||||
return true;
|
||||
}
|
||||
//强制佩戴铭牌
|
||||
case "forceequip" -> {
|
||||
|
||||
if (args.length < 3){
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender,ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.hasPermission("nameplates.forceequip") || sender.isOp()){
|
||||
if (Bukkit.getPlayer(args[1]) != null){
|
||||
Player player = Bukkit.getPlayer(args[1]);
|
||||
//铭牌是否存在
|
||||
Player player = Bukkit.getPlayer(args[1]);
|
||||
if (player != null){
|
||||
if (CustomNameplates.instance.getResourceManager().getNameplateInstance(args[2]) == null){
|
||||
if(sender instanceof Player) AdventureUtil.playerMessage((Player) sender,ConfigManager.Message.prefix + ConfigManager.Message.not_exist);
|
||||
if(sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.not_exist);
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.not_exist);
|
||||
return true;
|
||||
}
|
||||
DataManager.cache.get(player.getUniqueId()).equipNameplate(args[2]);
|
||||
CustomNameplates.instance.getDataManager().getCache().get(player.getUniqueId()).equipNameplate(args[2]);
|
||||
CustomNameplates.instance.getDataManager().savePlayer(player.getUniqueId());
|
||||
if (ConfigManager.MainConfig.tab) ScoreBoardManager.teams.get(TABHook.getTABTeam(args[1])).updateNameplates();
|
||||
else ScoreBoardManager.teams.get(args[1]).updateNameplates();
|
||||
if (ConfigManager.Nameplate.mode_team) {
|
||||
TeamPacketUtil.sendUpdateToAll(player);
|
||||
}
|
||||
CustomNameplates.instance.getTeamManager().getTeams().get(TeamManager.getTeamName(player)).updateNameplates();
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToAll(player);
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.force_equip.replace("{Nameplate}", CustomNameplates.instance.getResourceManager().getNameplateInstance(args[2]).getConfig().getName()).replace("{Player}", args[1]));
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.force_equip.replace("{Nameplate}", CustomNameplates.instance.getResourceManager().getNameplateInstance(args[2]).getConfig().getName()).replace("{Player}", args[1]));
|
||||
}else {
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender,ConfigManager.Message.prefix + ConfigManager.Message.not_online.replace("{Player}",args[1]));
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.not_online.replace("{Player}",args[1]));
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.not_online.replace("{Player}",args[1]));
|
||||
}
|
||||
}
|
||||
else AdventureUtil.playerMessage((Player) sender,ConfigManager.Message.prefix + ConfigManager.Message.noPerm);
|
||||
else AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.noPerm);
|
||||
|
||||
return true;
|
||||
}
|
||||
//卸下铭牌
|
||||
case "unequip" -> {
|
||||
|
||||
if (sender instanceof Player player){
|
||||
DataManager.cache.get(player.getUniqueId()).equipNameplate("none");
|
||||
CustomNameplates.instance.getDataManager().getCache().get(player.getUniqueId()).equipNameplate("none");
|
||||
CustomNameplates.instance.getDataManager().savePlayer(player.getUniqueId());
|
||||
if (ConfigManager.MainConfig.tab) ScoreBoardManager.teams.get(TABHook.getTABTeam(player.getName())).updateNameplates();
|
||||
else ScoreBoardManager.teams.get(player.getName()).updateNameplates();
|
||||
if (ConfigManager.Nameplate.mode_team) {
|
||||
TeamPacketUtil.sendUpdateToAll(player);
|
||||
}
|
||||
AdventureUtil.playerMessage(player, ConfigManager.Message.prefix + ConfigManager.Message.unequip);
|
||||
CustomNameplates.instance.getTeamManager().getTeams().get(TeamManager.getTeamName(player)).updateNameplates();
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToAll(player);
|
||||
AdventureUtil.playerMessage(player, ConfigManager.Message.prefix + ConfigManager.Message.unEquip);
|
||||
}
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.no_console);
|
||||
|
||||
return true;
|
||||
}
|
||||
//强制卸下铭牌
|
||||
case "forceunequip" -> {
|
||||
|
||||
if (args.length < 2){
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender,ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.hasPermission("nameplates.forceunequip")){
|
||||
if (Bukkit.getPlayer(args[1]) != null){
|
||||
Player player = Bukkit.getPlayer(args[1]);
|
||||
DataManager.cache.get(player.getUniqueId()).equipNameplate("none");
|
||||
|
||||
Player player = Bukkit.getPlayer(args[1]);
|
||||
if (player != null){
|
||||
CustomNameplates.instance.getDataManager().getCache().get(player.getUniqueId()).equipNameplate("none");
|
||||
CustomNameplates.instance.getDataManager().savePlayer(player.getUniqueId());
|
||||
if (ConfigManager.MainConfig.tab) ScoreBoardManager.teams.get(TABHook.getTABTeam(args[1])).updateNameplates();
|
||||
else ScoreBoardManager.teams.get(args[1]).updateNameplates();
|
||||
if (ConfigManager.Nameplate.mode_team) {
|
||||
TeamPacketUtil.sendUpdateToAll(player);
|
||||
}
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.force_unequip.replace("{Player}", args[1]));
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.force_unequip.replace("{Player}", args[1]));
|
||||
CustomNameplates.instance.getTeamManager().getTeams().get(TeamManager.getTeamName(player)).updateNameplates();
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToAll(player);
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.force_unEquip.replace("{Player}", args[1]));
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.force_unEquip.replace("{Player}", args[1]));
|
||||
}else {
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender,ConfigManager.Message.prefix + ConfigManager.Message.not_online.replace("{Player}",args[1]));
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.not_online.replace("{Player}",args[1]));
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.not_online.replace("{Player}",args[1]));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//预览铭牌
|
||||
case "preview" -> {
|
||||
|
||||
if (sender instanceof Player player){
|
||||
if (player.hasPermission("nameplates.preview") || player.isOp()){
|
||||
//指令冷却
|
||||
long time = System.currentTimeMillis();
|
||||
//冷却时间判断
|
||||
if (time - (coolDown.getOrDefault(player, time - ConfigManager.Nameplate.preview * 1050)) < ConfigManager.Nameplate.preview * 1050) {
|
||||
AdventureUtil.playerMessage(player, ConfigManager.Message.prefix + ConfigManager.Message.cooldown);
|
||||
AdventureUtil.playerMessage(player, ConfigManager.Message.prefix + ConfigManager.Message.coolDown);
|
||||
return true;
|
||||
}
|
||||
//重置冷却时间
|
||||
coolDown.put(player, time);
|
||||
AdventureUtil.playerMessage(player,ConfigManager.Message.prefix + ConfigManager.Message.preview);
|
||||
if (ConfigManager.Nameplate.mode_team) {
|
||||
NameplatesTeam team = CustomNameplates.instance.getScoreBoardManager().getOrCreateTeam(player);
|
||||
AdventureUtil.playerMessage(player, ConfigManager.Message.prefix + ConfigManager.Message.preview);
|
||||
if (ConfigManager.Nameplate.mode.equalsIgnoreCase("team")) {
|
||||
NameplatesTeam team = CustomNameplates.instance.getTeamManager().getTeams().get(TeamManager.getTeamName(player));
|
||||
Component full = team.getPrefix().append(Component.text(player.getName()).color(TextColor.color(color2decimal(team.getColor()))).font(Key.key("default")).append(team.getSuffix()));
|
||||
HoloUtil.showHolo(full, player, (int) ConfigManager.Nameplate.preview);
|
||||
}
|
||||
else {
|
||||
ArmorStandPacketUtil.sendPreviewToOne(player);
|
||||
// ArmorStandPacketUtil.sendPreviewToOne(player);
|
||||
}
|
||||
}else {
|
||||
AdventureUtil.playerMessage((Player) sender,ConfigManager.Message.prefix + ConfigManager.Message.noPerm);
|
||||
AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.noPerm);
|
||||
}
|
||||
}
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.no_console);
|
||||
|
||||
return true;
|
||||
}
|
||||
//强制预览铭牌
|
||||
case "forcepreview" -> {
|
||||
|
||||
if (sender.hasPermission("nameplates.forcepreview") || sender.isOp()) {
|
||||
|
||||
if (args.length < 3){
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender,ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.lackArgs);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(args[1]);
|
||||
if (player == null){
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.not_online);
|
||||
@@ -228,53 +232,49 @@ public class Execute implements CommandExecutor {
|
||||
}
|
||||
NameplateInstance nameplateInstance = CustomNameplates.instance.getResourceManager().getNameplateInstance(args[2]);
|
||||
if (nameplateInstance == null){
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender,ConfigManager.Message.prefix + ConfigManager.Message.not_exist);
|
||||
if (sender instanceof Player) AdventureUtil.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.not_exist);
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.not_exist);
|
||||
return true;
|
||||
}
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - ConfigManager.Nameplate.preview * 1050)) < ConfigManager.Nameplate.preview * 1050) {
|
||||
AdventureUtil.playerMessage(player, ConfigManager.Message.prefix + ConfigManager.Message.cooldown);
|
||||
AdventureUtil.playerMessage(player, ConfigManager.Message.prefix + ConfigManager.Message.coolDown);
|
||||
return true;
|
||||
}
|
||||
coolDown.put(player, time);
|
||||
if (ConfigManager.Nameplate.mode_team) {
|
||||
String playerPrefix;
|
||||
String playerSuffix;
|
||||
if (ConfigManager.MainConfig.placeholderAPI) {
|
||||
playerPrefix = PapiHook.parsePlaceholders(player, ConfigManager.Nameplate.player_prefix);
|
||||
playerSuffix = PapiHook.parsePlaceholders(player, ConfigManager.Nameplate.player_suffix);
|
||||
}else {
|
||||
playerPrefix = ConfigManager.Nameplate.player_prefix;
|
||||
playerSuffix = ConfigManager.Nameplate.player_suffix;
|
||||
}
|
||||
Component prefix = Component.text(NameplateUtil.makeCustomNameplate(MiniMessage.miniMessage().stripTags(playerPrefix), args[1], MiniMessage.miniMessage().stripTags(playerSuffix), nameplateInstance)).font(ConfigManager.MainConfig.key).append(MiniMessage.miniMessage().deserialize(playerPrefix));
|
||||
Component suffix = MiniMessage.miniMessage().deserialize(playerSuffix).append(Component.text(NameplateUtil.getSuffixChar(MiniMessage.miniMessage().stripTags(playerPrefix) + args[1] + MiniMessage.miniMessage().stripTags(playerSuffix))).font(ConfigManager.MainConfig.key));
|
||||
if (ConfigManager.Nameplate.mode.equalsIgnoreCase("team")) {
|
||||
String playerPrefix = ConfigManager.Nameplate.hidePrefix ? "" : ConfigManager.Main.placeholderAPI ? CustomNameplates.instance.getPlaceholderManager().parsePlaceholders(player, ConfigManager.Nameplate.player_prefix) : ConfigManager.Nameplate.player_prefix;
|
||||
String playerSuffix = ConfigManager.Nameplate.hideSuffix ? "" : ConfigManager.Main.placeholderAPI ? CustomNameplates.instance.getPlaceholderManager().parsePlaceholders(player, ConfigManager.Nameplate.player_suffix) : ConfigManager.Nameplate.player_suffix;
|
||||
Component prefix = Component.text(NameplateUtil.makeCustomNameplate(MiniMessage.miniMessage().stripTags(playerPrefix), args[1], MiniMessage.miniMessage().stripTags(playerSuffix), nameplateInstance)).font(ConfigManager.Main.key).append(MiniMessage.miniMessage().deserialize(playerPrefix));
|
||||
Component suffix = MiniMessage.miniMessage().deserialize(playerSuffix).append(Component.text(NameplateUtil.getSuffixChar(MiniMessage.miniMessage().stripTags(playerPrefix) + args[1] + MiniMessage.miniMessage().stripTags(playerSuffix))).font(ConfigManager.Main.key));
|
||||
Component full = prefix.append(Component.text(player.getName()).color(TextColor.color(color2decimal(nameplateInstance.getConfig().getColor()))).font(Key.key("default")).append(suffix));
|
||||
HoloUtil.showHolo(full, player, (int) ConfigManager.Nameplate.preview);
|
||||
}
|
||||
else {
|
||||
ArmorStandPacketUtil.sendPreviewToOne(player);
|
||||
// ArmorStandPacketUtil.sendPreviewToOne(player);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//显示可用铭牌
|
||||
case "list" -> {
|
||||
if (sender instanceof Player player) {
|
||||
if (player.isOp()) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
CustomNameplates.instance.getResourceManager().NAMEPLATES.keySet().forEach(key -> {
|
||||
ResourceManager.NAMEPLATES.keySet().forEach(key -> {
|
||||
if (key.equalsIgnoreCase("none")) return;
|
||||
stringBuilder.append(key).append(" ");
|
||||
});
|
||||
AdventureUtil.playerMessage(player, ConfigManager.Message.prefix + ConfigManager.Message.available.replace("{Nameplates}", stringBuilder.toString()));
|
||||
} else if (player.hasPermission("nameplates.list")) {
|
||||
}
|
||||
else if (player.hasPermission("nameplates.list")) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (PermissionAttachmentInfo info : player.getEffectivePermissions()) {
|
||||
String permission = info.getPermission().toLowerCase();
|
||||
if (permission.startsWith("nameplates.equip.")) {
|
||||
permission = StringUtils.replace(permission, "nameplates.equip.", "");
|
||||
if (CustomNameplates.instance.getResourceManager().NAMEPLATES.get(permission) != null) {
|
||||
if (ResourceManager.NAMEPLATES.get(permission) != null) {
|
||||
stringBuilder.append(permission).append(" ");
|
||||
}
|
||||
}
|
||||
@@ -286,6 +286,7 @@ public class Execute implements CommandExecutor {
|
||||
else AdventureUtil.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.no_console);
|
||||
return true;
|
||||
}
|
||||
//默认
|
||||
default -> {
|
||||
if (sender instanceof Player player){
|
||||
if (player.hasPermission("nameplates.help")){
|
||||
|
||||
@@ -38,17 +38,18 @@ public class TabComplete implements TabCompleter {
|
||||
public @Nullable List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
|
||||
if(1 == args.length){
|
||||
|
||||
List<String> tab = new ArrayList<>();
|
||||
if (sender.hasPermission("customnameplates.reload")) tab.add("reload");
|
||||
if (sender.hasPermission("customnameplates.help")) tab.add("help");
|
||||
if (sender.hasPermission("customnameplates.equip")) tab.add("equip");
|
||||
if (sender.hasPermission("customnameplates.forceequip")) tab.add("forceequip");
|
||||
if (sender.hasPermission("customnameplates.unequip")) tab.add("unequip");
|
||||
if (sender.hasPermission("customnameplates.forceunequip")) tab.add("forceunequip");
|
||||
if (sender.hasPermission("customnameplates.forcepreview")) tab.add("forcepreview");
|
||||
if (sender.hasPermission("customnameplates.preview")) tab.add("preview");
|
||||
if (sender.hasPermission("customnameplates.list")) tab.add("list");
|
||||
if (sender.hasPermission("customnameplates.generate")) tab.add("generate");
|
||||
if (sender.hasPermission("nameplates.reload")) tab.add("reload");
|
||||
if (sender.hasPermission("nameplates.help")) tab.add("help");
|
||||
if (sender.hasPermission("nameplates.equip")) tab.add("equip");
|
||||
if (sender.hasPermission("nameplates.forceequip")) tab.add("forceequip");
|
||||
if (sender.hasPermission("nameplates.unequip")) tab.add("unequip");
|
||||
if (sender.hasPermission("nameplates.forceunequip")) tab.add("forceunequip");
|
||||
if (sender.hasPermission("nameplates.forcepreview")) tab.add("forcepreview");
|
||||
if (sender.hasPermission("nameplates.preview")) tab.add("preview");
|
||||
if (sender.hasPermission("nameplates.list")) tab.add("list");
|
||||
if (sender.hasPermission("nameplates.generate")) tab.add("generate");
|
||||
|
||||
List<String> arrayList = new ArrayList<>();
|
||||
for (String cmd : tab) {
|
||||
@@ -66,7 +67,7 @@ public class TabComplete implements TabCompleter {
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("forceunequip") && sender.hasPermission("customnameplates.forceunequip")){
|
||||
if (args[0].equalsIgnoreCase("forceunequip") && sender.hasPermission("nameplates.forceunequip")){
|
||||
List<String> arrayList = new ArrayList<>();
|
||||
for (String cmd : online_players()) {
|
||||
if (cmd.startsWith(args[1]))
|
||||
@@ -74,7 +75,7 @@ public class TabComplete implements TabCompleter {
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("forceequip") && sender.hasPermission("customnameplates.forceequip")){
|
||||
if (args[0].equalsIgnoreCase("forceequip") && sender.hasPermission("nameplates.forceequip")){
|
||||
List<String> arrayList = new ArrayList<>();
|
||||
for (String cmd : online_players()) {
|
||||
if (cmd.startsWith(args[1]))
|
||||
@@ -82,7 +83,7 @@ public class TabComplete implements TabCompleter {
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("forcepreview") && sender.hasPermission("customnameplates.forcepreview")){
|
||||
if (args[0].equalsIgnoreCase("forcepreview") && sender.hasPermission("nameplates.forcepreview")){
|
||||
List<String> arrayList = new ArrayList<>();
|
||||
for (String cmd : online_players()) {
|
||||
if (cmd.startsWith(args[1]))
|
||||
@@ -92,7 +93,7 @@ public class TabComplete implements TabCompleter {
|
||||
}
|
||||
}
|
||||
if(3 == args.length){
|
||||
if (args[0].equalsIgnoreCase("forceequip") && sender.hasPermission("customnameplates.forceequip")){
|
||||
if (args[0].equalsIgnoreCase("forceequip") && sender.hasPermission("nameplates.forceequip")){
|
||||
List<String> arrayList = new ArrayList<>();
|
||||
for (String cmd : nameplates()) {
|
||||
if (cmd.startsWith(args[2]))
|
||||
@@ -100,7 +101,7 @@ public class TabComplete implements TabCompleter {
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("forcepreview") && sender.hasPermission("customnameplates.forcepreview")){
|
||||
if (args[0].equalsIgnoreCase("forcepreview") && sender.hasPermission("nameplates.forcepreview")){
|
||||
List<String> arrayList = new ArrayList<>();
|
||||
for (String cmd : nameplates()) {
|
||||
if (cmd.startsWith(args[2]))
|
||||
@@ -123,8 +124,8 @@ public class TabComplete implements TabCompleter {
|
||||
if (sender instanceof Player player){
|
||||
for (PermissionAttachmentInfo info : player.getEffectivePermissions()) {
|
||||
String permission = info.getPermission().toLowerCase();
|
||||
if (permission.startsWith("customnameplates.equip.")) {
|
||||
permission = StringUtils.replace(permission, "customnameplates.equip.", "");
|
||||
if (permission.startsWith("nameplates.equip.")) {
|
||||
permission = StringUtils.replace(permission, "nameplates.equip.", "");
|
||||
if (ResourceManager.NAMEPLATES.get(permission) != null){
|
||||
availableNameplates.add(permission);
|
||||
}
|
||||
|
||||
@@ -17,52 +17,47 @@
|
||||
|
||||
package net.momirealms.customnameplates.data;
|
||||
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.utils.ArmorStandPacketUtil;
|
||||
import net.momirealms.customnameplates.utils.TeamPacketUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DataManager {
|
||||
|
||||
public static Map<UUID, PlayerData> cache = new HashMap<>();
|
||||
private final HashMap<UUID, PlayerData> cache = new HashMap<>();
|
||||
|
||||
public PlayerData getOrEmpty(Player player) {
|
||||
if (cache.get(player.getUniqueId()) == null) {
|
||||
return new PlayerData("none");
|
||||
}
|
||||
else {
|
||||
return cache.get(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
public void loadData(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (ConfigManager.DatabaseConfig.async) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomNameplates.instance, () -> {
|
||||
PlayerData playerData = SqlHandler.getPlayerData(uuid);
|
||||
if (playerData == null) {
|
||||
playerData = new PlayerData(ConfigManager.Nameplate.default_nameplate, 0);
|
||||
}
|
||||
cache.put(uuid, playerData);
|
||||
CustomNameplates.instance.getScoreBoardManager().getOrCreateTeam(player);
|
||||
TeamPacketUtil.sendUpdateToOne(player);
|
||||
TeamPacketUtil.sendUpdateToAll(player);
|
||||
if (!ConfigManager.Nameplate.mode_team) {
|
||||
ArmorStandPacketUtil.preparePackets(player);
|
||||
}
|
||||
cache.put(uuid, Optional.ofNullable(playerData).orElse(new PlayerData(ConfigManager.Nameplate.default_nameplate)));
|
||||
CustomNameplates.instance.getTeamManager().createTeam(player);
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToAll(player);
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToOne(player);
|
||||
});
|
||||
}
|
||||
else {
|
||||
PlayerData playerData = SqlHandler.getPlayerData(uuid);
|
||||
if (playerData == null) {
|
||||
playerData = new PlayerData(ConfigManager.Nameplate.default_nameplate, 0);
|
||||
}
|
||||
cache.put(uuid, playerData);
|
||||
CustomNameplates.instance.getScoreBoardManager().getOrCreateTeam(player);
|
||||
cache.put(uuid, Optional.ofNullable(playerData).orElse(new PlayerData(ConfigManager.Nameplate.default_nameplate)));
|
||||
CustomNameplates.instance.getTeamManager().createTeam(player);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomNameplates.instance, () -> {
|
||||
TeamPacketUtil.sendUpdateToOne(player);
|
||||
TeamPacketUtil.sendUpdateToAll(player);
|
||||
if (!ConfigManager.Nameplate.mode_team) {
|
||||
ArmorStandPacketUtil.preparePackets(player);
|
||||
}
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToAll(player);
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToOne(player);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -73,7 +68,7 @@ public class DataManager {
|
||||
}
|
||||
PlayerData playerData = SqlHandler.getPlayerData(uuid);
|
||||
if (playerData == null) {
|
||||
playerData = new PlayerData(ConfigManager.Nameplate.default_nameplate, 0);
|
||||
playerData = new PlayerData(ConfigManager.Nameplate.default_nameplate);
|
||||
}
|
||||
cache.put(uuid, playerData);
|
||||
return playerData;
|
||||
@@ -117,4 +112,8 @@ public class DataManager {
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
public HashMap<UUID, PlayerData> getCache() {
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
@@ -17,23 +17,27 @@
|
||||
|
||||
package net.momirealms.customnameplates.data;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
|
||||
public class PlayerData {
|
||||
|
||||
public static PlayerData EMPTY = new PlayerData("none");
|
||||
|
||||
private String equipped;
|
||||
private int accepted;
|
||||
// private boolean accepted;
|
||||
|
||||
public PlayerData(String equipped, int accepted) {
|
||||
public PlayerData(String equipped) {
|
||||
this.equipped = equipped;
|
||||
this.accepted = accepted;
|
||||
// this.accepted = accepted;
|
||||
}
|
||||
|
||||
public int getAccepted(){
|
||||
return this.accepted;
|
||||
}
|
||||
|
||||
public void setAccepted(int accepted){
|
||||
this.accepted = accepted;
|
||||
}
|
||||
// public boolean getAccepted(){
|
||||
// return this.accepted;
|
||||
// }
|
||||
//
|
||||
// public void setAccepted(boolean accepted){
|
||||
// this.accepted = accepted;
|
||||
// }
|
||||
|
||||
public String getEquippedNameplate() {
|
||||
return this.equipped;
|
||||
@@ -42,4 +46,5 @@ public class PlayerData {
|
||||
public void equipNameplate(String nameplate) {
|
||||
this.equipped = nameplate.toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,13 +17,15 @@
|
||||
|
||||
package net.momirealms.customnameplates.data;
|
||||
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import net.momirealms.customnameplates.utils.SqlConnection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SqlHandler {
|
||||
@@ -95,7 +97,7 @@ public class SqlHandler {
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet rs = statement.executeQuery();
|
||||
if (rs.next()) {
|
||||
playerData = new PlayerData(rs.getString(2), rs.getInt(3));
|
||||
playerData = new PlayerData(rs.getString(2));
|
||||
}else {
|
||||
sql = "INSERT INTO " + ConfigManager.DatabaseConfig.tableName + "(player,equipped,accepted) values(?,?,?)";
|
||||
statement = connection.prepareStatement(sql);
|
||||
@@ -119,7 +121,7 @@ public class SqlHandler {
|
||||
String query = " SET equipped = ?, accepted = ? WHERE player = ?";
|
||||
PreparedStatement statement = connection.prepareStatement("UPDATE " + ConfigManager.DatabaseConfig.tableName + query);
|
||||
statement.setString(1, playerData.getEquippedNameplate());
|
||||
statement.setInt(2, playerData.getAccepted());
|
||||
statement.setInt(2, 1);
|
||||
statement.setString(3, uuid.toString());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
@@ -131,13 +133,14 @@ public class SqlHandler {
|
||||
|
||||
public static void saveAll() {
|
||||
Connection connection = database.getConnectionAndCheck();
|
||||
HashMap<UUID, PlayerData> data = CustomNameplates.instance.getDataManager().getCache();
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
try {
|
||||
PlayerData playerData = DataManager.cache.get(player.getUniqueId());
|
||||
PlayerData playerData = data.get(player.getUniqueId());
|
||||
String query = " SET equipped = ?, accepted = ? WHERE player = ?";
|
||||
PreparedStatement statement = connection.prepareStatement("UPDATE " + ConfigManager.DatabaseConfig.tableName + query);
|
||||
statement.setString(1, playerData.getEquippedNameplate());
|
||||
statement.setInt(2, playerData.getAccepted());
|
||||
statement.setInt(2, 1);
|
||||
statement.setString(3, String.valueOf(player.getUniqueId()));
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.customnameplates.font;
|
||||
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* 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.hook;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PapiHook {
|
||||
|
||||
public static String parsePlaceholders(Player player, String papi) {
|
||||
return PlaceholderAPI.setPlaceholders(player, papi);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.hook;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.Function;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PlaceholderManager extends Function {
|
||||
|
||||
private Placeholders placeholders;
|
||||
|
||||
public PlaceholderManager(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
this.placeholders = new Placeholders();
|
||||
this.placeholders.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
this.placeholders.unregister();
|
||||
}
|
||||
|
||||
public String parsePlaceholders(Player player, String papi) {
|
||||
return PlaceholderAPI.setPlaceholders(player, papi);
|
||||
}
|
||||
|
||||
private final Pattern placeholderPattern = Pattern.compile("%([^%]*)%");
|
||||
|
||||
public List<String> detectPlaceholders(String text){
|
||||
if (text == null || !text.contains("%")) return Collections.emptyList();
|
||||
List<String> placeholders = new ArrayList<>();
|
||||
Matcher matcher = placeholderPattern.matcher(text);
|
||||
while (matcher.find()) placeholders.add(matcher.group());
|
||||
return placeholders;
|
||||
}
|
||||
}
|
||||
@@ -20,20 +20,22 @@ package net.momirealms.customnameplates.hook;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.objects.BackGround;
|
||||
import net.momirealms.customnameplates.data.DataManager;
|
||||
import net.momirealms.customnameplates.data.PlayerData;
|
||||
import net.momirealms.customnameplates.nameplates.NameplateInstance;
|
||||
import net.momirealms.customnameplates.font.FontUtil;
|
||||
import net.momirealms.customnameplates.nameplates.NameplateUtil;
|
||||
import net.momirealms.customnameplates.resource.ResourceManager;
|
||||
import net.momirealms.customnameplates.scoreboard.NameplatesTeam;
|
||||
import net.momirealms.customnameplates.scoreboard.ScoreBoardManager;
|
||||
import net.momirealms.customnameplates.objects.BGInfo;
|
||||
import net.momirealms.customnameplates.objects.NPInfo;
|
||||
import net.momirealms.customnameplates.nameplates.NameplatesTeam;
|
||||
import net.momirealms.customnameplates.nameplates.TeamManager;
|
||||
import net.momirealms.customnameplates.objects.BackGroundText;
|
||||
import net.momirealms.customnameplates.objects.NameplateText;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class Placeholders extends PlaceholderExpansion {
|
||||
|
||||
@Override
|
||||
@@ -54,60 +56,49 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, String params) {
|
||||
if (params.equals("equipped")){
|
||||
PlayerData playerData = DataManager.cache.get(player.getUniqueId());
|
||||
String nameplate = playerData.getEquippedNameplate();
|
||||
String nameplate = Optional.ofNullable(CustomNameplates.instance.getDataManager().getCache().get(player.getUniqueId())).orElse(PlayerData.EMPTY).getEquippedNameplate();
|
||||
if (!nameplate.equals("none")) return ResourceManager.NAMEPLATES.get(nameplate).getName();
|
||||
else return ConfigManager.Message.noNameplate;
|
||||
}
|
||||
if (params.equals("prefix")){
|
||||
String teamName = player.getName();
|
||||
if (ConfigManager.MainConfig.tab) teamName = TABHook.getTABTeam(teamName);
|
||||
NameplatesTeam nameplatesTeam = ScoreBoardManager.teams.get(teamName);
|
||||
NameplatesTeam nameplatesTeam = CustomNameplates.instance.getTeamManager().getTeams().get(TeamManager.getTeamName(player.getPlayer()));
|
||||
if (nameplatesTeam != null) return nameplatesTeam.getPrefixText();
|
||||
else return "";
|
||||
}
|
||||
if (params.equals("suffix")){
|
||||
String teamName = player.getName();
|
||||
if (ConfigManager.MainConfig.tab) teamName = TABHook.getTABTeam(teamName);
|
||||
NameplatesTeam nameplatesTeam = ScoreBoardManager.teams.get(teamName);
|
||||
NameplatesTeam nameplatesTeam = CustomNameplates.instance.getTeamManager().getTeams().get(TeamManager.getTeamName(player.getPlayer()));
|
||||
if (nameplatesTeam != null) return nameplatesTeam.getSuffixText();
|
||||
else return "";
|
||||
}
|
||||
if (params.startsWith("bg_")){
|
||||
String bg = params.substring(3);
|
||||
BGInfo bgInfo = ConfigManager.papiBG.get(bg);
|
||||
if (bgInfo != null){
|
||||
BackGround backGround = ConfigManager.backgrounds.get(bgInfo.getBackground());
|
||||
if (backGround != null){
|
||||
String text = bgInfo.getText();
|
||||
if (ConfigManager.MainConfig.placeholderAPI) text = PlaceholderAPI.setPlaceholders(player, text);
|
||||
return backGround.getBackGround(FontUtil.getTotalWidth(text));
|
||||
}
|
||||
}
|
||||
BackGroundText backGroundText = ConfigManager.papiBG.get(bg);
|
||||
if (backGroundText == null) return "";
|
||||
BackGround backGround = ConfigManager.backgrounds.get(backGroundText.getBackground());
|
||||
if (backGround == null) return "";
|
||||
String text = backGroundText.getText();
|
||||
if (ConfigManager.Main.placeholderAPI) text = PlaceholderAPI.setPlaceholders(player, text);
|
||||
return backGround.getBackGround(FontUtil.getTotalWidth(text));
|
||||
}
|
||||
if (params.startsWith("npp_")){
|
||||
String np = params.substring(4);
|
||||
NPInfo npInfo = ConfigManager.papiNP.get(np);
|
||||
if (npInfo != null){
|
||||
NameplateInstance nameplateInstance = ResourceManager.NAMEPLATES.get(npInfo.getNameplate());
|
||||
if (nameplateInstance != null){
|
||||
String text = npInfo.getText();
|
||||
if (ConfigManager.MainConfig.placeholderAPI) text = PlaceholderAPI.setPlaceholders(player, text);
|
||||
return NameplateUtil.makeCustomNameplate("", text,"", nameplateInstance);
|
||||
}
|
||||
}
|
||||
NameplateText nameplateText = ConfigManager.papiNP.get(np);
|
||||
if (nameplateText == null) return "";
|
||||
NameplateInstance nameplateInstance = ResourceManager.NAMEPLATES.get(nameplateText.getNameplate());
|
||||
if (nameplateInstance == null) return "";
|
||||
String text = nameplateText.getText();
|
||||
if (ConfigManager.Main.placeholderAPI) text = PlaceholderAPI.setPlaceholders(player, text);
|
||||
return NameplateUtil.makeCustomNameplate("", text,"", nameplateInstance);
|
||||
}
|
||||
if (params.startsWith("nps_")){
|
||||
String np = params.substring(4);
|
||||
NPInfo npInfo = ConfigManager.papiNP.get(np);
|
||||
if (npInfo != null){
|
||||
NameplateInstance nameplateInstance = ResourceManager.NAMEPLATES.get(npInfo.getNameplate());
|
||||
if (nameplateInstance != null){
|
||||
String text = npInfo.getText();
|
||||
if (ConfigManager.MainConfig.placeholderAPI) text = PlaceholderAPI.setPlaceholders(player, text);
|
||||
return NameplateUtil.getSuffixChar(text);
|
||||
}
|
||||
}
|
||||
NameplateText nameplateText = ConfigManager.papiNP.get(np);
|
||||
if (nameplateText == null) return "";
|
||||
NameplateInstance nameplateInstance = ResourceManager.NAMEPLATES.get(nameplateText.getNameplate());
|
||||
if (nameplateInstance == null) return "";
|
||||
String text = nameplateText.getText();
|
||||
if (ConfigManager.Main.placeholderAPI) text = PlaceholderAPI.setPlaceholders(player, text);
|
||||
return NameplateUtil.getSuffixChar(text);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.momirealms.customnameplates.hook;
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
|
||||
public class TABHook {
|
||||
public class TABTeamHook {
|
||||
|
||||
public static String getTABTeam(String playerName){
|
||||
TAB tab = TAB.getInstance();
|
||||
@@ -1,42 +0,0 @@
|
||||
package net.momirealms.customnameplates.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.utils.ArmorStandPacketUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class EntityDestroyListener extends PacketAdapter {
|
||||
|
||||
public EntityDestroyListener(CustomNameplates plugin) {
|
||||
super(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.ENTITY_DESTROY);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
List<Integer> ids = packet.getIntLists().read(0);
|
||||
Player player = event.getPlayer();
|
||||
for (int id : ids) {
|
||||
int[] armor = ArmorStandPacketUtil.id2ids.get(id);
|
||||
if (armor != null) {
|
||||
ArmorStandPacketUtil.sendDestroyToOne(player, armor);
|
||||
HashMap<Integer, BukkitTask> taskMap = ArmorStandPacketUtil.taskCache.get(player.getEntityId());
|
||||
if (taskMap != null) {
|
||||
BukkitTask task = taskMap.remove(id);
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package net.momirealms.customnameplates.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.utils.ArmorStandPacketUtil;
|
||||
|
||||
public class MountPacketListener extends PacketAdapter {
|
||||
|
||||
public MountPacketListener(CustomNameplates plugin) {
|
||||
super(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.MOUNT);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
int[] ids = ArmorStandPacketUtil.id2ids.get(packet.getIntegers().read(0));
|
||||
if (ids != null) {
|
||||
int[] old = packet.getIntegerArrays().read(0);
|
||||
int[] idArray = new int[ids.length + old.length];
|
||||
int i = 0;
|
||||
while (i < ids.length) {
|
||||
idArray[i] = ids[i];
|
||||
i ++;
|
||||
}
|
||||
while (i < ids.length + old.length) {
|
||||
idArray[i] = old[i - ids.length];
|
||||
i ++;
|
||||
}
|
||||
packet.getModifier().write(1, idArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package net.momirealms.customnameplates.listener;
|
||||
|
||||
import me.clip.placeholderapi.events.ExpansionUnregisterEvent;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class PapiReload implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onReload(ExpansionUnregisterEvent event){
|
||||
if (CustomNameplates.placeholders != null){
|
||||
if (event.getExpansion().equals(CustomNameplates.placeholders)){
|
||||
CustomNameplates.placeholders.register();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.data.DataManager;
|
||||
import net.momirealms.customnameplates.data.PlayerData;
|
||||
import net.momirealms.customnameplates.data.SqlHandler;
|
||||
import net.momirealms.customnameplates.hook.TABHook;
|
||||
import net.momirealms.customnameplates.scoreboard.ScoreBoardManager;
|
||||
import net.momirealms.customnameplates.utils.ArmorStandPacketUtil;
|
||||
import net.momirealms.customnameplates.utils.TeamPacketUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
public static HashMap<Player, BukkitTask> taskCache = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
|
||||
CustomNameplates.instance.getDataManager().loadData(event.getPlayer());
|
||||
|
||||
if (ConfigManager.Nameplate.update && ConfigManager.Nameplate.mode_team) {
|
||||
Player player = event.getPlayer();
|
||||
BukkitTask task = Bukkit.getScheduler().runTaskTimerAsynchronously(CustomNameplates.instance, () -> {
|
||||
String teamName = player.getName();
|
||||
if (ConfigManager.MainConfig.tab) teamName = TABHook.getTABTeam(teamName);
|
||||
ScoreBoardManager.teams.get(teamName).updateNameplates();
|
||||
TeamPacketUtil.sendUpdateToAll(player);
|
||||
}, 20, ConfigManager.Nameplate.refresh);
|
||||
taskCache.put(player, task);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
CustomNameplates.instance.getDataManager().unloadPlayer(event.getPlayer().getUniqueId());
|
||||
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
Player player = event.getPlayer();
|
||||
String teamName = player.getName();
|
||||
if (ConfigManager.MainConfig.tab) teamName = TABHook.getTABTeam(teamName);
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
if (team != null) team.unregister();
|
||||
ScoreBoardManager.teams.remove(teamName);
|
||||
if (ConfigManager.Nameplate.update) {
|
||||
if (ConfigManager.Nameplate.mode_team) {
|
||||
TeamPacketUtil.teamInfoCache.remove(player);
|
||||
BukkitTask bukkitTask = taskCache.remove(player);
|
||||
if (bukkitTask != null) {
|
||||
bukkitTask.cancel();
|
||||
}
|
||||
}
|
||||
else {
|
||||
int id = event.getPlayer().getEntityId();
|
||||
HashMap<Integer, BukkitTask> taskMap = ArmorStandPacketUtil.taskCache.remove(id);
|
||||
if (taskMap != null) {
|
||||
for (int otherID : taskMap.keySet()) {
|
||||
HashMap<Integer, BukkitTask> otherTaskMap = ArmorStandPacketUtil.taskCache.get(otherID);
|
||||
if (otherTaskMap != null) {
|
||||
BukkitTask task = otherTaskMap.remove(id);
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
taskMap.values().forEach(BukkitTask::cancel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAccept(PlayerResourcePackStatusEvent event) {
|
||||
if (!ConfigManager.Nameplate.show_after) return;
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerData playerData = DataManager.cache.get(event.getPlayer().getUniqueId());
|
||||
if (playerData == null) {
|
||||
return;
|
||||
}
|
||||
if (event.getStatus() == PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED) {
|
||||
playerData.setAccepted(1);
|
||||
Player player = event.getPlayer();
|
||||
SqlHandler.save(playerData, player.getUniqueId());
|
||||
TeamPacketUtil.sendUpdateToOne(player);
|
||||
if (!ConfigManager.Nameplate.mode_team) {
|
||||
HashMap<Integer, BukkitTask> tasks = ArmorStandPacketUtil.taskCache.get(player.getEntityId());
|
||||
if (tasks == null) return;
|
||||
for (Integer id : tasks.keySet()){
|
||||
ArmorStandPacketUtil.forceUpdateOneToOne(id, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event.getStatus() == PlayerResourcePackStatusEvent.Status.DECLINED || event.getStatus() == PlayerResourcePackStatusEvent.Status.FAILED_DOWNLOAD) {
|
||||
playerData.setAccepted(0);
|
||||
SqlHandler.save(playerData, event.getPlayer().getUniqueId());
|
||||
Player player = event.getPlayer();
|
||||
TeamPacketUtil.sendUpdateToOne(player);
|
||||
if (!ConfigManager.Nameplate.mode_team) {
|
||||
HashMap<Integer, BukkitTask> tasks = ArmorStandPacketUtil.taskCache.get(player.getEntityId());
|
||||
if (tasks == null) return;
|
||||
for (Integer id : tasks.keySet()){
|
||||
ArmorStandPacketUtil.forceUpdateOneToOne(id, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(CustomNameplates.instance);
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package net.momirealms.customnameplates.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.utils.ArmorStandPacketUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PlayerPacketsListener extends PacketAdapter {
|
||||
|
||||
public PlayerPacketsListener(CustomNameplates plugin) {
|
||||
super(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public synchronized void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomNameplates.instance, ()-> {
|
||||
Player player = event.getPlayer();
|
||||
Player otherPlayer = Bukkit.getPlayer(packet.getUUIDs().read(0));
|
||||
if (otherPlayer != null) {
|
||||
ArmorStandPacketUtil.sendSummonOneToOne(player, otherPlayer);
|
||||
if (ConfigManager.Nameplate.update) {
|
||||
BukkitTask bukkitTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ArmorStandPacketUtil.sendUpdateOneToOne(otherPlayer, player);
|
||||
}
|
||||
}.runTaskTimerAsynchronously(CustomNameplates.instance, 20, ConfigManager.Nameplate.refresh);
|
||||
HashMap<Integer, BukkitTask> inner = ArmorStandPacketUtil.taskCache.get(player.getEntityId());
|
||||
if (inner == null) {
|
||||
inner = new HashMap<>();
|
||||
inner.put(otherPlayer.getEntityId(), bukkitTask);
|
||||
ArmorStandPacketUtil.taskCache.put(player.getEntityId(), inner);
|
||||
}
|
||||
else {
|
||||
int other = otherPlayer.getEntityId();
|
||||
BukkitTask bukkitTask2 = inner.get(other);
|
||||
if (bukkitTask2 != null) {
|
||||
bukkitTask2.cancel();
|
||||
}
|
||||
inner.put(other, bukkitTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.momirealms.customnameplates.nameplates;
|
||||
|
||||
import net.momirealms.customnameplates.objects.TextCache;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public interface ArmorStand {
|
||||
|
||||
void setOffset(double var1);
|
||||
|
||||
double getOffset();
|
||||
|
||||
TextCache getText();
|
||||
|
||||
void teleport();
|
||||
|
||||
void teleport(Player player);
|
||||
|
||||
void setSneak(boolean isSneaking, boolean respawn);
|
||||
|
||||
void destroy();
|
||||
|
||||
void destroy(Player player);
|
||||
|
||||
void refresh();
|
||||
|
||||
int getEntityId();
|
||||
|
||||
void spawn(Player player);
|
||||
|
||||
void respawn(Player player);
|
||||
}
|
||||
@@ -15,18 +15,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customnameplates.scoreboard;
|
||||
package net.momirealms.customnameplates.nameplates;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.data.DataManager;
|
||||
import net.momirealms.customnameplates.data.PlayerData;
|
||||
import net.momirealms.customnameplates.nameplates.NameplateInstance;
|
||||
import net.momirealms.customnameplates.hook.PapiHook;
|
||||
import net.momirealms.customnameplates.hook.TABHook;
|
||||
import net.momirealms.customnameplates.nameplates.NameplateUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -38,7 +33,6 @@ import java.util.Optional;
|
||||
public class NameplatesTeam {
|
||||
|
||||
private final Player player;
|
||||
private final Team team;
|
||||
private Component prefix;
|
||||
private Component suffix;
|
||||
private String prefixText;
|
||||
@@ -59,13 +53,11 @@ public class NameplatesTeam {
|
||||
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
String teamName = player.getName();
|
||||
|
||||
if (ConfigManager.MainConfig.tab) teamName = TABHook.getTABTeam(teamName);
|
||||
|
||||
Team teamTemp = scoreboard.getTeam(teamName);
|
||||
if (teamTemp == null) teamTemp = scoreboard.registerNewTeam(teamName);
|
||||
|
||||
this.team = teamTemp;
|
||||
this.team.addEntry(player.getName());
|
||||
if (!ConfigManager.Main.tab) {
|
||||
Team teamTemp = scoreboard.getTeam(teamName);
|
||||
if (teamTemp == null) teamTemp = scoreboard.registerNewTeam(teamName);
|
||||
teamTemp.addEntry(player.getName());
|
||||
}
|
||||
|
||||
updateNameplates();
|
||||
}
|
||||
@@ -79,9 +71,9 @@ public class NameplatesTeam {
|
||||
else nameplate = "none";
|
||||
|
||||
if (nameplate.equals("none")) {
|
||||
if (ConfigManager.MainConfig.placeholderAPI) {
|
||||
this.prefix = MiniMessage.miniMessage().deserialize(PapiHook.parsePlaceholders(this.player, ConfigManager.Nameplate.player_prefix));
|
||||
this.suffix = MiniMessage.miniMessage().deserialize(PapiHook.parsePlaceholders(this.player, ConfigManager.Nameplate.player_suffix));
|
||||
if (ConfigManager.Main.placeholderAPI) {
|
||||
this.prefix = MiniMessage.miniMessage().deserialize(CustomNameplates.instance.getPlaceholderManager().parsePlaceholders(this.player, ConfigManager.Nameplate.player_prefix));
|
||||
this.suffix = MiniMessage.miniMessage().deserialize(CustomNameplates.instance.getPlaceholderManager().parsePlaceholders(this.player, ConfigManager.Nameplate.player_suffix));
|
||||
}
|
||||
else {
|
||||
this.prefix = MiniMessage.miniMessage().deserialize(ConfigManager.Nameplate.player_prefix);
|
||||
@@ -101,17 +93,17 @@ public class NameplatesTeam {
|
||||
this.prefixText = "";
|
||||
this.suffixText = "";
|
||||
this.color = ChatColor.WHITE;
|
||||
DataManager.cache.get(player.getUniqueId()).equipNameplate("none");
|
||||
CustomNameplates.instance.getDataManager().getCache().get(player.getUniqueId()).equipNameplate("none");
|
||||
return;
|
||||
}
|
||||
|
||||
String playerPrefix;
|
||||
String playerSuffix;
|
||||
|
||||
if (ConfigManager.MainConfig.placeholderAPI) {
|
||||
if (!ConfigManager.Nameplate.hidePrefix) playerPrefix = PapiHook.parsePlaceholders(this.player, ConfigManager.Nameplate.player_prefix);
|
||||
if (ConfigManager.Main.placeholderAPI) {
|
||||
if (!ConfigManager.Nameplate.hidePrefix) playerPrefix = CustomNameplates.instance.getPlaceholderManager().parsePlaceholders(this.player, ConfigManager.Nameplate.player_prefix);
|
||||
else playerPrefix = "";
|
||||
if (!ConfigManager.Nameplate.hideSuffix) playerSuffix = PapiHook.parsePlaceholders(this.player, ConfigManager.Nameplate.player_suffix);
|
||||
if (!ConfigManager.Nameplate.hideSuffix) playerSuffix = CustomNameplates.instance.getPlaceholderManager().parsePlaceholders(this.player, ConfigManager.Nameplate.player_suffix);
|
||||
else playerSuffix = "";
|
||||
}
|
||||
else {
|
||||
@@ -144,7 +136,7 @@ public class NameplatesTeam {
|
||||
nameplateInstance
|
||||
)
|
||||
)
|
||||
.font(ConfigManager.MainConfig.key)
|
||||
.font(ConfigManager.Main.key)
|
||||
.append(MiniMessage.miniMessage().deserialize(playerPrefix));
|
||||
|
||||
this.suffix = MiniMessage.miniMessage().deserialize(playerSuffix)
|
||||
@@ -154,7 +146,7 @@ public class NameplatesTeam {
|
||||
name +
|
||||
MiniMessage.miniMessage().stripTags(playerSuffix))
|
||||
)
|
||||
.font(ConfigManager.MainConfig.key));
|
||||
.font(ConfigManager.Main.key));
|
||||
|
||||
this.color = nameplateInstance.getConfig().getColor();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.momirealms.customnameplates.scoreboard;
|
||||
package net.momirealms.customnameplates.nameplates;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -15,23 +15,33 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customnameplates.scoreboard;
|
||||
package net.momirealms.customnameplates.nameplates;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.hook.TABHook;
|
||||
import net.momirealms.customnameplates.hook.TABTeamHook;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ScoreBoardManager{
|
||||
public class TeamManager {
|
||||
|
||||
public static Map<String, NameplatesTeam> teams = new HashMap<>();
|
||||
private final HashMap<String, NameplatesTeam> teams = new HashMap<>();
|
||||
|
||||
public NameplatesTeam getOrCreateTeam(Player player) {
|
||||
public void createTeam(Player player) {
|
||||
String teamName = player.getName();
|
||||
if (ConfigManager.MainConfig.tab) teamName = TABHook.getTABTeam(teamName);
|
||||
if (ConfigManager.Main.tab) teamName = TABTeamHook.getTABTeam(teamName);
|
||||
if (!teams.containsKey(teamName)) teams.put(teamName, new NameplatesTeam(player));
|
||||
return teams.get(teamName);
|
||||
teams.get(teamName);
|
||||
}
|
||||
|
||||
public Map<String, NameplatesTeam> getTeams() {
|
||||
return teams;
|
||||
}
|
||||
|
||||
public static String getTeamName(Player player) {
|
||||
String teamName = player.getName();
|
||||
if (ConfigManager.Main.tab) teamName = TABTeamHook.getTABTeam(teamName);
|
||||
return teamName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.momirealms.customnameplates.nameplates;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface TeamPacketManager {
|
||||
|
||||
void sendUpdateToOne(Player player);
|
||||
void sendUpdateToAll(Player player);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.ArmorStand;
|
||||
import net.momirealms.customnameplates.objects.TextCache;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
|
||||
public class ArmorStandManager {
|
||||
|
||||
private final Map<String, ArmorStand> armorStands = new LinkedHashMap<>();
|
||||
private ArmorStand[] armorStandArray = new ArmorStand[0];
|
||||
private final List<Player> nearbyPlayers = new ArrayList<>();
|
||||
private Player[] nearbyPlayerArray = new Player[0];
|
||||
private final Player owner;
|
||||
|
||||
public ArmorStandManager(Player owner) {
|
||||
Set<Map.Entry<String, Double>> entries = ConfigManager.Nameplate.textMap.entrySet();
|
||||
this.owner = owner;
|
||||
entries.forEach(map -> {
|
||||
addArmorStand(map.getKey(), new FakeArmorStand(this, owner, new TextCache(owner, map.getKey()), map.getValue()));
|
||||
});
|
||||
}
|
||||
|
||||
public void teleport(Player viewer) {
|
||||
for (ArmorStand a : armorStandArray) a.teleport(viewer);
|
||||
}
|
||||
|
||||
public void teleport() {
|
||||
for (ArmorStand a : armorStandArray) a.teleport();
|
||||
}
|
||||
|
||||
public Player[] getNearbyPlayers(){
|
||||
return nearbyPlayerArray;
|
||||
}
|
||||
|
||||
public boolean hasArmorStandWithID(int entityId) {
|
||||
for (ArmorStand a : armorStandArray) {
|
||||
if (a.getEntityId() == entityId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setSneak(boolean sneaking, boolean respawn) {
|
||||
for (ArmorStand a : armorStandArray) a.setSneak(sneaking, respawn);
|
||||
}
|
||||
|
||||
public void respawn() {
|
||||
for (ArmorStand a : armorStandArray) {
|
||||
for (Player viewer : nearbyPlayerArray) {
|
||||
a.respawn(viewer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void spawn(Player viewer) {
|
||||
nearbyPlayers.add(viewer);
|
||||
nearbyPlayerArray = nearbyPlayers.toArray(new Player[0]);
|
||||
for (ArmorStand a : armorStandArray) a.spawn(viewer);
|
||||
}
|
||||
|
||||
public void addArmorStand(String name, ArmorStand as) {
|
||||
armorStands.put(name, as);
|
||||
armorStandArray = armorStands.values().toArray(new ArmorStand[0]);
|
||||
for (Player p : nearbyPlayerArray) as.spawn(p);
|
||||
}
|
||||
|
||||
public void unregisterPlayer(Player viewer) {
|
||||
if (nearbyPlayers.remove(viewer)) nearbyPlayerArray = nearbyPlayers.toArray(new Player[0]);
|
||||
}
|
||||
|
||||
public boolean isNearby(Player viewer) {
|
||||
return nearbyPlayers.contains(viewer);
|
||||
}
|
||||
|
||||
public void destroy(Player viewer) {
|
||||
for (ArmorStand a : armorStandArray) a.destroy(viewer);
|
||||
unregisterPlayer(viewer);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
for (ArmorStand a : armorStandArray) a.destroy();
|
||||
nearbyPlayers.clear();
|
||||
nearbyPlayerArray = new Player[0];
|
||||
}
|
||||
|
||||
public void refresh(boolean force) {
|
||||
for (ArmorStand as : armorStandArray) {
|
||||
if (as.getText().update() || force) {
|
||||
as.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void mount(Player receiver) {
|
||||
int[] passengers = new int[armorStandArray.length];
|
||||
for (int i = 0; i < armorStandArray.length; i++) {
|
||||
passengers[i] = armorStandArray[i].getEntityId();
|
||||
}
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(receiver, getMountPacket(passengers));
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Failed to mount player");
|
||||
}
|
||||
}
|
||||
|
||||
private PacketContainer getMountPacket(int[] passengers) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||
packet.getIntegers().write(0, owner.getEntityId());
|
||||
packet.getIntegerArrays().write(0, passengers);
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public abstract class EntityTag extends NameplateManager {
|
||||
|
||||
protected final HashMap<Player, ArmorStandManager> armorStandManagerMap = new HashMap<>();
|
||||
|
||||
private BukkitTask bukkitTask;
|
||||
|
||||
protected EntityTag(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
if (ConfigManager.Nameplate.update) {
|
||||
this.bukkitTask = Bukkit.getScheduler().runTaskTimerAsynchronously(CustomNameplates.instance, () -> {
|
||||
for (ArmorStandManager asm : armorStandManagerMap.values()) {
|
||||
asm.refresh(false);
|
||||
}
|
||||
}, 20, ConfigManager.Nameplate.refresh);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(){
|
||||
if (bukkitTask != null) {
|
||||
this.bukkitTask.cancel();
|
||||
}
|
||||
for (Player all : Bukkit.getOnlinePlayers()) {
|
||||
getArmorStandManager(all).destroy();
|
||||
}
|
||||
armorStandManagerMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(Player player) {
|
||||
super.onJoin(player);
|
||||
armorStandManagerMap.put(player, new ArmorStandManager(player));
|
||||
for (Player viewer : Bukkit.getOnlinePlayers()) {
|
||||
spawnArmorStands(viewer, player);
|
||||
spawnArmorStands(player, viewer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuit(Player player) {
|
||||
super.onQuit(player);
|
||||
for (Player all : Bukkit.getOnlinePlayers()) {
|
||||
if (getArmorStandManager(all) == null) continue;
|
||||
getArmorStandManager(all) .unregisterPlayer(player);
|
||||
}
|
||||
ArmorStandManager asm = armorStandManagerMap.remove(player);
|
||||
if (asm != null) {
|
||||
asm.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onRP(Player player, PlayerResourcePackStatusEvent.Status status) {
|
||||
// super.onRP(player, status);
|
||||
// }
|
||||
|
||||
public void onSneak(Player player, boolean isSneaking) {
|
||||
}
|
||||
|
||||
public void onRespawn(Player player) {
|
||||
}
|
||||
|
||||
public ArmorStandManager getArmorStandManager(Player player) {
|
||||
return armorStandManagerMap.get(player);
|
||||
}
|
||||
|
||||
public void refresh(Player refreshed, boolean force) {
|
||||
getArmorStandManager(refreshed).refresh(force);
|
||||
}
|
||||
|
||||
private void spawnArmorStands(Player viewer, Player target) {
|
||||
if (target == viewer) return;
|
||||
if (viewer.getWorld() != target.getWorld()) return;
|
||||
if (viewer.canSee(target))
|
||||
getArmorStandManager(target).spawn(viewer);
|
||||
}
|
||||
|
||||
// private double getDistance(Player player1, Player player2) {
|
||||
// Location loc1 = player1.getLocation();
|
||||
// Location loc2 = player2.getLocation();
|
||||
// return Math.sqrt(Math.pow(loc1.getX()-loc2.getX(), 2) + Math.pow(loc1.getZ()-loc2.getZ(), 2));
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public record EventListener(NameplateManager nameplateManager) implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
nameplateManager.onJoin(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
nameplateManager.onQuit(event.getPlayer());
|
||||
}
|
||||
|
||||
// @EventHandler
|
||||
// public void onAccept(PlayerResourcePackStatusEvent event) {
|
||||
// nameplateManager.onRP(event.getPlayer(), event.getStatus());
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
|
||||
public record EventListenerE(EntityTag entityTag) implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onSneak(PlayerToggleSneakEvent event) {
|
||||
entityTag.onSneak(event.getPlayer(), event.isSneaking());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
entityTag.onRespawn(event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.ArmorStand;
|
||||
import net.momirealms.customnameplates.objects.TextCache;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Pose;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FakeArmorStand implements ArmorStand {
|
||||
|
||||
private static int idCounter = 1145141919;
|
||||
|
||||
private final ArmorStandManager asm;
|
||||
private final Player owner;
|
||||
private double yOffset;
|
||||
private final int entityId = idCounter++;
|
||||
private final UUID uuid = UUID.randomUUID();
|
||||
private boolean sneaking;
|
||||
private final TextCache text;
|
||||
private final PacketContainer destroyPacket;
|
||||
|
||||
public FakeArmorStand(ArmorStandManager asm, Player owner, TextCache text, double yOffset) {
|
||||
this.asm = asm;
|
||||
this.owner = owner;
|
||||
this.yOffset = yOffset;
|
||||
this.text = text;
|
||||
sneaking = owner.isSneaking();
|
||||
destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
destroyPacket.getIntLists().write(0, List.of(entityId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
updateMetadata();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getOffset() {
|
||||
return yOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextCache getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOffset(double offset) {
|
||||
if (yOffset == offset) return;
|
||||
yOffset = offset;
|
||||
for (Player all : asm.getNearbyPlayers()) {
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(all, getTeleportPacket());
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(Player viewer) {
|
||||
for (PacketContainer packet : getSpawnPackets(viewer)) {
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(viewer, packet);
|
||||
}
|
||||
catch (InvocationTargetException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
for (Player all : asm.getNearbyPlayers()) {
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(all, destroyPacket);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy(Player viewer) {
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(viewer, destroyPacket);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport() {
|
||||
PacketContainer packet = getTeleportPacket();
|
||||
for (Player all : asm.getNearbyPlayers()) {
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(all, packet);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(Player viewer) {
|
||||
if (!asm.isNearby(viewer) && viewer != owner) {
|
||||
asm.spawn(viewer);
|
||||
} else {
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(viewer, getTeleportPacket());
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSneak(boolean isSneaking, boolean respawn) {
|
||||
this.sneaking = isSneaking;
|
||||
if (respawn) {
|
||||
for (Player viewer : asm.getNearbyPlayers()) {
|
||||
respawn(viewer);
|
||||
}
|
||||
}
|
||||
else {
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void respawn(Player viewer) {
|
||||
destroy(viewer);
|
||||
spawn(viewer);
|
||||
}
|
||||
|
||||
//传送包
|
||||
public PacketContainer getTeleportPacket() {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
Location location = getArmorStandLocation();
|
||||
packet.getDoubles().write(0, location.getX());
|
||||
packet.getDoubles().write(1, location.getY());
|
||||
packet.getDoubles().write(2, location.getZ());
|
||||
return packet;
|
||||
}
|
||||
|
||||
//更新盔甲架信息
|
||||
public void updateMetadata() {
|
||||
for (Player viewer : asm.getNearbyPlayers()) {
|
||||
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
metaPacket.getIntegers().write(0, entityId);
|
||||
metaPacket.getWatchableCollectionModifier().write(0, createDataWatcher(getText().getViewerText(viewer), viewer).getWatchableObjects());
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(viewer, metaPacket);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获取盔甲架的位置
|
||||
public Location getArmorStandLocation() {
|
||||
double x = owner.getLocation().getX();
|
||||
double y = getY() + yOffset;
|
||||
double z = owner.getLocation().getZ();
|
||||
if (!owner.isSleeping()) {
|
||||
if (sneaking) y += 1.37;
|
||||
else y += 1.8;
|
||||
}
|
||||
else y += 0.2;
|
||||
return new Location(null, x, y, z);
|
||||
}
|
||||
|
||||
//获取玩家Y坐标
|
||||
protected double getY() {
|
||||
Entity vehicle = owner.getVehicle();
|
||||
if (vehicle != null) {
|
||||
if (vehicle.getType() == EntityType.HORSE) {
|
||||
return vehicle.getLocation().getY() + 0.85;
|
||||
}
|
||||
if (vehicle.getType() == EntityType.DONKEY) {
|
||||
return vehicle.getLocation().getY() + 0.525;
|
||||
}
|
||||
if (vehicle.getType() == EntityType.PIG) {
|
||||
return vehicle.getLocation().getY() + 0.325;
|
||||
}
|
||||
if (vehicle.getType() == EntityType.STRIDER) {
|
||||
return vehicle.getLocation().getY() + 1.15;
|
||||
}
|
||||
}
|
||||
if (owner.getPose() == Pose.SWIMMING || owner.isGliding()) {
|
||||
return owner.getLocation().getY() - 1.22;
|
||||
}
|
||||
return owner.getLocation().getY();
|
||||
}
|
||||
|
||||
//创建实体信息包
|
||||
public WrappedDataWatcher createDataWatcher(String text, Player viewer) {
|
||||
|
||||
WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher();
|
||||
WrappedDataWatcher.Serializer serializer1 = WrappedDataWatcher.Registry.get(Boolean.class);
|
||||
WrappedDataWatcher.Serializer serializer2 = WrappedDataWatcher.Registry.get(Byte.class);
|
||||
//设置名称
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.getChatComponentSerializer(true)), Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(text))).getHandle()));
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, serializer1), true);
|
||||
byte flag = 0x20; //隐身
|
||||
if (sneaking) flag += (byte) 0x02;
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, serializer2), flag);
|
||||
if (ConfigManager.Nameplate.smallSize) {
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, serializer2), (byte) 0x01);
|
||||
}
|
||||
//设置名字可见
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, serializer1), true);
|
||||
return wrappedDataWatcher;
|
||||
}
|
||||
|
||||
//创建生成包
|
||||
public PacketContainer[] getSpawnPackets(Player viewer) {
|
||||
|
||||
PacketContainer entityPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||
entityPacket.getModifier().write(0, entityId);
|
||||
entityPacket.getModifier().write(1, uuid);
|
||||
entityPacket.getEntityTypeModifier().write(0, EntityType.ARMOR_STAND);
|
||||
Location location = getArmorStandLocation();
|
||||
entityPacket.getDoubles().write(0, location.getX());
|
||||
entityPacket.getDoubles().write(1, location.getY());
|
||||
entityPacket.getDoubles().write(2, location.getZ());
|
||||
|
||||
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
metaPacket.getIntegers().write(0, entityId);
|
||||
metaPacket.getWatchableCollectionModifier().write(0, createDataWatcher(getText().getViewerText(viewer), viewer).getWatchableObjects());
|
||||
|
||||
return new PacketContainer[] {entityPacket, metaPacket};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.Function;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
public abstract class NameplateManager extends Function {
|
||||
|
||||
protected NameplateManager(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(){
|
||||
}
|
||||
|
||||
public void onJoin(Player player) {
|
||||
CustomNameplates.instance.getDataManager().loadData(player);
|
||||
}
|
||||
|
||||
public void onQuit(Player player) {
|
||||
CustomNameplates.instance.getDataManager().unloadPlayer(player.getUniqueId());
|
||||
if (ConfigManager.Main.tab) return;
|
||||
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
String teamName = player.getName();
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
if (team != null) team.unregister();
|
||||
CustomNameplates.instance.getTeamManager().getTeams().remove(teamName);
|
||||
}
|
||||
|
||||
// public void onRP(Player player, PlayerResourcePackStatusEvent.Status status) {
|
||||
// if (!ConfigManager.Nameplate.show_after) return;
|
||||
// new BukkitRunnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// PlayerData playerData = CustomNameplates.instance.getDataManager().getCache().get(player.getUniqueId());
|
||||
// if (playerData == null) return;
|
||||
// if (status == PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED) {
|
||||
// playerData.setAccepted(true);
|
||||
// SqlHandler.save(playerData, player.getUniqueId());
|
||||
// CustomNameplates.instance.getTeamPacketManager().sendUpdateToOne(player);
|
||||
// }
|
||||
// else if (status == PlayerResourcePackStatusEvent.Status.DECLINED || status == PlayerResourcePackStatusEvent.Status.FAILED_DOWNLOAD) {
|
||||
// playerData.setAccepted(false);
|
||||
// SqlHandler.save(playerData, player.getUniqueId());
|
||||
// CustomNameplates.instance.getTeamPacketManager().sendUpdateToOne(player);
|
||||
// }
|
||||
// }
|
||||
// }.runTaskAsynchronously(CustomNameplates.instance);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode;
|
||||
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.Function;
|
||||
import net.momirealms.customnameplates.nameplates.mode.listener.BukkitListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class PacketsHandler extends Function {
|
||||
|
||||
protected Map<Integer, Player> entityIdMap = new ConcurrentHashMap<>();
|
||||
private BukkitListener bukkitListener;
|
||||
private final EntityTag entityTag;
|
||||
|
||||
protected PacketsHandler(String name, EntityTag entityTag) {
|
||||
super(name);
|
||||
this.entityTag = entityTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
this.bukkitListener = new BukkitListener(this);
|
||||
Bukkit.getPluginManager().registerEvents(bukkitListener, CustomNameplates.instance);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
entityIdMap.put(player.getEntityId(), player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
HandlerList.unregisterAll(bukkitListener);
|
||||
entityIdMap.clear();
|
||||
}
|
||||
|
||||
public void onJoin(Player player) {
|
||||
entityIdMap.put(player.getEntityId(), player);
|
||||
entityTag.onJoin(player);
|
||||
}
|
||||
|
||||
public void onQuit(Player player) {
|
||||
entityTag.onQuit(player);
|
||||
entityIdMap.remove(player.getEntityId());
|
||||
}
|
||||
|
||||
public void onEntityMove(Player receiver, int entityId) {
|
||||
}
|
||||
|
||||
public void onPlayerMove(Player mover) {
|
||||
}
|
||||
|
||||
public void onEntitySpawn(Player receiver, int entityId) {
|
||||
}
|
||||
|
||||
public void onEntityDestroy(Player receiver, List<Integer> entities) {
|
||||
}
|
||||
|
||||
public void onEntityDestroy(Player receiver, int entity) {
|
||||
}
|
||||
|
||||
public void onEntityMount(int vehicle, int[] passengers) {
|
||||
}
|
||||
|
||||
public Player getPlayerFromMap(int entityID) {
|
||||
return entityIdMap.get(entityID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.listener;
|
||||
|
||||
import net.momirealms.customnameplates.nameplates.mode.PacketsHandler;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public record BukkitListener(
|
||||
PacketsHandler handler) implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
handler.onJoin(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
handler.onQuit(event.getPlayer());
|
||||
}
|
||||
|
||||
// @EventHandler
|
||||
// public void onMove(PlayerMoveEvent event) {
|
||||
// handler.onPlayerMove(event.getPlayer());
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.mode.PacketsHandler;
|
||||
|
||||
public class EntityDestroyListener extends PacketAdapter {
|
||||
|
||||
private final PacketsHandler handler;
|
||||
|
||||
public EntityDestroyListener(PacketsHandler handler) {
|
||||
super(CustomNameplates.instance, ListenerPriority.HIGHEST, PacketType.Play.Server.ENTITY_DESTROY);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
handler.onEntityDestroy(event.getPlayer(), packet.getIntLists().read(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.mode.PacketsHandler;
|
||||
|
||||
public class EntityLookListener extends PacketAdapter {
|
||||
|
||||
private final PacketsHandler handler;
|
||||
|
||||
public EntityLookListener(PacketsHandler handler) {
|
||||
super(CustomNameplates.instance, ListenerPriority.HIGHEST, PacketType.Play.Server.REL_ENTITY_MOVE_LOOK);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
handler.onEntityMove(event.getPlayer(), packet.getIntegers().read(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.mode.PacketsHandler;
|
||||
|
||||
public class EntityMountListener extends PacketAdapter {
|
||||
|
||||
private final PacketsHandler handler;
|
||||
|
||||
public EntityMountListener(PacketsHandler handler) {
|
||||
super(CustomNameplates.instance, ListenerPriority.HIGHEST, PacketType.Play.Server.MOUNT);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
handler.onEntityMount(packet.getIntegers().read(0), packet.getIntegerArrays().read(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.mode.PacketsHandler;
|
||||
|
||||
public class EntityMoveListener extends PacketAdapter {
|
||||
|
||||
private final PacketsHandler handler;
|
||||
|
||||
public EntityMoveListener(PacketsHandler handler) {
|
||||
super(CustomNameplates.instance, ListenerPriority.NORMAL, PacketType.Play.Server.REL_ENTITY_MOVE);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
handler.onEntityMove(event.getPlayer(), packet.getIntegers().read(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.listener;
|
||||
|
||||
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.nameplates.mode.PacketsHandler;
|
||||
|
||||
public class EntitySpawnListener extends PacketAdapter {
|
||||
|
||||
private final PacketsHandler handler;
|
||||
|
||||
public EntitySpawnListener(PacketsHandler handler) {
|
||||
super(CustomNameplates.instance, ListenerPriority.HIGHEST, PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public synchronized void onPacketSending(PacketEvent event) {
|
||||
handler.onEntitySpawn(event.getPlayer(), event.getPacket().getIntegers().read(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.mode.PacketsHandler;
|
||||
|
||||
public class EntityTeleportListener extends PacketAdapter {
|
||||
|
||||
private final PacketsHandler handler;
|
||||
|
||||
public EntityTeleportListener(PacketsHandler handler) {
|
||||
super(CustomNameplates.instance, ListenerPriority.HIGHEST, PacketType.Play.Server.ENTITY_TELEPORT);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
handler.onEntityMove(event.getPlayer(), packet.getIntegers().read(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.rd;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.mode.ArmorStandManager;
|
||||
import net.momirealms.customnameplates.nameplates.mode.PacketsHandler;
|
||||
import net.momirealms.customnameplates.nameplates.mode.listener.EntityDestroyListener;
|
||||
import net.momirealms.customnameplates.nameplates.mode.listener.EntityMountListener;
|
||||
import net.momirealms.customnameplates.nameplates.mode.listener.EntitySpawnListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RdPacketsHandler extends PacketsHandler {
|
||||
|
||||
private final RidingTag ridingTag;
|
||||
|
||||
private EntityDestroyListener entityDestroyListener;
|
||||
private EntitySpawnListener entitySpawnListener;
|
||||
private EntityMountListener entityMountListener;
|
||||
|
||||
protected RdPacketsHandler(String name, RidingTag ridingTag) {
|
||||
super(name, ridingTag);
|
||||
this.ridingTag = ridingTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
this.entityDestroyListener = new EntityDestroyListener(this);
|
||||
this.entitySpawnListener = new EntitySpawnListener(this);
|
||||
CustomNameplates.protocolManager.addPacketListener(entityDestroyListener);
|
||||
CustomNameplates.protocolManager.addPacketListener(entitySpawnListener);
|
||||
if (ConfigManager.Nameplate.tryHook) {
|
||||
this.entityMountListener = new EntityMountListener(this);
|
||||
CustomNameplates.protocolManager.addPacketListener(entityMountListener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
super.unload();
|
||||
CustomNameplates.protocolManager.removePacketListener(entityDestroyListener);
|
||||
CustomNameplates.protocolManager.removePacketListener(entitySpawnListener);
|
||||
if (entityDestroyListener != null) {
|
||||
CustomNameplates.protocolManager.removePacketListener(entityMountListener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntitySpawn(Player receiver, int entityId) {
|
||||
Player spawnedPlayer = super.getPlayerFromMap(entityId);
|
||||
if (spawnedPlayer != null) {
|
||||
ArmorStandManager asm = ridingTag.getArmorStandManager(spawnedPlayer);
|
||||
asm.spawn(receiver);
|
||||
Bukkit.getScheduler().runTaskLater(CustomNameplates.instance, ()-> {
|
||||
asm.mount(receiver);
|
||||
},1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDestroy(Player receiver, List<Integer> entities) {
|
||||
for (int entity : entities) {
|
||||
onEntityDestroy(receiver, entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDestroy(Player receiver, int entity) {
|
||||
Player deSpawnedPlayer = super.getPlayerFromMap(entity);
|
||||
if (deSpawnedPlayer != null) {
|
||||
ridingTag.getArmorStandManager(deSpawnedPlayer).destroy(receiver);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityMount(int vehicle, int[] passengers) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.rd;
|
||||
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.mode.EntityTag;
|
||||
import net.momirealms.customnameplates.nameplates.mode.ArmorStandManager;
|
||||
import net.momirealms.customnameplates.nameplates.mode.EventListenerE;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class RidingTag extends EntityTag {
|
||||
|
||||
private RdPacketsHandler handler;
|
||||
|
||||
private EventListenerE listener;
|
||||
|
||||
public RidingTag(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
for (Player all : Bukkit.getOnlinePlayers()) {
|
||||
armorStandManagerMap.put(all, new ArmorStandManager(all));
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToOne(all);
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToAll(all);
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
ridingArmorStands(player, all);
|
||||
}
|
||||
this.handler = new RdPacketsHandler("RdHandler", this);
|
||||
this.handler.load();
|
||||
listener = new EventListenerE(this);
|
||||
Bukkit.getPluginManager().registerEvents(listener, CustomNameplates.instance);
|
||||
super.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
this.handler.unload();
|
||||
HandlerList.unregisterAll(listener);
|
||||
super.unload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(Player player) {
|
||||
super.onJoin(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuit(Player player) {
|
||||
super.onQuit(player);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onRP(Player player, PlayerResourcePackStatusEvent.Status status) {
|
||||
// super.onRP(player, status);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public ArmorStandManager getArmorStandManager(Player player) {
|
||||
return super.getArmorStandManager(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSneak(Player player, boolean isSneaking) {
|
||||
getArmorStandManager(player).setSneak(isSneaking, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRespawn(Player player) {
|
||||
//getArmorStandManager(player).teleport();
|
||||
}
|
||||
|
||||
private void ridingArmorStands(Player viewer, Player target) {
|
||||
if (target == viewer) return;
|
||||
if (viewer.getWorld() != target.getWorld()) return;
|
||||
if (viewer.canSee(target)) {
|
||||
ArmorStandManager asm = getArmorStandManager(target);
|
||||
asm.spawn(viewer);
|
||||
Bukkit.getScheduler().runTaskLater(CustomNameplates.instance, () -> {
|
||||
asm.mount(viewer);
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.tm;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.TeamManager;
|
||||
import net.momirealms.customnameplates.nameplates.mode.NameplateManager;
|
||||
import net.momirealms.customnameplates.nameplates.NameplatesTeam;
|
||||
import net.momirealms.customnameplates.nameplates.mode.EventListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TeamTag extends NameplateManager {
|
||||
|
||||
private EventListener listener;
|
||||
|
||||
private final HashMap<Player, BukkitTask> taskCache;
|
||||
|
||||
public TeamTag(String name) {
|
||||
super(name);
|
||||
this.taskCache = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
listener = new EventListener(this);
|
||||
Bukkit.getPluginManager().registerEvents(listener, CustomNameplates.instance);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToAll(player);
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToOne(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
HandlerList.unregisterAll(listener);
|
||||
taskCache.clear();
|
||||
listener = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(Player player) {
|
||||
|
||||
super.onJoin(player);
|
||||
|
||||
if (!ConfigManager.Nameplate.update) return;
|
||||
|
||||
startRefresh(player);
|
||||
}
|
||||
|
||||
private void startRefresh(Player player) {
|
||||
|
||||
if (!player.isOnline()) return;
|
||||
|
||||
String teamName = TeamManager.getTeamName(player);
|
||||
NameplatesTeam nameplatesTeam = CustomNameplates.instance.getTeamManager().getTeams().get(teamName);
|
||||
|
||||
if (nameplatesTeam != null) {
|
||||
BukkitTask task = Bukkit.getScheduler().runTaskTimerAsynchronously(CustomNameplates.instance, () -> {
|
||||
nameplatesTeam.updateNameplates();
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToAll(player);
|
||||
}, 20, ConfigManager.Nameplate.refresh);
|
||||
taskCache.put(player, task);
|
||||
}
|
||||
else {
|
||||
Bukkit.getScheduler().runTaskLater(CustomNameplates.instance, () -> {
|
||||
startRefresh(player);
|
||||
}, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuit(Player player) {
|
||||
|
||||
super.onQuit(player);
|
||||
|
||||
BukkitTask bukkitTask = taskCache.remove(player);
|
||||
if (bukkitTask != null) bukkitTask.cancel();
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onRP(Player player, PlayerResourcePackStatusEvent.Status status) {
|
||||
// super.onRP(player, status);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.tmpackets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.InternalStructure;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.data.PlayerData;
|
||||
import net.momirealms.customnameplates.hook.TABTeamHook;
|
||||
import net.momirealms.customnameplates.nameplates.NameplatesTeam;
|
||||
import net.momirealms.customnameplates.nameplates.TeamInfo;
|
||||
import net.momirealms.customnameplates.nameplates.TeamPacketManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TeamPacketA implements TeamPacketManager {
|
||||
|
||||
private final HashMap<Player, TeamInfo> teamInfoCache = new HashMap<>();
|
||||
|
||||
public void sendUpdateToOne(Player player) {
|
||||
// boolean accepted = CustomNameplates.instance.getDataManager().getCache().get(player.getUniqueId()).getAccepted();
|
||||
for (Player otherPlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (player == otherPlayer) return;
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
|
||||
packet.getIntegers().write(0,2);
|
||||
String teamName = otherPlayer.getName();
|
||||
if (ConfigManager.Main.tab) teamName = TABTeamHook.getTABTeam(teamName);
|
||||
packet.getStrings().write(0, teamName);
|
||||
NameplatesTeam nameplatesTeam = CustomNameplates.instance.getTeamManager().getTeams().get(teamName);
|
||||
if (nameplatesTeam == null) return;
|
||||
Optional<InternalStructure> optional = packet.getOptionalStructures().read(0);
|
||||
if (optional.isEmpty()) return;
|
||||
InternalStructure internalStructure = optional.get();
|
||||
internalStructure.getStrings().write(0, "always");
|
||||
// if (ConfigManager.Nameplate.show_after && !accepted) {
|
||||
// internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson("{\"text\":\"\"}"));
|
||||
// internalStructure.getChatComponents().write(2, WrappedChatComponent.fromJson("{\"text\":\"\"}"));
|
||||
// internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,ChatColor.WHITE);
|
||||
// }
|
||||
// else {
|
||||
internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(nameplatesTeam.getPrefix())));
|
||||
internalStructure.getChatComponents().write(2, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(nameplatesTeam.getSuffix())));
|
||||
internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,nameplatesTeam.getColor());
|
||||
// }
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(player, packet);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendUpdateToAll(Player player) {
|
||||
String teamName = player.getName();
|
||||
if (ConfigManager.Main.tab) teamName = TABTeamHook.getTABTeam(teamName);
|
||||
NameplatesTeam nameplatesTeam = CustomNameplates.instance.getTeamManager().getTeams().get(teamName);
|
||||
TeamInfo newInfo = new TeamInfo(nameplatesTeam.getPrefixText(), nameplatesTeam.getSuffixText());
|
||||
TeamInfo oldInfo = teamInfoCache.put(player, newInfo);
|
||||
if (oldInfo != null && oldInfo.equals(newInfo)) return;
|
||||
teamInfoCache.put(player, newInfo);
|
||||
for (Player otherPlayer : Bukkit.getOnlinePlayers()) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
|
||||
packet.getStrings().write(0, teamName);
|
||||
packet.getIntegers().write(0,2);
|
||||
Optional<InternalStructure> optional = packet.getOptionalStructures().read(0);
|
||||
if (optional.isEmpty()) return;
|
||||
InternalStructure internalStructure = optional.get();
|
||||
internalStructure.getStrings().write(0, "always");
|
||||
// if (ConfigManager.Nameplate.show_after) {
|
||||
// PlayerData playerData = CustomNameplates.instance.getDataManager().getCache().get(otherPlayer.getUniqueId());
|
||||
// if (playerData == null || !playerData.getAccepted()) {
|
||||
// internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson("{\"text\":\"\"}"));
|
||||
// internalStructure.getChatComponents().write(2, WrappedChatComponent.fromJson("{\"text\":\"\"}"));
|
||||
// internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,ChatColor.WHITE);
|
||||
// }
|
||||
// else {
|
||||
// internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(nameplatesTeam.getPrefix())));
|
||||
// internalStructure.getChatComponents().write(2, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(nameplatesTeam.getSuffix())));
|
||||
// internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,nameplatesTeam.getColor());
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(nameplatesTeam.getPrefix())));
|
||||
internalStructure.getChatComponents().write(2, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(nameplatesTeam.getSuffix())));
|
||||
internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,nameplatesTeam.getColor());
|
||||
// }
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(otherPlayer, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.tmpackets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.InternalStructure;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.data.PlayerData;
|
||||
import net.momirealms.customnameplates.nameplates.TeamManager;
|
||||
import net.momirealms.customnameplates.nameplates.TeamPacketManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TeamPacketB implements TeamPacketManager {
|
||||
|
||||
@Override
|
||||
public void sendUpdateToOne(Player player) {
|
||||
// boolean accepted = CustomNameplates.instance.getDataManager().getCache().get(player.getUniqueId()).getAccepted();
|
||||
for (Player otherPlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (player == otherPlayer) return;
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
|
||||
packet.getIntegers().write(0,2);
|
||||
String teamName = TeamManager.getTeamName(otherPlayer);
|
||||
packet.getStrings().write(0, teamName);
|
||||
Optional<InternalStructure> optional = packet.getOptionalStructures().read(0);
|
||||
if (optional.isEmpty()) return;
|
||||
InternalStructure internalStructure = optional.get();
|
||||
// if (ConfigManager.Nameplate.show_after && !accepted) {
|
||||
// internalStructure.getStrings().write(0, "always");
|
||||
// internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,ChatColor.WHITE);
|
||||
// }
|
||||
// else {
|
||||
if (ConfigManager.Nameplate.removeTag) internalStructure.getStrings().write(0, "never");
|
||||
else internalStructure.getStrings().write(0, "always");
|
||||
internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,ChatColor.WHITE);
|
||||
// }
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(player, packet);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendUpdateToAll(Player player) {
|
||||
String teamName = TeamManager.getTeamName(player);
|
||||
for (Player otherPlayer : Bukkit.getOnlinePlayers()) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
|
||||
packet.getStrings().write(0, teamName);
|
||||
packet.getIntegers().write(0,2);
|
||||
Optional<InternalStructure> optional = packet.getOptionalStructures().read(0);
|
||||
if (optional.isEmpty()) return;
|
||||
InternalStructure internalStructure = optional.get();
|
||||
// if (ConfigManager.Nameplate.show_after) {
|
||||
// PlayerData playerData = CustomNameplates.instance.getDataManager().getCache().get(otherPlayer.getUniqueId());
|
||||
// if (playerData == null || !playerData.getAccepted()) {
|
||||
// internalStructure.getStrings().write(0, "always");
|
||||
// }
|
||||
// else {
|
||||
// if (ConfigManager.Nameplate.removeTag) internalStructure.getStrings().write(0, "never");
|
||||
// else internalStructure.getStrings().write(0, "always");
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
if (ConfigManager.Nameplate.removeTag) internalStructure.getStrings().write(0, "never");
|
||||
else internalStructure.getStrings().write(0, "always");
|
||||
// }
|
||||
internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0, ChatColor.WHITE);
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(otherPlayer, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.tmpackets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.InternalStructure;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.TeamManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TeamPacketC {
|
||||
|
||||
public static void clearTeamInfo() {
|
||||
for (Player all : Bukkit.getOnlinePlayers()) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
|
||||
packet.getIntegers().write(0,2);
|
||||
String teamName = TeamManager.getTeamName(all);
|
||||
packet.getStrings().write(0, teamName);
|
||||
Optional<InternalStructure> optional = packet.getOptionalStructures().read(0);
|
||||
if (optional.isEmpty()) return;
|
||||
InternalStructure internalStructure = optional.get();
|
||||
internalStructure.getStrings().write(0, "always");
|
||||
internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,ChatColor.WHITE);
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(player, packet);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.tp;
|
||||
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.mode.ArmorStandManager;
|
||||
import net.momirealms.customnameplates.nameplates.mode.EntityTag;
|
||||
import net.momirealms.customnameplates.nameplates.mode.EventListenerE;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class TeleportingTag extends EntityTag {
|
||||
|
||||
private EventListenerE listener;
|
||||
|
||||
private VehicleChecker vehicleChecker;
|
||||
|
||||
private TpPacketsHandler handler;
|
||||
|
||||
private BukkitTask task;
|
||||
|
||||
public TeleportingTag(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
for (Player all : Bukkit.getOnlinePlayers()) {
|
||||
armorStandManagerMap.put(all, new ArmorStandManager(all));
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToOne(all);
|
||||
CustomNameplates.instance.getTeamPacketManager().sendUpdateToAll(all);
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
spawnArmorStands(player, all);
|
||||
}
|
||||
listener = new EventListenerE(this);
|
||||
Bukkit.getPluginManager().registerEvents(listener, CustomNameplates.instance);
|
||||
this.handler = new TpPacketsHandler("TpHandler", this);
|
||||
this.handler.load();
|
||||
this.vehicleChecker = new VehicleChecker(this);
|
||||
this.vehicleChecker.load();
|
||||
this.task = Bukkit.getScheduler().runTaskTimerAsynchronously(CustomNameplates.instance, () -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
this.vehicleChecker.refresh(player);
|
||||
}
|
||||
},10,20);
|
||||
super.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
HandlerList.unregisterAll(listener);
|
||||
super.unload();
|
||||
this.handler.unload();
|
||||
this.vehicleChecker.unload();
|
||||
this.task.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSneak(Player player, boolean isSneaking) {
|
||||
getArmorStandManager(player).setSneak(isSneaking, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRespawn(Player player) {
|
||||
getArmorStandManager(player).teleport();
|
||||
}
|
||||
|
||||
private void spawnArmorStands(Player viewer, Player target) {
|
||||
if (target == viewer) return;
|
||||
if (viewer.getWorld() != target.getWorld()) return;
|
||||
if (viewer.canSee(target))
|
||||
getArmorStandManager(target).spawn(viewer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(Player player) {
|
||||
super.onJoin(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuit(Player player) {
|
||||
super.onQuit(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.tp;
|
||||
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.nameplates.mode.PacketsHandler;
|
||||
import net.momirealms.customnameplates.nameplates.mode.listener.*;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TpPacketsHandler extends PacketsHandler {
|
||||
|
||||
private final TeleportingTag teleportingTag;
|
||||
|
||||
private EntityDestroyListener entityDestroyListener;
|
||||
private EntityMoveListener entityMoveListener;
|
||||
private EntitySpawnListener entitySpawnListener;
|
||||
private EntityTeleportListener entityTeleportListener;
|
||||
private EntityLookListener entityLookListener;
|
||||
|
||||
protected TpPacketsHandler(String name, TeleportingTag teleportingTag) {
|
||||
super(name, teleportingTag);
|
||||
this.teleportingTag = teleportingTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
this.entityDestroyListener = new EntityDestroyListener(this);
|
||||
this.entityMoveListener = new EntityMoveListener(this);
|
||||
this.entitySpawnListener = new EntitySpawnListener(this);
|
||||
this.entityTeleportListener = new EntityTeleportListener(this);
|
||||
this.entityLookListener = new EntityLookListener(this);
|
||||
CustomNameplates.protocolManager.addPacketListener(entityDestroyListener);
|
||||
CustomNameplates.protocolManager.addPacketListener(entityMoveListener);
|
||||
CustomNameplates.protocolManager.addPacketListener(entitySpawnListener);
|
||||
CustomNameplates.protocolManager.addPacketListener(entityTeleportListener);
|
||||
CustomNameplates.protocolManager.addPacketListener(entityLookListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
super.unload();
|
||||
CustomNameplates.protocolManager.removePacketListener(entityDestroyListener);
|
||||
CustomNameplates.protocolManager.removePacketListener(entityMoveListener);
|
||||
CustomNameplates.protocolManager.removePacketListener(entitySpawnListener);
|
||||
CustomNameplates.protocolManager.removePacketListener(entityTeleportListener);
|
||||
CustomNameplates.protocolManager.removePacketListener(entityLookListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityMove(Player receiver, int entityId) {
|
||||
Player mover = getPlayerFromMap(entityId);
|
||||
if (mover != null) {
|
||||
teleportingTag.getArmorStandManager(mover).teleport(receiver);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(Player mover) {
|
||||
teleportingTag.getArmorStandManager(mover).teleport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntitySpawn(Player receiver, int entityId) {
|
||||
Player spawnedPlayer = super.getPlayerFromMap(entityId);
|
||||
if (spawnedPlayer != null) {
|
||||
teleportingTag.getArmorStandManager(spawnedPlayer).spawn(receiver);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDestroy(Player receiver, List<Integer> entities) {
|
||||
for (int entity : entities) {
|
||||
onEntityDestroy(receiver, entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDestroy(Player receiver, int entity) {
|
||||
Player deSpawnedPlayer = super.getPlayerFromMap(entity);
|
||||
if (deSpawnedPlayer != null) {
|
||||
teleportingTag.getArmorStandManager(deSpawnedPlayer).destroy(receiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package net.momirealms.customnameplates.nameplates.mode.tp;
|
||||
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.Function;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class VehicleChecker extends Function {
|
||||
|
||||
private final WeakHashMap<Player, Entity> playersInVehicle = new WeakHashMap<>();
|
||||
|
||||
private final TeleportingTag teleportingTag;
|
||||
|
||||
private BukkitTask task;
|
||||
|
||||
public VehicleChecker(TeleportingTag teleportingTag) {
|
||||
super("VEHICLE");
|
||||
this.teleportingTag = teleportingTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
for (Player all : Bukkit.getOnlinePlayers()) {
|
||||
Entity vehicle = all.getVehicle();
|
||||
if (vehicle != null) {
|
||||
playersInVehicle.put(all, vehicle);
|
||||
}
|
||||
}
|
||||
this.task = Bukkit.getScheduler().runTaskTimerAsynchronously(CustomNameplates.instance, () -> {
|
||||
for (Player inVehicle : playersInVehicle.keySet()) {
|
||||
if (!inVehicle.isOnline() || teleportingTag.getArmorStandManager(inVehicle) == null) continue;
|
||||
teleportingTag.getArmorStandManager(inVehicle).teleport();
|
||||
}
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
this.task.cancel();
|
||||
playersInVehicle.clear();
|
||||
}
|
||||
|
||||
public void onJoin(Player player) {
|
||||
Entity vehicle = player.getVehicle();
|
||||
if (vehicle != null) playersInVehicle.put(player, vehicle);
|
||||
}
|
||||
|
||||
public void onQuit(Player player) {
|
||||
playersInVehicle.remove(player);
|
||||
}
|
||||
|
||||
public void refresh(Player player) {
|
||||
Entity vehicle = player.getVehicle();
|
||||
if (playersInVehicle.containsKey(player) && vehicle == null) {
|
||||
teleportingTag.getArmorStandManager(player).teleport();
|
||||
playersInVehicle.remove(player);
|
||||
}
|
||||
if (!playersInVehicle.containsKey(player) && vehicle != null) {
|
||||
teleportingTag.getArmorStandManager(player).respawn();
|
||||
playersInVehicle.put(player, vehicle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package net.momirealms.customnameplates.objects;
|
||||
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
||||
public class ASInfo {
|
||||
|
||||
private final String text;
|
||||
private final PacketContainer entityPacket;
|
||||
private final PacketContainer metaPacket;
|
||||
private final int id;
|
||||
|
||||
public ASInfo(int id ,String text, PacketContainer entityPacket, PacketContainer metaPacket) {
|
||||
this.id = id;
|
||||
this.text = text;
|
||||
this.entityPacket = entityPacket;
|
||||
this.metaPacket = metaPacket;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public PacketContainer getEntityPacket() {
|
||||
return entityPacket;
|
||||
}
|
||||
|
||||
public PacketContainer getMetaPacket() {
|
||||
return metaPacket;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package net.momirealms.customnameplates.objects;
|
||||
|
||||
public record BGInfo(String text, String background) {
|
||||
public record BackGroundText(String text, String background) {
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.momirealms.customnameplates.objects;
|
||||
|
||||
public class NMSStorage {
|
||||
|
||||
public Class<?> PacketPlayOutEntity;
|
||||
|
||||
public void loadClasses() throws ClassNotFoundException {
|
||||
PacketPlayOutEntity = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutEntity");
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package net.momirealms.customnameplates.objects;
|
||||
|
||||
public record NPInfo(String text, String nameplate) {
|
||||
public record NameplateText(String text, String nameplate) {
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
@@ -0,0 +1,84 @@
|
||||
package net.momirealms.customnameplates.objects;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TextCache {
|
||||
|
||||
//所属玩家
|
||||
private final Player owner;
|
||||
//初始值
|
||||
private final String rawValue;
|
||||
//原始文字加工后的值
|
||||
private String originalValue;
|
||||
//最近一次替换值
|
||||
private String latestValue;
|
||||
//持有者占位符
|
||||
private String[] ownerPlaceholders;
|
||||
|
||||
public TextCache(Player owner, String rawValue) {
|
||||
this.owner = owner;
|
||||
this.rawValue = rawValue;
|
||||
analyze(this.rawValue);
|
||||
}
|
||||
|
||||
private void analyze(String value) {
|
||||
List<String> placeholdersOwner = new ArrayList<>();
|
||||
for (String identifier : CustomNameplates.instance.getPlaceholderManager().detectPlaceholders(value)) {
|
||||
if (!identifier.startsWith("%rel_")) {
|
||||
placeholdersOwner.add(identifier);
|
||||
}
|
||||
}
|
||||
String origin = value;
|
||||
for (String placeholder : placeholdersOwner) {
|
||||
origin = origin.replace(placeholder, "%s");
|
||||
}
|
||||
originalValue = origin;
|
||||
ownerPlaceholders = placeholdersOwner.toArray(new String[0]);
|
||||
latestValue = originalValue;
|
||||
update();
|
||||
}
|
||||
|
||||
public String getRawValue() {
|
||||
return rawValue;
|
||||
}
|
||||
|
||||
public String updateAndGet() {
|
||||
update();
|
||||
return getLatestValue();
|
||||
}
|
||||
|
||||
public String getLatestValue() {
|
||||
return latestValue;
|
||||
}
|
||||
|
||||
//返回更新结果是否不一致
|
||||
public boolean update() {
|
||||
if (ownerPlaceholders.length == 0) return false;
|
||||
if (!ConfigManager.Main.placeholderAPI) return false;
|
||||
String string;
|
||||
if ("%s".equals(originalValue)) {
|
||||
string = CustomNameplates.instance.getPlaceholderManager().parsePlaceholders(owner, ownerPlaceholders[0]);
|
||||
}
|
||||
else {
|
||||
Object[] values = new String[ownerPlaceholders.length];
|
||||
for (int i = 0; i < ownerPlaceholders.length; i++) {
|
||||
values[i] = CustomNameplates.instance.getPlaceholderManager().parsePlaceholders(owner, ownerPlaceholders[i]);
|
||||
}
|
||||
string = String.format(originalValue, values);
|
||||
}
|
||||
if (!latestValue.equals(string)) {
|
||||
latestValue = string;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getViewerText(Player viewer) {
|
||||
return latestValue;
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static net.momirealms.customnameplates.ConfigManager.MainConfig.start;
|
||||
import static net.momirealms.customnameplates.ConfigManager.Main.start;
|
||||
|
||||
public class ResourceManager {
|
||||
|
||||
@@ -78,16 +78,16 @@ public class ResourceManager {
|
||||
Arrays.sort(pngFiles);
|
||||
deleteDirectory(g_file);
|
||||
|
||||
File f_file = new File(CustomNameplates.instance.getDataFolder() + File.separator + "ResourcePack" + File.separatorChar + ConfigManager.MainConfig.namespace + File.separatorChar + "font");
|
||||
File t_file = new File(CustomNameplates.instance.getDataFolder() + File.separator + "ResourcePack" + File.separatorChar + ConfigManager.MainConfig.namespace + File.separatorChar + "textures");
|
||||
File f_file = new File(CustomNameplates.instance.getDataFolder() + File.separator + "ResourcePack" + File.separatorChar + ConfigManager.Main.namespace + File.separatorChar + "font");
|
||||
File t_file = new File(CustomNameplates.instance.getDataFolder() + File.separator + "ResourcePack" + File.separatorChar + ConfigManager.Main.namespace + File.separatorChar + "textures");
|
||||
|
||||
if (!f_file.mkdirs() || !t_file.mkdirs()) {
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Error! Failed to generate resource pack folders...</red>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ConfigManager.MainConfig.offsets != null){
|
||||
ConfigManager.MainConfig.offsets.forEach(offset -> {
|
||||
if (ConfigManager.Main.offsets != null){
|
||||
ConfigManager.Main.offsets.forEach(offset -> {
|
||||
JsonObject jsonObject_offset = new JsonObject();
|
||||
JsonArray jsonArray_offset = new JsonArray();
|
||||
jsonObject_offset.add("providers", jsonArray_offset);
|
||||
@@ -126,7 +126,7 @@ public class ResourceManager {
|
||||
try (FileWriter fileWriter = new FileWriter(
|
||||
CustomNameplates.instance.getDataFolder() +
|
||||
File.separator + "ResourcePack" +
|
||||
File.separator + ConfigManager.MainConfig.namespace +
|
||||
File.separator + ConfigManager.Main.namespace +
|
||||
File.separator + "font" +
|
||||
File.separator + "offset_" + offset + ".json")) {
|
||||
fileWriter.write(jsonObject_offset.toString().replace("\\\\", "\\"));
|
||||
@@ -141,7 +141,7 @@ public class ResourceManager {
|
||||
JsonArray jsonArray_1 = new JsonArray();
|
||||
jsonObject_1.add("providers", jsonArray_1);
|
||||
getNegativeFontEnums().forEach(jsonArray_1::add);
|
||||
if (ConfigManager.nameplate){
|
||||
if (ConfigManager.Module.nameplate){
|
||||
for (File png : pngFiles) {
|
||||
JsonObject jsonObject_2 = new JsonObject();
|
||||
char left = start;
|
||||
@@ -153,28 +153,28 @@ public class ResourceManager {
|
||||
NameplateConfig config = this.getConfiguration(pngName);
|
||||
NAMEPLATES.put(pngName, new NameplateInstance(pngName, fontChar, config));
|
||||
jsonObject_2.add("type", new JsonPrimitive("bitmap"));
|
||||
jsonObject_2.add("file", new JsonPrimitive(ConfigManager.MainConfig.namespace + ":" + ConfigManager.MainConfig.folder_path.replaceAll("\\\\","/") + png.getName().toLowerCase()));
|
||||
jsonObject_2.add("file", new JsonPrimitive(ConfigManager.Main.namespace + ":" + ConfigManager.Main.folder_path.replaceAll("\\\\","/") + png.getName().toLowerCase()));
|
||||
jsonObject_2.add("ascent", new JsonPrimitive(config.getYOffset()));
|
||||
jsonObject_2.add("height", new JsonPrimitive(config.getHeight()));
|
||||
JsonArray jsonArray_2 = new JsonArray();
|
||||
jsonArray_2.add(native2ascii(fontChar.getLeft()) + native2ascii(fontChar.getMiddle()) + native2ascii(fontChar.getRight()));
|
||||
jsonObject_2.add("chars", jsonArray_2);
|
||||
jsonArray_1.add(jsonObject_2);
|
||||
try{
|
||||
FileUtils.copyFile(png, new File(t_file.getPath() + File.separatorChar + StringUtils.replace(ConfigManager.MainConfig.folder_path, "\\", String.valueOf(File.separatorChar)) + png.getName()));
|
||||
try {
|
||||
FileUtils.copyFile(png, new File(t_file.getPath() + File.separatorChar + StringUtils.replace(ConfigManager.Main.folder_path, "\\", String.valueOf(File.separatorChar)) + png.getName()));
|
||||
}catch (IOException e){
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Error! Failed to copy png files to resource pack...</red>");
|
||||
}
|
||||
}
|
||||
NAMEPLATES.put("none", NameplateInstance.EMPTY);
|
||||
}
|
||||
if (ConfigManager.background){
|
||||
if (ConfigManager.Module.background){
|
||||
ConfigManager.backgrounds.forEach((key, backGround) -> {
|
||||
getBackgrounds(backGround).forEach(jsonArray_1::add);
|
||||
});
|
||||
}
|
||||
|
||||
if (ConfigManager.MainConfig.extract) {
|
||||
if (ConfigManager.Main.extract) {
|
||||
String path = "ResourcePack" + File.separator + "minecraft" + File.separator + "shaders" + File.separator + "core" + File.separator;
|
||||
CustomNameplates.instance.saveResource(path + "rendertype_text.fsh", true);
|
||||
CustomNameplates.instance.saveResource(path + "rendertype_text.json", true);
|
||||
@@ -186,7 +186,7 @@ public class ResourceManager {
|
||||
|
||||
try{
|
||||
CustomNameplates.instance.saveResource("space_split.png", false);
|
||||
FileUtils.copyFile(new File(CustomNameplates.instance.getDataFolder(),"space_split.png"), new File(t_file.getPath() + File.separator + StringUtils.replace(ConfigManager.MainConfig.ss_folder_path, "\\", String.valueOf(File.separatorChar)) + "space_split.png"));
|
||||
FileUtils.copyFile(new File(CustomNameplates.instance.getDataFolder(),"space_split.png"), new File(t_file.getPath() + File.separator + StringUtils.replace(ConfigManager.Main.ss_folder_path, "\\", String.valueOf(File.separatorChar)) + "space_split.png"));
|
||||
new File(CustomNameplates.instance.getDataFolder(),"space_split.png").delete();
|
||||
}catch (IOException e){
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Error! Failed to copy space_split.png to resource pack...</red>");
|
||||
@@ -195,9 +195,9 @@ public class ResourceManager {
|
||||
try (FileWriter fileWriter = new FileWriter(
|
||||
CustomNameplates.instance.getDataFolder() +
|
||||
File.separator + "ResourcePack" +
|
||||
File.separator + ConfigManager.MainConfig.namespace +
|
||||
File.separator + ConfigManager.Main.namespace +
|
||||
File.separator + "font" +
|
||||
File.separator + ConfigManager.MainConfig.font + ".json"))
|
||||
File.separator + ConfigManager.Main.font + ".json"))
|
||||
{
|
||||
fileWriter.write(jsonObject_1.toString().replace("\\\\", "\\"));
|
||||
} catch (IOException e) {
|
||||
@@ -205,9 +205,9 @@ public class ResourceManager {
|
||||
}
|
||||
|
||||
AdventureUtil.consoleMessage("[CustomNameplates] ResourcePack has been generated!");
|
||||
AdventureUtil.consoleMessage("[CustomNameplates] Loaded <green>" + (NAMEPLATES.size() -1) + " <gray>nameplates");
|
||||
if (NAMEPLATES.size() != 0) AdventureUtil.consoleMessage("[CustomNameplates] Loaded <green>" + (NAMEPLATES.size() -1) + " <gray>nameplates");
|
||||
|
||||
if (ConfigManager.MainConfig.itemsAdder){
|
||||
if (ConfigManager.Main.itemsAdder){
|
||||
try{
|
||||
FileUtils.copyDirectory(g_file, new File(Bukkit.getPluginManager().getPlugin("ItemsAdder").getDataFolder() + File.separator + "data"+ File.separator + "resource_pack" + File.separator + "assets") );
|
||||
AdventureUtil.consoleMessage("<gradient:#2E8B57:#48D1CC>[CustomNameplates]</gradient> <color:#baffd1>Detected <color:#90EE90>ItemsAdder!<color:#baffd1> Automatically sent rp to ItemsAdder folder!");
|
||||
@@ -216,7 +216,7 @@ public class ResourceManager {
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Error! Failed to copy files to ItemsAdder...</red>");
|
||||
}
|
||||
}
|
||||
if (ConfigManager.MainConfig.oraxen){
|
||||
if (ConfigManager.Main.oraxen){
|
||||
try{
|
||||
FileUtils.copyDirectory(g_file, new File(Bukkit.getPluginManager().getPlugin("Oraxen").getDataFolder() + File.separator + "pack"+ File.separator + "assets"));
|
||||
AdventureUtil.consoleMessage("<gradient:#2E8B57:#48D1CC>[CustomNameplates]</gradient> <color:#baffd1>Detected <color:#90EE90>Oraxen!<color:#baffd1> Automatically sent rp to Oraxen folder!");
|
||||
@@ -287,7 +287,7 @@ public class ResourceManager {
|
||||
private JsonObject getNegativeFontChar(int height, char character) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.add("type", new JsonPrimitive("bitmap"));
|
||||
jsonObject.add("file", new JsonPrimitive(ConfigManager.MainConfig.namespace + ":" + ConfigManager.MainConfig.ss_folder_path.replaceAll("\\\\","/") + "space_split.png"));
|
||||
jsonObject.add("file", new JsonPrimitive(ConfigManager.Main.namespace + ":" + ConfigManager.Main.ss_folder_path.replaceAll("\\\\","/") + "space_split.png"));
|
||||
jsonObject.add("ascent", new JsonPrimitive(-5000));
|
||||
jsonObject.add("height", new JsonPrimitive(height));
|
||||
final JsonArray jsonArray = new JsonArray();
|
||||
@@ -335,7 +335,7 @@ public class ResourceManager {
|
||||
private JsonObject setBackgrounds(String name, int y_offset, int size, HashMap<String, Character> chars){
|
||||
JsonObject jsonObject_2 = new JsonObject();
|
||||
jsonObject_2.add("type", new JsonPrimitive("bitmap"));
|
||||
jsonObject_2.add("file", new JsonPrimitive(ConfigManager.MainConfig.namespace + ":" + ConfigManager.MainConfig.bg_folder_path.replaceAll("\\\\","/") + name.toLowerCase() + ".png"));
|
||||
jsonObject_2.add("file", new JsonPrimitive(ConfigManager.Main.namespace + ":" + ConfigManager.Main.bg_folder_path.replaceAll("\\\\","/") + name.toLowerCase() + ".png"));
|
||||
jsonObject_2.add("ascent", new JsonPrimitive(y_offset));
|
||||
jsonObject_2.add("height", new JsonPrimitive(size));
|
||||
JsonArray jsonArray_2 = new JsonArray();
|
||||
@@ -345,7 +345,7 @@ public class ResourceManager {
|
||||
start = (char)(start + '\u0001');
|
||||
chars.put(name, character);
|
||||
try {
|
||||
FileUtils.copyFile(new File(CustomNameplates.instance.getDataFolder() + File.separator + "backgrounds" + File.separator + name + ".png"), new File(CustomNameplates.instance.getDataFolder() + File.separator + "ResourcePack" + File.separator + ConfigManager.MainConfig.namespace + File.separatorChar + "textures" + File.separatorChar + StringUtils.replace(ConfigManager.MainConfig.bg_folder_path, "\\", String.valueOf(File.separatorChar)) + name + ".png"));
|
||||
FileUtils.copyFile(new File(CustomNameplates.instance.getDataFolder() + File.separator + "backgrounds" + File.separator + name + ".png"), new File(CustomNameplates.instance.getDataFolder() + File.separator + "ResourcePack" + File.separator + ConfigManager.Main.namespace + File.separatorChar + "textures" + File.separatorChar + StringUtils.replace(ConfigManager.Main.bg_folder_path, "\\", String.valueOf(File.separatorChar)) + name + ".png"));
|
||||
}
|
||||
catch (IOException e){
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
package net.momirealms.customnameplates.utils;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.data.DataManager;
|
||||
import net.momirealms.customnameplates.data.PlayerData;
|
||||
import net.momirealms.customnameplates.hook.PapiHook;
|
||||
import net.momirealms.customnameplates.objects.ASInfo;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ArmorStandPacketUtil {
|
||||
|
||||
public static ConcurrentHashMap<Integer, List<ASInfo>> cache = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<Player, int[]> player2ids = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<Integer, int[]> id2ids = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<Integer, HashMap<Integer, BukkitTask>> taskCache = new ConcurrentHashMap<>();
|
||||
|
||||
public static void preparePackets(Player player) {
|
||||
|
||||
int size = ConfigManager.Nameplate.texts.size();
|
||||
int[] ids = new int[size];
|
||||
List<ASInfo> asInfos = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
||||
PacketContainer entityPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||
|
||||
int id = new Random().nextInt(1000000000);
|
||||
ids[i] = id;
|
||||
|
||||
String text = ConfigManager.Nameplate.texts.get(i);
|
||||
entityPacket.getModifier().write(0, id);
|
||||
entityPacket.getModifier().write(1, UUID.randomUUID());
|
||||
entityPacket.getEntityTypeModifier().write(0, EntityType.ARMOR_STAND);
|
||||
Location location = player.getLocation();
|
||||
entityPacket.getDoubles().write(0, location.getX());
|
||||
entityPacket.getDoubles().write(1, location.getY());
|
||||
entityPacket.getDoubles().write(2, location.getZ());
|
||||
|
||||
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
|
||||
ASInfo asInfo = new ASInfo(id, text, entityPacket, metaPacket);
|
||||
|
||||
if (ConfigManager.MainConfig.placeholderAPI) text = PapiHook.parsePlaceholders(player, text);
|
||||
|
||||
metaPacket.getModifier().write(0, id);
|
||||
WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher();
|
||||
WrappedDataWatcher.Serializer serializer1 = WrappedDataWatcher.Registry.get(Boolean.class);
|
||||
WrappedDataWatcher.Serializer serializer2 = WrappedDataWatcher.Registry.get(Byte.class);
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.getChatComponentSerializer(true)), Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(text))).getHandle()));
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, serializer1), true);
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, serializer2), (byte) 0x20);
|
||||
if (ConfigManager.Nameplate.smallSize) {
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, serializer2), (byte) 0x01);
|
||||
}
|
||||
metaPacket.getWatchableCollectionModifier().write(0, wrappedDataWatcher.getWatchableObjects());
|
||||
|
||||
asInfos.add(asInfo);
|
||||
}
|
||||
|
||||
cache.put(player.getEntityId(), asInfos);
|
||||
player2ids.put(player, ids);
|
||||
id2ids.put(player.getEntityId(), ids);
|
||||
}
|
||||
|
||||
public static void sendPreviewToOne(Player player) {
|
||||
List<ASInfo> asInfos = cache.get(player.getEntityId());
|
||||
if (asInfos != null) {
|
||||
PacketContainer ridingPacket = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||
ridingPacket.getModifier().write(0, player.getEntityId());
|
||||
ridingPacket.getModifier().write(1, player2ids.get(player));
|
||||
Location location = player.getLocation();
|
||||
for (ASInfo asInfo : asInfos) {
|
||||
PacketContainer entityPacket = asInfo.getEntityPacket();
|
||||
entityPacket.getDoubles().write(0, location.getX());
|
||||
entityPacket.getDoubles().write(1, location.getY() + 1.45);
|
||||
entityPacket.getDoubles().write(2, location.getZ());
|
||||
PacketContainer metaPacket = asInfo.getMetaPacket().deepClone();
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entityPacket);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, metaPacket);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, ridingPacket);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sendUpdateOneToOne(player, player);
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomNameplates.instance, () -> {
|
||||
sendDestroyToOne(player, player2ids.get(player));
|
||||
}, ConfigManager.Nameplate.preview * 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendSummonOneToOne(Player player, Player otherPlayer) {
|
||||
List<ASInfo> asInfos = cache.get(otherPlayer.getEntityId());
|
||||
if (asInfos != null) {
|
||||
PacketContainer ridingPacket = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||
ridingPacket.getModifier().write(0, otherPlayer.getEntityId());
|
||||
ridingPacket.getModifier().write(1, player2ids.get(otherPlayer));
|
||||
Location location = otherPlayer.getLocation();
|
||||
|
||||
boolean canSee = false;
|
||||
if (ConfigManager.Nameplate.show_after) {
|
||||
PlayerData playerData = DataManager.cache.get(player.getUniqueId());
|
||||
if (playerData == null) {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomNameplates.instance, () -> {
|
||||
sendSummonOneToOne(player, otherPlayer);
|
||||
}, 20);
|
||||
return;
|
||||
} else if (playerData.getAccepted() == 1) {
|
||||
canSee = true;
|
||||
}
|
||||
} else {
|
||||
canSee = true;
|
||||
}
|
||||
|
||||
for (ASInfo asInfo : asInfos) {
|
||||
PacketContainer entityPacket = asInfo.getEntityPacket();
|
||||
entityPacket.getDoubles().write(0, location.getX());
|
||||
entityPacket.getDoubles().write(1, location.getY() + 1.45);
|
||||
entityPacket.getDoubles().write(2, location.getZ());
|
||||
PacketContainer metaPacket = asInfo.getMetaPacket().deepClone();
|
||||
if (!canSee) {
|
||||
WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher();
|
||||
WrappedDataWatcher.Serializer serializer1 = WrappedDataWatcher.Registry.get(Boolean.class);
|
||||
WrappedDataWatcher.Serializer serializer2 = WrappedDataWatcher.Registry.get(Byte.class);
|
||||
//名称是否可见
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, serializer1), false);
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, serializer2), (byte) 0x20);
|
||||
metaPacket.getWatchableCollectionModifier().write(0, wrappedDataWatcher.getWatchableObjects());
|
||||
}
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entityPacket);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, metaPacket);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, ridingPacket);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomNameplates.instance, () -> {
|
||||
sendSummonOneToOne(player, otherPlayer);
|
||||
}, 20);
|
||||
}
|
||||
}
|
||||
|
||||
//将左侧玩家的信息发送给右侧的
|
||||
public static void sendUpdateOneToOne(Player player, Player otherPlayer) {
|
||||
List<ASInfo> asInfos = cache.get(player.getEntityId());
|
||||
if (asInfos == null) return;
|
||||
for (ASInfo asInfo : asInfos) {
|
||||
PacketContainer metaPacket = asInfo.getMetaPacket().deepClone();
|
||||
String origin = asInfo.getText();
|
||||
if (ConfigManager.MainConfig.placeholderAPI) origin = PapiHook.parsePlaceholders(player, origin);
|
||||
WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher();
|
||||
WrappedDataWatcher.Serializer serializer2 = WrappedDataWatcher.Registry.get(Byte.class);
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, serializer2), (byte) 0x20);
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.getChatComponentSerializer(true)), Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(origin))).getHandle()));
|
||||
if (ConfigManager.Nameplate.smallSize) {
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, serializer2), (byte) 0x01);
|
||||
}
|
||||
metaPacket.getWatchableCollectionModifier().write(0, wrappedDataWatcher.getWatchableObjects());
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(otherPlayer, metaPacket);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void forceUpdateOneToOne(int id, Player player) {
|
||||
List<ASInfo> asInfos = cache.get(id);
|
||||
if (asInfos == null) return;
|
||||
for (ASInfo asInfo : asInfos) {
|
||||
PacketContainer metaPacket = asInfo.getMetaPacket().deepClone();
|
||||
boolean canSee = false;
|
||||
if (ConfigManager.Nameplate.show_after) {
|
||||
PlayerData playerData = DataManager.cache.get(player.getUniqueId());
|
||||
if (playerData == null) {
|
||||
return;
|
||||
} else if (playerData.getAccepted() == 1) {
|
||||
canSee = true;
|
||||
}
|
||||
} else {
|
||||
canSee = true;
|
||||
}
|
||||
WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher();
|
||||
WrappedDataWatcher.Serializer serializer1 = WrappedDataWatcher.Registry.get(Boolean.class);
|
||||
WrappedDataWatcher.Serializer serializer2 = WrappedDataWatcher.Registry.get(Byte.class);
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, serializer1), canSee);
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, serializer2), (byte) 0x20);
|
||||
if (ConfigManager.Nameplate.smallSize) {
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, serializer2), (byte) 0x01);
|
||||
}
|
||||
metaPacket.getWatchableCollectionModifier().write(0, wrappedDataWatcher.getWatchableObjects());
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, metaPacket);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendDestroyToOne(Player player, int[] entities) {
|
||||
List<Integer> idList = new ArrayList<>();
|
||||
for (int id : entities) {
|
||||
idList.add(id);
|
||||
}
|
||||
try {
|
||||
PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
destroyPacket.getIntLists().write(0, idList);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ public class ConfigUtil {
|
||||
public static void update(){
|
||||
try {
|
||||
YamlDocument.create(new File(CustomNameplates.instance.getDataFolder(), "config.yml"), CustomNameplates.instance.getResource("config.yml"), GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, UpdaterSettings.builder().setVersioning(new BasicVersioning("config-version")).build());
|
||||
YamlDocument.create(new File(CustomNameplates.instance.getDataFolder(), "nameplate.yml"), CustomNameplates.instance.getResource("nameplate.yml"), GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, UpdaterSettings.builder().setVersioning(new BasicVersioning("config-version")).build());
|
||||
}catch (IOException e){
|
||||
Log.warn(e.getMessage());
|
||||
}
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
package net.momirealms.customnameplates.utils;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.InternalStructure;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.data.DataManager;
|
||||
import net.momirealms.customnameplates.data.PlayerData;
|
||||
import net.momirealms.customnameplates.hook.TABHook;
|
||||
import net.momirealms.customnameplates.scoreboard.NameplatesTeam;
|
||||
import net.momirealms.customnameplates.scoreboard.ScoreBoardManager;
|
||||
import net.momirealms.customnameplates.scoreboard.TeamInfo;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TeamPacketUtil {
|
||||
|
||||
public static HashMap<Player, TeamInfo> teamInfoCache = new HashMap<>();
|
||||
|
||||
public static void sendUpdateToOne(Player player) {
|
||||
boolean accepted = DataManager.cache.get(player.getUniqueId()).getAccepted() == 1;
|
||||
for (Player otherPlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (player == otherPlayer) return;
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
|
||||
packet.getIntegers().write(0,2);
|
||||
String teamName = otherPlayer.getName();
|
||||
if (ConfigManager.MainConfig.tab) teamName = TABHook.getTABTeam(teamName);
|
||||
packet.getStrings().write(0, teamName);
|
||||
NameplatesTeam nameplatesTeam = ScoreBoardManager.teams.get(teamName);
|
||||
if (nameplatesTeam != null) {
|
||||
Optional<InternalStructure> optional = packet.getOptionalStructures().read(0);
|
||||
if (optional.isPresent()) {
|
||||
InternalStructure internalStructure = optional.get();
|
||||
if (ConfigManager.Nameplate.show_after && !accepted) {
|
||||
internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson("{\"text\":\"\"}"));
|
||||
internalStructure.getChatComponents().write(2, WrappedChatComponent.fromJson("{\"text\":\"\"}"));
|
||||
internalStructure.getStrings().write(0, "always");
|
||||
internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,ChatColor.WHITE);
|
||||
}
|
||||
else {
|
||||
if (ConfigManager.Nameplate.removeTag) {
|
||||
internalStructure.getStrings().write(0, "never");
|
||||
}
|
||||
else {
|
||||
internalStructure.getStrings().write(0, "always");
|
||||
}
|
||||
internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(nameplatesTeam.getPrefix())));
|
||||
internalStructure.getChatComponents().write(2, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(nameplatesTeam.getSuffix())));
|
||||
internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,nameplatesTeam.getColor());
|
||||
}
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(player, packet);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendUpdateToAll(Player player) {
|
||||
String teamName = player.getName();
|
||||
if (ConfigManager.MainConfig.tab) teamName = TABHook.getTABTeam(teamName);
|
||||
NameplatesTeam nameplatesTeam = ScoreBoardManager.teams.get(teamName);
|
||||
TeamInfo newInfo = new TeamInfo(nameplatesTeam.getPrefixText(), nameplatesTeam.getSuffixText());
|
||||
TeamInfo oldInfo = teamInfoCache.put(player, newInfo);
|
||||
if (oldInfo == null || !oldInfo.equals(newInfo)) {
|
||||
for (Player otherPlayer : Bukkit.getOnlinePlayers()) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
|
||||
packet.getStrings().write(0, teamName);
|
||||
packet.getIntegers().write(0,2);
|
||||
Optional<InternalStructure> optional = packet.getOptionalStructures().read(0);
|
||||
if (optional.isPresent()) {
|
||||
InternalStructure internalStructure = optional.get();
|
||||
|
||||
if (ConfigManager.Nameplate.show_after) {
|
||||
PlayerData playerData = DataManager.cache.get(otherPlayer.getUniqueId());
|
||||
if (playerData == null || playerData.getAccepted() == 0) {
|
||||
internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson("{\"text\":\"\"}"));
|
||||
internalStructure.getChatComponents().write(2, WrappedChatComponent.fromJson("{\"text\":\"\"}"));
|
||||
internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,ChatColor.WHITE);
|
||||
}
|
||||
else {
|
||||
if (ConfigManager.Nameplate.removeTag) {
|
||||
internalStructure.getStrings().write(0, "never");
|
||||
}
|
||||
else {
|
||||
internalStructure.getStrings().write(0, "always");
|
||||
internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(nameplatesTeam.getPrefix())));
|
||||
internalStructure.getChatComponents().write(2, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(nameplatesTeam.getSuffix())));
|
||||
internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,nameplatesTeam.getColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ConfigManager.Nameplate.removeTag) {
|
||||
internalStructure.getStrings().write(0, "never");
|
||||
}
|
||||
else {
|
||||
internalStructure.getStrings().write(0, "always");
|
||||
internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(nameplatesTeam.getPrefix())));
|
||||
internalStructure.getChatComponents().write(2, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(nameplatesTeam.getSuffix())));
|
||||
internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,nameplatesTeam.getColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
CustomNameplates.protocolManager.sendServerPacket(otherPlayer, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
#Modules require a restart
|
||||
#Nameplate module require a restart because it requires a SQL connection
|
||||
nameplate: true
|
||||
|
||||
#These modules can be toggled by reloading
|
||||
background: true
|
||||
bossbar: true
|
||||
actionbar: false
|
||||
@@ -1,14 +1,6 @@
|
||||
# You need a restart when you add/remove a bossbar
|
||||
|
||||
# IMPORTANT NOTICE
|
||||
# mode: Adventure / ProtocolLib
|
||||
# There's a bug that font can't be applied to Adventure bossbar. This is an Adventure API bug that I can't fix for the moment.
|
||||
# It requires a restart to change mode
|
||||
mode: ProtocolLib
|
||||
|
||||
bossbar:
|
||||
example_1:
|
||||
text: '<font:nameplates:default><color:#FFFEFD>%nameplates_bg_player%<font:nameplates:offset_3>Hello! %player_name%</font> <font:nameplates:default><color:#FFFEFD>%nameplates_bg_pos%<font:nameplates:offset_3>You are now at: %player_x%, %player_y%, %player_z%</font>'
|
||||
text: '<font:nameplates:default><color:#FFFEFD>%nameplates_bg_player%<font:nameplates:offset_3>Hello! %player_name%</font></font> <font:nameplates:default><color:#FFFEFD>%nameplates_bg_pos%<font:nameplates:offset_3>You are now at: %player_x%, %player_y%, %player_z%</font>'
|
||||
refresh-rate: 5
|
||||
# PINK
|
||||
# YELLOW
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# don't change
|
||||
config-version: '2'
|
||||
config-version: '3'
|
||||
|
||||
config:
|
||||
# Language
|
||||
@@ -11,7 +11,7 @@ config:
|
||||
# When enabled, the plugin will be able to parse prefix and suffix
|
||||
# Require restart to register papi
|
||||
PlaceholderAPI: true
|
||||
# When enabled, the plugin will automatically place the nameplates
|
||||
# When enabled, the plugin will automatically place the resource pack
|
||||
# folder into the resource pack generated by ItemsAdder/Oraxen.
|
||||
ItemsAdder: false
|
||||
Oraxen: false
|
||||
@@ -21,7 +21,7 @@ config:
|
||||
|
||||
# Your namespace
|
||||
# If you don't know how font works, don't change this
|
||||
# Don't use minecraft:default or you will get no support
|
||||
# Never use minecraft:default, or you will get no support
|
||||
namespace: "nameplates"
|
||||
|
||||
# Font Name
|
||||
@@ -52,7 +52,7 @@ config:
|
||||
use-thin-font: false
|
||||
|
||||
# For ItemsAdder users:
|
||||
# You need to override assets/minecraft/shaders/core/rendertype_text.vsh in the generated pack to apply this shader
|
||||
# You need to override assets/minecraft/shaders/core/rendertype_text.xxx in the generated pack to apply this shader
|
||||
# For Oraxen users:
|
||||
# extract the shaders to Oraxen/pack/shaders/core
|
||||
#
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
config-version: '3'
|
||||
|
||||
nameplate:
|
||||
# mode: Team / Entity
|
||||
# ================ Team ===================
|
||||
# Team is based on vanilla mechanic team
|
||||
# Advantage:
|
||||
# No lag
|
||||
#
|
||||
# Disadvantage:
|
||||
# Player name's colors are limited
|
||||
# Only support one-line text
|
||||
# May exist conflict with other plugins that use team
|
||||
#
|
||||
# ================ Entity ================
|
||||
# Plugin would summon fake armorstands packets riding the player
|
||||
# Advantage:
|
||||
# No lag (The principle is different from TAB)
|
||||
# Support multiple lines (based on resource pack side tech)
|
||||
#
|
||||
# Disadvantage:
|
||||
# May not compatible with some cosmetics plugins
|
||||
# mode: Team / Riding / Teleporting
|
||||
# ============================== Team ==================================
|
||||
# Team is based on vanilla team mechanic
|
||||
# But only supports one line
|
||||
# ============================= Riding =================================
|
||||
# Plugin would summon fake armor stands packets riding the player
|
||||
# to provide additional tag lines for players
|
||||
# ========================== Teleporting ===============================
|
||||
# Plugin would summon fake armor stands packets teleporting the player
|
||||
# to provide additional tag lines for players
|
||||
# (requires a restart)
|
||||
mode: Team
|
||||
|
||||
@@ -34,42 +27,53 @@ nameplate:
|
||||
# "none" represents no default nameplate.
|
||||
default-nameplate: 'none'
|
||||
|
||||
# Recommended to keep this true, otherwise players may see weird characters
|
||||
# above their heads if they have not accepted the resource pack.
|
||||
# This option supports proxy when using Mysql
|
||||
# If you meet problem with this, set it to false to always display nameplates
|
||||
show-after-load-resourcepack: true
|
||||
# Placeholder based prefix and suffix system. When enabled, it is recommended
|
||||
# to use PlaceholderAPI to be able to use this feature to the fullest extent.
|
||||
# keep it empty if you don't want to enable this feature.
|
||||
# You should make sure the papi doesn't contain "&" (legacy color code)
|
||||
# Nameplates work on the custom font system where legacy color code is not supported!
|
||||
# Please use MiniMessage format: https://docs.adventure.kyori.net/minimessage/format.html
|
||||
prefix: '<font:minecraft:default><rainbow>Hello! </rainbow></font>'
|
||||
suffix: ' <red>%player_health_rounded%♥'
|
||||
|
||||
# These option only works when using mode team
|
||||
# These options only work when using mode Team
|
||||
team:
|
||||
# Team mode only supports one line, so it is using a prefix/suffix system to extend the player name info
|
||||
|
||||
# Placeholder based prefix and suffix system. When enabled, it is recommended
|
||||
# to use PlaceholderAPI to be able to use this feature to the fullest extent.
|
||||
# keep it empty if you don't want to enable this feature.
|
||||
# You should make sure the papi doesn't contain "&" (legacy color code)
|
||||
# Nameplates work on the custom font system where legacy color code is not supported!
|
||||
# Please use minimessage format: https://docs.adventure.kyori.net/minimessage/format.html
|
||||
prefix: '<font:minecraft:default><rainbow>Hello! </rainbow></font>'
|
||||
suffix: ' <red>%player_health_rounded%♥'
|
||||
|
||||
# should prefix/suffix be hidden when player is equipping a nameplate
|
||||
hide-prefix-when-equipped: false
|
||||
hide-suffix-when-equipped: false
|
||||
hide-prefix-when-equipped: true
|
||||
hide-suffix-when-equipped: true
|
||||
|
||||
# These option only works when using mode entity
|
||||
entity:
|
||||
# These options only work when using mode Riding
|
||||
riding:
|
||||
# If you are having trouble with plugin conflict
|
||||
# Set this to "true" might help (let other plugin handle armor_stand mounting) (requires a restart)
|
||||
# MagicCosmetics has been tested, and it proves to work well
|
||||
# Set this to "true" might help (let other plugin handle armor stand mounting) (requires a restart)
|
||||
# MagicCosmetics is tested, and it proves to work well
|
||||
try-to-hook-cosmetics-plugin: false
|
||||
# Remove player original name-tag (requires Vanilla Team)
|
||||
# If you have another plugin that is using team please disable team management in that plugin or turn player's name off in that plugin
|
||||
# Make player's original name-tag invisible
|
||||
# If you have another plugin that is using team please disable team management in that plugin or make player's name invisible in that plugin
|
||||
remove-nametag: true
|
||||
# If it is the normal size, more lines can be displayed but it would go obviously abnormal when you look at it in a certain angle
|
||||
# If armor stand is the normal size, more lines can be displayed but texts would go obviously abnormal when you look at it in a certain angle
|
||||
small-size: true
|
||||
# nameplates content
|
||||
text:
|
||||
- '<font:nameplates:default>%nameplates_prefix%</font><font:minecraft:default>%player_name%</font><font:nameplates:default>%nameplates_suffix%</font>'
|
||||
- '<font:nameplates:default>%nameplates_bg_health%</font><font:nameplates:offset_-11><red>%player_health_rounded% Health</font> <font:nameplates:default>%nameplates_bg_food%</font><font:nameplates:offset_-11><#F0E68C>%player_food_level% Hunger</font>'
|
||||
- '<font:nameplates:offset_-24>Multiple lines are supported!</font>'
|
||||
- '<font:nameplates:offset_-24>Multiple lines are supported!</font>'
|
||||
|
||||
# These options only work when using mode Teleporting
|
||||
teleporting:
|
||||
# Make player's original name-tag invisible
|
||||
# If you have another plugin that is using team please disable team management in that plugin or make player's name invisible in that plugin
|
||||
remove-nametag: true
|
||||
# Small size armor stand
|
||||
small-size: true
|
||||
# nameplates content
|
||||
text:
|
||||
text_1:
|
||||
content: '<font:nameplates:default>%nameplates_prefix%</font><font:minecraft:default>%player_name%</font><font:nameplates:default>%nameplates_suffix%</font>'
|
||||
offset: -1
|
||||
text_2:
|
||||
content: '<font:nameplates:default>%nameplates_bg_health%</font><font:nameplates:offset_-11><red>%player_health_rounded% Health</font> <font:nameplates:default>%nameplates_bg_food%</font><font:nameplates:offset_-11><#F0E68C>%player_food_level% Hunger</font>'
|
||||
offset: 0
|
||||
text_3:
|
||||
content: 'Multiple lines are supported!'
|
||||
offset: 0
|
||||
Reference in New Issue
Block a user