From a23d10c095333e7da242ff6c4c772c138c8fb203 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 16:45:10 -0500 Subject: [PATCH 01/69] Update readme.md --- readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index da0e643..4f8cb5c 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,5 @@ +#Updated Picture Login to Minecraft 1.18.2 + Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === @@ -13,4 +15,4 @@ It is a plugin for [Spigot](http://www.spigotmc.org/) and you can find further i License --- -This plugin is licensed under the MIT License. For more information please refer to LICENSE. \ No newline at end of file +This plugin is licensed under the MIT License. For more information please refer to LICENSE. From 9f6aaedddeb68351df70d4610bb277c8f4781984 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 16:45:19 -0500 Subject: [PATCH 02/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 4f8cb5c..bdaa858 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -#Updated Picture Login to Minecraft 1.18.2 +Updated Picture Login to Minecraft 1.18.2 Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === From ba145aaca8b809fd4a7dc24886cf71c19ef18b08 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Apr 2022 16:48:03 -0500 Subject: [PATCH 03/69] Working on Minecraft 1.18.2 --- pom.xml | 9 +-- .../itsnathang/picturelogin/PictureLogin.java | 61 +++++++++---------- src/main/resources/plugin.yml | 2 +- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index 097a44f..9762943 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ org.bstats bstats-bukkit - 1.7 + 3.0.0 compile @@ -69,7 +69,8 @@ - src/main/java + ${dir} + clean install @@ -94,7 +95,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.1.0 + 3.3.0 @@ -130,5 +131,5 @@ - + \ No newline at end of file diff --git a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java index f9b3f31..75e9841 100644 --- a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java +++ b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java @@ -8,49 +8,48 @@ import me.itsnathang.picturelogin.util.PictureUtil; import me.itsnathang.picturelogin.util.Updater; -import org.bukkit.command.CommandExecutor; import org.bukkit.plugin.java.JavaPlugin; import org.bstats.bukkit.Metrics; public class PictureLogin extends JavaPlugin { - private ConfigManager configManager; - private PictureUtil pictureUtil; + private ConfigManager configManager; + private PictureUtil pictureUtil; - @Override - public void onEnable() { - // load config & languages file - configManager = new ConfigManager(this); + @Override + public void onEnable() { + // load config & languages file + configManager = new ConfigManager(this); - // Register Plugin Hooks - new Hooks(getServer().getPluginManager(), configManager, getLogger()); + // Register Plugin Hooks + new Hooks(getServer().getPluginManager(), configManager, getLogger()); - // Initialize Picture Utility - pictureUtil = new PictureUtil(this); + // Initialize Picture Utility + pictureUtil = new PictureUtil(this); - // register Listeners - getServer().getPluginManager().registerEvents(new JoinListener(this), this); + // register Listeners + getServer().getPluginManager().registerEvents(new JoinListener(this), this); - // (only register leave listener if enabled in config) - if (configManager.getBoolean("show-leave-message", false)) - getServer().getPluginManager().registerEvents(new QuitListener(this), this); + // (only register leave listener if enabled in config) + if (configManager.getBoolean("show-leave-message", false)) + getServer().getPluginManager().registerEvents(new QuitListener(this), this); - // register /picturelogin command - getCommand("picturelogin").setExecutor(new BaseCommand(this)); + // register /picturelogin command + getCommand("picturelogin").setExecutor(new BaseCommand(this)); - // Update Checker - if (configManager.getBoolean("update-check", true)) - new Updater(getLogger(), getDescription().getVersion()); + // Update Checker + if (configManager.getBoolean("update-check", true)) + new Updater(getLogger(), getDescription().getVersion()); - // bStats integration - if (configManager.getBoolean("metrics", true)) - new Metrics(this, 2225); - } + // bStats integration + if (configManager.getBoolean("metrics", true)) + new Metrics(this, 2225); + } - public ConfigManager getConfigManager() { - return configManager; - } + public ConfigManager getConfigManager() { + return configManager; + } - public PictureUtil getPictureUtil() { - return pictureUtil; - } + public PictureUtil getPictureUtil() { + return pictureUtil; + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3517d01..b3903b1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: PictureLogin main: me.itsnathang.picturelogin.PictureLogin -api-version: 1.16 +api-version: 1.18 author: NathanG description: Display a cool login message with a picture of the player's skin. From bcdc1b809617587635e808f6d13a2caaff1f7fef Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 16:49:18 -0500 Subject: [PATCH 04/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index bdaa858..8553431 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -Updated Picture Login to Minecraft 1.18.2 +Updated to Minecraft 1.18.2 Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === From 950250ab79e4eae36f3c75479969548987cdd763 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Apr 2022 17:08:58 -0500 Subject: [PATCH 05/69] commit before cleanup. works --- .../bobacadodl/imgmessage/ImageMessage.java | 54 +++---------------- .../picturelogin/commands/BaseCommand.java | 1 - .../picturelogin/listeners/JoinListener.java | 7 ++- 3 files changed, 11 insertions(+), 51 deletions(-) diff --git a/src/main/java/com/bobacadodl/imgmessage/ImageMessage.java b/src/main/java/com/bobacadodl/imgmessage/ImageMessage.java index 22a41f4..374eb48 100644 --- a/src/main/java/com/bobacadodl/imgmessage/ImageMessage.java +++ b/src/main/java/com/bobacadodl/imgmessage/ImageMessage.java @@ -1,6 +1,6 @@ package com.bobacadodl.imgmessage; -import org.bukkit.ChatColor; +import net.md_5.bungee.api.ChatColor; import org.bukkit.entity.Player; import org.bukkit.util.ChatPaginator; @@ -17,25 +17,6 @@ public class ImageMessage { private final static char TRANSPARENT_CHAR = ' '; - private final Color[] colors = { - new Color(0, 0, 0), - new Color(0, 0, 170), - new Color(0, 170, 0), - new Color(0, 170, 170), - new Color(170, 0, 0), - new Color(170, 0, 170), - new Color(255, 170, 0), - new Color(170, 170, 170), - new Color(85, 85, 85), - new Color(85, 85, 255), - new Color(85, 255, 85), - new Color(85, 255, 255), - new Color(255, 85, 85), - new Color(255, 85, 255), - new Color(255, 255, 85), - new Color(255, 255, 255), - }; - private String[] lines; public ImageMessage(BufferedImage image, int height, char imgChar) { @@ -92,12 +73,12 @@ private ChatColor[][] toChatColorArray(BufferedImage image, int height) { private String[] toImgMessage(ChatColor[][] colors, char imgchar) { lines = new String[colors[0].length]; for (int y = 0; y < colors[0].length; y++) { - String line = ""; - for (int x = 0; x < colors.length; x++) { - ChatColor color = colors[x][y]; - line += (color != null) ? colors[x][y].toString() + imgchar : TRANSPARENT_CHAR; + StringBuilder line = new StringBuilder(); + for (ChatColor[] chatColors : colors) { + ChatColor color = chatColors[y]; + line.append((color != null) ? chatColors[y].toString() + imgchar : TRANSPARENT_CHAR); } - lines[y] = line + ChatColor.RESET; + lines[y] = line.toString() + ChatColor.RESET; } return lines; } @@ -132,26 +113,7 @@ private boolean areIdentical(Color c1, Color c2) { private ChatColor getClosestChatColor(Color color) { if (color.getAlpha() < 128) return null; - - int index = 0; - double best = -1; - - for (int i = 0; i < colors.length; i++) { - if (areIdentical(colors[i], color)) { - return ChatColor.values()[i]; - } - } - - for (int i = 0; i < colors.length; i++) { - double distance = getDistance(color, colors[i]); - if (distance < best || best == -1) { - best = distance; - index = i; - } - } - - // Minecraft has 15 colors - return ChatColor.values()[index]; + return ChatColor.of(color); } private String center(String s, int length) { @@ -165,7 +127,7 @@ private String center(String s, int length) { for (int i = 0; i < leftPadding; i++) { leftBuilder.append(" "); } - return leftBuilder.toString() + s; + return leftBuilder + s; } } diff --git a/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java b/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java index 3d12b46..b2cbae6 100644 --- a/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java +++ b/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java @@ -19,7 +19,6 @@ public BaseCommand(PictureLogin plugin) { @Override public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) { - // Permission Check if (!s.hasPermission("picturelogin.main")) { s.sendMessage(tl("no_permission")); return false; diff --git a/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java b/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java index 69dbcdc..2644178 100644 --- a/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java +++ b/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java @@ -15,15 +15,14 @@ import org.bukkit.scheduler.BukkitRunnable; public class JoinListener implements Listener { - private PictureLogin plugin; - private PictureUtil pictureUtil; - private ConfigManager config; + private final PictureLogin plugin; + private final ConfigManager config; private Player player; public JoinListener(PictureLogin plugin) { this.plugin = plugin; this.config = plugin.getConfigManager(); - this.pictureUtil = plugin.getPictureUtil(); + PictureUtil pictureUtil = plugin.getPictureUtil(); } @EventHandler (priority = EventPriority.HIGH) From fb613f2ca866bf73df806314a776e18a1130f36c Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Apr 2022 17:26:26 -0500 Subject: [PATCH 06/69] Finished cleanup --- pom.xml | 8 + .../com/bobacadodl/imgmessage/ImageChar.java | 2 +- .../itsnathang/picturelogin/PictureLogin.java | 14 +- .../picturelogin/commands/BaseCommand.java | 56 +++--- .../picturelogin/config/ConfigManager.java | 155 ++++++++-------- .../picturelogin/config/FallbackPicture.java | 10 +- .../picturelogin/config/LanguageManager.java | 9 +- .../picturelogin/listeners/JoinListener.java | 87 ++++----- .../picturelogin/listeners/QuitListener.java | 49 ++--- .../picturelogin/util/ImageMessage.java | 27 ++- .../picturelogin/util/PictureUtil.java | 171 +++++++++--------- .../picturelogin/util/PictureWrapper.java | 32 ++-- .../itsnathang/picturelogin/util/Updater.java | 6 +- src/main/resources/plugin.yml | 2 +- 14 files changed, 324 insertions(+), 304 deletions(-) diff --git a/pom.xml b/pom.xml index 9762943..03d3836 100644 --- a/pom.xml +++ b/pom.xml @@ -129,6 +129,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 10 + 10 + + diff --git a/src/main/java/com/bobacadodl/imgmessage/ImageChar.java b/src/main/java/com/bobacadodl/imgmessage/ImageChar.java index 86bb74c..c431363 100644 --- a/src/main/java/com/bobacadodl/imgmessage/ImageChar.java +++ b/src/main/java/com/bobacadodl/imgmessage/ImageChar.java @@ -10,7 +10,7 @@ public enum ImageChar { DARK_SHADE('\u2593'), MEDIUM_SHADE('\u2592'), LIGHT_SHADE('\u2591'); - private char c; + private final char c; ImageChar(char c) { this.c = c; diff --git a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java index 75e9841..297c85f 100644 --- a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java +++ b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java @@ -11,6 +11,9 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bstats.bukkit.Metrics; +/* +Updated to work with Minecraft 1.18.2 by _NickV on 4/7/2022 + */ public class PictureLogin extends JavaPlugin { private ConfigManager configManager; private PictureUtil pictureUtil; @@ -30,19 +33,22 @@ public void onEnable() { getServer().getPluginManager().registerEvents(new JoinListener(this), this); // (only register leave listener if enabled in config) - if (configManager.getBoolean("show-leave-message", false)) + if (configManager.getBoolean("show-leave-message", false)) { getServer().getPluginManager().registerEvents(new QuitListener(this), this); + } // register /picturelogin command getCommand("picturelogin").setExecutor(new BaseCommand(this)); // Update Checker - if (configManager.getBoolean("update-check", true)) + if (configManager.getBoolean("update-check", true)) { new Updater(getLogger(), getDescription().getVersion()); + } // bStats integration - if (configManager.getBoolean("metrics", true)) - new Metrics(this, 2225); + if (configManager.getBoolean("metrics", true)) { + new Metrics(this, 2225); // 2225 is the bStats plugin ID for PictureLogin + } } public ConfigManager getConfigManager() { diff --git a/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java b/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java index b2cbae6..4eebf98 100644 --- a/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java +++ b/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java @@ -10,33 +10,31 @@ import static me.itsnathang.picturelogin.util.Translate.tl; public class BaseCommand implements CommandExecutor { - private final PictureLogin plugin; - - // TODO: Remove plugin - public BaseCommand(PictureLogin plugin) { - this.plugin = plugin; - } - - @Override - public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) { - if (!s.hasPermission("picturelogin.main")) { - s.sendMessage(tl("no_permission")); - return false; - } - - // Check if command is /picturelogin reload - if (args.length == 1 && args[0].equalsIgnoreCase("reload")) { - plugin.getConfigManager().reloadConfig(); - s.sendMessage(tl("reload_config")); - return true; - } - - // Default to sending help - s.sendMessage(ChatColor.GREEN + "PictureLogin " + ChatColor.GRAY + "v" + - ChatColor.GREEN + plugin.getDescription().getVersion() + ChatColor.GRAY + " by " + - ChatColor.GREEN + "NathanG"); - s.sendMessage(tl("reload_config_help")); - - return true; - } + private final PictureLogin plugin; + + public BaseCommand(PictureLogin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) { + if (!s.hasPermission("picturelogin.main")) { + s.sendMessage(tl("no_permission")); + return false; + } + + // Check if command is /picturelogin reload + if (args.length == 1 && args[0].equalsIgnoreCase("reload")) { + plugin.getConfigManager().reloadConfig(); + s.sendMessage(tl("reload_config")); + return true; + } + + // Default to sending help + s.sendMessage(ChatColor.GREEN + "PictureLogin " + ChatColor.GRAY + "v" + + ChatColor.GREEN + plugin.getDescription().getVersion() + ChatColor.GRAY + " by " + + ChatColor.GREEN + "NathanG"); + s.sendMessage(tl("reload_config_help")); + return true; + } } diff --git a/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java b/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java index 5da3ded..bb4af7d 100644 --- a/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java +++ b/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java @@ -1,91 +1,88 @@ package me.itsnathang.picturelogin.config; +import com.bobacadodl.imgmessage.ImageChar; +import me.itsnathang.picturelogin.PictureLogin; +import me.itsnathang.picturelogin.util.ImageMessage; +import org.bukkit.configuration.file.YamlConfiguration; + import java.awt.image.BufferedImage; import java.io.File; -import java.util.Arrays; import java.util.List; -import java.util.Optional; import java.util.logging.Level; -import com.sun.tools.sjavac.Log; -import org.bukkit.configuration.file.YamlConfiguration; +public class ConfigManager { + private final PictureLogin plugin; + private final LanguageManager languageManager; + private YamlConfiguration config; -import com.bobacadodl.imgmessage.ImageChar; -import me.itsnathang.picturelogin.util.ImageMessage; -import me.itsnathang.picturelogin.PictureLogin; + public ConfigManager(PictureLogin plugin) { + this.plugin = plugin; + + languageManager = new LanguageManager(plugin); + reloadConfig(); + } + + public void reloadConfig() { + File conf = new File(plugin.getDataFolder() + File.separator + "config.yml"); + + if (!conf.exists()) { + plugin.saveResource("config.yml", true); + } -public class ConfigManager { - private final PictureLogin plugin; - private LanguageManager languageManager; - private YamlConfiguration config; - - public ConfigManager(PictureLogin plugin) { - this.plugin = plugin; - - languageManager = new LanguageManager(plugin); - - reloadConfig(); - } - - public void reloadConfig() { - File conf = new File(plugin.getDataFolder() + File.separator + "config.yml"); - - if(!conf.exists()) - plugin.saveResource("config.yml", true); - config = YamlConfiguration.loadConfiguration(conf); + languageManager.reloadLanguage(); + } + + private char getChar() { + try { + return ImageChar.valueOf(config.getString("character").toUpperCase()).getChar(); + } catch (IllegalArgumentException e) { + return ImageChar.BLOCK.getChar(); + } + } + + public ImageMessage getMessage(List messages, BufferedImage image) { + int imageDimensions = 8, count = 0; + ImageMessage imageMessage = new ImageMessage(image, imageDimensions, getChar()); + String[] msg = new String[imageDimensions]; + + for (String message : messages) { + if (count > msg.length) break; + msg[count++] = message; + } + + while (count < imageDimensions) { + msg[count++] = ""; + } + + if (config.getBoolean("center-text", false)) + return imageMessage.appendCenteredText(msg); + + return imageMessage.appendText(msg); + } + + public boolean getBoolean(String key) { + return config.getBoolean(key); + } + + public boolean getBoolean(String key, Boolean def) { + return config.getBoolean(key, def); + } + + public List getStringList(String key) { + return config.getStringList(key); + } + + public String getURL() { + String url = config.getString("url"); + + if (url == null) { + plugin.getLogger().log(Level.SEVERE, "Could not read picture url from config.yml!"); + + return "https://minepic.org/avatar/8/%uuid%"; + } + + return url; + } - languageManager.reloadLanguage(); - } - - private char getChar() { - try { - return ImageChar.valueOf(config.getString("character").toUpperCase()).getChar(); - } catch (IllegalArgumentException e) { - return ImageChar.BLOCK.getChar(); - } - } - - public ImageMessage getMessage(List messages, BufferedImage image) { - int imageDimensions = 8, count = 0; - ImageMessage imageMessage = new ImageMessage(image, imageDimensions, getChar()); - String[] msg = new String[imageDimensions]; - - for (String message : messages) { - if (count > msg.length) break; - msg[count++] = message; - } - - while (count < imageDimensions) { - msg[count++] = ""; - } - - if (config.getBoolean("center-text", false)) - return imageMessage.appendCenteredText(msg); - - return imageMessage.appendText(msg); - } - - public boolean getBoolean(String key) { - return config.getBoolean(key); - } - - public boolean getBoolean(String key, Boolean def) { return config.getBoolean(key, def); } - - public List getStringList(String key) { - return config.getStringList(key); - } - - public String getURL() { - String url = config.getString("url"); - - if (url == null) { - plugin.getLogger().log(Level.SEVERE, "Could not read picture url from config.yml!"); - - return "https://minepic.org/avatar/8/%uuid%"; - } - - return url; - } - } diff --git a/src/main/java/me/itsnathang/picturelogin/config/FallbackPicture.java b/src/main/java/me/itsnathang/picturelogin/config/FallbackPicture.java index 8a2c81c..5e5cc08 100644 --- a/src/main/java/me/itsnathang/picturelogin/config/FallbackPicture.java +++ b/src/main/java/me/itsnathang/picturelogin/config/FallbackPicture.java @@ -16,15 +16,11 @@ public File get() { File image = new File(FALLBACK_PATH); - if (!image.exists()) + if (!image.exists()) { plugin.saveResource("fallback.png", false); + } - if (plugin.getConfigManager().getBoolean("fallback", true)) - image = new File(FALLBACK_PATH); - else - image = null; - - return image; + return plugin.getConfigManager().getBoolean("fallback", true) ? new File(FALLBACK_PATH) : null; } } diff --git a/src/main/java/me/itsnathang/picturelogin/config/LanguageManager.java b/src/main/java/me/itsnathang/picturelogin/config/LanguageManager.java index 3ac9a4d..6345038 100644 --- a/src/main/java/me/itsnathang/picturelogin/config/LanguageManager.java +++ b/src/main/java/me/itsnathang/picturelogin/config/LanguageManager.java @@ -7,7 +7,7 @@ import java.io.File; public class LanguageManager { - private PictureLogin plugin; + private final PictureLogin plugin; LanguageManager(PictureLogin plugin) { this.plugin = plugin; @@ -18,16 +18,15 @@ public class LanguageManager { private YamlConfiguration loadLanguage() { File language_file = new File(plugin.getDataFolder() + File.separator + "messages.yml"); - if (!language_file.exists()) + if (!language_file.exists()) { plugin.saveResource("messages.yml", false); + } return YamlConfiguration.loadConfiguration(language_file); } public void reloadLanguage() { - YamlConfiguration messages = loadLanguage(); - - Translate.messages = messages; + Translate.messages = loadLanguage(); } } diff --git a/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java b/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java index 2644178..ef9f298 100644 --- a/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java +++ b/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java @@ -15,57 +15,58 @@ import org.bukkit.scheduler.BukkitRunnable; public class JoinListener implements Listener { - private final PictureLogin plugin; - private final ConfigManager config; - private Player player; + private final PictureLogin plugin; + private final ConfigManager config; + private Player player; - public JoinListener(PictureLogin plugin) { - this.plugin = plugin; - this.config = plugin.getConfigManager(); - PictureUtil pictureUtil = plugin.getPictureUtil(); - } + public JoinListener(PictureLogin plugin) { + this.plugin = plugin; + this.config = plugin.getConfigManager(); + } - @EventHandler (priority = EventPriority.HIGH) - public void onJoin(PlayerJoinEvent event) { - this.player = event.getPlayer(); + @EventHandler(priority = EventPriority.HIGH) + public void onJoin(PlayerJoinEvent event) { + this.player = event.getPlayer(); - // block the default join message - if (config.getBoolean("block-join-message", false)) - event.setJoinMessage(null); + // block the default join message + if (config.getBoolean("block-join-message", false)) { + event.setJoinMessage(null); + } - if (Hooks.AUTHME) { - authMeLogin(); - return; - } + if (Hooks.AUTHME) { + authMeLogin(); + return; + } - sendImage(); - } + sendImage(); + } - private void authMeLogin() { - new BukkitRunnable() { + private void authMeLogin() { + new BukkitRunnable() { + @Override + public void run() { + // Stop if player left the server + if (player == null || !player.isOnline()) { + this.cancel(); + } - @Override - public void run() { - // Stop if player left the server - if (player == null || !player.isOnline()) - this.cancel(); + // Check for authentication + if (AuthMeApi.getInstance().isAuthenticated(player)) { + sendImage(); + this.cancel(); + } + } - // Check for authentication - if (AuthMeApi.getInstance().isAuthenticated(player)) { - sendImage(); - this.cancel(); - } - } + }.runTaskTimer(plugin, 0L, 20L); + } - }.runTaskTimer(plugin, 0L, 20L); - } + private void sendImage() { + PictureWrapper wrapper = new PictureWrapper(plugin, player); - private void sendImage() { - PictureWrapper wrapper = new PictureWrapper(plugin, player); - - if (config.getBoolean("async", true)) - wrapper.runTaskAsynchronously(plugin); - else - wrapper.runTask(plugin); - } + if (config.getBoolean("async", true)) { + wrapper.runTaskAsynchronously(plugin); + } else { + wrapper.runTask(plugin); + } + } } diff --git a/src/main/java/me/itsnathang/picturelogin/listeners/QuitListener.java b/src/main/java/me/itsnathang/picturelogin/listeners/QuitListener.java index ef017db..3dd043a 100644 --- a/src/main/java/me/itsnathang/picturelogin/listeners/QuitListener.java +++ b/src/main/java/me/itsnathang/picturelogin/listeners/QuitListener.java @@ -10,33 +10,40 @@ import me.itsnathang.picturelogin.config.ConfigManager; import me.itsnathang.picturelogin.util.PictureUtil; +import java.util.List; + public class QuitListener implements Listener { - private PictureUtil pictureUtil; - private ConfigManager config; + private final PictureUtil pictureUtil; + private final ConfigManager config; + + public QuitListener(PictureLogin plugin) { + this.config = plugin.getConfigManager(); + this.pictureUtil = plugin.getPictureUtil(); + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + if (!config.getBoolean("show-leave-message", true)) + return; - public QuitListener(PictureLogin plugin) { - this.config = plugin.getConfigManager(); - this.pictureUtil = plugin.getPictureUtil(); - } + Player player = event.getPlayer(); - @EventHandler - public void onQuit(PlayerQuitEvent event) { - if (!config.getBoolean("show-leave-message", true)) - return; + if (!player.hasPermission("picturelogin.show") && config.getBoolean("require-permission", true)) { + return; + } - Player player = event.getPlayer(); - - if(!player.hasPermission("picturelogin.show") && config.getBoolean("require-permission", true)) - return; - - if (config.getBoolean("block-leave-message", true)) - event.setQuitMessage(null); + if (config.getBoolean("block-leave-message", true)) { + event.setQuitMessage(null); + } - ImageMessage picture_message = pictureUtil.createPictureMessage(player, config.getStringList("leave-messages")); + List leaveMessages = config.getStringList("leave-messages"); + var picture_message = pictureUtil.createPictureMessage(player, leaveMessages); - if (picture_message == null) return; + if (picture_message == null) { + return; + } - pictureUtil.sendOutPictureMessage(picture_message); - } + pictureUtil.sendOutPictureMessage(picture_message); + } } diff --git a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java index 659fa43..ba43d74 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java +++ b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java @@ -12,9 +12,9 @@ public class ImageMessage { private final static char TRANSPARENT_CHAR = ' '; - + private String[] lines; - + public ImageMessage(BufferedImage image, int height, char imgChar) { Color[][] chatColors = toChatColorArray(image, height); lines = toImgMessage(chatColors, imgChar); @@ -39,8 +39,8 @@ private Color[][] toChatColorArray(BufferedImage image, int height) { private BufferedImage resizeImage(BufferedImage originalImage, int width, int height) { AffineTransform af = new AffineTransform(); af.scale( - width / (double) originalImage.getWidth(), - height / (double) originalImage.getHeight()); + width / (double) originalImage.getWidth(), + height / (double) originalImage.getHeight()); AffineTransformOp operation = new AffineTransformOp(af, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); return operation.filter(originalImage, null); @@ -48,28 +48,27 @@ private BufferedImage resizeImage(BufferedImage originalImage, int width, int he private String[] toImgMessage(Color[][] colors, char imgchar) { lines = new String[colors[0].length]; - + for (int y = 0; y < colors[0].length; y++) { StringBuilder line = new StringBuilder(); - for (int x = 0; x < colors.length; x++) { - Color color = colors[x][y]; + for (Color[] value : colors) { + Color color = value[y]; // convert to minedown-styled color string if (color != null) { line.append("&") - .append(colorToHex(colors[x][y])) - .append("&") - .append(imgchar); - } - else { + .append(colorToHex(value[y])) + .append("&") + .append(imgchar); + } else { line.append(TRANSPARENT_CHAR); } } lines[y] = line.toString() + ChatColor.RESET; } - + return lines; } - + private String colorToHex(Color c) { return String.format("#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue()); } diff --git a/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java b/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java index a1dfde0..314173c 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java +++ b/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java @@ -19,93 +19,98 @@ import org.bukkit.entity.Player; public class PictureUtil { - private final PictureLogin plugin; - private ConfigManager config; - - public PictureUtil(PictureLogin plugin) { - this.plugin = plugin; - this.config = plugin.getConfigManager(); - } - - private URL newURL(String player_uuid, String player_name) { - String url = config.getURL() - .replace("%uuid%" , player_uuid) - .replace("%pname%", player_name); - - try { - return new URL(url); - } catch (Exception e) { - plugin.getLogger().warning("Could not read url from file."); - return null; - } - } - - private BufferedImage getImage(Player player) { - URL head_image = newURL(player.getUniqueId().toString(), player.getName()); - - // URL Formatted correctly. - if (head_image != null) { + private final PictureLogin plugin; + private final ConfigManager config; + + public PictureUtil(PictureLogin plugin) { + this.plugin = plugin; + this.config = plugin.getConfigManager(); + } + + private URL newURL(String player_uuid, String player_name) { + String url = config.getURL() + .replace("%uuid%", player_uuid) + .replace("%pname%", player_name); + try { + return new URL(url); + } catch (Exception e) { + plugin.getLogger().warning("Could not read url from file."); + return null; + } + } + + private BufferedImage getImage(Player player) { + URL head_image = newURL(player.getUniqueId().toString(), player.getName()); + + // URL Formatted correctly. + if (head_image != null) { try { - //User-Agent is needed for HTTP requests - HttpURLConnection connection = (HttpURLConnection) head_image.openConnection(); - connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); + //User-Agent is needed for HTTP requests + HttpURLConnection connection = (HttpURLConnection) head_image.openConnection(); + connection.setRequestProperty("User-Agent", + "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); return ImageIO.read(connection.getInputStream()); } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); plugin.getLogger().warning(tl("error_retrieving_avatar")); } - } - - // Incorrectly formatted URL or couldn't load from URL - try { - return ImageIO.read(new FallbackPicture(plugin).get()); - } catch (Exception e) { - plugin.getLogger().warning(tl("error_fallback_img")); - return null; - } - } - - public ImageMessage createPictureMessage(Player player, List messages) { - BufferedImage image = getImage(player); - - if (image == null) return null; - - messages.replaceAll((message) -> addPlaceholders(message, player)); - - return config.getMessage(messages, image); - } - - public void sendOutPictureMessage(ImageMessage picture_message) { - plugin.getServer().getOnlinePlayers().forEach((online_player) -> { - if (config.getBoolean("clear-chat", false)) - clearChat(online_player); - - picture_message.sendToPlayer(online_player); - }); - } - - // String Utility Functions - - private String addPlaceholders(String msg, Player player) { - msg = ChatColor.translateAlternateColorCodes('&', msg); - - msg = msg.replace("%pname%", player.getName()); - msg = msg.replace("%uuid%", player.getUniqueId().toString()); - msg = msg.replace("%online%", String.valueOf(plugin.getServer().getOnlinePlayers().size())); - msg = msg.replace("%max%", String.valueOf(plugin.getServer().getMaxPlayers())); - msg = msg.replace("%motd%", plugin.getServer().getMotd()); - msg = msg.replace("%displayname%", player.getDisplayName()); - - if (Hooks.PLACEHOLDER_API) - msg = PlaceholderAPI.setPlaceholders(player, msg); - - return msg; - } - - public void clearChat(Player player) { - for (int i = 0; i < 20; i++) { - player.sendMessage(""); - } - } + } + + // Incorrectly formatted URL or couldn't load from URL + try { + return ImageIO.read(new FallbackPicture(plugin).get()); + } catch (Exception e) { + plugin.getLogger().warning(tl("error_fallback_img")); + return null; + } + } + + public ImageMessage createPictureMessage(Player player, List messages) { + BufferedImage image = getImage(player); + + if (image == null) { + return null; + } + + messages.replaceAll((message) -> addPlaceholders(message, player)); + + return config.getMessage(messages, image); + } + + public void sendOutPictureMessage(ImageMessage picture_message) { + plugin.getServer().getOnlinePlayers().forEach((online_player) -> { + if (config.getBoolean("clear-chat", false)) + clearChat(online_player); + + picture_message.sendToPlayer(online_player); + }); + } + + /* + Here be String utility methods + */ + + private String addPlaceholders(String msg, Player player) { + msg = ChatColor.translateAlternateColorCodes('&', msg); + + msg = msg.replace("%pname%", player.getName()); + msg = msg.replace("%uuid%", player.getUniqueId().toString()); + msg = msg.replace("%online%", String.valueOf(plugin.getServer().getOnlinePlayers().size())); + msg = msg.replace("%max%", String.valueOf(plugin.getServer().getMaxPlayers())); + msg = msg.replace("%motd%", plugin.getServer().getMotd()); + msg = msg.replace("%displayname%", player.getDisplayName()); + + if (Hooks.PLACEHOLDER_API) { + msg = PlaceholderAPI.setPlaceholders(player, msg); + } + + return msg; + } + + public void clearChat(Player player) { + for (int i = 0; i < 20; i++) { + player.sendMessage(""); + } + } } diff --git a/src/main/java/me/itsnathang/picturelogin/util/PictureWrapper.java b/src/main/java/me/itsnathang/picturelogin/util/PictureWrapper.java index 318a954..31ed8fb 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/PictureWrapper.java +++ b/src/main/java/me/itsnathang/picturelogin/util/PictureWrapper.java @@ -7,14 +7,14 @@ import org.bukkit.scheduler.BukkitRunnable; public class PictureWrapper extends BukkitRunnable { - private PictureUtil pictureUtil; - private ConfigManager config; - private Player player; + private final PictureUtil pictureUtil; + private final ConfigManager config; + private final Player player; public PictureWrapper(PictureLogin plugin, Player player) { this.pictureUtil = plugin.getPictureUtil(); - this.config = plugin.getConfigManager(); - this.player = player; + this.config = plugin.getConfigManager(); + this.player = player; } @Override @@ -23,36 +23,38 @@ public void run() { } private boolean checkPermission() { - if (!config.getBoolean("require-permission", true)) + if (!config.getBoolean("require-permission", true)) { return true; + } return player.hasPermission("picturelogin.show"); } private ImageMessage getMessage() { - String msgType; + boolean firstTime = config.getBoolean("show-first-join", true) && !player.hasPlayedBefore(); // if it's a player's first time and feature is enabled, show different message - if (config.getBoolean("show-first-join", true) && !player.hasPlayedBefore()) - msgType = "first-join-messages"; - else - msgType = "messages"; + String msgType = firstTime ? "first-join-messages" : "messages"; return pictureUtil.createPictureMessage(player, config.getStringList(msgType)); } private void sendImage() { - // only show message for players with picturelogin.show permission - if(!checkPermission()) return; + if (!checkPermission()) { // only show message for players with picturelogin.show permission + return; + } ImageMessage pictureMessage = getMessage(); - if (pictureMessage == null) return; + if (pictureMessage == null) { + return; + } // send only to the player that joined? if (config.getBoolean("player-only", true)) { - if (config.getBoolean("clear-chat", false)) + if (config.getBoolean("clear-chat", false)) { pictureUtil.clearChat(player); + } pictureMessage.sendToPlayer(player); return; diff --git a/src/main/java/me/itsnathang/picturelogin/util/Updater.java b/src/main/java/me/itsnathang/picturelogin/util/Updater.java index 73a371a..20cbe22 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/Updater.java +++ b/src/main/java/me/itsnathang/picturelogin/util/Updater.java @@ -12,7 +12,7 @@ public class Updater { - public Updater(Logger log, String currentVersion) { + public Updater(Logger log, String currentVersion) { final String USER_AGENT = "PictureLogin Plugin"; final String PLUGIN_ID = "4514"; @@ -21,8 +21,10 @@ public Updater(Logger log, String currentVersion) { URL url = new URL("https://api.spiget.org/v2/resources/" + PLUGIN_ID + "/versions/latest"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.addRequestProperty("User-Agent", USER_AGENT);// Set User-Agent + // Read downloaded file - JsonObject jsonObject = new JsonParser().parse(new InputStreamReader(connection.getInputStream())).getAsJsonObject(); + var streamReader = new InputStreamReader(connection.getInputStream()); + JsonObject jsonObject = new JsonParser().parse(streamReader).getAsJsonObject(); String latest_version = jsonObject.get("name").toString().replace("\"", ""); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b3903b1..36e5caf 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: PictureLogin main: me.itsnathang.picturelogin.PictureLogin api-version: 1.18 -author: NathanG +author: NathanG, _NickV description: Display a cool login message with a picture of the player's skin. version: ${version} From 32ac93177eeb7e2997d4f11bbfd181566616315a Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:10:42 -0500 Subject: [PATCH 07/69] Update readme.md --- readme.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/readme.md b/readme.md index 8553431..cc7bf20 100644 --- a/readme.md +++ b/readme.md @@ -5,13 +5,7 @@ Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v Picture Login provides a much nicer login message by displaying a picture of the player's head inside of chat. -
- - - -
- -It is a plugin for [Spigot](http://www.spigotmc.org/) and you can find further information [here, on it's plugin page](http://www.spigotmc.org/resources/picture-login.4514/). +For more information, check out the Spigot page: https://www.spigotmc.org/resources/picturelogin-continued.101216/ License --- From 6cadf3cdb4e2e4c5d39bc6873e3e1d4d0733ad1a Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:11:31 -0500 Subject: [PATCH 08/69] Update readme.md --- readme.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index cc7bf20..9ba3721 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,12 @@ Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v Picture Login provides a much nicer login message by displaying a picture of the player's head inside of chat. -For more information, check out the Spigot page: https://www.spigotmc.org/resources/picturelogin-continued.101216/ +Obtaining the plugin +--- + +You can download the plugin here on GitHub, or over at Spigot: + +https://www.spigotmc.org/resources/picturelogin-continued.101216/ License --- From 9cf56c62186d87eacef877edf51f9669f433ed2e Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:12:03 -0500 Subject: [PATCH 09/69] Update readme.md --- readme.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/readme.md b/readme.md index 9ba3721..0c030a0 100644 --- a/readme.md +++ b/readme.md @@ -12,6 +12,13 @@ You can download the plugin here on GitHub, or over at Spigot: https://www.spigotmc.org/resources/picturelogin-continued.101216/ +Credit to... +--- + +The original plugin author, NathanG / ItsNathanG +bobacadodl for his Image Message Library +Crafatar for their avatar service + License --- This plugin is licensed under the MIT License. For more information please refer to LICENSE. From ce1b15028f87fa7e18320e0c042082b3765181b3 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:12:15 -0500 Subject: [PATCH 10/69] Update readme.md --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 0c030a0..e244730 100644 --- a/readme.md +++ b/readme.md @@ -15,9 +15,9 @@ https://www.spigotmc.org/resources/picturelogin-continued.101216/ Credit to... --- -The original plugin author, NathanG / ItsNathanG -bobacadodl for his Image Message Library -Crafatar for their avatar service +- The original plugin author, NathanG / ItsNathanG +- bobacadodl for his Image Message Library +- Crafatar for their avatar service License --- From 33ad5fd6c2b67cf9c9f34420207a7cc59271472e Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:12:46 -0500 Subject: [PATCH 11/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index e244730..fd8a8c3 100644 --- a/readme.md +++ b/readme.md @@ -15,7 +15,7 @@ https://www.spigotmc.org/resources/picturelogin-continued.101216/ Credit to... --- -- The original plugin author, NathanG / ItsNathanG +- The original plugin author, NathanG / ![ItsNathanG](https://github.com/ItsNathanG) - bobacadodl for his Image Message Library - Crafatar for their avatar service From 9d2f115e4c74d03d79913bf569c482946ea197ce Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:12:54 -0500 Subject: [PATCH 12/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index fd8a8c3..53de828 100644 --- a/readme.md +++ b/readme.md @@ -15,7 +15,7 @@ https://www.spigotmc.org/resources/picturelogin-continued.101216/ Credit to... --- -- The original plugin author, NathanG / ![ItsNathanG](https://github.com/ItsNathanG) +- The original plugin author, ![ItsNathanG](https://github.com/ItsNathanG) - bobacadodl for his Image Message Library - Crafatar for their avatar service From e784f951e267ae8fd420018a12d66df3deb1a674 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:28:59 -0500 Subject: [PATCH 13/69] Update readme.md --- readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 53de828..3ecd382 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,6 @@ -Updated to Minecraft 1.18.2 +This is a popular plugin for Minecraft servers (over 50,000 downloads) that has sadly been unsupported for a while; I've updated it to Minecraft 1.18 and will be supporting future versions! + +If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === From 37c6db8e24d36e0cb680f238dd8e8017285253df Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:29:48 -0500 Subject: [PATCH 14/69] Update readme.md --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 3ecd382..cfc7a1b 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,8 @@ This is a popular plugin for Minecraft servers (over 50,000 downloads) that has If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV +![logo](https://user-images.githubusercontent.com/60233722/162335618-c184038f-dcc3-4308-b2f4-0cec9feb12a3.PNG) + Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === From dc90407f61fc540b9fb040faa723cd021f2c8113 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:30:08 -0500 Subject: [PATCH 15/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index cfc7a1b..36e5f55 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ This is a popular plugin for Minecraft servers (over 50,000 downloads) that has If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -![logo](https://user-images.githubusercontent.com/60233722/162335618-c184038f-dcc3-4308-b2f4-0cec9feb12a3.PNG) +![pic](https://user-images.githubusercontent.com/60233722/162335606-abeae73c-3523-4ffd-a49d-9e5e73b735a9.jpg) Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === From fe5a4ca1db83d0950209545ad2b10c57c05573cd Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:30:18 -0500 Subject: [PATCH 16/69] Update readme.md --- readme.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 36e5f55..218ce37 100644 --- a/readme.md +++ b/readme.md @@ -2,9 +2,7 @@ This is a popular plugin for Minecraft servers (over 50,000 downloads) that has If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -![pic](https://user-images.githubusercontent.com/60233722/162335606-abeae73c-3523-4ffd-a49d-9e5e73b735a9.jpg) - -Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) +Picture Login ![pic](https://user-images.githubusercontent.com/60233722/162335606-abeae73c-3523-4ffd-a49d-9e5e73b735a9.jpg) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === Picture Login provides a much nicer login message by displaying a picture of the player's head inside of chat. From c23c255a0dada3557476ece0836711d2d8de297c Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:30:29 -0500 Subject: [PATCH 17/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 218ce37..ae473ae 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ This is a popular plugin for Minecraft servers (over 50,000 downloads) that has If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -Picture Login ![pic](https://user-images.githubusercontent.com/60233722/162335606-abeae73c-3523-4ffd-a49d-9e5e73b735a9.jpg) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) +![pic](https://user-images.githubusercontent.com/60233722/162335606-abeae73c-3523-4ffd-a49d-9e5e73b735a9.jpg) Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === Picture Login provides a much nicer login message by displaying a picture of the player's head inside of chat. From 37aa3264ba136a2370a1a99a51a6cd084401faa7 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:31:14 -0500 Subject: [PATCH 18/69] Update readme.md --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index ae473ae..c1c7f5a 100644 --- a/readme.md +++ b/readme.md @@ -14,6 +14,10 @@ You can download the plugin here on GitHub, or over at Spigot: https://www.spigotmc.org/resources/picturelogin-continued.101216/ +Example +--- +![pictureLogin](https://user-images.githubusercontent.com/60233722/162335735-1ed09b90-4071-4a4a-86d4-882dc9e5c14b.PNG) + Credit to... --- From 644e6fefac41bf7d94d519ba14858f7718d78ded Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:31:30 -0500 Subject: [PATCH 19/69] Update readme.md --- readme.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index c1c7f5a..68b3771 100644 --- a/readme.md +++ b/readme.md @@ -7,6 +7,8 @@ If you're looking for plugin support, you can ping me on my Discord server: http Picture Login provides a much nicer login message by displaying a picture of the player's head inside of chat. +![pictureLogin](https://user-images.githubusercontent.com/60233722/162335735-1ed09b90-4071-4a4a-86d4-882dc9e5c14b.PNG) + Obtaining the plugin --- @@ -14,10 +16,6 @@ You can download the plugin here on GitHub, or over at Spigot: https://www.spigotmc.org/resources/picturelogin-continued.101216/ -Example ---- -![pictureLogin](https://user-images.githubusercontent.com/60233722/162335735-1ed09b90-4071-4a4a-86d4-882dc9e5c14b.PNG) - Credit to... --- From 51de54cb1a2fb459de951f78cf5ca22690369bd7 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:32:01 -0500 Subject: [PATCH 20/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 68b3771..6a21244 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ If you're looking for plugin support, you can ping me on my Discord server: http ![pic](https://user-images.githubusercontent.com/60233722/162335606-abeae73c-3523-4ffd-a49d-9e5e73b735a9.jpg) Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === -Picture Login provides a much nicer login message by displaying a picture of the player's head inside of chat. +Picture Login creates a fancy login message by displaying a picture of the player's head inside of chat! ![pictureLogin](https://user-images.githubusercontent.com/60233722/162335735-1ed09b90-4071-4a4a-86d4-882dc9e5c14b.PNG) From ce0ece0f96341208fa8bfe36620913166eaa9b7a Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:32:55 -0500 Subject: [PATCH 21/69] Update readme.md --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 6a21244..644864b 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,7 @@ This is a popular plugin for Minecraft servers (over 50,000 downloads) that has sadly been unsupported for a while; I've updated it to Minecraft 1.18 and will be supporting future versions! +You can download the plugin here or over on Spigot: https://www.spigotmc.org/resources/picturelogin-continued.101216/ + If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV ![pic](https://user-images.githubusercontent.com/60233722/162335606-abeae73c-3523-4ffd-a49d-9e5e73b735a9.jpg) Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) From 6cf78bd8a5179f2ab2233c01e10d17b9194d8d82 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:33:05 -0500 Subject: [PATCH 22/69] Update readme.md --- readme.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/readme.md b/readme.md index 644864b..6ceaac8 100644 --- a/readme.md +++ b/readme.md @@ -11,13 +11,6 @@ Picture Login creates a fancy login message by displaying a picture of the playe ![pictureLogin](https://user-images.githubusercontent.com/60233722/162335735-1ed09b90-4071-4a4a-86d4-882dc9e5c14b.PNG) -Obtaining the plugin ---- - -You can download the plugin here on GitHub, or over at Spigot: - -https://www.spigotmc.org/resources/picturelogin-continued.101216/ - Credit to... --- From 873568b2d4a2dfae25325dfbef8730b0b91c840e Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 9 Apr 2022 10:04:43 -0500 Subject: [PATCH 23/69] v1.0.1 - Added configurable delay to the sending of images --- pom.xml | 23 +++++-------- .../picturelogin/config/ConfigManager.java | 4 ++- .../picturelogin/listeners/JoinListener.java | 34 ++++++++++++++++--- src/main/resources/config.yml | 11 ++++++ 4 files changed, 51 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 03d3836..2b1a52d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,15 +4,15 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - me.itsnathang - PictureLogin - 1.6 + me.nickv + PictureLogin-Continued + 1.0.1 jar Picture Login - NathanG + NathanG, _NickV me.itsnathang.picturelogin.PictureLogin @@ -23,7 +23,7 @@ placeholderapi - http://repo.extendedclip.com/content/repositories/placeholderapi/ + https://repo.extendedclip.com/content/repositories/placeholderapi/ CodeMC @@ -80,11 +80,12 @@ + org.apache.maven.plugins maven-compiler-plugin 3.1 - 1.8 - 1.8 + 10 + 10 @@ -129,14 +130,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - - 10 - 10 - - diff --git a/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java b/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java index bb4af7d..e3e8efd 100644 --- a/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java +++ b/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java @@ -26,7 +26,7 @@ public void reloadConfig() { File conf = new File(plugin.getDataFolder() + File.separator + "config.yml"); if (!conf.exists()) { - plugin.saveResource("config.yml", true); + plugin.saveResource("config.yml", true); // Create new config } config = YamlConfiguration.loadConfiguration(conf); @@ -61,6 +61,8 @@ public ImageMessage getMessage(List messages, BufferedImage image) { return imageMessage.appendText(msg); } + public long getLong(String key) { return config.getLong(key); } + public boolean getBoolean(String key) { return config.getBoolean(key); } diff --git a/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java b/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java index ef9f298..aeceabb 100644 --- a/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java +++ b/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java @@ -35,10 +35,9 @@ public void onJoin(PlayerJoinEvent event) { if (Hooks.AUTHME) { authMeLogin(); - return; + } else { + sendImage(); } - - sendImage(); } private void authMeLogin() { @@ -63,10 +62,35 @@ public void run() { private void sendImage() { PictureWrapper wrapper = new PictureWrapper(plugin, player); + long delay = config.getLong("message-delay"); + + // Don't allow invalid number here + if (delay < 0) { + delay = 0; + } + if (config.getBoolean("async", true)) { - wrapper.runTaskAsynchronously(plugin); + wrapper.runTaskLaterAsynchronously(plugin, delay); } else { - wrapper.runTask(plugin); + wrapper.runTaskLater(plugin, delay); } } } + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6360dde..17e76e8 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -75,6 +75,17 @@ leave-messages: - '&7ยป &aPictureLogin &7by &aNathanG&7.' - '' +############# +# Message delay +######## +# Whether to delay the sending of all picture messages. +# +# This delay is in server ticks! For reference, there are 20 server ticks in 1 second. +# +# For example: To set a delay of 2 seconds, set message-delay to 40. + +message-delay: 0 + ############# # Fallback ######## From 082aec4a49edde50d5ad1c005b5ebbbca17cc12a Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 9 Apr 2022 21:09:55 -0500 Subject: [PATCH 24/69] Updated bStats id --- src/main/java/me/itsnathang/picturelogin/PictureLogin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java index 297c85f..5e9e2e4 100644 --- a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java +++ b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java @@ -47,7 +47,7 @@ public void onEnable() { // bStats integration if (configManager.getBoolean("metrics", true)) { - new Metrics(this, 2225); // 2225 is the bStats plugin ID for PictureLogin + new Metrics(this, 14892); // 2225 is the bStats plugin ID for PictureLogin } } From bc921866440998c15ecd2b298d65885c6344838a Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 10 Apr 2022 18:56:01 -0500 Subject: [PATCH 25/69] working on centering image --- pom.xml | 4 +- .../picturelogin/commands/BaseCommand.java | 80 ++++++++++++++++--- .../picturelogin/config/ConfigManager.java | 12 ++- .../picturelogin/listeners/JoinListener.java | 30 ++----- .../picturelogin/listeners/QuitListener.java | 3 +- .../picturelogin/util/ImageMessage.java | 22 +---- .../picturelogin/util/PictureUtil.java | 30 ++++++- .../picturelogin/util/Translate.java | 3 +- src/main/resources/config.yml | 4 + 9 files changed, 126 insertions(+), 62 deletions(-) diff --git a/pom.xml b/pom.xml index 2b1a52d..903b3e0 100644 --- a/pom.xml +++ b/pom.xml @@ -84,8 +84,8 @@ maven-compiler-plugin 3.1 - 10 - 10 + 16 + 16 diff --git a/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java b/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java index 4eebf98..356d9a8 100644 --- a/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java +++ b/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java @@ -1,40 +1,100 @@ package me.itsnathang.picturelogin.commands; +import me.itsnathang.picturelogin.util.PictureUtil; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import me.itsnathang.picturelogin.PictureLogin; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import static me.itsnathang.picturelogin.util.Translate.tl; -public class BaseCommand implements CommandExecutor { +public class BaseCommand implements CommandExecutor, TabCompleter { private final PictureLogin plugin; + private final PictureUtil util; public BaseCommand(PictureLogin plugin) { this.plugin = plugin; + util = plugin.getPictureUtil(); } @Override public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) { if (!s.hasPermission("picturelogin.main")) { s.sendMessage(tl("no_permission")); - return false; + return true; + } + + if (args.length < 1) { + s.sendMessage(ChatColor.GREEN + "PictureLogin-Continued " + ChatColor.GRAY + "v" + ChatColor.GREEN + plugin.getDescription().getVersion() + ChatColor.GRAY + " by " + ChatColor.GREEN + "_NickVo"); + s.sendMessage(tl("reload_config_help")); + return true; } - // Check if command is /picturelogin reload - if (args.length == 1 && args[0].equalsIgnoreCase("reload")) { + if (args[0].equalsIgnoreCase("reload")) { plugin.getConfigManager().reloadConfig(); s.sendMessage(tl("reload_config")); return true; } - // Default to sending help - s.sendMessage(ChatColor.GREEN + "PictureLogin " + ChatColor.GRAY + "v" + - ChatColor.GREEN + plugin.getDescription().getVersion() + ChatColor.GRAY + " by " + - ChatColor.GREEN + "NathanG"); - s.sendMessage(tl("reload_config_help")); - return true; + if (!(s instanceof Player player)) { + s.sendMessage(ChatColor.RED + "The test command can only be ran in-game."); + return true; + } + + // Test command allows admins to test the images they've configured + if (args[0].equalsIgnoreCase("test")) { + if (args.length < 2) { + util.sendImage(player); // If they don't specify another arg, just show join image + return true; + } + + switch (args[1]) { + case "leave" -> util.getLeaveMessage(player).sendToPlayer(player); + case "join" -> util.sendImage(player); + case "first-join" -> util.getFirstJoinMessage(player).sendToPlayer(player); + } + } + + return false; + } + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { + if (!sender.hasPermission("picturelogin.main")) { + return List.of(); // Empty list to stop further tab completion + } + + if (args.length == 1) { + return getResults(args, List.of("reload", "test")); + } + + // Sub-commands for the test command + if (args.length == 2 && args[0].equalsIgnoreCase("test")) { + return getResults(args, List.of("first-join", "join", "leave")); + } + + return List.of(); // Empty list to stop further tab completion + } + + private List getResults(String[] args, List toSearch) { + List results = new ArrayList<>(); + // This loop narrows down the tab complete results while typing + for (String s : toSearch) { + int index = args.length - 1; + if (s.toLowerCase().startsWith(args[index].toLowerCase())) { + results.add(s); + } + } + return results; } + } diff --git a/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java b/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java index e3e8efd..4b57cb2 100644 --- a/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java +++ b/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java @@ -43,6 +43,7 @@ private char getChar() { public ImageMessage getMessage(List messages, BufferedImage image) { int imageDimensions = 8, count = 0; + ImageMessage imageMessage = new ImageMessage(image, imageDimensions, getChar()); String[] msg = new String[imageDimensions]; @@ -55,13 +56,16 @@ public ImageMessage getMessage(List messages, BufferedImage image) { msg[count++] = ""; } - if (config.getBoolean("center-text", false)) + if (config.getBoolean("center-text", false)) { return imageMessage.appendCenteredText(msg); - - return imageMessage.appendText(msg); + } else { + return imageMessage.appendText(msg); + } } - public long getLong(String key) { return config.getLong(key); } + public long getLong(String key) { + return config.getLong(key); + } public boolean getBoolean(String key) { return config.getBoolean(key); diff --git a/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java b/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java index aeceabb..a0102ea 100644 --- a/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java +++ b/src/main/java/me/itsnathang/picturelogin/listeners/JoinListener.java @@ -1,27 +1,27 @@ package me.itsnathang.picturelogin.listeners; import fr.xephi.authme.api.v3.AuthMeApi; +import me.itsnathang.picturelogin.PictureLogin; +import me.itsnathang.picturelogin.config.ConfigManager; import me.itsnathang.picturelogin.util.Hooks; -import me.itsnathang.picturelogin.util.PictureWrapper; +import me.itsnathang.picturelogin.util.PictureUtil; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; - -import me.itsnathang.picturelogin.PictureLogin; -import me.itsnathang.picturelogin.config.ConfigManager; -import me.itsnathang.picturelogin.util.PictureUtil; import org.bukkit.scheduler.BukkitRunnable; public class JoinListener implements Listener { private final PictureLogin plugin; private final ConfigManager config; + private final PictureUtil utils; private Player player; public JoinListener(PictureLogin plugin) { this.plugin = plugin; this.config = plugin.getConfigManager(); + this.utils = plugin.getPictureUtil(); } @EventHandler(priority = EventPriority.HIGH) @@ -36,7 +36,7 @@ public void onJoin(PlayerJoinEvent event) { if (Hooks.AUTHME) { authMeLogin(); } else { - sendImage(); + utils.sendImage(player); } } @@ -51,7 +51,7 @@ public void run() { // Check for authentication if (AuthMeApi.getInstance().isAuthenticated(player)) { - sendImage(); + utils.sendImage(player); this.cancel(); } } @@ -59,22 +59,6 @@ public void run() { }.runTaskTimer(plugin, 0L, 20L); } - private void sendImage() { - PictureWrapper wrapper = new PictureWrapper(plugin, player); - - long delay = config.getLong("message-delay"); - - // Don't allow invalid number here - if (delay < 0) { - delay = 0; - } - - if (config.getBoolean("async", true)) { - wrapper.runTaskLaterAsynchronously(plugin, delay); - } else { - wrapper.runTaskLater(plugin, delay); - } - } } diff --git a/src/main/java/me/itsnathang/picturelogin/listeners/QuitListener.java b/src/main/java/me/itsnathang/picturelogin/listeners/QuitListener.java index 3dd043a..061c482 100644 --- a/src/main/java/me/itsnathang/picturelogin/listeners/QuitListener.java +++ b/src/main/java/me/itsnathang/picturelogin/listeners/QuitListener.java @@ -36,8 +36,7 @@ public void onQuit(PlayerQuitEvent event) { event.setQuitMessage(null); } - List leaveMessages = config.getStringList("leave-messages"); - var picture_message = pictureUtil.createPictureMessage(player, leaveMessages); + ImageMessage picture_message = pictureUtil.getLeaveMessage(player); if (picture_message == null) { return; diff --git a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java index ba43d74..44df91f 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java +++ b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java @@ -1,11 +1,11 @@ package me.itsnathang.picturelogin.util; import de.themoep.minedown.MineDown; +import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import org.bukkit.util.ChatPaginator; -import java.awt.*; +import java.awt.Color; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; @@ -85,8 +85,7 @@ public ImageMessage appendText(String... text) { public ImageMessage appendCenteredText(String... text) { for (int y = 0; y < lines.length; y++) { if (text.length > y) { - int len = ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH - lines[y].length(); - lines[y] = lines[y] + center(text[y], len); + lines[y] += StringUtils.center(text[y], lines[y].length()); } else { return this; } @@ -94,21 +93,6 @@ public ImageMessage appendCenteredText(String... text) { return this; } - private String center(String s, int length) { - if (s.length() > length) { - return s.substring(0, length); - } else if (s.length() == length) { - return s; - } else { - int leftPadding = (length - s.length()) / 2; - StringBuilder leftBuilder = new StringBuilder(); - for (int i = 0; i < leftPadding; i++) { - leftBuilder.append(" "); - } - return leftBuilder.toString() + s; - } - } - public void sendToPlayer(Player player) { for (String line : lines) { player.spigot().sendMessage(MineDown.parse(line)); diff --git a/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java b/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java index 314173c..82d2590 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java +++ b/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java @@ -79,13 +79,41 @@ public ImageMessage createPictureMessage(Player player, List messages) { public void sendOutPictureMessage(ImageMessage picture_message) { plugin.getServer().getOnlinePlayers().forEach((online_player) -> { - if (config.getBoolean("clear-chat", false)) + if (config.getBoolean("clear-chat", false)) { clearChat(online_player); + } picture_message.sendToPlayer(online_player); }); } + public void sendImage(Player player) { + PictureWrapper wrapper = new PictureWrapper(plugin, player); + + long delay = config.getLong("message-delay"); + + // Don't allow invalid number here + if (delay < 0) { + delay = 0; + } + + if (config.getBoolean("async", true)) { + wrapper.runTaskLaterAsynchronously(plugin, delay); + } else { + wrapper.runTaskLater(plugin, delay); + } + } + + public ImageMessage getLeaveMessage(Player player) { + List list = config.getStringList("leave-messages"); + return createPictureMessage(player, list); + } + + public ImageMessage getFirstJoinMessage(Player player) { + List list = plugin.getConfigManager().getStringList("first-join-messages"); + return createPictureMessage(player, list); + } + /* Here be String utility methods */ diff --git a/src/main/java/me/itsnathang/picturelogin/util/Translate.java b/src/main/java/me/itsnathang/picturelogin/util/Translate.java index 5b7149c..1cf771e 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/Translate.java +++ b/src/main/java/me/itsnathang/picturelogin/util/Translate.java @@ -21,7 +21,8 @@ private static String translate(String key) { private static String getFilteredTranslation(String key) { return color(messages.getString(key) .replace("%prefix%", messages.getString("prefix")) - .replace("%new_line%", "\n")); + .replace("%new_line%", "\n") + ); } private static String color(String message) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 17e76e8..e30ad8d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -22,10 +22,12 @@ # %max% - Maximum players # %motd% - MOTD # %displayname% - Joined player's display name +# %new_line% - Create a new line on the screen ######## # NOTE: You may also use variables from the plugin # PlaceholderAPI if it is installed. +# Do not add additional messages to this list - Max of 8 allowed (that's the length of the player head image!) messages: - '' - '&7Welcome to &e&lGeneric Server Name&7!' @@ -45,6 +47,7 @@ messages: show-first-join: true +# Do not add additional messages to this list - Max of 8 allowed first-join-messages: - '' - '&7Welcome to &e&lGeneric Server Name&7!' @@ -65,6 +68,7 @@ first-join-messages: show-leave-message: false +# Do not add additional messages to this list - Max of 8 allowed leave-messages: - '' - '&e%pname% &7has left the server!' From b2c7c221b0dfe285658251581c659021953e18ae Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 14 Apr 2022 09:53:25 -0500 Subject: [PATCH 26/69] RGB support added for text --- pom.xml | 9 ++++++ .../itsnathang/picturelogin/PictureLogin.java | 9 +++--- .../picturelogin/commands/BaseCommand.java | 8 ++--- .../picturelogin/config/ConfigManager.java | 2 +- .../picturelogin/util/ImageMessage.java | 5 +++- .../picturelogin/util/PictureUtil.java | 29 +++++++++---------- .../picturelogin/util/Translate.java | 28 ++++++++++++++++-- 7 files changed, 61 insertions(+), 29 deletions(-) diff --git a/pom.xml b/pom.xml index 903b3e0..7b2032e 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,10 @@ minedown-repo https://repo.minebench.de/ + + sonatype-oss-snapshots1 + https://s01.oss.sonatype.org/content/repositories/snapshots/ + @@ -66,6 +70,11 @@ 1.6.1-SNAPSHOT compile
+ + net.kyori + adventure-text-minimessage + 4.10.1 + diff --git a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java index 5e9e2e4..74f6290 100644 --- a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java +++ b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java @@ -1,15 +1,15 @@ package me.itsnathang.picturelogin; -import me.itsnathang.picturelogin.listeners.JoinListener; -import me.itsnathang.picturelogin.listeners.QuitListener; import me.itsnathang.picturelogin.commands.BaseCommand; import me.itsnathang.picturelogin.config.ConfigManager; +import me.itsnathang.picturelogin.listeners.JoinListener; +import me.itsnathang.picturelogin.listeners.QuitListener; import me.itsnathang.picturelogin.util.Hooks; import me.itsnathang.picturelogin.util.PictureUtil; - import me.itsnathang.picturelogin.util.Updater; -import org.bukkit.plugin.java.JavaPlugin; import org.bstats.bukkit.Metrics; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; /* Updated to work with Minecraft 1.18.2 by _NickV on 4/7/2022 @@ -49,6 +49,7 @@ public void onEnable() { if (configManager.getBoolean("metrics", true)) { new Metrics(this, 14892); // 2225 is the bStats plugin ID for PictureLogin } + } public ConfigManager getConfigManager() { diff --git a/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java b/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java index 356d9a8..ae16654 100644 --- a/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java +++ b/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java @@ -1,19 +1,16 @@ package me.itsnathang.picturelogin.commands; +import me.itsnathang.picturelogin.PictureLogin; import me.itsnathang.picturelogin.util.PictureUtil; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; - -import me.itsnathang.picturelogin.PictureLogin; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import static me.itsnathang.picturelogin.util.Translate.tl; @@ -34,7 +31,8 @@ public boolean onCommand(CommandSender s, Command cmd, String label, String[] ar } if (args.length < 1) { - s.sendMessage(ChatColor.GREEN + "PictureLogin-Continued " + ChatColor.GRAY + "v" + ChatColor.GREEN + plugin.getDescription().getVersion() + ChatColor.GRAY + " by " + ChatColor.GREEN + "_NickVo"); + s.sendMessage(ChatColor.GREEN + "PictureLogin " + ChatColor.GRAY + "v" + ChatColor.GREEN + + plugin.getDescription().getVersion() + ChatColor.GRAY + " by " + ChatColor.GREEN + "_NickVo"); s.sendMessage(tl("reload_config_help")); return true; } diff --git a/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java b/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java index 4b57cb2..e2c7a37 100644 --- a/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java +++ b/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java @@ -44,7 +44,7 @@ private char getChar() { public ImageMessage getMessage(List messages, BufferedImage image) { int imageDimensions = 8, count = 0; - ImageMessage imageMessage = new ImageMessage(image, imageDimensions, getChar()); + ImageMessage imageMessage = new ImageMessage(messages, image, imageDimensions, getChar()); String[] msg = new String[imageDimensions]; for (String message : messages) { diff --git a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java index 44df91f..4bcfc0b 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java +++ b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java @@ -9,13 +9,14 @@ import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; +import java.util.List; public class ImageMessage { private final static char TRANSPARENT_CHAR = ' '; private String[] lines; - public ImageMessage(BufferedImage image, int height, char imgChar) { + public ImageMessage(List messages, BufferedImage image, int height, char imgChar) { Color[][] chatColors = toChatColorArray(image, height); lines = toImgMessage(chatColors, imgChar); } @@ -85,6 +86,8 @@ public ImageMessage appendText(String... text) { public ImageMessage appendCenteredText(String... text) { for (int y = 0; y < lines.length; y++) { if (text.length > y) { + System.out.println("String length: " + lines[y].length()); + System.out.println("String " + lines[y]); lines[y] += StringUtils.center(text[y], lines[y].length()); } else { return this; diff --git a/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java b/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java index 82d2590..d46f020 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java +++ b/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java @@ -1,23 +1,25 @@ package me.itsnathang.picturelogin.util; -import static me.itsnathang.picturelogin.util.Translate.tl; - -import java.awt.image.BufferedImage; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.util.List; - -import javax.imageio.ImageIO; - -import me.itsnathang.picturelogin.util.ImageMessage; import me.clip.placeholderapi.PlaceholderAPI; import me.itsnathang.picturelogin.PictureLogin; import me.itsnathang.picturelogin.config.ConfigManager; import me.itsnathang.picturelogin.config.FallbackPicture; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static me.itsnathang.picturelogin.util.Translate.tl; + public class PictureUtil { private final PictureLogin plugin; private final ConfigManager config; @@ -114,11 +116,8 @@ public ImageMessage getFirstJoinMessage(Player player) { return createPictureMessage(player, list); } - /* - Here be String utility methods - */ - private String addPlaceholders(String msg, Player player) { + msg = Translate.translateHexColor(msg); msg = ChatColor.translateAlternateColorCodes('&', msg); msg = msg.replace("%pname%", player.getName()); diff --git a/src/main/java/me/itsnathang/picturelogin/util/Translate.java b/src/main/java/me/itsnathang/picturelogin/util/Translate.java index 1cf771e..df62692 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/Translate.java +++ b/src/main/java/me/itsnathang/picturelogin/util/Translate.java @@ -1,8 +1,12 @@ package me.itsnathang.picturelogin.util; -import org.bukkit.ChatColor; +//import org.bukkit.ChatColor; +import net.md_5.bungee.api.ChatColor; import org.bukkit.configuration.file.YamlConfiguration; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public class Translate { public static YamlConfiguration messages; @@ -21,8 +25,26 @@ private static String translate(String key) { private static String getFilteredTranslation(String key) { return color(messages.getString(key) .replace("%prefix%", messages.getString("prefix")) - .replace("%new_line%", "\n") - ); + .replace("%new_line%", "\n")); + } + + public static String translateHexColor(final String message) { + final char colorChar = ChatColor.COLOR_CHAR; + + Pattern pattern = Pattern.compile("(#[a-fA-F0-9]{6})"); + final Matcher matcher = pattern.matcher(message); + final StringBuilder buffer = new StringBuilder(message.length() + 4 * 8); + + while (matcher.find()) { + final String group = matcher.group(1); + + matcher.appendReplacement(buffer, colorChar + "x" + + colorChar + group.charAt(0) + colorChar + group.charAt(1) + + colorChar + group.charAt(2) + colorChar + group.charAt(3) + + colorChar + group.charAt(4) + colorChar + group.charAt(5)); + } + + return matcher.appendTail(buffer).toString(); } private static String color(String message) { From 00c82710420b9027e2b43dd36e229adfffe48b2b Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 14 Apr 2022 09:57:50 -0500 Subject: [PATCH 27/69] RGB support added for text --- src/main/java/me/itsnathang/picturelogin/util/Updater.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/itsnathang/picturelogin/util/Updater.java b/src/main/java/me/itsnathang/picturelogin/util/Updater.java index 20cbe22..359ca41 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/Updater.java +++ b/src/main/java/me/itsnathang/picturelogin/util/Updater.java @@ -14,7 +14,7 @@ public class Updater { public Updater(Logger log, String currentVersion) { final String USER_AGENT = "PictureLogin Plugin"; - final String PLUGIN_ID = "4514"; + final String PLUGIN_ID = "101216"; // This is the Spigot plugin ID try { // Connect to SpiGet From 29adcc59a3fd9a449a3de170690aa7a0d16d8111 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 14 Apr 2022 09:58:24 -0500 Subject: [PATCH 28/69] RGB support added for text --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7b2032e..f08a133 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.nickv PictureLogin-Continued - 1.0.1 + 1.0.2 jar Picture Login From 65027d83ebb6112da50cf53bb5b4171517904310 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 14 Apr 2022 21:51:08 -0500 Subject: [PATCH 29/69] RGB support added for text --- .../java/me/itsnathang/picturelogin/util/ImageMessage.java | 3 +-- src/main/java/me/itsnathang/picturelogin/util/Translate.java | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java index 4bcfc0b..0349362 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java +++ b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java @@ -9,6 +9,7 @@ import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; +import java.util.Arrays; import java.util.List; public class ImageMessage { @@ -86,8 +87,6 @@ public ImageMessage appendText(String... text) { public ImageMessage appendCenteredText(String... text) { for (int y = 0; y < lines.length; y++) { if (text.length > y) { - System.out.println("String length: " + lines[y].length()); - System.out.println("String " + lines[y]); lines[y] += StringUtils.center(text[y], lines[y].length()); } else { return this; diff --git a/src/main/java/me/itsnathang/picturelogin/util/Translate.java b/src/main/java/me/itsnathang/picturelogin/util/Translate.java index df62692..e758324 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/Translate.java +++ b/src/main/java/me/itsnathang/picturelogin/util/Translate.java @@ -1,6 +1,5 @@ package me.itsnathang.picturelogin.util; -//import org.bukkit.ChatColor; import net.md_5.bungee.api.ChatColor; import org.bukkit.configuration.file.YamlConfiguration; From 0d1ded9efed0d67f4baeba8745f17df56a1f06a6 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 14 Apr 2022 22:44:27 -0500 Subject: [PATCH 30/69] Centering feature works! --- .../itsnathang/picturelogin/PictureLogin.java | 1 - .../picturelogin/util/DefaultFontInfo.java | 130 ++++++++++++++++++ .../itsnathang/picturelogin/util/Hooks.java | 6 +- .../picturelogin/util/ImageMessage.java | 52 ++++++- .../picturelogin/util/PictureUtil.java | 2 +- 5 files changed, 179 insertions(+), 12 deletions(-) create mode 100644 src/main/java/me/itsnathang/picturelogin/util/DefaultFontInfo.java diff --git a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java index 74f6290..40540e1 100644 --- a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java +++ b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java @@ -8,7 +8,6 @@ import me.itsnathang.picturelogin.util.PictureUtil; import me.itsnathang.picturelogin.util.Updater; import org.bstats.bukkit.Metrics; -import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; /* diff --git a/src/main/java/me/itsnathang/picturelogin/util/DefaultFontInfo.java b/src/main/java/me/itsnathang/picturelogin/util/DefaultFontInfo.java new file mode 100644 index 0000000..a989667 --- /dev/null +++ b/src/main/java/me/itsnathang/picturelogin/util/DefaultFontInfo.java @@ -0,0 +1,130 @@ +package me.itsnathang.picturelogin.util; + +public enum DefaultFontInfo { + A('A', 5), + a('a', 5), + B('B', 5), + b('b', 5), + C('C', 5), + c('c', 5), + D('D', 5), + d('d', 5), + E('E', 5), + e('e', 5), + F('F', 5), + f('f', 4), + G('G', 5), + g('g', 5), + H('H', 5), + h('h', 5), + I('I', 3), + i('i', 1), + J('J', 5), + j('j', 5), + K('K', 5), + k('k', 4), + L('L', 5), + l('l', 1), + M('M', 5), + m('m', 5), + N('N', 5), + n('n', 5), + O('O', 5), + o('o', 5), + P('P', 5), + p('p', 5), + Q('Q', 5), + q('q', 5), + R('R', 5), + r('r', 5), + S('S', 5), + s('s', 5), + T('T', 5), + t('t', 4), + U('U', 5), + u('u', 5), + V('V', 5), + v('v', 5), + W('W', 5), + w('w', 5), + X('X', 5), + x('x', 5), + Y('Y', 5), + y('y', 5), + Z('Z', 5), + z('z', 5), + NUM_1('1', 5), + NUM_2('2', 5), + NUM_3('3', 5), + NUM_4('4', 5), + NUM_5('5', 5), + NUM_6('6', 5), + NUM_7('7', 5), + NUM_8('8', 5), + NUM_9('9', 5), + NUM_0('0', 5), + EXCLAMATION_POINT('!', 1), + AT_SYMBOL('@', 6), + NUM_SIGN('#', 5), + DOLLAR_SIGN('$', 5), + PERCENT('%', 5), + UP_ARROW('^', 5), + AMPERSAND('&', 5), + ASTERISK('*', 5), + LEFT_PARENTHESIS('(', 4), + RIGHT_PERENTHESIS(')', 4), + MINUS('-', 5), + UNDERSCORE('_', 5), + PLUS_SIGN('+', 5), + EQUALS_SIGN('=', 5), + LEFT_CURL_BRACE('{', 4), + RIGHT_CURL_BRACE('}', 4), + LEFT_BRACKET('[', 3), + RIGHT_BRACKET(']', 3), + COLON(':', 1), + SEMI_COLON(';', 1), + DOUBLE_QUOTE('"', 3), + SINGLE_QUOTE('\'', 1), + LEFT_ARROW('<', 4), + RIGHT_ARROW('>', 4), + QUESTION_MARK('?', 5), + SLASH('/', 5), + BACK_SLASH('\\', 5), + LINE('|', 1), + TILDE('~', 5), + TICK('`', 2), + PERIOD('.', 1), + COMMA(',', 1), + SPACE(' ', 3), + DEFAULT('a', 4); + + private final char character; + private final int length; + + DefaultFontInfo(char character, int length) { + this.character = character; + this.length = length; + } + + public char getCharacter() { + return this.character; + } + + public int getLength() { + return this.length; + } + + public int getBoldLength() { + if (this == DefaultFontInfo.SPACE) { + return this.getLength(); + } + return this.length + 1; + } + + public static DefaultFontInfo getDefaultFontInfo(char c) { + for (DefaultFontInfo dFI : DefaultFontInfo.values()) { + if (dFI.getCharacter() == c) return dFI; + } + return DefaultFontInfo.DEFAULT; + } +} diff --git a/src/main/java/me/itsnathang/picturelogin/util/Hooks.java b/src/main/java/me/itsnathang/picturelogin/util/Hooks.java index 9563918..07f2348 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/Hooks.java +++ b/src/main/java/me/itsnathang/picturelogin/util/Hooks.java @@ -6,9 +6,9 @@ import java.util.logging.Logger; public class Hooks { - private PluginManager plugins; - private ConfigManager config; - private Logger logger; + private final PluginManager plugins; + private final ConfigManager config; + private final Logger logger; public static boolean AUTHME; public static boolean PLACEHOLDER_API; diff --git a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java index 0349362..ba139ac 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java +++ b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java @@ -1,7 +1,6 @@ package me.itsnathang.picturelogin.util; import de.themoep.minedown.MineDown; -import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -9,7 +8,6 @@ import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; -import java.util.Arrays; import java.util.List; public class ImageMessage { @@ -57,10 +55,7 @@ private String[] toImgMessage(Color[][] colors, char imgchar) { Color color = value[y]; // convert to minedown-styled color string if (color != null) { - line.append("&") - .append(colorToHex(value[y])) - .append("&") - .append(imgchar); + line.append("&").append(colorToHex(value[y])).append("&").append(imgchar); } else { line.append(TRANSPARENT_CHAR); } @@ -87,7 +82,7 @@ public ImageMessage appendText(String... text) { public ImageMessage appendCenteredText(String... text) { for (int y = 0; y < lines.length; y++) { if (text.length > y) { - lines[y] += StringUtils.center(text[y], lines[y].length()); + lines[y] += centerMessage(text[y]); } else { return this; } @@ -95,9 +90,52 @@ public ImageMessage appendCenteredText(String... text) { return this; } + /* + Credit to https://www.spigotmc.org/members/sirspoodles.109063/ for this method + https://www.spigotmc.org/threads/free-code-sending-perfectly-centered-chat-message.95872/ + */ + public String centerMessage(String message) { + if (message == null || message.equals("")) { + message = ""; + } + + message = ChatColor.translateAlternateColorCodes('&', message); + + int messagePxSize = 0; + boolean previousCode = false; + boolean isBold = false; + + for (char c : message.toCharArray()) { + if (c == 'ยง') { + previousCode = true; + } else if (previousCode) { + previousCode = false; + isBold = c == 'l' || c == 'L'; + } else { + var dFI = DefaultFontInfo.getDefaultFontInfo(c); + messagePxSize += isBold ? dFI.getBoldLength() : dFI.getLength(); + messagePxSize++; + } + } + + int halvedMessageSize = messagePxSize / 2; + int CENTER_PX = 154; + int toCompensate = CENTER_PX - halvedMessageSize; + int spaceLength = DefaultFontInfo.SPACE.getLength() + 1; + int compensated = 0; + + StringBuilder sb = new StringBuilder(); + while (compensated < toCompensate) { + sb.append(" "); + compensated += spaceLength; + } + return sb + message; + } + public void sendToPlayer(Player player) { for (String line : lines) { player.spigot().sendMessage(MineDown.parse(line)); } } + } diff --git a/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java b/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java index d46f020..3e5d9e5 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java +++ b/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java @@ -58,7 +58,7 @@ private BufferedImage getImage(Player player) { } } - // Incorrectly formatted URL or couldn't load from URL + // Incorrectly formatted URL, or couldn't load from URL try { return ImageIO.read(new FallbackPicture(plugin).get()); } catch (Exception e) { From 0185b956d23c6b39f62210c2000ec683e42224f6 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 14 Apr 2022 23:03:17 -0500 Subject: [PATCH 31/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 6ceaac8..e818c9a 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ This is a popular plugin for Minecraft servers (over 50,000 downloads) that has sadly been unsupported for a while; I've updated it to Minecraft 1.18 and will be supporting future versions! -You can download the plugin here or over on Spigot: https://www.spigotmc.org/resources/picturelogin-continued.101216/ +You can download the plugin on Spigot: https://www.spigotmc.org/resources/picturelogin-continued.101216/ If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV From 358523523bb7072a1a7f0d2c992f75aaed277422 Mon Sep 17 00:00:00 2001 From: nicholas-vo Date: Fri, 15 Apr 2022 12:36:17 -0500 Subject: [PATCH 32/69] Fixed center (again) --- pom.xml | 2 +- .../java/me/itsnathang/picturelogin/util/ImageMessage.java | 6 ++++++ src/main/resources/config.yml | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f08a133..0ae4c06 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.nickv PictureLogin-Continued - 1.0.2 + 1.0.3 jar Picture Login diff --git a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java index ba139ac..eb9a1ad 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java +++ b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java @@ -129,6 +129,12 @@ public String centerMessage(String message) { sb.append(" "); compensated += spaceLength; } + + int offset = 8; // account for the player head (8 wide) + for (int j = 0; j < offset; j++) { + sb.deleteCharAt(sb.length() - 1); + } + return sb + message; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e30ad8d..b6f4c0a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -119,6 +119,11 @@ clear-chat: false center-text: false +############# +# Center offset +######## +# + ############# # Block join / leave messages ######## From bdceeac42498fff4afb26ea949cd400c89df6a10 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:20:23 -0500 Subject: [PATCH 33/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index e818c9a..cfddf7d 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -![pic](https://user-images.githubusercontent.com/60233722/162335606-abeae73c-3523-4ffd-a49d-9e5e73b735a9.jpg) Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) +![pcl](https://user-images.githubusercontent.com/60233722/163606659-39914c1a-9632-44d5-8841-6a389fe61b62.PNG) Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === Picture Login creates a fancy login message by displaying a picture of the player's head inside of chat! From d86d3348d20721fd530b6cb8514f5ce5d5f74b6a Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:21:57 -0500 Subject: [PATCH 34/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index cfddf7d..9ce53e2 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -![pcl](https://user-images.githubusercontent.com/60233722/163606659-39914c1a-9632-44d5-8841-6a389fe61b62.PNG) Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) +![asdf](https://user-images.githubusercontent.com/60233722/163606833-27671a07-1187-424f-abf7-f5a5d35abda8.PNG) Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === Picture Login creates a fancy login message by displaying a picture of the player's head inside of chat! From 8805e820f7da674a16d33fc107963c6286b26115 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:22:20 -0500 Subject: [PATCH 35/69] Update readme.md --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 9ce53e2..0fe61aa 100644 --- a/readme.md +++ b/readme.md @@ -4,12 +4,12 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -![asdf](https://user-images.githubusercontent.com/60233722/163606833-27671a07-1187-424f-abf7-f5a5d35abda8.PNG) Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) +creeperhere Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === Picture Login creates a fancy login message by displaying a picture of the player's head inside of chat! -![pictureLogin](https://user-images.githubusercontent.com/60233722/162335735-1ed09b90-4071-4a4a-86d4-882dc9e5c14b.PNG) +![demo](https://user-images.githubusercontent.com/60233722/163606833-27671a07-1187-424f-abf7-f5a5d35abda8.PNG) Credit to... --- From f48678eeea80c8257e98e8a42517b8fad1920f47 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:23:05 -0500 Subject: [PATCH 36/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 0fe61aa..74dc72b 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -creeperhere Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) +creeper Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) === Picture Login creates a fancy login message by displaying a picture of the player's head inside of chat! From 1703cbb1a7db8cad8c8af1e24a1cca9425e076d6 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:23:49 -0500 Subject: [PATCH 37/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 74dc72b..5fc17c5 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -creeper Picture Login ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ItsNathanG/PictureLogin?style=flat-square) +Picture Login ![GitHub release (1.0.4)] === Picture Login creates a fancy login message by displaying a picture of the player's head inside of chat! From e8a8f0246df41c8d9d5be7002b86a840958f840e Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:26:25 -0500 Subject: [PATCH 38/69] Update readme.md --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 5fc17c5..f9db789 100644 --- a/readme.md +++ b/readme.md @@ -4,10 +4,10 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -Picture Login ![GitHub release (1.0.4)] +PictureLogin-Continued [![Version](1.0.04)] === -Picture Login creates a fancy login message by displaying a picture of the player's head inside of chat! +PictureLogin creates a fancy login message by displaying a picture of the player's head inside of chat! ![demo](https://user-images.githubusercontent.com/60233722/163606833-27671a07-1187-424f-abf7-f5a5d35abda8.PNG) From 9ce42799d8a96627808e0121d44ed965e88081c4 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:26:52 -0500 Subject: [PATCH 39/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index f9db789..341647e 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -PictureLogin-Continued [![Version](1.0.04)] +PictureLogin-Continued [![Version]1.0.04] === PictureLogin creates a fancy login message by displaying a picture of the player's head inside of chat! From 2f55457943c32226e01983acb86389bdd13873cd Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:28:12 -0500 Subject: [PATCH 40/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 341647e..e05747a 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -PictureLogin-Continued [![Version]1.0.04] +PictureLogin-Continued [![Version]](https://www.spigotmc.org/resources/picturelogin-continued.101216/) === PictureLogin creates a fancy login message by displaying a picture of the player's head inside of chat! From 595c198a959f4f6456f063ea0e2cfa9d0c1e82fe Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:29:03 -0500 Subject: [PATCH 41/69] Update readme.md --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index e05747a..7313122 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,8 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -PictureLogin-Continued [![Version]](https://www.spigotmc.org/resources/picturelogin-continued.101216/) +PictureLogin-Continued [![Version](https://www.spigotmc.org/resources/picturelogin-continued.101216/)](https://www.spigotmc.org/resources/picturelogin-continued.101216/) + === PictureLogin creates a fancy login message by displaying a picture of the player's head inside of chat! From 5609489c7295f0ce40963a6638fb683eca6fe0bb Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:30:00 -0500 Subject: [PATCH 42/69] Update readme.md --- readme.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 7313122..5a174e3 100644 --- a/readme.md +++ b/readme.md @@ -4,8 +4,7 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -PictureLogin-Continued [![Version](https://www.spigotmc.org/resources/picturelogin-continued.101216/)](https://www.spigotmc.org/resources/picturelogin-continued.101216/) - +PictureLogin-Continued https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued === PictureLogin creates a fancy login message by displaying a picture of the player's head inside of chat! From ad34214ca761c28be897b34eb805e3765f914d25 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:30:40 -0500 Subject: [PATCH 43/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 5a174e3..895e786 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -PictureLogin-Continued https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued +PictureLogin-Continued [![Version](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) === PictureLogin creates a fancy login message by displaying a picture of the player's head inside of chat! From 1114d1903973b4c6615a0a8a6e2c5750fc92edde Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:31:33 -0500 Subject: [PATCH 44/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 895e786..5a72aa9 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -PictureLogin-Continued [![Version](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) +PictureLogin-Continued ![License](https://img.shields.io/github/version/Nicholas-Vo/PictureLogin-Continued) ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) === PictureLogin creates a fancy login message by displaying a picture of the player's head inside of chat! From 8a3549ecb249e24c86da817ad373d3517dcf75d6 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:32:42 -0500 Subject: [PATCH 45/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 5a72aa9..685e5b7 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -PictureLogin-Continued ![License](https://img.shields.io/github/version/Nicholas-Vo/PictureLogin-Continued) ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) +PictureLogin-Continued ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) === PictureLogin creates a fancy login message by displaying a picture of the player's head inside of chat! From 59b1481bbd3828f05fccacfd7dc56647fe73f069 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:33:49 -0500 Subject: [PATCH 46/69] Update readme.md --- readme.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index 685e5b7..833930d 100644 --- a/readme.md +++ b/readme.md @@ -1,16 +1,16 @@ -This is a popular plugin for Minecraft servers (over 50,000 downloads) that has sadly been unsupported for a while; I've updated it to Minecraft 1.18 and will be supporting future versions! - -You can download the plugin on Spigot: https://www.spigotmc.org/resources/picturelogin-continued.101216/ - -If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV - PictureLogin-Continued ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) === -PictureLogin creates a fancy login message by displaying a picture of the player's head inside of chat! +This is a popular plugin for Minecraft servers (over 50,000 downloads) that has sadly been unsupported for a while; I've updated it to Minecraft 1.18 and will be supporting future versions! + +PictureLogin creates a fancy login message by displaying a picture of the player's head inside of chat. ![demo](https://user-images.githubusercontent.com/60233722/163606833-27671a07-1187-424f-abf7-f5a5d35abda8.PNG) +Obtaining the plugin +--- +You can download the plugin on Spigot: https://www.spigotmc.org/resources/picturelogin-continued.101216/ + Credit to... --- @@ -18,6 +18,10 @@ Credit to... - bobacadodl for his Image Message Library - Crafatar for their avatar service +Support +--- +If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV + License --- This plugin is licensed under the MIT License. For more information please refer to LICENSE. From 7fce1eb5369a2c445c625978f08c7f3ccc1dbf9b Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:35:12 -0500 Subject: [PATCH 47/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 833930d..3e27987 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -PictureLogin-Continued ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) +PictureLogin-Continued ![Version](https://img.shields.io/badge/version-1.0.4-blue) ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) === This is a popular plugin for Minecraft servers (over 50,000 downloads) that has sadly been unsupported for a while; I've updated it to Minecraft 1.18 and will be supporting future versions! From 8df5a3bada1339c53a389c1fd2a78f057a9d0bd3 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:35:28 -0500 Subject: [PATCH 48/69] Update readme.md --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 3e27987..c825a7f 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -PictureLogin-Continued ![Version](https://img.shields.io/badge/version-1.0.4-blue) ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) +PictureLogin-Continued ![Version](https://img.shields.io/badge/version-1.0.4-blue) === This is a popular plugin for Minecraft servers (over 50,000 downloads) that has sadly been unsupported for a while; I've updated it to Minecraft 1.18 and will be supporting future versions! @@ -22,6 +22,6 @@ Support --- If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV -License +License ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) --- This plugin is licensed under the MIT License. For more information please refer to LICENSE. From e206bc5134ff2dae1e73ac9c87eb53056f769371 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:36:26 -0500 Subject: [PATCH 49/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index c825a7f..22f4882 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,7 @@ Credit to... Support --- -If you're looking for plugin support, you can ping me on my Discord server: https://discord.gg/fGzb73sPmV +If you're looking for plugin support, you can ping me on my Discord server: ![Discord](https://img.shields.io/badge/discord-Nick's%20Place-orange) License ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) --- From 6fab775bc67d7acce140c7687bc8ff93b976d742 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:36:38 -0500 Subject: [PATCH 50/69] Update readme.md --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 22f4882..03b6745 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,8 @@ Credit to... Support --- -If you're looking for plugin support, you can ping me on my Discord server: ![Discord](https://img.shields.io/badge/discord-Nick's%20Place-orange) +If you're looking for plugin support, you can ping me on my Discord server: +![Discord](https://img.shields.io/badge/discord-Nick's%20Place-orange) License ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) --- From 706e8e6b1ef4442461ae1048a962b5172f9aee22 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:36:53 -0500 Subject: [PATCH 51/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 03b6745..d39d6ab 100644 --- a/readme.md +++ b/readme.md @@ -14,7 +14,7 @@ You can download the plugin on Spigot: https://www.spigotmc.org/resources/pictur Credit to... --- -- The original plugin author, ![ItsNathanG](https://github.com/ItsNathanG) +- The original plugin author, ItsNathanG - bobacadodl for his Image Message Library - Crafatar for their avatar service From 6dbb19e7110c6668fb3211f4588ddcb80bf67fde Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:38:02 -0500 Subject: [PATCH 52/69] Update readme.md --- readme.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index d39d6ab..40ffcc6 100644 --- a/readme.md +++ b/readme.md @@ -18,10 +18,9 @@ Credit to... - bobacadodl for his Image Message Library - Crafatar for their avatar service -Support +Support ![Discord](https://img.shields.io/badge/discord-Nick's%20Place-orange) --- -If you're looking for plugin support, you can ping me on my Discord server: -![Discord](https://img.shields.io/badge/discord-Nick's%20Place-orange) +You can reach out to me on the Spigot forums or here on GitHub, although the best way to reach me is on Discord. License ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) --- From 761aa2b195b9838982a4c96fcff32d30b13bde81 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:38:27 -0500 Subject: [PATCH 53/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 40ffcc6..02beb4b 100644 --- a/readme.md +++ b/readme.md @@ -22,6 +22,6 @@ Support ![Discord](https://img.shields.io/badge/discord-Nick's%20Place-orange) --- You can reach out to me on the Spigot forums or here on GitHub, although the best way to reach me is on Discord. -License ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued) +License ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued)(https://github.com/Nicholas-Vo/PictureLogin-Continued/blob/master/LICENSE) --- This plugin is licensed under the MIT License. For more information please refer to LICENSE. From 942af1eae538e9fdfcc910774730b8cf85443aab Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:38:58 -0500 Subject: [PATCH 54/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 02beb4b..52a63e8 100644 --- a/readme.md +++ b/readme.md @@ -22,6 +22,6 @@ Support ![Discord](https://img.shields.io/badge/discord-Nick's%20Place-orange) --- You can reach out to me on the Spigot forums or here on GitHub, although the best way to reach me is on Discord. -License ![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued)(https://github.com/Nicholas-Vo/PictureLogin-Continued/blob/master/LICENSE) +License [![License](https://img.shields.io/github/license/Nicholas-Vo/PictureLogin-Continued)](https://github.com/Nicholas-Vo/PictureLogin-Continued/blob/master/LICENSE) --- This plugin is licensed under the MIT License. For more information please refer to LICENSE. From 6aefee6250b675d193b9720b3f3f7b6f44826ee8 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:39:50 -0500 Subject: [PATCH 55/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 52a63e8..b8c3779 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,7 @@ Credit to... - bobacadodl for his Image Message Library - Crafatar for their avatar service -Support ![Discord](https://img.shields.io/badge/discord-Nick's%20Place-orange) +Support [![Discord](https://img.shields.io/badge/discord-Nick's%20Place-orange)](https://discord.gg/fGzb73sPmV) --- You can reach out to me on the Spigot forums or here on GitHub, although the best way to reach me is on Discord. From 76e53c6acb2529cd4e66dba621cf4f066591b5e8 Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:40:14 -0500 Subject: [PATCH 56/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index b8c3779..a66db6d 100644 --- a/readme.md +++ b/readme.md @@ -9,7 +9,7 @@ PictureLogin creates a fancy login message by displaying a picture of the player Obtaining the plugin --- -You can download the plugin on Spigot: https://www.spigotmc.org/resources/picturelogin-continued.101216/ +You can download the plugin over on Spigot: https://www.spigotmc.org/resources/picturelogin-continued.101216/ Credit to... --- From 381c0d6bfa4ad28ce8799fbe0195f9dfe23b120b Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:40:31 -0500 Subject: [PATCH 57/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index a66db6d..db5095c 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -PictureLogin-Continued ![Version](https://img.shields.io/badge/version-1.0.4-blue) +PictureLogin-Continued [![Version](https://img.shields.io/badge/version-1.0.4-blue)](https://www.spigotmc.org/resources/picturelogin-continued.101216/) === This is a popular plugin for Minecraft servers (over 50,000 downloads) that has sadly been unsupported for a while; I've updated it to Minecraft 1.18 and will be supporting future versions! From 5335848f56fd56201b1b3a44f2a9afa172069531 Mon Sep 17 00:00:00 2001 From: nicholas-vo Date: Fri, 15 Apr 2022 13:43:54 -0500 Subject: [PATCH 58/69] Fixed center (again) --- pom.xml | 2 +- .../bobacadodl/imgmessage/ImageMessage.java | 2 +- .../picturelogin/commands/BaseCommand.java | 1 - .../picturelogin/config/ConfigManager.java | 10 ++++------ .../picturelogin/util/ImageMessage.java | 6 ++---- src/main/resources/config.yml | 18 ++++++------------ src/main/resources/fallback.png | Bin 144 -> 345 bytes 7 files changed, 14 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index 0ae4c06..180040f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.nickv PictureLogin-Continued - 1.0.3 + 1.0.4 jar Picture Login diff --git a/src/main/java/com/bobacadodl/imgmessage/ImageMessage.java b/src/main/java/com/bobacadodl/imgmessage/ImageMessage.java index 374eb48..061cf2e 100644 --- a/src/main/java/com/bobacadodl/imgmessage/ImageMessage.java +++ b/src/main/java/com/bobacadodl/imgmessage/ImageMessage.java @@ -4,7 +4,7 @@ import org.bukkit.entity.Player; import org.bukkit.util.ChatPaginator; -import java.awt.*; +import java.awt.Color; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; diff --git a/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java b/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java index ae16654..aba9fdc 100644 --- a/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java +++ b/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java @@ -33,7 +33,6 @@ public boolean onCommand(CommandSender s, Command cmd, String label, String[] ar if (args.length < 1) { s.sendMessage(ChatColor.GREEN + "PictureLogin " + ChatColor.GRAY + "v" + ChatColor.GREEN + plugin.getDescription().getVersion() + ChatColor.GRAY + " by " + ChatColor.GREEN + "_NickVo"); - s.sendMessage(tl("reload_config_help")); return true; } diff --git a/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java b/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java index e2c7a37..4209e69 100644 --- a/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java +++ b/src/main/java/me/itsnathang/picturelogin/config/ConfigManager.java @@ -44,11 +44,13 @@ private char getChar() { public ImageMessage getMessage(List messages, BufferedImage image) { int imageDimensions = 8, count = 0; - ImageMessage imageMessage = new ImageMessage(messages, image, imageDimensions, getChar()); + ImageMessage imageMessage = new ImageMessage(image, imageDimensions, getChar()); String[] msg = new String[imageDimensions]; for (String message : messages) { - if (count > msg.length) break; + if (count > msg.length) { + break; + } msg[count++] = message; } @@ -67,10 +69,6 @@ public long getLong(String key) { return config.getLong(key); } - public boolean getBoolean(String key) { - return config.getBoolean(key); - } - public boolean getBoolean(String key, Boolean def) { return config.getBoolean(key, def); } diff --git a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java index eb9a1ad..55759e6 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java +++ b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java @@ -8,14 +8,12 @@ import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; -import java.util.List; public class ImageMessage { private final static char TRANSPARENT_CHAR = ' '; + private String[] lines; // The 8 lines next to the playerhead - private String[] lines; - - public ImageMessage(List messages, BufferedImage image, int height, char imgChar) { + public ImageMessage(BufferedImage image, int height, char imgChar) { Color[][] chatColors = toChatColorArray(image, height); lines = toImgMessage(chatColors, imgChar); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b6f4c0a..44d315d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -13,8 +13,7 @@ # Messsages ######## # Each message is a line, leave blank for a blank line -# (If image height is 8, you can have eight lines; etc.) -# Chat codes supported. +# Chat codes supported ######## # Variables: # %pname% - Joined player's name (no formatting) @@ -22,12 +21,13 @@ # %max% - Maximum players # %motd% - MOTD # %displayname% - Joined player's display name -# %new_line% - Create a new line on the screen + ######## # NOTE: You may also use variables from the plugin # PlaceholderAPI if it is installed. -# Do not add additional messages to this list - Max of 8 allowed (that's the length of the player head image!) +# Do not add additional messages to this list! +# Max of 8 allowed (that's the length of the player head image) messages: - '' - '&7Welcome to &e&lGeneric Server Name&7!' @@ -113,17 +113,11 @@ clear-chat: false ############# # Center Text ######## -# Whether or not to center -# the text beside the image. +# Whether to center the text beside the image. # Acceptable: [true|false] center-text: false -############# -# Center offset -######## -# - ############# # Block join / leave messages ######## @@ -161,7 +155,7 @@ character: 'BLOCK' # URL ######## # Where to get the picture from. -# By default it uses crafatar. +# By default, this is set to minepic.org # You should probably leave this where it is. ######## # Variables: diff --git a/src/main/resources/fallback.png b/src/main/resources/fallback.png index 3982c61ed20ae75ba68b225934be723e01a15338..6992369760426b6578b1156d5c5dca28c9667ece 100644 GIT binary patch delta 318 zcmV-E0m1%|0oekOB!3BTNLh0L01m_e01m_fl`9S#0003CNklkkPeTqsppaMkB6NVW0fhPu;5J+bw#-lM_7$Eo5I=^Pgw&Y1aeomlTKSgQ%gKs_cVf4%=0>L zW|eGn4@cZNL;q5c$Zm|C^=+hInH#-G>N3TrT*DC}fL3|nBzMfm**5^mo&>X-aT4|- za@aG7PXy4^5;ys002ovPDHLkV1fq%FyjCK From f8c64962a28d33de8670ce3d3c0ccf16618fb8ac Mon Sep 17 00:00:00 2001 From: nicholas-vo Date: Fri, 15 Apr 2022 16:42:47 -0500 Subject: [PATCH 59/69] fixed update link --- src/main/resources/messages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index c89f37f..ecb965e 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -13,7 +13,7 @@ no_permission: "%prefix% &cYou do not have permission to do this!" # Misc update_available: "New update available! Current Version: %current% New Version: %new%" -update_available_download: "Download at https://www.spigotmc.org/resources/picture-login.4514/" +update_available_download: "Download at https://www.spigotmc.org/resources/picturelogin-continued.101216/" # Error Messages (Printed in console.) error_reload_config: "Could not access the configuration file." From f77c5f230b4230603034ee3b51dc193d379fbfc4 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 19 Apr 2022 09:29:46 -0500 Subject: [PATCH 60/69] Fixed updater --- pom.xml | 2 +- src/main/resources/messages.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f08a133..0ae4c06 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.nickv PictureLogin-Continued - 1.0.2 + 1.0.3 jar Picture Login diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index c89f37f..ecb965e 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -13,7 +13,7 @@ no_permission: "%prefix% &cYou do not have permission to do this!" # Misc update_available: "New update available! Current Version: %current% New Version: %new%" -update_available_download: "Download at https://www.spigotmc.org/resources/picture-login.4514/" +update_available_download: "Download at https://www.spigotmc.org/resources/picturelogin-continued.101216/" # Error Messages (Printed in console.) error_reload_config: "Could not access the configuration file." From f271712308956103a265c9ee624cf25c654baf86 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 19 Apr 2022 09:30:26 -0500 Subject: [PATCH 61/69] Fixed updater --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f08a133..180040f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.nickv PictureLogin-Continued - 1.0.2 + 1.0.4 jar Picture Login From 746eeb06f8f5f33139b02f0061046fa81edd8e7e Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 1 Feb 2023 19:59:16 -0600 Subject: [PATCH 62/69] Moved the position of the PlaceholderAPI check to attempt to fix a bug --- .../java/com/bobacadodl/imgmessage/ImageMessage.java | 7 +------ .../java/me/itsnathang/picturelogin/PictureLogin.java | 1 - .../picturelogin/config/LanguageManager.java | 1 - .../picturelogin/listeners/QuitListener.java | 11 +++-------- .../itsnathang/picturelogin/util/DefaultFontInfo.java | 2 +- .../me/itsnathang/picturelogin/util/PictureUtil.java | 8 ++++---- 6 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/bobacadodl/imgmessage/ImageMessage.java b/src/main/java/com/bobacadodl/imgmessage/ImageMessage.java index 061cf2e..2389e2a 100644 --- a/src/main/java/com/bobacadodl/imgmessage/ImageMessage.java +++ b/src/main/java/com/bobacadodl/imgmessage/ImageMessage.java @@ -108,7 +108,6 @@ private boolean areIdentical(Color c1, Color c2) { return Math.abs(c1.getRed() - c2.getRed()) <= 5 && Math.abs(c1.getGreen() - c2.getGreen()) <= 5 && Math.abs(c1.getBlue() - c2.getBlue()) <= 5; - } private ChatColor getClosestChatColor(Color color) { @@ -123,11 +122,7 @@ private String center(String s, int length) { return s; } else { int leftPadding = (length - s.length()) / 2; - StringBuilder leftBuilder = new StringBuilder(); - for (int i = 0; i < leftPadding; i++) { - leftBuilder.append(" "); - } - return leftBuilder + s; + return " ".repeat(leftPadding) + s; } } diff --git a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java index 40540e1..31061de 100644 --- a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java +++ b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java @@ -48,7 +48,6 @@ public void onEnable() { if (configManager.getBoolean("metrics", true)) { new Metrics(this, 14892); // 2225 is the bStats plugin ID for PictureLogin } - } public ConfigManager getConfigManager() { diff --git a/src/main/java/me/itsnathang/picturelogin/config/LanguageManager.java b/src/main/java/me/itsnathang/picturelogin/config/LanguageManager.java index 6345038..b393383 100644 --- a/src/main/java/me/itsnathang/picturelogin/config/LanguageManager.java +++ b/src/main/java/me/itsnathang/picturelogin/config/LanguageManager.java @@ -21,7 +21,6 @@ private YamlConfiguration loadLanguage() { if (!language_file.exists()) { plugin.saveResource("messages.yml", false); } - return YamlConfiguration.loadConfiguration(language_file); } diff --git a/src/main/java/me/itsnathang/picturelogin/listeners/QuitListener.java b/src/main/java/me/itsnathang/picturelogin/listeners/QuitListener.java index 061c482..a37fed0 100644 --- a/src/main/java/me/itsnathang/picturelogin/listeners/QuitListener.java +++ b/src/main/java/me/itsnathang/picturelogin/listeners/QuitListener.java @@ -1,17 +1,14 @@ package me.itsnathang.picturelogin.listeners; -import me.itsnathang.picturelogin.util.ImageMessage; import me.itsnathang.picturelogin.PictureLogin; +import me.itsnathang.picturelogin.config.ConfigManager; +import me.itsnathang.picturelogin.util.ImageMessage; +import me.itsnathang.picturelogin.util.PictureUtil; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; -import me.itsnathang.picturelogin.config.ConfigManager; -import me.itsnathang.picturelogin.util.PictureUtil; - -import java.util.List; - public class QuitListener implements Listener { private final PictureUtil pictureUtil; private final ConfigManager config; @@ -27,7 +24,6 @@ public void onQuit(PlayerQuitEvent event) { return; Player player = event.getPlayer(); - if (!player.hasPermission("picturelogin.show") && config.getBoolean("require-permission", true)) { return; } @@ -37,7 +33,6 @@ public void onQuit(PlayerQuitEvent event) { } ImageMessage picture_message = pictureUtil.getLeaveMessage(player); - if (picture_message == null) { return; } diff --git a/src/main/java/me/itsnathang/picturelogin/util/DefaultFontInfo.java b/src/main/java/me/itsnathang/picturelogin/util/DefaultFontInfo.java index a989667..be87844 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/DefaultFontInfo.java +++ b/src/main/java/me/itsnathang/picturelogin/util/DefaultFontInfo.java @@ -72,7 +72,7 @@ public enum DefaultFontInfo { AMPERSAND('&', 5), ASTERISK('*', 5), LEFT_PARENTHESIS('(', 4), - RIGHT_PERENTHESIS(')', 4), + RIGHT_PARENTHESIS(')', 4), MINUS('-', 5), UNDERSCORE('_', 5), PLUS_SIGN('+', 5), diff --git a/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java b/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java index 3e5d9e5..87d284a 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java +++ b/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java @@ -117,6 +117,10 @@ public ImageMessage getFirstJoinMessage(Player player) { } private String addPlaceholders(String msg, Player player) { + if (Hooks.PLACEHOLDER_API) { + msg = PlaceholderAPI.setPlaceholders(player, msg); + } + msg = Translate.translateHexColor(msg); msg = ChatColor.translateAlternateColorCodes('&', msg); @@ -127,10 +131,6 @@ private String addPlaceholders(String msg, Player player) { msg = msg.replace("%motd%", plugin.getServer().getMotd()); msg = msg.replace("%displayname%", player.getDisplayName()); - if (Hooks.PLACEHOLDER_API) { - msg = PlaceholderAPI.setPlaceholders(player, msg); - } - return msg; } From fe59e1e5f45562a5eb410d4eff3ea2c425a82699 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 2 Feb 2023 19:18:23 -0600 Subject: [PATCH 63/69] Possibly resolved issue where vault prefixes with hex colors don't display the rest of their formatting properly --- src/main/java/me/itsnathang/picturelogin/PictureLogin.java | 4 ++++ src/main/java/me/itsnathang/picturelogin/util/Translate.java | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java index 31061de..cc5e892 100644 --- a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java +++ b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java @@ -10,6 +10,10 @@ import org.bstats.bukkit.Metrics; import org.bukkit.plugin.java.JavaPlugin; +// TODO + +// Setting any of the messages too long will result in the picture not displaying and an error in the server console + /* Updated to work with Minecraft 1.18.2 by _NickV on 4/7/2022 */ diff --git a/src/main/java/me/itsnathang/picturelogin/util/Translate.java b/src/main/java/me/itsnathang/picturelogin/util/Translate.java index e758324..61f1b3f 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/Translate.java +++ b/src/main/java/me/itsnathang/picturelogin/util/Translate.java @@ -30,7 +30,9 @@ private static String getFilteredTranslation(String key) { public static String translateHexColor(final String message) { final char colorChar = ChatColor.COLOR_CHAR; - Pattern pattern = Pattern.compile("(#[a-fA-F0-9]{6})"); + // Added optional catch for & because some plugins (Essentials?) require + // or allow the & symbol before hex. + Pattern pattern = Pattern.compile("&?(#[a-fA-F0-9]{6})"); final Matcher matcher = pattern.matcher(message); final StringBuilder buffer = new StringBuilder(message.length() + 4 * 8); From d7cac05d6cbc5e8fb4ab15111b6659892d33978c Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 2 Feb 2023 19:29:37 -0600 Subject: [PATCH 64/69] Code cleanup --- .../picturelogin/commands/BaseCommand.java | 8 ++-- .../picturelogin/config/FallbackPicture.java | 1 - .../picturelogin/config/LanguageManager.java | 6 +-- .../itsnathang/picturelogin/util/Hooks.java | 17 +++----- .../picturelogin/util/ImageMessage.java | 8 ++-- .../picturelogin/util/PictureUtil.java | 11 ++--- .../picturelogin/util/PictureWrapper.java | 40 ++++++++----------- .../picturelogin/util/Translate.java | 16 +++----- .../itsnathang/picturelogin/util/Updater.java | 8 ++-- 9 files changed, 47 insertions(+), 68 deletions(-) diff --git a/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java b/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java index aba9fdc..9f497ae 100644 --- a/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java +++ b/src/main/java/me/itsnathang/picturelogin/commands/BaseCommand.java @@ -12,7 +12,7 @@ import java.util.ArrayList; import java.util.List; -import static me.itsnathang.picturelogin.util.Translate.tl; +import static me.itsnathang.picturelogin.util.Translate.translateString; public class BaseCommand implements CommandExecutor, TabCompleter { private final PictureLogin plugin; @@ -26,7 +26,7 @@ public BaseCommand(PictureLogin plugin) { @Override public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) { if (!s.hasPermission("picturelogin.main")) { - s.sendMessage(tl("no_permission")); + s.sendMessage(translateString("no_permission")); return true; } @@ -38,7 +38,7 @@ public boolean onCommand(CommandSender s, Command cmd, String label, String[] ar if (args[0].equalsIgnoreCase("reload")) { plugin.getConfigManager().reloadConfig(); - s.sendMessage(tl("reload_config")); + s.sendMessage(translateString("reload_config")); return true; } @@ -67,7 +67,7 @@ public boolean onCommand(CommandSender s, Command cmd, String label, String[] ar @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { if (!sender.hasPermission("picturelogin.main")) { - return List.of(); // Empty list to stop further tab completion + return List.of(); } if (args.length == 1) { diff --git a/src/main/java/me/itsnathang/picturelogin/config/FallbackPicture.java b/src/main/java/me/itsnathang/picturelogin/config/FallbackPicture.java index 5e5cc08..d189758 100644 --- a/src/main/java/me/itsnathang/picturelogin/config/FallbackPicture.java +++ b/src/main/java/me/itsnathang/picturelogin/config/FallbackPicture.java @@ -15,7 +15,6 @@ public File get() { final String FALLBACK_PATH = plugin.getDataFolder() + File.separator + "fallback.png"; File image = new File(FALLBACK_PATH); - if (!image.exists()) { plugin.saveResource("fallback.png", false); } diff --git a/src/main/java/me/itsnathang/picturelogin/config/LanguageManager.java b/src/main/java/me/itsnathang/picturelogin/config/LanguageManager.java index b393383..d3247e4 100644 --- a/src/main/java/me/itsnathang/picturelogin/config/LanguageManager.java +++ b/src/main/java/me/itsnathang/picturelogin/config/LanguageManager.java @@ -16,12 +16,12 @@ public class LanguageManager { } private YamlConfiguration loadLanguage() { - File language_file = new File(plugin.getDataFolder() + File.separator + "messages.yml"); + File yml = new File(plugin.getDataFolder() + File.separator + "messages.yml"); - if (!language_file.exists()) { + if (!yml.exists()) { plugin.saveResource("messages.yml", false); } - return YamlConfiguration.loadConfiguration(language_file); + return YamlConfiguration.loadConfiguration(yml); } public void reloadLanguage() { diff --git a/src/main/java/me/itsnathang/picturelogin/util/Hooks.java b/src/main/java/me/itsnathang/picturelogin/util/Hooks.java index 07f2348..b7a5873 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/Hooks.java +++ b/src/main/java/me/itsnathang/picturelogin/util/Hooks.java @@ -18,27 +18,22 @@ public Hooks(PluginManager plugins, ConfigManager config, Logger logger) { this.config = config; this.logger = logger; - hookAuthMe(); - hookPlaceHolderAPI(); + AUTHME = hookPlugin("AuthMe"); + PLACEHOLDER_API = hookPlugin("PlaceholderAPI"); } private boolean hookPlugin(String plugin) { - if (!plugins.isPluginEnabled(plugin)) + if (!plugins.isPluginEnabled(plugin)) { return false; + } // Make sure user wants to hook into the plugin - if (!config.getBoolean("hooks." + plugin, true)) + if (!config.getBoolean("hooks." + plugin, true)) { return false; + } logger.info(() -> "Hooked into: " + plugin); return true; } - private void hookAuthMe() { - AUTHME = hookPlugin("AuthMe"); - } - - private void hookPlaceHolderAPI() { - PLACEHOLDER_API = hookPlugin("PlaceholderAPI"); - } } diff --git a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java index 55759e6..5b608dc 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java +++ b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java @@ -36,9 +36,11 @@ private Color[][] toChatColorArray(BufferedImage image, int height) { private BufferedImage resizeImage(BufferedImage originalImage, int width, int height) { AffineTransform af = new AffineTransform(); - af.scale( - width / (double) originalImage.getWidth(), - height / (double) originalImage.getHeight()); + + double newWidth = width / (double) originalImage.getWidth(); + double newHeight = height / (double) originalImage.getHeight(); + + af.scale(newWidth, newHeight); AffineTransformOp operation = new AffineTransformOp(af, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); return operation.filter(originalImage, null); diff --git a/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java b/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java index 87d284a..64dc6e1 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java +++ b/src/main/java/me/itsnathang/picturelogin/util/PictureUtil.java @@ -4,9 +4,6 @@ import me.itsnathang.picturelogin.PictureLogin; import me.itsnathang.picturelogin.config.ConfigManager; import me.itsnathang.picturelogin.config.FallbackPicture; -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -15,10 +12,8 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import static me.itsnathang.picturelogin.util.Translate.tl; +import static me.itsnathang.picturelogin.util.Translate.translateString; public class PictureUtil { private final PictureLogin plugin; @@ -54,7 +49,7 @@ private BufferedImage getImage(Player player) { return ImageIO.read(connection.getInputStream()); } catch (Exception e) { e.printStackTrace(); - plugin.getLogger().warning(tl("error_retrieving_avatar")); + plugin.getLogger().warning(translateString("error_retrieving_avatar")); } } @@ -62,7 +57,7 @@ private BufferedImage getImage(Player player) { try { return ImageIO.read(new FallbackPicture(plugin).get()); } catch (Exception e) { - plugin.getLogger().warning(tl("error_fallback_img")); + plugin.getLogger().warning(translateString("error_fallback_img")); return null; } } diff --git a/src/main/java/me/itsnathang/picturelogin/util/PictureWrapper.java b/src/main/java/me/itsnathang/picturelogin/util/PictureWrapper.java index 31ed8fb..6134c17 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/PictureWrapper.java +++ b/src/main/java/me/itsnathang/picturelogin/util/PictureWrapper.java @@ -1,6 +1,5 @@ package me.itsnathang.picturelogin.util; -import me.itsnathang.picturelogin.util.ImageMessage; import me.itsnathang.picturelogin.PictureLogin; import me.itsnathang.picturelogin.config.ConfigManager; import org.bukkit.entity.Player; @@ -19,33 +18,11 @@ public PictureWrapper(PictureLogin plugin, Player player) { @Override public void run() { - sendImage(); - } - - private boolean checkPermission() { - if (!config.getBoolean("require-permission", true)) { - return true; - } - - return player.hasPermission("picturelogin.show"); - } - - private ImageMessage getMessage() { - boolean firstTime = config.getBoolean("show-first-join", true) && !player.hasPlayedBefore(); - - // if it's a player's first time and feature is enabled, show different message - String msgType = firstTime ? "first-join-messages" : "messages"; - - return pictureUtil.createPictureMessage(player, config.getStringList(msgType)); - } - - private void sendImage() { if (!checkPermission()) { // only show message for players with picturelogin.show permission return; } ImageMessage pictureMessage = getMessage(); - if (pictureMessage == null) { return; } @@ -63,4 +40,21 @@ private void sendImage() { pictureUtil.sendOutPictureMessage(pictureMessage); } + private boolean checkPermission() { + if (!config.getBoolean("require-permission", true)) { + return true; + } + + return player.hasPermission("picturelogin.show"); + } + + private ImageMessage getMessage() { + boolean firstTime = config.getBoolean("show-first-join", true) && !player.hasPlayedBefore(); + + // if it's a player's first time and feature is enabled, show different message + String msgType = firstTime ? "first-join-messages" : "messages"; + + return pictureUtil.createPictureMessage(player, config.getStringList(msgType)); + } + } diff --git a/src/main/java/me/itsnathang/picturelogin/util/Translate.java b/src/main/java/me/itsnathang/picturelogin/util/Translate.java index 61f1b3f..1bc145e 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/Translate.java +++ b/src/main/java/me/itsnathang/picturelogin/util/Translate.java @@ -13,18 +13,16 @@ private Translate() { throw new IllegalStateException("Utility Class"); } - public static String tl(String key) { - return translate(key); - } - - private static String translate(String key) { + public static String translateString(String key) { return getFilteredTranslation(key); } private static String getFilteredTranslation(String key) { - return color(messages.getString(key) + final String message = messages.getString(key) .replace("%prefix%", messages.getString("prefix")) - .replace("%new_line%", "\n")); + .replace("%new_line%", "\n"); + + return ChatColor.translateAlternateColorCodes('&', message); } public static String translateHexColor(final String message) { @@ -48,8 +46,4 @@ public static String translateHexColor(final String message) { return matcher.appendTail(buffer).toString(); } - private static String color(String message) { - return ChatColor.translateAlternateColorCodes('&', message); - } - } diff --git a/src/main/java/me/itsnathang/picturelogin/util/Updater.java b/src/main/java/me/itsnathang/picturelogin/util/Updater.java index 359ca41..075bed7 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/Updater.java +++ b/src/main/java/me/itsnathang/picturelogin/util/Updater.java @@ -8,7 +8,7 @@ import java.net.URL; import java.util.logging.Logger; -import static me.itsnathang.picturelogin.util.Translate.tl; +import static me.itsnathang.picturelogin.util.Translate.translateString; public class Updater { @@ -30,12 +30,12 @@ public Updater(Logger log, String currentVersion) { // Compare current plugin version with downloaded one if (!currentVersion.equalsIgnoreCase(latest_version)) { - log.info(tl("update_available").replace("%current%", currentVersion).replace("%new%", latest_version)); - log.info(tl("update_available_download")); + log.info(translateString("update_available").replace("%current%", currentVersion).replace("%new%", latest_version)); + log.info(translateString("update_available_download")); } } catch (Exception e) { - log.warning(tl("error_update_check")); + log.warning(translateString("error_update_check")); } } From 736127478853421cad204bff500f016330bed28e Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 2 Feb 2023 19:46:50 -0600 Subject: [PATCH 65/69] Fixed bug where message would not display and an error would appear in the console when the message length was too long. --- pom.xml | 2 +- .../java/me/itsnathang/picturelogin/util/ImageMessage.java | 7 ++++++- src/main/resources/plugin.yml | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 180040f..927040f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.nickv PictureLogin-Continued - 1.0.4 + 1.0.5 jar Picture Login diff --git a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java index 5b608dc..251a87c 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java +++ b/src/main/java/me/itsnathang/picturelogin/util/ImageMessage.java @@ -1,6 +1,7 @@ package me.itsnathang.picturelogin.util; import de.themoep.minedown.MineDown; +import me.itsnathang.picturelogin.PictureLogin; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -8,6 +9,7 @@ import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; +import java.util.logging.Level; public class ImageMessage { private final static char TRANSPARENT_CHAR = ' '; @@ -132,7 +134,10 @@ public String centerMessage(String message) { int offset = 8; // account for the player head (8 wide) for (int j = 0; j < offset; j++) { - sb.deleteCharAt(sb.length() - 1); + int anIndex = sb.length() - 1; + if (anIndex >= 0) { + sb.deleteCharAt(anIndex); + } } return sb + message; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 36e5caf..d13b6af 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: PictureLogin main: me.itsnathang.picturelogin.PictureLogin -api-version: 1.18 +api-version: 1.19 author: NathanG, _NickV description: Display a cool login message with a picture of the player's skin. From c29709430d45fe47b814aceb9eab06c7c34f9d0b Mon Sep 17 00:00:00 2001 From: Nick <60233722+Nicholas-Vo@users.noreply.github.com> Date: Thu, 2 Feb 2023 19:54:36 -0600 Subject: [PATCH 66/69] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index db5095c..91b1613 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ PictureLogin-Continued [![Version](https://img.shields.io/badge/version-1.0.4-blue)](https://www.spigotmc.org/resources/picturelogin-continued.101216/) === -This is a popular plugin for Minecraft servers (over 50,000 downloads) that has sadly been unsupported for a while; I've updated it to Minecraft 1.18 and will be supporting future versions! +This is a popular plugin for Minecraft servers (over 50,000 downloads) that has sadly been unsupported for a while; I've updated it to Minecraft 1.18 and will be supporting future versions! (Now confirmed working on Minecraft 1.19.3) PictureLogin creates a fancy login message by displaying a picture of the player's head inside of chat. From 350aac767206ca009a423068c0e140c1ec05318b Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 2 Feb 2023 20:19:57 -0600 Subject: [PATCH 67/69] Fixed hex colors coming through incorrectly (tweaked regex, thanks JeevS) --- .../java/me/itsnathang/picturelogin/util/Translate.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/me/itsnathang/picturelogin/util/Translate.java b/src/main/java/me/itsnathang/picturelogin/util/Translate.java index 1bc145e..9dd848c 100644 --- a/src/main/java/me/itsnathang/picturelogin/util/Translate.java +++ b/src/main/java/me/itsnathang/picturelogin/util/Translate.java @@ -14,10 +14,6 @@ private Translate() { } public static String translateString(String key) { - return getFilteredTranslation(key); - } - - private static String getFilteredTranslation(String key) { final String message = messages.getString(key) .replace("%prefix%", messages.getString("prefix")) .replace("%new_line%", "\n"); @@ -30,7 +26,7 @@ public static String translateHexColor(final String message) { // Added optional catch for & because some plugins (Essentials?) require // or allow the & symbol before hex. - Pattern pattern = Pattern.compile("&?(#[a-fA-F0-9]{6})"); + Pattern pattern = Pattern.compile("&?#([a-fA-F0-9]{6})"); final Matcher matcher = pattern.matcher(message); final StringBuilder buffer = new StringBuilder(message.length() + 4 * 8); From 550bbd0444f6fb2a7b714036dcf6fc0a3038c8f6 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 17 Aug 2024 08:05:20 -0500 Subject: [PATCH 68/69] Updated error message --- src/main/resources/messages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index ecb965e..c749ce3 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -17,6 +17,6 @@ update_available_download: "Download at https://www.spigotmc.org/resources/pictu # Error Messages (Printed in console.) error_reload_config: "Could not access the configuration file." -error_retrieving_avatar: "Could not retrieve avatar from URL. Reverting to fallback image." +error_retrieving_avatar: "Could not retrieve avatar from URL. Reverting to fallback image. Cracked servers: Make sure you're using %pname% in the config." error_fallback_img: "Could not load fallback image." error_update_check: "Could not check for update." \ No newline at end of file From 4c9a5e939e5669c534aacda107da9d086e35e540 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 17 Aug 2024 08:09:25 -0500 Subject: [PATCH 69/69] Updating version number to 1.0.6 --- pom.xml | 2 +- readme.md | 2 +- src/main/java/me/itsnathang/picturelogin/PictureLogin.java | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 927040f..98a34bf 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.nickv PictureLogin-Continued - 1.0.5 + 1.0.6 jar Picture Login diff --git a/readme.md b/readme.md index 91b1613..83b98df 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ PictureLogin-Continued [![Version](https://img.shields.io/badge/version-1.0.4-blue)](https://www.spigotmc.org/resources/picturelogin-continued.101216/) === -This is a popular plugin for Minecraft servers (over 50,000 downloads) that has sadly been unsupported for a while; I've updated it to Minecraft 1.18 and will be supporting future versions! (Now confirmed working on Minecraft 1.19.3) +This is a popular plugin for Minecraft servers (over 50,000 downloads) that has sadly been unsupported for a while; I've updated it to Minecraft 1.18 and will be supporting future versions! (Now confirmed working on Minecraft 1.21.1) PictureLogin creates a fancy login message by displaying a picture of the player's head inside of chat. diff --git a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java index cc5e892..31061de 100644 --- a/src/main/java/me/itsnathang/picturelogin/PictureLogin.java +++ b/src/main/java/me/itsnathang/picturelogin/PictureLogin.java @@ -10,10 +10,6 @@ import org.bstats.bukkit.Metrics; import org.bukkit.plugin.java.JavaPlugin; -// TODO - -// Setting any of the messages too long will result in the picture not displaying and an error in the server console - /* Updated to work with Minecraft 1.18.2 by _NickV on 4/7/2022 */