Add default color and add conversion for hex

Signed-off-by: Etzelia <etzelia@hotmail.com>
grief
Etzelia 2020-07-29 11:32:47 -05:00
parent 2e3d7acde1
commit 08d244b002
No known key found for this signature in database
GPG Key ID: 3CAEB74806C4ADE5
3 changed files with 20 additions and 10 deletions

View File

@ -3,7 +3,20 @@ package xyz.etztech.orealert;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
public class Color { public class Color {
public static ChatColor DEFAULT = ChatColor.GRAY;
public static ChatColor ERROR = ChatColor.of("#f14668"); public static ChatColor ERROR = ChatColor.of("#f14668");
public static ChatColor INFO = ChatColor.of("#3298dc"); public static ChatColor INFO = ChatColor.of("#3298dc");
public static ChatColor PRIMARY = ChatColor.of("#3273dc"); public static ChatColor PRIMARY = ChatColor.of("#3273dc");
public static int hexToInt(String hex) {
if (hex.startsWith("#")) {
hex = hex.substring(1);
}
if (hex.length() != 6) {
return 0;
}
return Integer.parseInt(hex, 16);
}
} }

View File

@ -11,7 +11,7 @@ public enum Lang {
NO_PERMISSION("You don't have permission to do that.", Color.ERROR), NO_PERMISSION("You don't have permission to do that.", Color.ERROR),
UNKNOWN_COMMAND("This command wasn't recognized.", Color.ERROR), UNKNOWN_COMMAND("This command wasn't recognized.", Color.ERROR),
PLUGIN_RELOADED("Plugin reloaded.", Color.INFO), PLUGIN_RELOADED("Plugin reloaded.", Color.INFO),
ALERT("%s has found %d %s veins.", null); ALERT("%s has found %d %s veins.", Color.DEFAULT);
private final String message; private final String message;
private final ChatColor color; private final ChatColor color;

View File

@ -7,23 +7,20 @@ import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import xyz.etztech.orealert.Color;
import xyz.etztech.orealert.Lang; import xyz.etztech.orealert.Lang;
import xyz.etztech.orealert.OreAlert; import xyz.etztech.orealert.OreAlert;
import java.awt.*;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Queue;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
@ -128,9 +125,9 @@ public class BlockBreakListener implements Listener {
private void alert(BlockEvent event, int strikes, boolean ping) { private void alert(BlockEvent event, int strikes, boolean ping) {
String message = String.format(Lang.ALERT.getMessage(), String message = String.format(Lang.ALERT.getMessage(),
event.getPlayer().getName(), strikes, Lang.getMaterialName(event.getMaterial())); event.getPlayer().getName(), strikes, Lang.getMaterialName(event.getMaterial()));
ChatColor color = ChatColor.of(this.plugin.getConfig().getString(String.format("blocks.%s.color", Lang.getMaterialKey(event.getMaterial())), "#00ffff")); String hexColor = this.plugin.getConfig().getString(String.format("blocks.%s.color", Lang.getMaterialKey(event.getMaterial())), "#00ffff");
BaseComponent[] component = new ComponentBuilder() BaseComponent[] component = new ComponentBuilder()
.append(message).color(color) .append(message).color(ChatColor.of(hexColor))
.create(); .create();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
@ -143,7 +140,7 @@ public class BlockBreakListener implements Listener {
String globalWebhook = this.plugin.getConfig().getString("webhook", ""); String globalWebhook = this.plugin.getConfig().getString("webhook", "");
String webhook = this.plugin.getConfig().getString(String.format("blocks.%s.webhook", Lang.getMaterialKey(event.getMaterial())), globalWebhook); String webhook = this.plugin.getConfig().getString(String.format("blocks.%s.webhook", Lang.getMaterialKey(event.getMaterial())), globalWebhook);
if (!"".equals(webhook)) { if (!"".equals(webhook)) {
String embed = embed(event, message, ping, color.getColor()); String embed = embed(event, message, ping, hexColor);
this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> { this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> {
try { try {
sendWebhook(webhook, embed); sendWebhook(webhook, embed);
@ -154,7 +151,7 @@ public class BlockBreakListener implements Listener {
} }
} }
private String embed(BlockEvent event, String message, boolean ping, Color color) { private String embed(BlockEvent event, String message, boolean ping, String hexColor) {
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
if (ping) { if (ping) {
json.addProperty("content", "@here"); json.addProperty("content", "@here");
@ -162,7 +159,7 @@ public class BlockBreakListener implements Listener {
JsonArray embeds = new JsonArray(); JsonArray embeds = new JsonArray();
JsonObject embed = new JsonObject(); JsonObject embed = new JsonObject();
embed.addProperty("color", color.getRGB()); embed.addProperty("color", Color.hexToInt(hexColor));
embed.addProperty("description", message); embed.addProperty("description", message);
JsonObject author = new JsonObject(); JsonObject author = new JsonObject();