Simplify image rendering settings

This commit is contained in:
filoghost 2021-07-10 16:11:32 +02:00
parent 0cb6fed921
commit 6948afcfa9
3 changed files with 11 additions and 37 deletions

View File

@ -10,7 +10,6 @@ import me.filoghost.fcommons.Strings;
import me.filoghost.fcommons.logging.ErrorCollector;
import me.filoghost.holographicdisplays.common.DebugLogger;
import me.filoghost.holographicdisplays.plugin.format.DisplayFormat;
import org.bukkit.ChatColor;
import java.time.DateTimeException;
import java.time.ZoneId;
@ -27,7 +26,6 @@ public class Settings {
public static String imageSymbol;
public static String transparencySymbol;
public static ChatColor transparencyColor;
public static int bungeeRefreshSeconds;
public static boolean useRedisBungee;
@ -47,7 +45,6 @@ public class Settings {
imageSymbol = DisplayFormat.apply(config.imageSymbol);
transparencySymbol = DisplayFormat.apply(config.transparencySymbol);
transparencyColor = parseTransparencyColor(config.transparencyColor, errorCollector);
bungeeRefreshSeconds = parseBungeeRefreshInterval(config.bungeeRefreshSeconds, errorCollector);
useRedisBungee = config.useRedisBungee;
@ -90,19 +87,6 @@ public class Settings {
return timeFormat;
}
private static ChatColor parseTransparencyColor(String transparencyColor, ErrorCollector errorCollector) {
transparencyColor = transparencyColor.replace('&', ChatColor.COLOR_CHAR);
for (ChatColor chatColor : ChatColor.values()) {
if (chatColor.toString().equals(transparencyColor)) {
return chatColor;
}
}
errorCollector.add("chat color for transparency in the configuration is not valid, light gray (&7) will be used");
return ChatColor.GRAY;
}
private static int parseBungeeRefreshInterval(int interval, ErrorCollector errorCollector) {
if (interval < 1) {
errorCollector.add("the minimum interval for pinging BungeeCord's servers is 1 second. It has been automatically set");

View File

@ -26,9 +26,6 @@ public class SettingsModel implements MappedConfig {
@Path("images.transparency.space")
String transparencySymbol = " [|] ";
@Path("images.transparency.color")
String transparencyColor = "&7";
@Path("bungee.refresh-seconds")
int bungeeRefreshSeconds = 3;
@ -88,7 +85,8 @@ public class SettingsModel implements MappedConfig {
"using-RedisBungee",
"bungee-online-format",
"bungee-offline-format",
"precise-hologram-movement"
"precise-hologram-movement",
"images.transparency.color"
);
boolean modified = false;

View File

@ -5,6 +5,7 @@
*/
package me.filoghost.holographicdisplays.plugin.image;
import me.filoghost.fcommons.Colors;
import me.filoghost.holographicdisplays.plugin.disk.Settings;
import org.bukkit.ChatColor;
import org.jetbrains.annotations.Nullable;
@ -53,35 +54,26 @@ public class ImageMessage {
private List<String> toChatLines(BufferedImage image) {
List<String> lines = new ArrayList<>(image.getHeight());
ChatColor transparencyColor = Settings.transparencyColor;
String transparencySymbol = Settings.transparencySymbol;
String imageSymbol = Settings.imageSymbol;
for (int y = 0; y < image.getHeight(); y++) {
StringBuilder line = new StringBuilder();
ChatColor previousColor = null;
for (int x = 0; x < image.getWidth(); x++) {
ChatColor currentColor = getClosestChatColor(image, x, y);
String symbol;
ChatColor pixelColor = getClosestChatColor(image, x, y);
if (currentColor == null) {
// Use the transparent char
currentColor = transparencyColor;
symbol = transparencySymbol;
if (pixelColor == null) {
// "null" means transparent is the closest color
line.append(ChatColor.RESET);
line.append(transparencySymbol);
} else {
symbol = imageSymbol;
line.append(pixelColor);
line.append(imageSymbol);
}
if (currentColor != previousColor) {
// Append the different color and save it
line.append(currentColor);
previousColor = currentColor;
}
line.append(symbol);
}
lines.add(line.toString());
lines.add(Colors.optimize(line.toString()));
}
return lines;