9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2026-01-04 15:31:47 +00:00

Added generate option for bitmaps

This commit is contained in:
XiaoMoMi
2024-11-21 02:14:49 +08:00
parent ed2fb60748
commit fccaa059ff
9 changed files with 126 additions and 6 deletions

View File

@@ -111,6 +111,7 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
protected boolean chatCarbon; protected boolean chatCarbon;
protected boolean chatAdvanced; protected boolean chatAdvanced;
protected boolean chatEss; protected boolean chatEss;
protected boolean chatChatControlRed;
protected String configVersion; protected String configVersion;
@@ -189,6 +190,7 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
chatAdvanced = config.getBoolean("integrations.chat.AdvancedChat", false); chatAdvanced = config.getBoolean("integrations.chat.AdvancedChat", false);
chatTR = config.getBoolean("integrations.chat.TrChat", false); chatTR = config.getBoolean("integrations.chat.TrChat", false);
chatVenture = config.getBoolean("integrations.chat.VentureChat", false); chatVenture = config.getBoolean("integrations.chat.VentureChat", false);
chatChatControlRed = config.getBoolean("integrations.chat.ChatControlRed", false);
// Packs // Packs
generateOnStart = !config.getBoolean("resource-pack.disable-generation-on-start", false); generateOnStart = !config.getBoolean("resource-pack.disable-generation-on-start", false);
@@ -411,6 +413,10 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
return instance.chatAdvanced; return instance.chatAdvanced;
} }
public static boolean chatChatControlRed() {
return instance.chatChatControlRed;
}
@Override @Override
public YamlDocument loadConfig(String filePath) { public YamlDocument loadConfig(String filePath) {
return loadConfig(filePath, '.'); return loadConfig(filePath, '.');

View File

@@ -522,6 +522,8 @@ public class AdvanceManagerImpl implements AdvanceManager {
String codePoints = requireNonNull(section.getString("codepoints", ""), "codepoints should be NonNull"); String codePoints = requireNonNull(section.getString("codepoints", ""), "codepoints should be NonNull");
int height = section.getInt("height", 8); int height = section.getInt("height", 8);
boolean custom = section.getBoolean("custom", false); boolean custom = section.getBoolean("custom", false);
boolean copy = section.getBoolean("generate", false);
String namespace = section.getString("namespace", ConfigManager.namespace());
File bitmapCache = new File(plugin.getDataDirectory().toFile(), "tmp" + File.separator + id + ".tmp"); File bitmapCache = new File(plugin.getDataDirectory().toFile(), "tmp" + File.separator + id + ".tmp");
if (!bitmapCache.exists()) { if (!bitmapCache.exists()) {
@@ -586,9 +588,25 @@ public class AdvanceManagerImpl implements AdvanceManager {
} }
registerCharacterFontData(id, bitmapCache, (properties) -> { registerCharacterFontData(id, bitmapCache, (properties) -> {
int ascent = (int) properties.get("shift_y"); int ascent = (int) properties.get("shift_y");
String filePath = custom ? ConfigManager.namespace() + ":font/" + file : "minecraft:font/" + codePoints + ".png"; String filePath = custom ? namespace + ":font/" + file : "minecraft:font/" + codePoints + ".png";
plugin.getConfigManager().saveResource("tmp/" + codePoints + ".json"); plugin.getConfigManager().saveResource("tmp/" + codePoints + ".json");
StringBuilder jsonContent = new StringBuilder(); StringBuilder jsonContent = new StringBuilder();
if (copy) {
File pngFile = new File(plugin.getDataDirectory().toFile(), "font" + File.separator + file);
File destination = new File(plugin.getDataDirectory().toFile(),
"ResourcePack"
+ File.separator + "assets"
+ File.separator + (custom ? namespace : "minecraft")
+ File.separator + "textures"
+ File.separator + "font"
+ File.separator + (custom ? file : codePoints + ".png")
);
try {
FileUtils.copyFile(pngFile, destination);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
try (BufferedReader reader = new BufferedReader(new FileReader(new File(plugin.getDataDirectory().toFile(), "tmp" + File.separator + codePoints + ".json")))) { try (BufferedReader reader = new BufferedReader(new FileReader(new File(plugin.getDataDirectory().toFile(), "tmp" + File.separator + codePoints + ".json")))) {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {

View File

@@ -33,6 +33,7 @@ integrations:
CarbonChat: false # Integration with CarbonChat CarbonChat: false # Integration with CarbonChat
AdvancedChat: false # Integration with AdvancedChat AdvancedChat: false # Integration with AdvancedChat
Essentials: false # Integration with Essentials chat Essentials: false # Integration with Essentials chat
ChatControlRed: false # Integration with ChatControlRed
# Resource Pack Generation Settings: Configure resource pack generation behavior. # Resource Pack Generation Settings: Configure resource pack generation behavior.
resource-pack: resource-pack:
@@ -72,6 +73,7 @@ other-settings:
"%player_name%": 100 "%player_name%": 100
"%vault_prefix%": 20 "%vault_prefix%": 20
# Font Templates: Define different fonts and their settings. # Font Templates: Define different fonts and their settings.
# Requires a restart to apply because it can be laggy to read thousands of character
font-templates: font-templates:
space: space:
space: space:
@@ -80,7 +82,7 @@ other-settings:
unihex: unihex:
unifont: unifont:
file: unifont.zip # Load font from unifont.zip file: unifont.zip # Load font from unifont.zip
generate: false # Don't include font in the generated resource pack generate: false # Should this unihex file be included in the generated pack
size_overrides: # Override size for specific Unicode ranges size_overrides: # Override size for specific Unicode ranges
- from: "\\u3001" - from: "\\u3001"
to: "\\u30FF" to: "\\u30FF"
@@ -120,7 +122,7 @@ other-settings:
right: 15 right: 15
unifont_jp: unifont_jp:
file: unifont_jp.zip # Load Japanese unifont file: unifont_jp.zip # Load Japanese unifont
generate: false # Don't generate in the resource pack generate: false # Should this unihex file be included in the generated pack
filter: filter:
"jp": true # Apply to Japanese characters only "jp": true # Apply to Japanese characters only
size_overrides: size_overrides:
@@ -137,7 +139,9 @@ other-settings:
codepoints: ascii # Define ASCII bitmap font codepoints: ascii # Define ASCII bitmap font
file: ascii.png # Use ascii.png file for the font file: ascii.png # Use ascii.png file for the font
height: 8 # Font height is 8 units height: 8 # Font height is 8 units
custom: false # Not a custom font (default Minecraft) custom: false # Does this png path point to a non-default font path??
generate: false # Should this png file be included in the generated pack
# namespace: custom # Optional namespace if you don't want to use the global namespace set in config.yml
ascii_sga: ascii_sga:
codepoints: ascii_sga codepoints: ascii_sga
file: ascii_sga.png file: ascii_sga.png

View File

@@ -1,7 +1,7 @@
# Project settings # Project settings
# Rule: [major update].[feature update].[bug fix] # Rule: [major update].[feature update].[bug fix]
project_version=3.0.13 project_version=3.0.14
config_version=32 config_version=33
project_group=net.momirealms project_group=net.momirealms
# Supported languages # Supported languages

View File

@@ -29,6 +29,7 @@ dependencies {
compileOnly(files("libs/carbonchat-paper-3.0.0-beta.27.jar")) compileOnly(files("libs/carbonchat-paper-3.0.0-beta.27.jar"))
compileOnly(files("libs/AdvancedChat-1.3.7.jar")) compileOnly(files("libs/AdvancedChat-1.3.7.jar"))
compileOnly(files("libs/CMIAPI-9.7.4.1.jar")) compileOnly(files("libs/CMIAPI-9.7.4.1.jar"))
compileOnly(files("libs/ChatControl-Red-10.28.3.jar"))
compileOnly("net.william278.huskchat:huskchat-bukkit:3.0.4") compileOnly("net.william278.huskchat:huskchat-bukkit:3.0.4")
compileOnly("net.essentialsx:EssentialsX:2.20.1") compileOnly("net.essentialsx:EssentialsX:2.20.1")
compileOnly("net.essentialsx:EssentialsXChat:2.20.1") compileOnly("net.essentialsx:EssentialsXChat:2.20.1")

View File

@@ -0,0 +1,87 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.bukkit.compatibility.chat;
import net.momirealms.customnameplates.api.CNPlayer;
import net.momirealms.customnameplates.api.CustomNameplates;
import net.momirealms.customnameplates.api.feature.chat.AbstractChatMessageProvider;
import net.momirealms.customnameplates.api.feature.chat.ChatManager;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.mineacademy.chatcontrol.PlayerCache;
import org.mineacademy.chatcontrol.api.ChatChannelEvent;
import org.mineacademy.chatcontrol.model.Channel;
import java.util.Objects;
public class ChatControlRedProvider extends AbstractChatMessageProvider implements Listener {
public ChatControlRedProvider(CustomNameplates plugin, ChatManager manager) {
super(plugin, manager);
}
@EventHandler(ignoreCancelled = true)
public void onChat(ChatChannelEvent event) {
plugin.debug(() -> {
return "ChatChannelEvent triggered";
});
final CommandSender sender = event.getSender();
if (!(sender instanceof Player player)) {
return;
}
if (!player.isOnline()) return;
CNPlayer cnPlayer = plugin.getPlayer(player.getUniqueId());
if (cnPlayer == null) return;
plugin.getScheduler().async().execute(() -> {
manager.onChat(cnPlayer, event.getMessage(), event.getChannel().getName());
});
}
@Override
public boolean hasJoinedChannel(CNPlayer player, String channelID) {
Channel channel = Channel.findChannel(channelID);
if (channel == null) return false;
return channel.isInChannel((Player) player.player());
}
@Override
public boolean canJoinChannel(CNPlayer player, String channelID) {
return ((Player) player).hasPermission("chatcontrol.channel.join."+channelID+".read");
}
@Override
public boolean isIgnoring(CNPlayer sender, CNPlayer receiver) {
PlayerCache cache = PlayerCache.from((Player) receiver.player());
if (cache == null) return false;
return cache.isIgnoringPlayer(sender.uuid());
}
@Override
public void register() {
Bukkit.getPluginManager().registerEvents(this, Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("CustomNameplates")));
}
@Override
public void unregister() {
HandlerList.unregisterAll(this);
}
}

View File

@@ -51,6 +51,9 @@ public class BukkitChatManager extends AbstractChatManager {
} else if (ConfigManager.chatEss() && Bukkit.getPluginManager().isPluginEnabled("EssentialsChat")) { } else if (ConfigManager.chatEss() && Bukkit.getPluginManager().isPluginEnabled("EssentialsChat")) {
this.chatProvider = new EssentialsChatProvider(plugin, this); this.chatProvider = new EssentialsChatProvider(plugin, this);
plugin.getPluginLogger().info("EssentialsChat hooked!"); plugin.getPluginLogger().info("EssentialsChat hooked!");
} else if (ConfigManager.chatChatControlRed() && Bukkit.getPluginManager().isPluginEnabled("ChatControlRed")) {
this.chatProvider = new ChatControlRedProvider(plugin, this);
plugin.getPluginLogger().info("ChatControlRed hooked!");
} else { } else {
this.chatProvider = new AsyncChatProvider(plugin, this); this.chatProvider = new AsyncChatProvider(plugin, this);
} }

View File

@@ -15,6 +15,7 @@ softdepend:
- AdvancedChat - AdvancedChat
- VentureChat - VentureChat
- EssentialsChat - EssentialsChat
- ChatControlRed
- WorldGuard - WorldGuard
permissions: permissions:
nameplates.command.equip: nameplates.command.equip: