parent
6f29b43193
commit
3494a28ac5
|
@ -1,12 +1,42 @@
|
||||||
package xyz.etztech.minealert;
|
package xyz.etztech.minealert;
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class Color {
|
public enum Color {
|
||||||
public static ChatColor DEFAULT = ChatColor.GRAY;
|
DEFAULT("#AAAAAA"),
|
||||||
public static ChatColor ERROR = ChatColor.of("#f14668");
|
ERROR("#F14668"),
|
||||||
public static ChatColor INFO = ChatColor.of("#3298dc");
|
INFO("#3298DC"),
|
||||||
public static ChatColor PRIMARY = ChatColor.of("#3273dc");
|
PRIMARY("#3273DC");
|
||||||
|
|
||||||
|
private final String hex;
|
||||||
|
private final ChatColor chatColor;
|
||||||
|
|
||||||
|
Color(String hex) {
|
||||||
|
this.hex = hex;
|
||||||
|
this.chatColor = ChatColor.of(hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHex() {
|
||||||
|
return hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatColor getChatColor() {
|
||||||
|
return chatColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sms(CommandSender commandSender, String message) {
|
||||||
|
if (commandSender instanceof ConsoleCommandSender) {
|
||||||
|
MineAlert.getInstance().log(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TextComponent text = new TextComponent(message);
|
||||||
|
text.setColor(this.chatColor);
|
||||||
|
commandSender.spigot().sendMessage(text);
|
||||||
|
}
|
||||||
|
|
||||||
public static int hexToInt(String hex) {
|
public static int hexToInt(String hex) {
|
||||||
if (hex.startsWith("#")) {
|
if (hex.startsWith("#")) {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package xyz.etztech.minealert;
|
package xyz.etztech.minealert;
|
||||||
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import org.apache.commons.lang.WordUtils;
|
import org.apache.commons.lang.WordUtils;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -11,12 +9,14 @@ 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("MineAlert reloaded.", Color.INFO),
|
PLUGIN_RELOADED("MineAlert reloaded.", Color.INFO),
|
||||||
ALERT("%s has found %d %s veins.", Color.DEFAULT);
|
ALERT("%s has found %d %s veins.", Color.DEFAULT),
|
||||||
|
NOT_ENOUGH_ARGS("%s requires %d arguments.", Color.ERROR),
|
||||||
|
WEBHOOK_FAILED("Could not send webhook.", Color.ERROR);
|
||||||
|
|
||||||
private final String message;
|
private final String message;
|
||||||
private final ChatColor color;
|
private final Color color;
|
||||||
|
|
||||||
Lang(String message, ChatColor color) {
|
Lang(String message, Color color) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
@ -25,14 +25,12 @@ public enum Lang {
|
||||||
return this.message;
|
return this.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatColor getColor() {
|
public Color getColor() {
|
||||||
return this.color;
|
return this.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sms(CommandSender sender) {
|
public void sms(CommandSender sender, Object ...args) {
|
||||||
TextComponent text = new TextComponent(this.message);
|
this.color.sms(sender, String.format(this.message, args));
|
||||||
text.setColor(this.color);
|
|
||||||
sender.spigot().sendMessage(text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMaterialName(Material material) {
|
public static String getMaterialName(Material material) {
|
||||||
|
|
|
@ -9,9 +9,11 @@ import java.util.logging.Logger;
|
||||||
|
|
||||||
public class MineAlert extends JavaPlugin {
|
public class MineAlert extends JavaPlugin {
|
||||||
|
|
||||||
|
private static MineAlert instance;
|
||||||
private final Logger log = Logger.getLogger( "Minecraft" );
|
private final Logger log = Logger.getLogger( "Minecraft" );
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
instance = this;
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
|
|
||||||
|
@ -25,6 +27,10 @@ public class MineAlert extends JavaPlugin {
|
||||||
log.info( "[MineAlert]: " + message );
|
log.info( "[MineAlert]: " + message );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MineAlert getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param def The default if no paths resolve
|
* @param def The default if no paths resolve
|
||||||
* @param path Config paths to check, from specific -> fallback
|
* @param path Config paths to check, from specific -> fallback
|
||||||
|
|
|
@ -18,10 +18,11 @@ public class Webhook {
|
||||||
byte[] out = embed.getBytes(StandardCharsets.UTF_8);
|
byte[] out = embed.getBytes(StandardCharsets.UTF_8);
|
||||||
int length = out.length;
|
int length = out.length;
|
||||||
http.setFixedLengthStreamingMode(length);
|
http.setFixedLengthStreamingMode(length);
|
||||||
http.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
http.setRequestProperty("Content-Type", "application/json; utf-8");
|
||||||
http.connect();
|
http.setRequestProperty("User-Agent", "MineAlert Agent");
|
||||||
|
|
||||||
OutputStream os = http.getOutputStream();
|
try (OutputStream os = http.getOutputStream()) {
|
||||||
os.write(out);
|
os.write(out, 0, out.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package xyz.etztech.minealert.commands;
|
package xyz.etztech.minealert.commands;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
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;
|
||||||
|
@ -9,6 +11,7 @@ import org.bukkit.command.CommandSender;
|
||||||
import xyz.etztech.minealert.Color;
|
import xyz.etztech.minealert.Color;
|
||||||
import xyz.etztech.minealert.Lang;
|
import xyz.etztech.minealert.Lang;
|
||||||
import xyz.etztech.minealert.MineAlert;
|
import xyz.etztech.minealert.MineAlert;
|
||||||
|
import xyz.etztech.minealert.Webhook;
|
||||||
|
|
||||||
public class MainCommand implements CommandExecutor {
|
public class MainCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
@ -36,6 +39,9 @@ public class MainCommand implements CommandExecutor {
|
||||||
case "reload":
|
case "reload":
|
||||||
reload(commandSender);
|
reload(commandSender);
|
||||||
break;
|
break;
|
||||||
|
case "webhook":
|
||||||
|
webhook(commandSender);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Lang.UNKNOWN_COMMAND.sms(commandSender);
|
Lang.UNKNOWN_COMMAND.sms(commandSender);
|
||||||
break;
|
break;
|
||||||
|
@ -47,9 +53,10 @@ public class MainCommand implements CommandExecutor {
|
||||||
private void help(CommandSender commandSender) {
|
private void help(CommandSender commandSender) {
|
||||||
String version = Bukkit.getPluginManager().getPlugin("MineAlert").getDescription().getVersion();
|
String version = Bukkit.getPluginManager().getPlugin("MineAlert").getDescription().getVersion();
|
||||||
BaseComponent[] message = new ComponentBuilder()
|
BaseComponent[] message = new ComponentBuilder()
|
||||||
.append(String.format("===== MineAlert v%s =====", version)).color(Color.PRIMARY)
|
.append(String.format("===== MineAlert v%s =====", version)).color(Color.PRIMARY.getChatColor())
|
||||||
.append("\n/minealert help - Show this message").color(Color.INFO)
|
.append("\n/minealert help - Show this message").color(Color.INFO.getChatColor())
|
||||||
.append("\n/minealert reload - Reload the config").color(Color.INFO)
|
.append("\n/minealert reload - Reload the config").color(Color.INFO.getChatColor())
|
||||||
|
.append("\n/minealert webhook - Test the global webhook").color(Color.INFO.getChatColor())
|
||||||
.create();
|
.create();
|
||||||
commandSender.spigot().sendMessage(message);
|
commandSender.spigot().sendMessage(message);
|
||||||
}
|
}
|
||||||
|
@ -58,4 +65,41 @@ public class MainCommand implements CommandExecutor {
|
||||||
this.plugin.reloadConfig();
|
this.plugin.reloadConfig();
|
||||||
Lang.PLUGIN_RELOADED.sms(commandSender);
|
Lang.PLUGIN_RELOADED.sms(commandSender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void webhook(CommandSender commandSender) {
|
||||||
|
String webhook = this.plugin.getConfig().getString("webhook", "");
|
||||||
|
if ("".equals(webhook)) {
|
||||||
|
Color.ERROR.sms(commandSender, "Global webhook cannot be blank to test.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||||
|
try {
|
||||||
|
Webhook.send(webhook, embed());
|
||||||
|
Color.INFO.sms(commandSender, "Webhook sent!");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Lang.WEBHOOK_FAILED.sms(commandSender);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String embed() {
|
||||||
|
JsonObject json = new JsonObject();
|
||||||
|
JsonArray embeds = new JsonArray();
|
||||||
|
|
||||||
|
JsonObject embed = new JsonObject();
|
||||||
|
embed.addProperty("color", Color.hexToInt("#3273dc"));
|
||||||
|
embed.addProperty("description", "Test Message");
|
||||||
|
|
||||||
|
JsonObject author = new JsonObject();
|
||||||
|
author.addProperty("name", "Console");
|
||||||
|
author.addProperty("icon_url", "https://minotar.net/helm/Notch/100.png");
|
||||||
|
embed.add("author", author);
|
||||||
|
|
||||||
|
embeds.add(embed);
|
||||||
|
json.add("embeds", embeds);
|
||||||
|
|
||||||
|
return json.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class BlockBreakListener implements Listener {
|
||||||
for (int x = -radius; x < radius; x++) {
|
for (int x = -radius; x < radius; x++) {
|
||||||
for (int y = -radius; y < radius; y++) {
|
for (int y = -radius; y < radius; y++) {
|
||||||
for (int z = -radius; z < radius; z++) {
|
for (int z = -radius; z < radius; z++) {
|
||||||
|
if (x == 0 && y == 0 && z == 0) continue;
|
||||||
queue.add(new BlockEvent(event.getPlayer(), event.getBlock().getRelative(x, y, z).getType(), false));
|
queue.add(new BlockEvent(event.getPlayer(), event.getBlock().getRelative(x, y, z).getType(), false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +61,9 @@ public class BlockBreakListener implements Listener {
|
||||||
for (String s: this.plugin.getConfig().getConfigurationSection("ore.blocks").getKeys(false)) {
|
for (String s: this.plugin.getConfig().getConfigurationSection("ore.blocks").getKeys(false)) {
|
||||||
if (Lang.getMaterialKey(event.getMaterial()).equals(s)) {
|
if (Lang.getMaterialKey(event.getMaterial()).equals(s)) {
|
||||||
addStrike(event);
|
addStrike(event);
|
||||||
check(event);
|
if (event.isParent()) {
|
||||||
|
check(event);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,7 +171,7 @@ public class BlockBreakListener implements Listener {
|
||||||
try {
|
try {
|
||||||
Webhook.send(webhook, embed);
|
Webhook.send(webhook, embed);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
this.plugin.log(String.format("Could not send webhook: %s", e.getMessage()));
|
this.plugin.log(Lang.WEBHOOK_FAILED.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue