diff --git a/build.gradle b/build.gradle index 86a4b41..e56b403 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '1.7.1' +version = '1.8.0-SNAPSHOT' repositories { mavenCentral() @@ -37,14 +37,15 @@ repositories { dependencies { compileOnly fileTree(dir:'libs',includes:['*.jar']) compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT' - compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "4.8.0" + compileOnly 'com.comphenix.protocol:ProtocolLib:4.8.0' compileOnly 'me.clip:placeholderapi:2.11.1' compileOnly 'com.zaxxer:HikariCP:5.0.1' + compileOnly 'commons-io:commons-io:2.11.0' implementation('net.kyori:adventure-api:4.11.0') implementation('net.kyori:adventure-platform-bukkit:4.1.1') implementation('net.kyori:adventure-text-minimessage:4.11.0') implementation("net.kyori:adventure-text-serializer-gson:4.11.0") - compileOnly group: 'commons-io', name: 'commons-io', version: '2.11.0' + } def targetJavaVersion = 16 diff --git a/src/main/java/net/momirealms/customnameplates/AdventureManager.java b/src/main/java/net/momirealms/customnameplates/AdventureManager.java index 06d6390..435d17d 100644 --- a/src/main/java/net/momirealms/customnameplates/AdventureManager.java +++ b/src/main/java/net/momirealms/customnameplates/AdventureManager.java @@ -1,24 +1,66 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates; import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.title.Title; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.time.Duration; + public class AdventureManager { - //发送控制台消息 + public static void consoleMessage(String s) { Audience au = CustomNameplates.adventure.sender(Bukkit.getConsoleSender()); MiniMessage mm = MiniMessage.miniMessage(); Component parsed = mm.deserialize(s); au.sendMessage(parsed); } - //发送玩家消息 + public static void playerMessage(Player player, String s){ Audience au = CustomNameplates.adventure.player(player); MiniMessage mm = MiniMessage.miniMessage(); Component parsed = mm.deserialize(s); au.sendMessage(parsed); } + + public static void playerTitle(Player player, String s1, String s2, int in, int duration, int out) { + Audience au = CustomNameplates.adventure.player(player); + MiniMessage mm = MiniMessage.miniMessage(); + Title.Times times = Title.Times.times(Duration.ofMillis(in), Duration.ofMillis(duration), Duration.ofMillis(out)); + Title title = Title.title(mm.deserialize(s1), mm.deserialize(s2), times); + au.showTitle(title); + } + + public static void playerActionbar(Player player, String s) { + Audience au = CustomNameplates.adventure.player(player); + MiniMessage mm = MiniMessage.miniMessage(); + au.sendActionBar(mm.deserialize(s)); + } + + public static void playerSound(Player player, Sound.Source source, Key key) { + Sound sound = Sound.sound(key, source, 1, 1); + Audience au = CustomNameplates.adventure.player(player); + au.playSound(sound); + } } diff --git a/src/main/java/net/momirealms/customnameplates/ConfigManager.java b/src/main/java/net/momirealms/customnameplates/ConfigManager.java index 772db06..0deb1a4 100644 --- a/src/main/java/net/momirealms/customnameplates/ConfigManager.java +++ b/src/main/java/net/momirealms/customnameplates/ConfigManager.java @@ -1,30 +1,70 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates; +import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.key.Key; +import net.momirealms.customnameplates.background.BackGround; +import net.momirealms.customnameplates.bossbar.BossbarConfig; +import net.momirealms.customnameplates.utils.BGInfo; +import net.momirealms.customnameplates.utils.NPInfo; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; +import java.util.HashMap; +import java.util.TreeMap; public class ConfigManager { - //根据文件名获取配置文件 + public static TreeMap backgrounds = new TreeMap<>(); + public static TreeMap bossbars = new TreeMap<>(); + public static HashMap papiBG = new HashMap<>(); + public static HashMap papiNP = new HashMap<>(); + public static YamlConfiguration getConfig(String configName) { File file = new File(CustomNameplates.instance.getDataFolder(), configName); - //文件不存在则生成默认配置 if (!file.exists()) { CustomNameplates.instance.saveResource(configName, false); } return YamlConfiguration.loadConfiguration(file); } - //主配置文件 - public static class MainConfig{ + public static boolean nameplate; + public static boolean background; + public static boolean bossbar; + public static boolean actionbar; + public static void loadModule(){ + YamlConfiguration module = getConfig("module.yml"); + nameplate = module.getBoolean("nameplate"); + background = module.getBoolean("background"); + bossbar = module.getBoolean("bossbar"); + actionbar = module.getBoolean("actionbar"); + } + + public static class MainConfig{ public static String namespace; public static String fontName; public static String start_char; + public static char start; public static String folder_path; + public static String bg_folder_path; public static String font; public static String default_nameplate; public static String player_prefix; @@ -38,23 +78,37 @@ public class ConfigManager { public static boolean thin_font; public static boolean hidePrefix; public static boolean hideSuffix; - public static void ReloadConfig(){ CustomNameplates.instance.saveDefaultConfig(); CustomNameplates.instance.reloadConfig(); FileConfiguration config = CustomNameplates.instance.getConfig(); - lang = config.getString("config.lang"); namespace = config.getString("config.namespace"); font = config.getString("config.font"); fontName = namespace + ":" + font; start_char = config.getString("config.start-char"); - folder_path = config.getString("config.folder-path"); + start = start_char.charAt(0); + folder_path = config.getString("config.nameplate-folder-path","font\\nameplates\\"); + bg_folder_path = config.getString("config.background-folder-path","font\\backgrounds\\"); default_nameplate = config.getString("config.default-nameplate"); player_prefix = config.getString("config.prefix"); player_suffix = config.getString("config.suffix"); itemsAdder =config.getBoolean("config.integrations.ItemsAdder"); + if (itemsAdder){ + if(CustomNameplates.instance.getServer().getPluginManager().getPlugin("ItemsAdder") == null){ + CustomNameplates.instance.getLogger().warning("Failed to initialize ItemsAdder!"); + itemsAdder = false; + } + } placeholderAPI = config.getBoolean("config.integrations.PlaceholderAPI"); + if (placeholderAPI){ + if(CustomNameplates.instance.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null){ + loadPapi(); + }else { + CustomNameplates.instance.getLogger().warning("Failed to initialize PlaceholderAPI!"); + placeholderAPI = false; + } + } show_after = config.getBoolean("config.show-after-load-resourcepack"); key = Key.key(fontName); preview = config.getLong("config.preview-duration"); @@ -63,9 +117,8 @@ public class ConfigManager { hideSuffix = config.getBoolean("config.hide-suffix-when-equipped",false); } } - //消息文件 - public static class Message{ + public static class Message{ public static String noPerm; public static String prefix; public static String lackArgs; @@ -81,7 +134,7 @@ public class ConfigManager { public static String available; public static String cooldown; public static String preview; - + public static String generate; public static void ReloadConfig(){ YamlConfiguration messagesConfig = getConfig("messages/messages_" + MainConfig.lang +".yml"); noPerm = messagesConfig.getString("messages.no-perm"); @@ -99,11 +152,67 @@ public class ConfigManager { available = messagesConfig.getString("messages.available"); cooldown = messagesConfig.getString("messages.cooldown"); preview = messagesConfig.getString("messages.preview"); + generate = messagesConfig.getString("messages.generate"); } } - //数据库配置 - public static class DatabaseConfig{ + public static void loadBGConfig(){ + backgrounds.clear(); + YamlConfiguration bgConfig = getConfig("background.yml"); + bgConfig.getConfigurationSection("background").getKeys(false).forEach(key -> { + backgrounds.put(key, new BackGround(bgConfig.getString("background." + key + ".start"),bgConfig.getString("background." + key + ".offset_1"), + bgConfig.getString("background." + key + ".offset_2"),bgConfig.getString("background." + key + ".offset_4"),bgConfig.getString("background." + key + ".offset_8"), + bgConfig.getString("background." + key + ".offset_16"),bgConfig.getString("background." + key + ".offset_32"),bgConfig.getString("background." + key + ".offset_64"), + bgConfig.getString("background." + key + ".offset_128"),bgConfig.getString("background." + key + ".end"),bgConfig.getInt("background." + key + ".y-offset"),bgConfig.getInt("background." + key + ".x-offset") + )); + }); + } + + public static void loadBossBar(){ + YamlConfiguration bossbarConfig = getConfig("bossbar.yml"); + bossbarConfig.getConfigurationSection("bossbar").getKeys(false).forEach(key -> { + BossbarConfig bossbarConfig1 = ConfigManager.bossbars.get(key); + if (bossbarConfig1 != null){ + bossbarConfig1.setColor(BossBar.Color.valueOf(bossbarConfig.getString("bossbar." + key + ".color").toUpperCase())); + bossbarConfig1.setOverlay(BossBar.Overlay.valueOf(bossbarConfig.getString("bossbar." + key + ".overlay").toUpperCase())); + bossbarConfig1.setRate(bossbarConfig.getInt("bossbar." + key + ".refresh-rate") - 1); + bossbarConfig1.setText(bossbarConfig.getString("bossbar." + key + ".text")); + }else { + bossbars.put(key, new BossbarConfig( + bossbarConfig.getString("bossbar." + key + ".text"), + BossBar.Overlay.valueOf(bossbarConfig.getString("bossbar." + key + ".overlay").toUpperCase()), + BossBar.Color.valueOf(bossbarConfig.getString("bossbar." + key + ".color").toUpperCase()), + bossbarConfig.getInt("bossbar." + key + ".refresh-rate") - 1 + )); + } + }); + } + + public static void loadPapi(){ + papiBG.clear(); + papiNP.clear(); + 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"))); + } + if (papiInfo.contains("papi." + key + ".nameplate")){ + papiNP.put(key, new NPInfo(papiInfo.getString("papi."+key+".text"), papiInfo.getString("papi." + key + ".nameplate"))); + } + }); + } + + public static class ActionbarConfig{ + public static int rate; + public static String text; + public static void LoadConfig(){ + YamlConfiguration actionbarConfig = getConfig("actionbar.yml"); + rate = actionbarConfig.getInt("refresh-rate") - 1; + text = actionbarConfig.getString("text"); + } + } + + public static class DatabaseConfig{ public static String user; public static String password; public static String url; @@ -116,27 +225,21 @@ public class ConfigManager { public static int minimum_idle; public static int maximum_lifetime; public static int idle_timeout; - public static void LoadConfig(){ YamlConfiguration databaseConfig = getConfig("database.yml"); String storage_mode = databaseConfig.getString("settings.storage-mode"); - async = !databaseConfig.getBoolean("settings.disable-async", true); - //使用SQLite if(storage_mode.equals("SQLite")){ enable_pool = false; use_mysql = false; tableName = "nameplates"; } - //使用MYSQL else if(storage_mode.equals("MYSQL")){ - use_mysql = true; ENCODING = databaseConfig.getString("MySQL.property.encoding"); tableName = databaseConfig.getString("MySQL.table-name"); user = databaseConfig.getString("MySQL.user"); password = databaseConfig.getString("MySQL.password"); - url = "jdbc:mysql://" + databaseConfig.getString("MySQL.host") + ":" + databaseConfig.getString("MySQL.port") + "/" + databaseConfig.getString("MySQL.database") + "?characterEncoding=" @@ -162,4 +265,4 @@ public class ConfigManager { } } } -} +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customnameplates/CustomNameplates.java b/src/main/java/net/momirealms/customnameplates/CustomNameplates.java index 574dfae..146de23 100644 --- a/src/main/java/net/momirealms/customnameplates/CustomNameplates.java +++ b/src/main/java/net/momirealms/customnameplates/CustomNameplates.java @@ -1,13 +1,32 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates; import com.comphenix.protocol.ProtocolLibrary; import net.kyori.adventure.platform.bukkit.BukkitAudiences; +import net.momirealms.customnameplates.actionbar.Timer; +import net.momirealms.customnameplates.bossbar.QuitAndJoin; 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.HookManager; +import net.momirealms.customnameplates.hook.Placeholders; import net.momirealms.customnameplates.listener.PlayerListener; import net.momirealms.customnameplates.listener.PacketsListener; import net.momirealms.customnameplates.resource.ResourceManager; @@ -25,19 +44,17 @@ public final class CustomNameplates extends JavaPlugin { private ResourceManager resourceManager; private DataManager dataManager; - private HookManager hookManager; private ScoreBoardManager scoreBoardManager; + private Timer timer; public ResourceManager getResourceManager() { return this.resourceManager; } public DataManager getDataManager() { return this.dataManager; } - public HookManager getHookManager() { return this.hookManager; } public ScoreBoardManager getScoreBoardManager() { return this.scoreBoardManager; } @Override public void onLoad(){ - instance = this; LibraryLoader.load("commons-io","commons-io","2.11.0","https://repo.maven.apache.org/maven2/"); LibraryLoader.load("com.zaxxer","HikariCP","5.0.1","https://repo.maven.apache.org/maven2/"); @@ -45,42 +62,55 @@ public final class CustomNameplates extends JavaPlugin { @Override public void onEnable() { - adventure = BukkitAudiences.create(this); AdventureManager.consoleMessage("[CustomNameplates] Running on " + Bukkit.getVersion()); - //重载插件 + ConfigManager.loadModule(); ConfigManager.MainConfig.ReloadConfig(); ConfigManager.Message.ReloadConfig(); - ConfigManager.DatabaseConfig.LoadConfig(); - //指令注册 + if (ConfigManager.bossbar){ + ConfigManager.loadBossBar(); + Bukkit.getPluginManager().registerEvents(new QuitAndJoin(),this); + } + if (ConfigManager.actionbar){ + ConfigManager.ActionbarConfig.LoadConfig(); + timer = new Timer(); + } + if (ConfigManager.background){ + ConfigManager.loadBGConfig(); + } + if (ConfigManager.nameplate){ + ConfigManager.DatabaseConfig.LoadConfig(); + Bukkit.getPluginManager().registerEvents(new PlayerListener(this),this); + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketsListener(this)); + } + if (ConfigManager.MainConfig.placeholderAPI){ + new Placeholders().register(); + AdventureManager.consoleMessage("[CustomNameplates] PlaceholderAPI Hooked!"); + } Objects.requireNonNull(Bukkit.getPluginCommand("customnameplates")).setExecutor(new Execute(this)); Objects.requireNonNull(Bukkit.getPluginCommand("customnameplates")).setTabCompleter(new TabComplete(this)); - //事件注册 - Bukkit.getPluginManager().registerEvents(new PlayerListener(this),this); - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketsListener(this)); - //新建单例 this.resourceManager = new ResourceManager(this); this.dataManager = new DataManager(this); - this.hookManager = new HookManager(this); this.scoreBoardManager = new ScoreBoardManager(this); - //生成资源包 resourceManager.generateResourcePack(); if (!DataManager.create()) { AdventureManager.consoleMessage("[CustomNameplates] Error! Failed to enable Data Manager! Disabling plugin..."); instance.getPluginLoader().disablePlugin(instance); return; } - //启动完成 AdventureManager.consoleMessage("[CustomNameplates] Plugin Enabled!"); } @Override public void onDisable() { - SqlHandler.saveAll(); - SqlHandler.close(); - //清除缓存实体 + if (ConfigManager.nameplate){ + SqlHandler.saveAll(); + SqlHandler.close(); + } Execute.pCache.forEach(Entity::remove); - //关闭adventure + if (timer != null){ + timer.stopTimer(timer.getTaskID()); + } if(adventure != null) { adventure.close(); adventure = null; diff --git a/src/main/java/net/momirealms/customnameplates/actionbar/ActionbarSender.java b/src/main/java/net/momirealms/customnameplates/actionbar/ActionbarSender.java new file mode 100644 index 0000000..f54a01c --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/actionbar/ActionbarSender.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + +package net.momirealms.customnameplates.actionbar; + +import me.clip.placeholderapi.PlaceholderAPI; +import net.momirealms.customnameplates.AdventureManager; +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){ + AdventureManager.playerActionbar(player, PlaceholderAPI.setPlaceholders(player, ConfigManager.ActionbarConfig.text)); + }else { + AdventureManager.playerActionbar(player, ConfigManager.ActionbarConfig.text); + } + }); + timer = 0; + } + } +} diff --git a/src/main/java/net/momirealms/customnameplates/actionbar/Timer.java b/src/main/java/net/momirealms/customnameplates/actionbar/Timer.java new file mode 100644 index 0000000..4ecf7dd --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/actionbar/Timer.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + +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; + } +} diff --git a/src/main/java/net/momirealms/customnameplates/background/BackGround.java b/src/main/java/net/momirealms/customnameplates/background/BackGround.java new file mode 100644 index 0000000..855f156 --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/background/BackGround.java @@ -0,0 +1,141 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + +package net.momirealms.customnameplates.background; + +import net.momirealms.customnameplates.font.FontNegative; +import net.momirealms.customnameplates.resource.ResourceManager; + +public class BackGround { + + private final String start; + private final String offset_1; + private final String offset_2; + private final String offset_4; + private final String offset_8; + private final String offset_16; + private final String offset_32; + private final String offset_64; + private final String offset_128; + private final String end; + private final int offset_y; + private final int offset_x; + + public BackGround(String start, String offset_1, String offset_2, + String offset_4, String offset_8, String offset_16, + String offset_32, String offset_64, String offset_128, String end, int offset_y, int offset_x){ + this.start = start; this.offset_1 = offset_1; this.offset_2 = offset_2; + this.end = end; this.offset_4 = offset_4; this.offset_8 = offset_8; + this.offset_16 = offset_16; this.offset_32 = offset_32; this.offset_64 = offset_64; + this.offset_128 = offset_128; + this.offset_y = offset_y; + this.offset_x = offset_x; + } + + public String getBackGround(int n) { + n += offset_x; + String offset = FontNegative.getShortestNegChars(n); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(ResourceManager.bgCaches.get(start)); + if (n > 128) { + stringBuilder.append(FontNegative.NEG_1.getCharacter()); + stringBuilder.append(ResourceManager.bgCaches.get(offset_128)); + n -= 128; + } + if (n - 64 > 0) { + stringBuilder.append(FontNegative.NEG_1.getCharacter()); + stringBuilder.append(ResourceManager.bgCaches.get(offset_64)); + n -= 64; + } + if (n - 32 > 0) { + stringBuilder.append(FontNegative.NEG_1.getCharacter()); + stringBuilder.append(ResourceManager.bgCaches.get(offset_32)); + n -= 32; + } + if (n - 16 > 0) { + stringBuilder.append(FontNegative.NEG_1.getCharacter()); + stringBuilder.append(ResourceManager.bgCaches.get(offset_16)); + n -= 16; + } + if (n - 8 > 0) { + stringBuilder.append(FontNegative.NEG_1.getCharacter()); + stringBuilder.append(ResourceManager.bgCaches.get(offset_8)); + n -= 8; + } + if (n - 4 > 0) { + stringBuilder.append(FontNegative.NEG_1.getCharacter()); + stringBuilder.append(ResourceManager.bgCaches.get(offset_4)); + n -= 4; + } + if (n - 2 > 0) { + stringBuilder.append(FontNegative.NEG_1.getCharacter()); + stringBuilder.append(ResourceManager.bgCaches.get(offset_2)); + n -= 2; + } + if (n - 1 > 0) { + stringBuilder.append(FontNegative.NEG_1.getCharacter()); + stringBuilder.append(ResourceManager.bgCaches.get(offset_1)); + } + stringBuilder.append(FontNegative.NEG_1.getCharacter()); + stringBuilder.append(ResourceManager.bgCaches.get(end)).append(offset); + return stringBuilder.toString(); + } + + public String getStart() { + return start; + } + + public String getEnd() { + return end; + } + + public int getOffset_y() { + return offset_y; + } + + public String getOffset_1() { + return offset_1; + } + + public String getOffset_2() { + return offset_2; + } + + public String getOffset_4() { + return offset_4; + } + + public String getOffset_8() { + return offset_8; + } + + public String getOffset_16() { + return offset_16; + } + + public String getOffset_32() { + return offset_32; + } + + public String getOffset_64() { + return offset_64; + } + + public String getOffset_128() { + return offset_128; + } +} diff --git a/src/main/java/net/momirealms/customnameplates/bossbar/BossbarConfig.java b/src/main/java/net/momirealms/customnameplates/bossbar/BossbarConfig.java new file mode 100644 index 0000000..6acd9aa --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/bossbar/BossbarConfig.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + +package net.momirealms.customnameplates.bossbar; + +import net.kyori.adventure.bossbar.BossBar; + +public class BossbarConfig { + + private String text; + private BossBar.Overlay overlay; + private BossBar.Color color; + private int rate; + + public BossbarConfig(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; + } +} diff --git a/src/main/java/net/momirealms/customnameplates/bossbar/BossbarSender.java b/src/main/java/net/momirealms/customnameplates/bossbar/BossbarSender.java new file mode 100644 index 0000000..2d47a43 --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/bossbar/BossbarSender.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + +package net.momirealms.customnameplates.bossbar; + +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 BossbarSender extends BukkitRunnable { + + private final Player player; + private final Audience audience; + private BossBar bossBar; + private int timer; + private final BossbarConfig bossbarConfig; + + public BossbarSender(Player player, BossbarConfig 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; + } + } +} diff --git a/src/main/java/net/momirealms/customnameplates/bossbar/QuitAndJoin.java b/src/main/java/net/momirealms/customnameplates/bossbar/QuitAndJoin.java new file mode 100644 index 0000000..a9c1180 --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/bossbar/QuitAndJoin.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + +package net.momirealms.customnameplates.bossbar; + +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 QuitAndJoin implements Listener { + + public static HashMap cache = new HashMap<>(); + + @EventHandler + public void onJoin(PlayerJoinEvent event){ + Player player = event.getPlayer(); + TimerTask timerTask = new TimerTask(player); + cache.put(player, timerTask); + } + + @EventHandler + public void onQuit(PlayerQuitEvent event){ + Player player = event.getPlayer(); + TimerTask timerTask = cache.get(player); + if (timerTask != null){ + timerTask.stopTimer(); + } + cache.remove(player); + } +} diff --git a/src/main/java/net/momirealms/customnameplates/bossbar/TimerTask.java b/src/main/java/net/momirealms/customnameplates/bossbar/TimerTask.java new file mode 100644 index 0000000..a269022 --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/bossbar/TimerTask.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + +package net.momirealms.customnameplates.bossbar; + +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 TimerTask { + + private final HashMap bossbarCache = new HashMap<>(); + + public TimerTask(Player player){ + ConfigManager.bossbars.forEach((key, bossbarConfig) -> { + BossbarSender bossbar = new BossbarSender(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); + }); + } +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customnameplates/commands/Execute.java b/src/main/java/net/momirealms/customnameplates/commands/Execute.java index 5b6d860..b6124f3 100644 --- a/src/main/java/net/momirealms/customnameplates/commands/Execute.java +++ b/src/main/java/net/momirealms/customnameplates/commands/Execute.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.commands; import com.comphenix.protocol.PacketType; @@ -62,6 +79,12 @@ public class Execute implements CommandExecutor { if (sender.hasPermission("customnameplates.reload") || sender.isOp()) { ConfigManager.MainConfig.ReloadConfig(); ConfigManager.Message.ReloadConfig(); + if (ConfigManager.actionbar){ + ConfigManager.ActionbarConfig.LoadConfig(); + } + if (ConfigManager.bossbar){ + ConfigManager.loadBossBar(); + } if (sender instanceof Player) { AdventureManager.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.reload); } else { @@ -72,6 +95,20 @@ public class Execute implements CommandExecutor { } return true; } + case "generate" -> { + if (sender.hasPermission("customnameplates.generate") || sender.isOp()) { + ConfigManager.MainConfig.ReloadConfig(); + plugin.getResourceManager().generateResourcePack(); + if (sender instanceof Player) { + AdventureManager.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.generate); + }else { + AdventureManager.consoleMessage(ConfigManager.Message.prefix + ConfigManager.Message.generate); + } + } else { + AdventureManager.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.noPerm); + } + return true; + } case "equip" -> { if (sender instanceof Player player) { if (args.length < 2) { @@ -238,7 +275,7 @@ public class Execute implements CommandExecutor { NameplateUtil nameplateUtil = new NameplateUtil(fontCache); String playerPrefix; String playerSuffix; - if (plugin.getHookManager().hasPlaceholderAPI()) { + if (ConfigManager.MainConfig.placeholderAPI) { playerPrefix = ParsePapi.parsePlaceholders(player, ConfigManager.MainConfig.player_prefix); playerSuffix = ParsePapi.parsePlaceholders(player, ConfigManager.MainConfig.player_suffix); }else { diff --git a/src/main/java/net/momirealms/customnameplates/commands/TabComplete.java b/src/main/java/net/momirealms/customnameplates/commands/TabComplete.java index 7c32881..fe4368d 100644 --- a/src/main/java/net/momirealms/customnameplates/commands/TabComplete.java +++ b/src/main/java/net/momirealms/customnameplates/commands/TabComplete.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.commands; import net.momirealms.customnameplates.CustomNameplates; @@ -37,6 +54,7 @@ public class TabComplete implements TabCompleter { 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"); return tab; } if(2 == args.length){ diff --git a/src/main/java/net/momirealms/customnameplates/data/DataManager.java b/src/main/java/net/momirealms/customnameplates/data/DataManager.java index 1fc9c3f..88f03c7 100644 --- a/src/main/java/net/momirealms/customnameplates/data/DataManager.java +++ b/src/main/java/net/momirealms/customnameplates/data/DataManager.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.data; import net.momirealms.customnameplates.AdventureManager; @@ -13,7 +30,7 @@ import java.util.UUID; public class DataManager { public static Map cache; - private CustomNameplates plugin; + private final CustomNameplates plugin; public DataManager(CustomNameplates plugin) { this.plugin = plugin; diff --git a/src/main/java/net/momirealms/customnameplates/data/PlayerData.java b/src/main/java/net/momirealms/customnameplates/data/PlayerData.java index d7fd941..71ccd72 100644 --- a/src/main/java/net/momirealms/customnameplates/data/PlayerData.java +++ b/src/main/java/net/momirealms/customnameplates/data/PlayerData.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.data; public class PlayerData { diff --git a/src/main/java/net/momirealms/customnameplates/data/SqlHandler.java b/src/main/java/net/momirealms/customnameplates/data/SqlHandler.java index f6fbdcd..b134473 100644 --- a/src/main/java/net/momirealms/customnameplates/data/SqlHandler.java +++ b/src/main/java/net/momirealms/customnameplates/data/SqlHandler.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.data; import net.momirealms.customnameplates.AdventureManager; diff --git a/src/main/java/net/momirealms/customnameplates/font/FontCache.java b/src/main/java/net/momirealms/customnameplates/font/FontCache.java index ec8d38e..7360b25 100644 --- a/src/main/java/net/momirealms/customnameplates/font/FontCache.java +++ b/src/main/java/net/momirealms/customnameplates/font/FontCache.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.font; import net.momirealms.customnameplates.nameplates.NameplateConfig; diff --git a/src/main/java/net/momirealms/customnameplates/font/FontChar.java b/src/main/java/net/momirealms/customnameplates/font/FontChar.java index 2b93266..08d5c9f 100644 --- a/src/main/java/net/momirealms/customnameplates/font/FontChar.java +++ b/src/main/java/net/momirealms/customnameplates/font/FontChar.java @@ -1,5 +1,21 @@ -package net.momirealms.customnameplates.font; +/* + * Copyright (C) <2022> + * + * 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 . + */ +package net.momirealms.customnameplates.font; public record FontChar(char left, char middle, char right) { diff --git a/src/main/java/net/momirealms/customnameplates/font/FontNegative.java b/src/main/java/net/momirealms/customnameplates/font/FontNegative.java index c7153d9..2170973 100644 --- a/src/main/java/net/momirealms/customnameplates/font/FontNegative.java +++ b/src/main/java/net/momirealms/customnameplates/font/FontNegative.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.font; public enum FontNegative { diff --git a/src/main/java/net/momirealms/customnameplates/font/FontWidth.java b/src/main/java/net/momirealms/customnameplates/font/FontWidth.java index 61945f4..12b6b5a 100644 --- a/src/main/java/net/momirealms/customnameplates/font/FontWidth.java +++ b/src/main/java/net/momirealms/customnameplates/font/FontWidth.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.font; public enum FontWidth { diff --git a/src/main/java/net/momirealms/customnameplates/font/FontWidthThin.java b/src/main/java/net/momirealms/customnameplates/font/FontWidthThin.java index fdba100..11c7801 100644 --- a/src/main/java/net/momirealms/customnameplates/font/FontWidthThin.java +++ b/src/main/java/net/momirealms/customnameplates/font/FontWidthThin.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.font; public enum FontWidthThin { diff --git a/src/main/java/net/momirealms/customnameplates/hook/HookManager.java b/src/main/java/net/momirealms/customnameplates/hook/HookManager.java deleted file mode 100644 index 6dd1456..0000000 --- a/src/main/java/net/momirealms/customnameplates/hook/HookManager.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.momirealms.customnameplates.hook; - -import net.momirealms.customnameplates.AdventureManager; -import net.momirealms.customnameplates.ConfigManager; -import net.momirealms.customnameplates.CustomNameplates; - -public class HookManager { - - private boolean placeholderAPI; - private boolean itemsAdder; - - public boolean hasPlaceholderAPI() { - return this.placeholderAPI; - } - public boolean hasItemsAdder() { - return this.itemsAdder; - } - - public HookManager(CustomNameplates plugin) { - this.initializePlaceholderAPI(); - this.initializeItemsAdder(); - } - - private void initializePlaceholderAPI() { - if(!ConfigManager.MainConfig.placeholderAPI){ - this.placeholderAPI = false; - return; - } - if(CustomNameplates.instance.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null){ - AdventureManager.consoleMessage("[CustomNameplates] PlaceholderAPI Hooked!"); - this.placeholderAPI = true; - new Placeholders().register(); - } - } - - private void initializeItemsAdder() { - if (!ConfigManager.MainConfig.itemsAdder) { - this.itemsAdder = false; - } - if(CustomNameplates.instance.getServer().getPluginManager().getPlugin("ItemsAdder") != null){ - this.itemsAdder = true; - } - } -} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customnameplates/hook/ParsePapi.java b/src/main/java/net/momirealms/customnameplates/hook/ParsePapi.java index 5560092..831c41a 100644 --- a/src/main/java/net/momirealms/customnameplates/hook/ParsePapi.java +++ b/src/main/java/net/momirealms/customnameplates/hook/ParsePapi.java @@ -1,15 +1,30 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.hook; import me.clip.placeholderapi.PlaceholderAPI; import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; public class ParsePapi { public static String parsePlaceholders(Player player, String papi) { String s = StringUtils.replace(StringUtils.replace(papi, "%player_name%", player.getName()), "%player_displayname%", player.getDisplayName()); - s = PlaceholderAPI.setPlaceholders(player, s); - return ChatColor.translateAlternateColorCodes('&', s); + return PlaceholderAPI.setPlaceholders(player, s); } } diff --git a/src/main/java/net/momirealms/customnameplates/hook/Placeholders.java b/src/main/java/net/momirealms/customnameplates/hook/Placeholders.java index 305ca9f..e7f802e 100644 --- a/src/main/java/net/momirealms/customnameplates/hook/Placeholders.java +++ b/src/main/java/net/momirealms/customnameplates/hook/Placeholders.java @@ -1,7 +1,34 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + 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.background.BackGround; +import net.momirealms.customnameplates.font.FontCache; +import net.momirealms.customnameplates.font.FontWidth; +import net.momirealms.customnameplates.font.FontWidthThin; +import net.momirealms.customnameplates.nameplates.NameplateUtil; +import net.momirealms.customnameplates.resource.ResourceManager; import net.momirealms.customnameplates.scoreboard.ScoreBoardManager; +import net.momirealms.customnameplates.utils.BGInfo; +import net.momirealms.customnameplates.utils.NPInfo; import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.NotNull; @@ -34,6 +61,54 @@ public class Placeholders extends PlaceholderExpansion { return ScoreBoardManager.teams.get(player.getName()).getSuffixText(); } } + 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; + if (ConfigManager.MainConfig.placeholderAPI){ + text = PlaceholderAPI.setPlaceholders(player, bgInfo.getText()); + }else { + text = bgInfo.getText(); + } + if (ConfigManager.MainConfig.thin_font){ + return backGround.getBackGround(FontWidthThin.getTotalWidth(text)); + }else { + return backGround.getBackGround(FontWidth.getTotalWidth(text)); + } + } + } + } + if (params.startsWith("npp_")){ + String np = params.substring(4); + NPInfo npInfo = ConfigManager.papiNP.get(np); + if (npInfo != null){ + FontCache fontCache = ResourceManager.caches.get(npInfo.getNameplate()); + if (fontCache != null){ + if (ConfigManager.MainConfig.placeholderAPI){ + return new NameplateUtil(fontCache).makeCustomNameplate("", PlaceholderAPI.setPlaceholders(player, npInfo.getText()),""); + }else { + return new NameplateUtil(fontCache).makeCustomNameplate("", npInfo.getText(),""); + } + } + } + } + if (params.startsWith("nps_")){ + String np = params.substring(4); + NPInfo npInfo = ConfigManager.papiNP.get(np); + if (npInfo != null){ + FontCache fontCache = ResourceManager.caches.get(npInfo.getNameplate()); + if (fontCache != null){ + if (ConfigManager.MainConfig.placeholderAPI){ + return new NameplateUtil(fontCache).getSuffixLength(PlaceholderAPI.setPlaceholders(player, npInfo.getText())); + }else { + return new NameplateUtil(fontCache).getSuffixLength(npInfo.getText()); + } + } + } + } return null; } } diff --git a/src/main/java/net/momirealms/customnameplates/listener/PacketsListener.java b/src/main/java/net/momirealms/customnameplates/listener/PacketsListener.java index 2515028..fe0c77d 100644 --- a/src/main/java/net/momirealms/customnameplates/listener/PacketsListener.java +++ b/src/main/java/net/momirealms/customnameplates/listener/PacketsListener.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.listener; import com.comphenix.protocol.PacketType; @@ -27,7 +44,6 @@ public class PacketsListener extends PacketAdapter { public void onPacketSending(PacketEvent event) { Integer n = event.getPacket().getIntegers().read(0); - //create team && update team info if (n != 0 && n != 2) { return; } @@ -47,7 +63,6 @@ public class PacketsListener extends PacketAdapter { internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,ChatColor.WHITE); return; } - //在新建队伍名字的时候其实就是以玩家名命名,所以获得的teamName=playerName if (team.getPrefix() != null){ internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(team.getPrefix()))); } diff --git a/src/main/java/net/momirealms/customnameplates/listener/PlayerListener.java b/src/main/java/net/momirealms/customnameplates/listener/PlayerListener.java index f69888b..79f5db2 100644 --- a/src/main/java/net/momirealms/customnameplates/listener/PlayerListener.java +++ b/src/main/java/net/momirealms/customnameplates/listener/PlayerListener.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.listener; import net.momirealms.customnameplates.CustomNameplates; diff --git a/src/main/java/net/momirealms/customnameplates/nameplates/NameplateConfig.java b/src/main/java/net/momirealms/customnameplates/nameplates/NameplateConfig.java index 2b41276..406d9cb 100644 --- a/src/main/java/net/momirealms/customnameplates/nameplates/NameplateConfig.java +++ b/src/main/java/net/momirealms/customnameplates/nameplates/NameplateConfig.java @@ -1,29 +1,30 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.nameplates; import org.bukkit.ChatColor; public record NameplateConfig(ChatColor color, int height, String name, int yoffset) { - public static NameplateConfig EMPTY; - - static { - EMPTY = new NameplateConfig(ChatColor.WHITE, 16, "none", 12); - } - - //获取Team颜色 - public ChatColor getColor() { - return this.color; - } - - //获取自定义font大小 - public int getHeight() { - return this.height; - } - - //获取铭牌名 - public String getName() { - return this.name; - } + public static NameplateConfig EMPTY = new NameplateConfig(ChatColor.WHITE, 16, "none", 12); + public ChatColor getColor() {return this.color;} + public int getHeight() {return this.height;} + public String getName() {return this.name;} public int getyoffset() {return this.yoffset; } } diff --git a/src/main/java/net/momirealms/customnameplates/nameplates/NameplateUtil.java b/src/main/java/net/momirealms/customnameplates/nameplates/NameplateUtil.java index 610c7ba..73ffd5c 100644 --- a/src/main/java/net/momirealms/customnameplates/nameplates/NameplateUtil.java +++ b/src/main/java/net/momirealms/customnameplates/nameplates/NameplateUtil.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.nameplates; import net.momirealms.customnameplates.ConfigManager; @@ -15,10 +32,6 @@ public class NameplateUtil { this.fontcache = font; } - /* - 根据玩家名构造长度适合的铭牌字符 - 当然这个玩家名是带上前缀与后缀的 - */ public String makeCustomNameplate(String prefix, String name, String suffix) { int totalWidth; if (ConfigManager.MainConfig.thin_font){ @@ -26,30 +39,26 @@ public class NameplateUtil { }else { totalWidth = FontWidth.getTotalWidth(ChatColor.stripColor(prefix + name + suffix)); } - boolean isEven = totalWidth % 2 == 0; //奇偶判断 + boolean isEven = totalWidth % 2 == 0; char left = this.fontcache.getChar().getLeft(); char middle = this.fontcache.getChar().getMiddle(); char right = this.fontcache.getChar().getRight(); char neg_1 = FontNegative.NEG_1.getCharacter(); int left_offset = totalWidth + 16 + 1; StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(FontNegative.getShortestNegChars(isEven ? left_offset : left_offset + 1)); //先向左平移一个正方形的距离 - stringBuilder.append(left).append(neg_1); //将铭牌的左部分拼接 - int mid_amount = (totalWidth + 1) / 16; //显示名称的总长,如果超过一个正方形则多复制几个正方形 + stringBuilder.append(FontNegative.getShortestNegChars(isEven ? left_offset : left_offset + 1)); + stringBuilder.append(left).append(neg_1); + int mid_amount = (totalWidth + 1) / 16; for (int i = 0; i < (mid_amount == 0 ? 1 : mid_amount); i++) { - stringBuilder.append(middle).append(neg_1); //减一是字符之间的间距(3) + stringBuilder.append(middle).append(neg_1); } stringBuilder.append(FontNegative.getShortestNegChars(16 - ((totalWidth + 1) % 16 + (isEven ? 0 : 1)))); stringBuilder.append(middle).append(neg_1); - stringBuilder.append(right).append(neg_1); //将铭牌的右部分拼接 - stringBuilder.append(FontNegative.getShortestNegChars(isEven ? left_offset : left_offset + 1)); //首尾对称处理,保证铭牌位于正中央 + stringBuilder.append(right).append(neg_1); + stringBuilder.append(FontNegative.getShortestNegChars(isEven ? left_offset : left_offset + 1)); return stringBuilder.toString(); } - /* - 用于为增加了后缀的玩家名计算负空格 - 保证铭牌总是位于玩家头顶中央的位置 - */ public String getSuffixLength(String name) { int totalWidth; if (ConfigManager.MainConfig.thin_font){ @@ -60,9 +69,6 @@ public class NameplateUtil { return FontNegative.getShortestNegChars(totalWidth + totalWidth % 2 + 1); } - /* - 获取铭牌上玩家名的颜色 - */ public ChatColor getColor() { return this.fontcache.getConfig().getColor(); } diff --git a/src/main/java/net/momirealms/customnameplates/resource/ResourceManager.java b/src/main/java/net/momirealms/customnameplates/resource/ResourceManager.java index d7b7773..7a87bd7 100644 --- a/src/main/java/net/momirealms/customnameplates/resource/ResourceManager.java +++ b/src/main/java/net/momirealms/customnameplates/resource/ResourceManager.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.resource; import com.google.gson.JsonArray; @@ -6,6 +23,7 @@ import com.google.gson.JsonPrimitive; import net.momirealms.customnameplates.ConfigManager; import net.momirealms.customnameplates.CustomNameplates; import net.momirealms.customnameplates.AdventureManager; +import net.momirealms.customnameplates.background.BackGround; import net.momirealms.customnameplates.font.FontCache; import net.momirealms.customnameplates.font.FontChar; import net.momirealms.customnameplates.font.FontNegative; @@ -20,40 +38,49 @@ import java.io.FileWriter; import java.io.IOException; import java.util.*; +import static net.momirealms.customnameplates.ConfigManager.MainConfig.start; + public class ResourceManager { - public final HashMap caches; + public static HashMap caches = new HashMap<>(); + public static HashMap bgCaches = new HashMap<>(); private final CustomNameplates plugin; public ResourceManager(CustomNameplates plugin) { - this.caches = new HashMap<>(); this.plugin = plugin; } - /* - 此方法用于生成资源包 - */ public void generateResourcePack() { File r_file = new File(CustomNameplates.instance.getDataFolder() + File.separator + "resources"); + File b_file = new File(CustomNameplates.instance.getDataFolder() + File.separator + "backgrounds"); File g_file = new File(CustomNameplates.instance.getDataFolder() + File.separator + "generated"); - //如果资源文件夹不存在则创建 + if (!r_file.exists()) { - AdventureManager.consoleMessage("[CustomNameplates] Failed to detect resources folder! Generating default resources..."); if (!r_file.mkdir()) { AdventureManager.consoleMessage("[CustomNameplates] Error! Failed to create resources folder..."); return; } saveDefaultResources(); } - //获取资源文件夹下的所有png文件 + + if (!b_file.exists()) { + if (!b_file.mkdir()) { + AdventureManager.consoleMessage("[CustomNameplates] Error! Failed to create resources folder..."); + return; + } + saveDefaultBGResources(); + } + File[] pngFiles = r_file.listFiles(file -> file.getName().endsWith(".png")); + if (pngFiles == null) { AdventureManager.consoleMessage("[CustomNameplates] Error! No png files detected in resource folder..."); return; } - Arrays.sort(pngFiles); //将png文件按照首字母进行排序 - deleteDirectory(g_file); //删除文件夹以重置自动生成的资源 + + Arrays.sort(pngFiles); + deleteDirectory(g_file); File f_file = new File(CustomNameplates.instance.getDataFolder() + File.separator + "generated" + File.separatorChar + ConfigManager.MainConfig.namespace + File.separatorChar + "font"); File t_file = new File(CustomNameplates.instance.getDataFolder() + File.separator + "generated" + File.separatorChar + ConfigManager.MainConfig.namespace + File.separatorChar + "textures"); @@ -62,36 +89,49 @@ public class ResourceManager { AdventureManager.consoleMessage("[CustomNameplates] Error! Failed to generate resource pack folders..."); return; } - char start = ConfigManager.MainConfig.start_char.charAt(0); //获取起始字符 - JsonObject jsonObject_1 = new JsonObject(); //新建json对象 + + JsonObject jsonObject_1 = new JsonObject(); JsonArray jsonArray_1 = new JsonArray(); jsonObject_1.add("providers", jsonArray_1); - for (File png : pngFiles) { - JsonObject jsonObject_2 = new JsonObject(); - char left = start; - char middle; - char right; - start = (char)((right = (char)((middle = (char)(start + '\u0001')) + '\u0001')) + '\u0001'); //依次+1 - FontChar fontChar = new FontChar(left, middle, right); - String pngName = png.getName().substring(0, png.getName().length() - 4); //删除.png后缀 - NameplateConfig config = this.getConfiguration(pngName); - caches.put(pngName, new FontCache(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("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 + ConfigManager.MainConfig.folder_path + png.getName())); - }catch (IOException e){ - e.printStackTrace(); - AdventureManager.consoleMessage("[CustomNameplates] Error! Failed to copy png files to resource pack..."); + + if (ConfigManager.nameplate){ + for (File png : pngFiles) { + JsonObject jsonObject_2 = new JsonObject(); + char left = start; + char middle; + char right; + start = (char)((right = (char)((middle = (char)(start + '\u0001')) + '\u0001')) + '\u0001'); + FontChar fontChar = new FontChar(left, middle, right); + String pngName = png.getName().substring(0, png.getName().length() - 4); + NameplateConfig config = this.getConfiguration(pngName); + caches.put(pngName, new FontCache(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("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 + ConfigManager.MainConfig.folder_path + png.getName())); + }catch (IOException e){ + e.printStackTrace(); + AdventureManager.consoleMessage("[CustomNameplates] Error! Failed to copy png files to resource pack..."); + } } + caches.put("none", FontCache.EMPTY); } - caches.put("none", FontCache.EMPTY); + + if (ConfigManager.background){ + ConfigManager.backgrounds.forEach((key, backGround) -> { + getBackgrounds(backGround).forEach(jsonArray_1::add); + }); + } + + getNegativeFontEnums().forEach(jsonArray_1::add); + CustomNameplates.instance.saveResource("space_split.png", false); //复制space_split.png try{ FileUtils.copyFile(new File(CustomNameplates.instance.getDataFolder(),"space_split.png"), new File(t_file.getPath() + File.separatorChar + ConfigManager.MainConfig.folder_path + "space_split.png")); @@ -101,18 +141,17 @@ public class ResourceManager { return; } new File(CustomNameplates.instance.getDataFolder(),"space_split.png").delete(); //删除拷贝出的默认文件 - this.getNegativeFontEnums().forEach(jsonArray_1::add); //添加负空格 - //存储default.json - try (FileWriter fileWriter = new FileWriter(f_file.getPath() + File.separatorChar + ConfigManager.MainConfig.font + ".json")) { + + try (FileWriter fileWriter = new FileWriter(CustomNameplates.instance.getDataFolder() + File.separator + "generated" + File.separatorChar + ConfigManager.MainConfig.namespace + File.separatorChar + "font" + File.separatorChar + ConfigManager.MainConfig.font + ".json")) { fileWriter.write(jsonObject_1.toString().replace("\\\\", "\\")); } catch (IOException e) { e.printStackTrace(); AdventureManager.consoleMessage("[CustomNameplates] Error! Failed to generate font json..."); return; } - //资源包生成成功提示 + AdventureManager.consoleMessage("[CustomNameplates] ResourcePack has been generated! " + (this.caches.size() -1) + " nameplates loaded!"); - if (this.plugin.getHookManager().hasItemsAdder()){ + if (ConfigManager.MainConfig.itemsAdder){ try{ FileUtils.copyDirectory(g_file, new File(Bukkit.getPluginManager().getPlugin("ItemsAdder").getDataFolder() + File.separator + "data"+ File.separator + "resource_pack" + File.separator + "assets") ); AdventureManager.consoleMessage("[CustomNameplates] Detected ItemsAdder! Automatically sent rp to ItemsAdder folder!"); @@ -123,17 +162,15 @@ public class ResourceManager { } } - /* - 保存插件预设资源 - */ private void saveDefaultResources() { List list = Arrays.asList("cat", "egg", "cheems", "wither", "xmas", "halloween","hutao","starsky","trident","rabbit"); list.forEach(name -> CustomNameplates.instance.saveResource("resources" + File.separatorChar + name + ".png", false)); } + private void saveDefaultBGResources() { + List list = Arrays.asList("b0", "b1", "b2", "b4", "b8", "b16","b32","b64","b128"); + list.forEach(name -> CustomNameplates.instance.saveResource("backgrounds" + File.separatorChar + name + ".png", false)); + } - /* - 删除文件夹 - */ private void deleteDirectory(File file){ if(file.exists()){ try{ @@ -145,9 +182,6 @@ public class ResourceManager { } } - /* - 获取铭牌的config - */ private NameplateConfig getConfiguration(String nameplate) { try { File file = new File(CustomNameplates.instance.getDataFolder().getPath() + File.separator + "resources" + File.separator + nameplate + ".yml"); @@ -191,9 +225,6 @@ public class ResourceManager { } } - /* - 获取负空格并返回list - */ private List getNegativeFontEnums() { ArrayList list = new ArrayList<>(); for (FontNegative negativeFont : FontNegative.values()) { @@ -201,6 +232,7 @@ public class ResourceManager { } return list; } + private JsonObject getNegativeFontChar(int height, char character) { JsonObject jsonObject = new JsonObject(); jsonObject.add("type", new JsonPrimitive("bitmap")); @@ -213,16 +245,10 @@ public class ResourceManager { return jsonObject; } - /* - 根据铭牌名获取铭牌的FontCache - */ public FontCache getNameplateInfo(String nameplate) { return caches.get(nameplate); } - /* - 字符转换 - */ private String native2ascii(char ch) { if (ch > '\u007f') { StringBuilder stringBuilder_1 = new StringBuilder("\\u"); @@ -238,4 +264,41 @@ public class ResourceManager { } return Character.toString(ch); } + + private List getBackgrounds(BackGround backGround) { + ArrayList list = new ArrayList<>(); + int y_offset = backGround.getOffset_y(); + list.add(setBackgrounds(backGround.getStart(),y_offset)); + list.add(setBackgrounds(backGround.getOffset_1(),y_offset)); + list.add(setBackgrounds(backGround.getOffset_2(),y_offset)); + list.add(setBackgrounds(backGround.getOffset_4(),y_offset)); + list.add(setBackgrounds(backGround.getOffset_8(),y_offset)); + list.add(setBackgrounds(backGround.getOffset_16(),y_offset)); + list.add(setBackgrounds(backGround.getOffset_32(),y_offset)); + list.add(setBackgrounds(backGround.getOffset_64(),y_offset)); + list.add(setBackgrounds(backGround.getOffset_128(),y_offset)); + list.add(setBackgrounds(backGround.getEnd(),y_offset)); + return list; + } + + private JsonObject setBackgrounds(String name, int y_offset){ + 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("ascent", new JsonPrimitive(y_offset)); + jsonObject_2.add("height", new JsonPrimitive(14)); + JsonArray jsonArray_2 = new JsonArray(); + char character = start; + jsonArray_2.add(native2ascii(character)); + jsonObject_2.add("chars", jsonArray_2); + start = (char)(start + '\u0001'); + bgCaches.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 + "generated" + File.separator + ConfigManager.MainConfig.namespace + File.separatorChar + "textures" + File.separator + ConfigManager.MainConfig.bg_folder_path + name + ".png")); + }catch (IOException e){ + e.printStackTrace(); + AdventureManager.consoleMessage("[CustomNameplates] Error! Failed to copy background png files to resource pack..."); + } + return jsonObject_2; + } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customnameplates/scoreboard/NameplatesTeam.java b/src/main/java/net/momirealms/customnameplates/scoreboard/NameplatesTeam.java index 6ea5b91..6c31c18 100644 --- a/src/main/java/net/momirealms/customnameplates/scoreboard/NameplatesTeam.java +++ b/src/main/java/net/momirealms/customnameplates/scoreboard/NameplatesTeam.java @@ -1,8 +1,26 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.scoreboard; import net.kyori.adventure.key.Key; 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.CustomNameplates; import net.momirealms.customnameplates.data.DataManager; @@ -27,32 +45,13 @@ public class NameplatesTeam { private Component suffix; private String prefixText; private String suffixText; - private ChatColor color; - public void hideNameplate() { - this.team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); - } - public void showNameplate() { - this.team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); - } - public Component getPrefix() { - return this.prefix; - } - public Component getSuffix() { - return this.suffix; - } - public ChatColor getColor() { - return this.color; - } - - public String getPrefixText() { - return prefixText; - } - - public String getSuffixText() { - return suffixText; - } + public Component getPrefix() {return this.prefix;} + public Component getSuffix() {return this.suffix;} + public ChatColor getColor() {return this.color;} + public String getPrefixText() {return prefixText;} + public String getSuffixText() {return suffixText;} public NameplatesTeam(CustomNameplates plugin, Player player) { this.color = ChatColor.WHITE; @@ -72,9 +71,8 @@ public class NameplatesTeam { }else { nameplate = "none"; } - //如果是空铭牌直接飞机票送走 if (nameplate.equals("none")) { - if (plugin.getHookManager().hasPlaceholderAPI()) { + if (ConfigManager.MainConfig.placeholderAPI) { this.prefix = Component.text(ParsePapi.parsePlaceholders(this.player, ConfigManager.MainConfig.player_prefix)); this.suffix = Component.text(ParsePapi.parsePlaceholders(this.player, ConfigManager.MainConfig.player_suffix)); this.prefixText = ParsePapi.parsePlaceholders(this.player, ConfigManager.MainConfig.player_prefix); @@ -89,7 +87,6 @@ public class NameplatesTeam { this.team.setPrefix(""); return; } - //根据铭牌名获取FontCache FontCache fontCache = this.plugin.getResourceManager().getNameplateInfo(nameplate); if (fontCache == null){ this.prefix = Component.text(""); @@ -103,8 +100,7 @@ public class NameplatesTeam { String name = this.player.getName(); String playerPrefix; String playerSuffix; - //有Papi才解析 - if (plugin.getHookManager().hasPlaceholderAPI()) { + if (ConfigManager.MainConfig.placeholderAPI) { if (!ConfigManager.MainConfig.hidePrefix){ playerPrefix = ParsePapi.parsePlaceholders(this.player, ConfigManager.MainConfig.player_prefix); }else { @@ -127,12 +123,14 @@ public class NameplatesTeam { playerSuffix = ""; } } - //最终prefix: 偏移 + 铭牌左 + 偏移 + 铭牌中 + 偏移 + 铭牌右 + 偏移 + 前缀 - //最终suffix: 偏移 + 后缀 - this.prefix = Component.text(nameplateUtil.makeCustomNameplate(playerPrefix, name, playerSuffix)).color(TextColor.color(255, 255, 255)).font(ConfigManager.MainConfig.key).append(Component.text(playerPrefix).font(Key.key("default"))); - this.suffix = Component.text(playerSuffix).append(Component.text(nameplateUtil.getSuffixLength(playerPrefix + name + playerSuffix)).font(ConfigManager.MainConfig.key)); - this.prefixText = nameplateUtil.makeCustomNameplate(playerPrefix, name, playerSuffix) + playerPrefix; - this.suffixText = playerSuffix + nameplateUtil.getSuffixLength(playerPrefix + name + playerSuffix); + this.prefixText = nameplateUtil.makeCustomNameplate(MiniMessage.miniMessage().stripTags(playerPrefix), name, MiniMessage.miniMessage().stripTags(playerSuffix)); + this.suffixText = nameplateUtil.getSuffixLength(MiniMessage.miniMessage().stripTags(playerPrefix) + name + MiniMessage.miniMessage().stripTags(playerSuffix)); + this.prefix = Component.text(nameplateUtil.makeCustomNameplate(MiniMessage.miniMessage().stripTags(playerPrefix), name, MiniMessage.miniMessage().stripTags(playerSuffix))).font(ConfigManager.MainConfig.key).append(MiniMessage.miniMessage().deserialize(playerPrefix)); + this.suffix = MiniMessage.miniMessage().deserialize(playerSuffix).append(Component.text(nameplateUtil.getSuffixLength(MiniMessage.miniMessage().stripTags(playerPrefix) + name + MiniMessage.miniMessage().stripTags(playerSuffix))).font(ConfigManager.MainConfig.key)); +// this.prefixText = nameplateUtil.makeCustomNameplate(playerPrefix, name, playerSuffix) + playerPrefix; +// this.suffixText = playerSuffix + nameplateUtil.getSuffixLength(playerPrefix + name + playerSuffix); +// this.prefix = Component.text(nameplateUtil.makeCustomNameplate(playerPrefix, name, playerSuffix)).font(ConfigManager.MainConfig.key).append(Component.text(playerPrefix).font(Key.key("default"))); +// this.suffix = Component.text(playerSuffix).append(Component.text(nameplateUtil.getSuffixLength(playerPrefix + name + playerSuffix)).font(ConfigManager.MainConfig.key)); this.color = nameplateUtil.getColor(); this.team.setPrefix(""); } diff --git a/src/main/java/net/momirealms/customnameplates/scoreboard/ScoreBoardManager.java b/src/main/java/net/momirealms/customnameplates/scoreboard/ScoreBoardManager.java index d22ebb2..036e041 100644 --- a/src/main/java/net/momirealms/customnameplates/scoreboard/ScoreBoardManager.java +++ b/src/main/java/net/momirealms/customnameplates/scoreboard/ScoreBoardManager.java @@ -1,21 +1,32 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.scoreboard; import net.momirealms.customnameplates.CustomNameplates; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.util.HashMap; import java.util.Map; -public class ScoreBoardManager { +public record ScoreBoardManager(CustomNameplates plugin) { - private final CustomNameplates plugin; public static Map teams = new HashMap<>(); - public ScoreBoardManager(CustomNameplates plugin) { - this.plugin = plugin; - } - public NameplatesTeam getOrCreateTeam(Player player) { if (!teams.containsKey(player.getName())) { teams.put(player.getName(), new NameplatesTeam(this.plugin, player)); diff --git a/src/main/java/net/momirealms/customnameplates/utils/BGInfo.java b/src/main/java/net/momirealms/customnameplates/utils/BGInfo.java new file mode 100644 index 0000000..aa37b60 --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/utils/BGInfo.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + +package net.momirealms.customnameplates.utils; + +public record BGInfo(String text, String background) { + + public String getText() { + return text; + } + + public String getBackground() { + return background; + } +} diff --git a/src/main/java/net/momirealms/customnameplates/utils/NPInfo.java b/src/main/java/net/momirealms/customnameplates/utils/NPInfo.java new file mode 100644 index 0000000..b97e459 --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/utils/NPInfo.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + +package net.momirealms.customnameplates.utils; + +public record NPInfo(String text, String nameplate) { + + public String getText() { + return text; + } + + public String getNameplate() { + return nameplate; + } +} diff --git a/src/main/java/net/momirealms/customnameplates/utils/SqlConnection.java b/src/main/java/net/momirealms/customnameplates/utils/SqlConnection.java index c409104..2516b0b 100644 --- a/src/main/java/net/momirealms/customnameplates/utils/SqlConnection.java +++ b/src/main/java/net/momirealms/customnameplates/utils/SqlConnection.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * 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 . + */ + package net.momirealms.customnameplates.utils; import com.zaxxer.hikari.HikariDataSource; diff --git a/src/main/resources/actionbar.yml b/src/main/resources/actionbar.yml new file mode 100644 index 0000000..149946a --- /dev/null +++ b/src/main/resources/actionbar.yml @@ -0,0 +1,2 @@ +text: '%nameplates_bg_player%Hello! %player_name% %nameplates_bg_season%Current Season: %customcrops_season%' +refresh-rate: 1 \ No newline at end of file diff --git a/src/main/resources/background.yml b/src/main/resources/background.yml new file mode 100644 index 0000000..3151f26 --- /dev/null +++ b/src/main/resources/background.yml @@ -0,0 +1,14 @@ +background: + bedrock: + x-offset: 5 + y-offset: 10 + start: b0 + offset_1: b1 + offset_2: b2 + offset_4: b4 + offset_8: b8 + offset_16: b16 + offset_32: b32 + offset_64: b64 + offset_128: b128 + end: b0 \ No newline at end of file diff --git a/src/main/resources/backgrounds/b0.png b/src/main/resources/backgrounds/b0.png new file mode 100644 index 0000000..45cb173 Binary files /dev/null and b/src/main/resources/backgrounds/b0.png differ diff --git a/src/main/resources/backgrounds/b1.png b/src/main/resources/backgrounds/b1.png new file mode 100644 index 0000000..86ff93d Binary files /dev/null and b/src/main/resources/backgrounds/b1.png differ diff --git a/src/main/resources/backgrounds/b128.png b/src/main/resources/backgrounds/b128.png new file mode 100644 index 0000000..9a1e971 Binary files /dev/null and b/src/main/resources/backgrounds/b128.png differ diff --git a/src/main/resources/backgrounds/b16.png b/src/main/resources/backgrounds/b16.png new file mode 100644 index 0000000..009ec0e Binary files /dev/null and b/src/main/resources/backgrounds/b16.png differ diff --git a/src/main/resources/backgrounds/b2.png b/src/main/resources/backgrounds/b2.png new file mode 100644 index 0000000..4469ef4 Binary files /dev/null and b/src/main/resources/backgrounds/b2.png differ diff --git a/src/main/resources/backgrounds/b32.png b/src/main/resources/backgrounds/b32.png new file mode 100644 index 0000000..ca23db5 Binary files /dev/null and b/src/main/resources/backgrounds/b32.png differ diff --git a/src/main/resources/backgrounds/b4.png b/src/main/resources/backgrounds/b4.png new file mode 100644 index 0000000..f1bdd43 Binary files /dev/null and b/src/main/resources/backgrounds/b4.png differ diff --git a/src/main/resources/backgrounds/b64.png b/src/main/resources/backgrounds/b64.png new file mode 100644 index 0000000..217322e Binary files /dev/null and b/src/main/resources/backgrounds/b64.png differ diff --git a/src/main/resources/backgrounds/b8.png b/src/main/resources/backgrounds/b8.png new file mode 100644 index 0000000..496b4b5 Binary files /dev/null and b/src/main/resources/backgrounds/b8.png differ diff --git a/src/main/resources/bossbar.yml b/src/main/resources/bossbar.yml new file mode 100644 index 0000000..7d5168e --- /dev/null +++ b/src/main/resources/bossbar.yml @@ -0,0 +1,13 @@ +# You need a restart when you add/remove a bossbar +# There's a bug that font can't be applied to bossbar. This is an Adventure API bug that I can't fix for the moment. +bossbar: + example_1: + text: 'Hi %player_name%! This is you nameplate!' + color: YELLOW + refresh-rate: 1 + overlay: PROGRESS + example_2: + text: '%nameplates_prefix%Hello! %player_name% %player_health_rounded%❤%nameplates_suffix%' + color: WHITE + refresh-rate: 1 + overlay: PROGRESS \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 507cbc3..46e614e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,17 +3,28 @@ config: # en/cn lang: en + # Should the plugin hook into other plugins + integrations: + # 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 + # folder into the resource pack generated by ItemsAdder. + ItemsAdder: false + # 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 namespace: "nameplates" # Font Name - # Recommended not to set "default" when you are using "minecraft" as your namespace. - # You can use font like "nameplate" instead. + # If you don't know how font works, don't change this font: "default" # Customize the folder where png files should be generated. # This is useful for those who want to keep their resource pack structure in order. - folder-path: 'font\nameplates\' + nameplate-folder-path: 'font\nameplates\' + background-folder-path: 'font\backgrounds\' # The initial character of all nameplates. # 뀁 is the first character of Korean \ub001. @@ -35,20 +46,12 @@ config: # 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. - prefix: '' - suffix: '' + prefix: '%vault_prefix%' + suffix: ' %player_health_rounded%❤' # should prefix/suffix be hidden when player is equipping a nameplate hide-prefix-when-equipped: false hide-suffix-when-equipped: false # Thin-font support - use-thin-font: false - - # Should the plugin hook into other plugins - integrations: - # When enabled, the plugin will be able to parse prefix and suffix - PlaceholderAPI: false - # When enabled, the plugin will automatically place the nameplates - # folder into the resource pack generated by ItemsAdder. - ItemsAdder: false \ No newline at end of file + use-thin-font: false \ No newline at end of file diff --git a/src/main/resources/custom-papi.yml b/src/main/resources/custom-papi.yml new file mode 100644 index 0000000..dc67b08 --- /dev/null +++ b/src/main/resources/custom-papi.yml @@ -0,0 +1,23 @@ +# %nameplates_bg_xx% BackGround +# %nameplates_npp_xx% NamePlatePrefix +# %nameplates_nps_xx% NamePlateSuffix + +papi: + #This papi will not return text with background + #It will only return the background + #So you need to do something like this in your bossbar/actionbar plugin: + #%nameplates_bg_player%Hello! %player_name% + player: + text: 'Hello! %player_name%' + background: bedrock + season: + text: 'Current Season: %customcrops_season%' + background: bedrock + + #This papi will not return text with nameplate + #It will only return the nameplate + #So you need to do something like this in your bossbar/actionbar plugin: + #%nameplates_npp_halloween%%player_name% Trick or Treat!%nameplates_nps_halloween% + halloween: + text: '%player_name% Trick or Treat!' + nameplate: halloween \ No newline at end of file diff --git a/src/main/resources/messages/messages_cn.yml b/src/main/resources/messages/messages_cn.yml index 0bcb81a..ee87b6b 100644 --- a/src/main/resources/messages/messages_cn.yml +++ b/src/main/resources/messages/messages_cn.yml @@ -13,4 +13,5 @@ messages: no-console: '这个指令不能由控制台执行!' not-available: '你还未拥有这个铭牌!' available: '可用铭牌: {Nameplates}' - cooldown: '上一个预览还没结束!' \ No newline at end of file + cooldown: '上一个预览还没结束!' + generate: '正在生成资源包...' \ No newline at end of file diff --git a/src/main/resources/messages/messages_en.yml b/src/main/resources/messages/messages_en.yml index db78048..a53aa50 100644 --- a/src/main/resources/messages/messages_en.yml +++ b/src/main/resources/messages/messages_en.yml @@ -13,4 +13,5 @@ messages: no-console: 'This command can be only executed by player!' not-available: 'This nameplate is currently not available!' available: 'Available nameplates: {Nameplates}.' - cooldown: 'Previewing is still Ongoing!' \ No newline at end of file + cooldown: 'Previewing is still Ongoing!' + generate: 'Resource Pack is generating..' \ No newline at end of file diff --git a/src/main/resources/module.yml b/src/main/resources/module.yml new file mode 100644 index 0000000..6d29f54 --- /dev/null +++ b/src/main/resources/module.yml @@ -0,0 +1,5 @@ +#Modules require a restart +nameplate: true +background: true +bossbar: true +actionbar: true \ No newline at end of file