9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-19 15:09:23 +00:00

fix images

This commit is contained in:
XiaoMoMi
2024-01-23 16:53:01 +08:00
parent 44ded3388c
commit 85c6621a78
37 changed files with 241 additions and 59 deletions

6
.gitignore vendored
View File

@@ -1,14 +1,12 @@
.gradle
build/
target/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
.idea
*.iws
*.iml
*.ipr

View File

@@ -40,7 +40,8 @@ public class BackGround {
ConfiguredChar offset_128,
ConfiguredChar right,
int leftMargin,
int rightMargin
int rightMargin,
boolean removeShadow
) {
this.left = left;
this.offset_1 = offset_1;

View File

@@ -26,13 +26,15 @@ public class BackGroundText {
private String text;
private BackGround backGround;
private boolean removeShadow;
private BackGroundText() {
}
public BackGroundText(String text, BackGround backGround) {
public BackGroundText(String text, BackGround backGround, boolean removeShadow) {
this.text = text;
this.backGround = backGround;
this.removeShadow = removeShadow;
}
public String getText() {
@@ -46,7 +48,8 @@ public class BackGroundText {
public String getValue(OfflinePlayer player) {
String parsed = PlaceholderAPI.setPlaceholders(player, text);
int parsedWidth = FontUtils.getTextWidth(parsed);
return FontUtils.surroundNameplateFont(backGround.getBackGroundImage(parsedWidth)) + parsed;
String bg = FontUtils.surroundNameplateFont(backGround.getBackGroundImage(parsedWidth));
return (removeShadow ? "<#FFFEFD>" + bg + "</#FFFEFD>" : bg)+ parsed;
}
public static Builder builder() {
@@ -75,6 +78,11 @@ public class BackGroundText {
return this;
}
public Builder removeShadow(boolean remove) {
text.removeShadow = remove;
return this;
}
public BackGroundText build() {
return text;
}

View File

@@ -7,7 +7,7 @@ plugins {
allprojects {
version = "2.3.0.0-beta-1"
version = "2.3.0.0-beta-2"
apply<JavaPlugin>()
apply(plugin = "java")

View File

@@ -0,0 +1,8 @@
systemProp.socks.proxyHost=127.0.0.1
systemProp.socks.proxyPort=7890
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=7890
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=7890

View File

@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -17,6 +17,7 @@
package net.momirealms.customnameplates.paper;
import me.clip.placeholderapi.PlaceholderAPI;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.api.event.CustomNameplatesReloadEvent;
import net.momirealms.customnameplates.api.util.LogUtils;
@@ -43,11 +44,16 @@ import net.momirealms.customnameplates.paper.setting.CNLocale;
import net.momirealms.customnameplates.paper.storage.StorageManagerImpl;
import net.momirealms.customnameplates.paper.util.ReflectionUtils;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import java.io.File;
import java.util.TimeZone;
public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin {
public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin implements Listener {
private CoolDownManager coolDownManager;
private PacketManager packetManager;
@@ -83,6 +89,7 @@ public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin {
if (!outDated) this.getAdventure().sendConsoleMessage("[CustomNameplates] You are using the latest version.");
else this.getAdventure().sendConsoleMessage("[CustomNameplates] Update is available: <u>https://polymart.org/resource/2543<!u>");
});
this.getServer().getPluginManager().registerEvents((VersionManagerImpl) versionManager, this);
}
@Override
@@ -101,6 +108,7 @@ public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin {
((WidthManagerImpl) this.widthManager).unload();
((StorageManagerImpl) this.storageManager).disable();
((AdventureManagerImpl) this.adventureManager).close();
HandlerList.unregisterAll((VersionManagerImpl) versionManager);
}
@Override

View File

@@ -36,6 +36,7 @@ import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar;
import net.momirealms.customnameplates.api.mechanic.font.FontData;
import net.momirealms.customnameplates.api.mechanic.font.OffsetFont;
import net.momirealms.customnameplates.api.mechanic.nameplate.Nameplate;
import net.momirealms.customnameplates.api.mechanic.placeholder.DescentText;
import net.momirealms.customnameplates.api.util.LogUtils;
import net.momirealms.customnameplates.common.Key;
import net.momirealms.customnameplates.common.Tuple;
@@ -126,6 +127,37 @@ public class WidthManagerImpl implements WidthManager {
registerFontData(
Key.of(CNConfig.namespace, CNConfig.font), fontData
);
ArrayList<Integer> ascentTexts = new ArrayList<>();
ArrayList<Integer> ascentUnicodes = new ArrayList<>();
for (DescentText descentText : plugin.getPlaceholderManager().getDescentTexts()) {
if (descentText.isUnicode()) {
ascentUnicodes.add(descentText.getAscent());
} else {
ascentTexts.add(descentText.getAscent());
}
}
ascentTexts.removeAll(ascentUnicodes);
for (int ascent : ascentTexts) {
FontData descentFont = new FontData(8);
descentFont.overrideWith(NONLATIN_EUROPEAN_DATA);
descentFont.overrideWith(ACCENTED_DATA);
descentFont.overrideWith(ASCII_DATA);
registerFontData(
Key.of(CNConfig.namespace, "ascent_" + ascent), descentFont
);
}
for (int ascent : ascentUnicodes) {
FontData descentFont = new FontData(8);
descentFont.overrideWith(UNICODE_DATA);
descentFont.overrideWith(NONLATIN_EUROPEAN_DATA);
descentFont.overrideWith(ACCENTED_DATA);
descentFont.overrideWith(ASCII_DATA);
registerFontData(
Key.of(CNConfig.namespace, "ascent_" + ascent), descentFont
);
}
}
private void loadUserConfigs() {

View File

@@ -23,6 +23,7 @@ import net.momirealms.customnameplates.api.mechanic.character.CharacterArranger;
import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar;
import net.momirealms.customnameplates.api.util.LogUtils;
import net.momirealms.customnameplates.paper.setting.CNConfig;
import net.momirealms.customnameplates.paper.util.ImageUtils;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
@@ -91,6 +92,11 @@ public class ImageManagerImpl implements ImageManager {
LogUtils.warn("Found duplicated image: " + key);
}
}
File[] pgFiles = imgFolder.listFiles(file -> file.getName().endsWith(".png"));
for (File pg : pgFiles) {
ImageUtils.removeImageShadow(pg);
}
}
@Override

View File

@@ -17,9 +17,15 @@
package net.momirealms.customnameplates.paper.mechanic.misc;
import me.clip.placeholderapi.PlaceholderAPI;
import net.momirealms.customnameplates.api.manager.VersionManager;
import net.momirealms.customnameplates.api.util.LogUtils;
import net.momirealms.customnameplates.paper.CustomNameplatesPluginImpl;
import net.momirealms.customnameplates.paper.adventure.AdventureManagerImpl;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import java.io.BufferedReader;
import java.io.InputStream;
@@ -31,7 +37,7 @@ import java.util.concurrent.CompletableFuture;
/**
* This class implements the VersionManager interface and is responsible for managing version-related information.
*/
public class VersionManagerImpl implements VersionManager {
public class VersionManagerImpl implements VersionManager, Listener {
private final boolean isNewerThan1_19;
private final boolean isNewerThan1_19_R2;
@@ -224,4 +230,14 @@ public class VersionManagerImpl implements VersionManager {
}
return newVS.length > currentVS.length;
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
final Player player = event.getPlayer();
if (player.isOp()) {
if (!PlaceholderAPI.isRegistered("player")) {
AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, "You haven't installed Player Expansion yet. Click <b><gold><click:run_command:/papi ecloud download Player>HERE</click></gold><b> to download.");
}
}
}
}

View File

@@ -32,6 +32,9 @@ import net.momirealms.customnameplates.api.util.LogUtils;
import net.momirealms.customnameplates.paper.setting.CNConfig;
import net.momirealms.customnameplates.paper.util.ConfigUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.codehaus.plexus.util.FileUtils;
import javax.imageio.ImageIO;
@@ -235,6 +238,8 @@ public class ResourcePackManagerImpl implements ResourcePackManager {
}
}
ascentTexts.removeAll(ascentUnicodes);
for (int ascent : ascentTexts) {
String line;
StringBuilder sb = new StringBuilder();
@@ -313,20 +318,41 @@ public class ResourcePackManagerImpl implements ResourcePackManager {
}
private void copyResourcePackToHookedPlugins(File resourcePackFolder) {
Plugin ia = Bukkit.getPluginManager().getPlugin("ItemsAdder");
if (ia != null) {
File file = new File(ia.getDataFolder(), "config.yml");
YamlConfiguration iaConfig = YamlConfiguration.loadConfiguration(file);
List<String> folders = iaConfig.getStringList("resource-pack.zip.merge_other_plugins_resourcepacks_folders");
boolean changed = false;
if (CNConfig.copyPackIA) {
if (!folders.contains("CustomNameplates/ResourcePack")) {
folders.add("CustomNameplates/ResourcePack");
iaConfig.set("resource-pack.zip.merge_other_plugins_resourcepacks_folders", folders);
changed = true;
}
} else {
if (folders.contains("CustomNameplates/ResourcePack")) {
folders.remove("CustomNameplates/ResourcePack");
iaConfig.set("resource-pack.zip.merge_other_plugins_resourcepacks_folders", folders);
changed = true;
}
}
if (changed) {
try {
FileUtils.copyDirectory(new File(resourcePackFolder, "assets"), new File(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("ItemsAdder")).getDataFolder() + File.separator + "contents" + File.separator + "nameplates" + File.separator + "resourcepack" + File.separator + "assets") );
iaConfig.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
if (CNConfig.copyPackOraxen) {
try {
FileUtils.copyDirectory(new File(resourcePackFolder, "assets"), new File(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Oraxen")).getDataFolder() + File.separator + "pack" + File.separator + "assets"));
} catch (IOException e) {
e.printStackTrace();
}
}
// if (CNConfig.copyPackOraxen) {
// try {
// FileUtils.copyDirectory(new File(resourcePackFolder, "assets"), new File(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Oraxen")).getDataFolder() + File.separator + "pack" + File.separator + "assets"));
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
}
private List<JsonObject> getNameplates(File texturesFolder) {

View File

@@ -193,6 +193,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
BackGroundText.builder()
.background(Objects.requireNonNull(plugin.getBackGroundManager().getBackGround(innerSection.getString("background"))))
.text(innerSection.getString("text", ""))
.removeShadow(innerSection.getBoolean("remove-shadow"))
.build()
);
}
@@ -228,7 +229,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
DescentText.builder()
.descent(innerSection.getInt("descent", 0))
.text(innerSection.getString("text", ""))
.unicode(unicode)
.unicode(unicode || innerSection.getBoolean("is-unicode"))
.build()
);
}

View File

@@ -23,16 +23,14 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.api.manager.TeamManager;
import net.momirealms.customnameplates.api.util.LogUtils;
import net.momirealms.customnameplates.common.message.MessageType;
import net.momirealms.customnameplates.common.team.TeamCollisionRule;
import net.momirealms.customnameplates.common.team.TeamColor;
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
import net.momirealms.customnameplates.paper.mechanic.misc.PacketManager;
import net.momirealms.customnameplates.paper.mechanic.team.packet.*;
import net.momirealms.customnameplates.paper.mechanic.team.provider.CMIProvider;
import net.momirealms.customnameplates.paper.mechanic.team.provider.DefaultProvider;
import net.momirealms.customnameplates.paper.mechanic.team.provider.TABProvider;
import net.momirealms.customnameplates.paper.mechanic.team.provider.TeamProvider;
import net.momirealms.customnameplates.paper.mechanic.team.provider.*;
import net.momirealms.customnameplates.paper.setting.CNConfig;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -57,9 +55,14 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
@Override
public void createTeam(Player player) {
if (CNConfig.disableTeamManage) return;
String team = teamProvider.getTeam(player);
if (team == null) {
LogUtils.warn("Failed to get player " + player.getName() + "'s team.");
return;
}
PacketContainer createOwner = teamPacketAdaptor.getTeamCreatePacket(
TeamCreate.builder()
.teamName(teamProvider.getTeam(player))
.teamName(team)
.color(TeamColor.WHITE)
.display("")
.prefix("")
@@ -72,9 +75,10 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
for (Player online : Bukkit.getOnlinePlayers()) {
PacketManager.getInstance().send(online, createOwner);
if (online == player) continue;
String onlineTeam = teamProvider.getTeam(online);
PacketContainer createOther = teamPacketAdaptor.getTeamCreatePacket(
TeamCreate.builder()
.teamName(teamProvider.getTeam(online))
.teamName(onlineTeam)
.color(TeamColor.WHITE)
.display("")
.prefix("")
@@ -91,9 +95,10 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
@Override
public void removeTeam(Player player) {
if (CNConfig.disableTeamManage) return;
String team = teamProvider.getTeam(player);
PacketContainer packet = teamPacketAdaptor.getTeamRemovePacket(
TeamRemove.builder()
.teamName(teamProvider.getTeam(player))
.teamName(team)
.build()
);
for (Player online : Bukkit.getOnlinePlayers()) {
@@ -105,6 +110,7 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
@Override
public void updateTeam(Player owner, Player viewer, String prefix, String suffix, TeamColor color, TeamTagVisibility visibility) {
if (CNConfig.disableTeamManage) return;
String team = teamProvider.getTeam(owner);
if (color == TeamColor.NONE || color == TeamColor.CUSTOM)
color = TeamColor.WHITE;
if (plugin.getNameplateManager().isProxyMode()) {
@@ -120,7 +126,7 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
} else {
PacketContainer packet = teamPacketAdaptor.getTeamUpdatePacket(
TeamUpdate.builder()
.teamName(teamProvider.getTeam(owner))
.teamName(team)
.color(color)
.display("")
.prefix(prefix)
@@ -148,6 +154,8 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
teamProvider = new TABProvider();
} else if (CNConfig.cmiTeam) {
teamProvider = new CMIProvider();
} else if (CNConfig.unknownTeam) {
teamProvider = new UnknownProvider();
} else {
teamProvider = new DefaultProvider();
}

View File

@@ -26,7 +26,7 @@ public class CMIProvider implements TeamProvider {
@Override
public String getTeam(Player player) {
Team team = CMI.getInstance().getSB().getPlayerTeam(player);
if (team == null) return player.getName();
if (team == null) return null;
return team.getName();
}
}

View File

@@ -0,0 +1,36 @@
/*
* 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.paper.mechanic.team.provider;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
public class UnknownProvider implements TeamProvider {
@Override
public String getTeam(Player player) {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
Team team = scoreboard.getPlayerTeam(player);
if (team == null) {
return null;
}
return team.getName();
}
}

View File

@@ -79,6 +79,7 @@ public class CNConfig {
public static boolean textEffects;
public static boolean disableTeamManage;
public static boolean velocitab;
public static boolean unknownTeam;
public static void load() {
try {
@@ -128,6 +129,7 @@ public class CNConfig {
tabTeam = integrationSection.getBoolean("team.TAB", false);
cmiTeam = integrationSection.getBoolean("team.CMI", false);
velocitab = integrationSection.getBoolean("team.Velocitab", false);
unknownTeam = integrationSection.getBoolean("team.unknown", false);
}
ConfigurationSection packSection = config.getConfigurationSection("resource-pack");

View File

@@ -0,0 +1,36 @@
package net.momirealms.customnameplates.paper.util;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class ImageUtils {
public static void removeImageShadow(File file) {
try {
BufferedImage inputImage = ImageIO.read(file);
int width = inputImage.getWidth();
int height = inputImage.getHeight();
BufferedImage outputImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
int[] pixels = new int[width * height];
inputImage.getRGB(0, 0, width, height, pixels, 0, width);
for (int i = 0; i < pixels.length; i++) {
int alpha = (pixels[i] >> 24) & 0xFF;
int red = (pixels[i] >> 16) & 0xFF;
int green = (pixels[i] >> 8) & 0xFF;
int blue = pixels[i] & 0xFF;
if (alpha > 0) {
alpha = 254;
}
int newPixel = (alpha << 24) | (red << 16) | (green << 8) | blue;
pixels[i] = newPixel;
}
outputImage.setRGB(0, 0, width, height, pixels, 0, width);
ImageIO.write(outputImage, "png", file);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -23,13 +23,14 @@ modules:
actionbars: true
images: true
# Integrations
# Integrations (Please read the wiki)
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customnameplates/compatibility
integrations:
resource-pack:
ItemsAdder: false
Oraxen: false
team:
unknown: false
TAB: false
CMI: false
Velocitab: false

View File

@@ -136,36 +136,30 @@ static-text:
# Note: If you want to make an image lower, edit the y position/ascent in that plugin instead of
# using descent text or descent unicode because they are designed for characters
descent-text:
name:
text: "%player_name%"
descent: 0
player:
text: "%player_name%"
descent: 5
position:
text: "Your Position: %player_x%, %player_y%, %player_z%"
location:
text: "Your Location: [X: %player_x%, Y: %player_y%, Z: %player_z%]"
descent: 5
is-unicode: false
time:
text: "Time: %nameplates_time%"
descent: 5
is-unicode: false
weather:
text: "Weather: %nameplates_conditional_weather%"
descent: 5
region:
text: "Region: %worldguard_region%"
descent: 5
is-unicode: false
update:
text: "A newer version of CustomNameplates is available!"
descent: 3
is-unicode: false
money:
text: "%vault_eco_balance%"
descent: 13
# %nameplates_unicode_{0}%
descent-unicode:
is-unicode: false
hello:
text: "Hello 여보세요 你好 こんにちは"
text: "Hello 여보세요 你好 こんにちは, Thanks for using CustomNameplates"
descent: 5
is-unicode: true
# %nameplates_switch_{0}%
switch-text:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 210 B

After

Width:  |  Height:  |  Size: 156 B

View File

@@ -1,4 +1,4 @@
image: bell
height: 10
ascent: 7
ascent: 6
width: 10

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 B

After

Width:  |  Height:  |  Size: 118 B

View File

@@ -1,4 +1,4 @@
image: bubble
height: 10
ascent: 5
ascent: 4
width: 10

Binary file not shown.

Before

Width:  |  Height:  |  Size: 954 B

After

Width:  |  Height:  |  Size: 143 B

View File

@@ -1,4 +1,4 @@
image: clock
height: 10
ascent: 5
ascent: 4
width: 10

Binary file not shown.

Before

Width:  |  Height:  |  Size: 213 B

After

Width:  |  Height:  |  Size: 163 B

View File

@@ -1,4 +1,4 @@
image: coin
height: 10
ascent: -2
ascent: -3
width: 10

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 B

After

Width:  |  Height:  |  Size: 175 B

View File

@@ -1,4 +1,4 @@
image: compass
height: 10
ascent: 5
ascent: 4
width: 10

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 B

After

Width:  |  Height:  |  Size: 121 B

View File

@@ -1,4 +1,4 @@
image: stamina_0
height: 9
ascent: -15
ascent: -16
width: 9

Binary file not shown.

Before

Width:  |  Height:  |  Size: 230 B

After

Width:  |  Height:  |  Size: 157 B

View File

@@ -1,4 +1,4 @@
image: stamina_1
height: 9
ascent: -15
ascent: -16
width: 9

Binary file not shown.

Before

Width:  |  Height:  |  Size: 301 B

After

Width:  |  Height:  |  Size: 207 B

View File

@@ -1,4 +1,4 @@
image: stamina_2
height: 9
ascent: -15
ascent: -16
width: 9

Binary file not shown.

Before

Width:  |  Height:  |  Size: 179 B

After

Width:  |  Height:  |  Size: 126 B

View File

@@ -1,4 +1,4 @@
image: weather
height: 10
ascent: 5
ascent: 4
width: 10