Skip to content

Commit

Permalink
UltraStaffChat - Version 5.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
LooFifteen authored Nov 20, 2021
2 parents 003cef4 + 66cac37 commit 04a9581
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.5
- uses: actions/checkout@v2.4.0
- name: Set up JDK 1.8
uses: actions/setup-java@v2
with:
Expand Down
16 changes: 12 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<groupId>dev.hypera</groupId>
<artifactId>UltraStaffChat</artifactId>
<version>5.1.2</version>
<version>5.1.3</version>
<packaging>jar</packaging>

<name>UltraStaffChat</name>
Expand Down Expand Up @@ -57,6 +57,14 @@
<pattern>org.bstats</pattern>
<shadedPattern>dev.hypera.ultrastaffchat.metrics</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori.adventure</pattern>
<shadedPattern>dev.hypera.ultrastaffchat.adventure</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori.examination</pattern>
<shadedPattern>dev.hypera.ultrastaffchat.examination</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
Expand Down Expand Up @@ -105,21 +113,21 @@
<dependency>
<groupId>dev.hypera</groupId>
<artifactId>UpdateLib</artifactId>
<version>3.1.2</version>
<version>4.0.0</version>
</dependency>

<!-- Reflections for automatic registry -->
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.12</version>
<version>0.10.2</version>
</dependency>

<!-- Adventure for advanced messages -->
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.9.1</version>
<version>4.9.3</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/dev/hypera/ultrastaffchat/UltraStaffChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import dev.hypera.ultrastaffchat.utils.Debug;
import dev.hypera.ultrastaffchat.utils.Discord;
import dev.hypera.updatelib.UpdateLib;
import dev.hypera.updatelib.UpdateLibBuilder;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.md_5.bungee.api.plugin.Plugin;
import org.bstats.bungeecord.Metrics;
Expand Down Expand Up @@ -65,10 +64,13 @@ public void onEnable() {
}

adventure = BungeeAudiences.create(this);
updateLib = UpdateLibBuilder.create(getDescription().getVersion(), Common.getResourceId()).setCompleteAction(status -> {
if(status.isAvailable())
Common.logPrefix("&cAn update is available! " + getDescription().getVersion() + " -> " + status.getDistributedVersion());
}).setErrorHandler(error -> {}).build();
updateLib = UpdateLib.builder()
.version(getDescription().getVersion())
.resource(Common.getResourceId())
.handler(status -> {
if (status.isAvailable())
Common.logPrefix("&cAn update is available! " + getDescription().getVersion() + " -> " + status.getDistributedVersion());
}).build();

ListenerManager.setup();
CommandManager.setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;

import java.io.File;
import java.io.FileWriter;
Expand Down Expand Up @@ -81,12 +82,12 @@ private void reload(CommandSender sender, Audience audience) {
return;
}

audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Reloading configuration files...").color(NamedTextColor.GREEN)));
audience.sendMessage(Common.getLogPrefixAdventure().append(Component.text("Reloading configuration files...").color(NamedTextColor.GREEN)));

UltraStaffChat.getConfig().reload();
Discord.reload();

audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Successfully reloaded configuration files").color(NamedTextColor.GREEN)));
audience.sendMessage(Common.getLogPrefixAdventure().append(Component.text("Successfully reloaded configuration files").color(NamedTextColor.GREEN)));
}

private void debug(CommandSender sender, String[] args, Audience audience) {
Expand All @@ -95,6 +96,7 @@ private void debug(CommandSender sender, String[] args, Audience audience) {
return;
}

boolean isPlayer = sender instanceof ProxiedPlayer;
String log;

boolean advanced = false;
Expand All @@ -108,17 +110,17 @@ private void debug(CommandSender sender, String[] args, Audience audience) {
}

if(advanced) {
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Generating advanced debug log...").color(NamedTextColor.WHITE)));
audience.sendMessage(Common.getLogPrefixAdventure().append(Component.text("Generating advanced debug log...").color(NamedTextColor.WHITE)));
log = generateAdvancedDebugLog();
} else {
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Generating debug log...").color(NamedTextColor.WHITE)));
audience.sendMessage(Common.getLogPrefixAdventure().append(Component.text("Generating debug log...").color(NamedTextColor.WHITE)));
log = generateDebugLog();
}

logDebug(audience, log, advanced);
logDebug(audience, isPlayer, log, advanced);
}

private void logDebug(Audience audience, String log, boolean advanced) {
private void logDebug(Audience audience, boolean isPlayer, String log, boolean advanced) {
try {
String filename = "USC-" + TimeUtils.formatFileDateTime(Date.from(Instant.now())) + "-Debug.txt";
File logFolder = new File(UltraStaffChat.getInstance().getDataFolder() + "/logs");
Expand All @@ -137,14 +139,20 @@ private void logDebug(Audience audience, String log, boolean advanced) {
String pasteURL = PasteUtils.createPaste(log);
if(pasteURL == null)
throw new Exception();
if(advanced) {
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Successfully generated debug log ").color(NamedTextColor.GREEN), Component.text().content("[View]").color(NamedTextColor.GRAY).clickEvent(ClickEvent.openUrl(pasteURL)).hoverEvent(HoverEvent.showText(Component.text().content(pasteURL)))));

Component component;
if (advanced) {
component = Common.getLogPrefixAdventure().append(Component.text("Successfully generated debug log").color(NamedTextColor.GREEN));
if (isPlayer) component = component.append(Component.text(" [View]").color(NamedTextColor.GRAY).clickEvent(ClickEvent.openUrl(pasteURL)).hoverEvent(HoverEvent.showText(Component.text(pasteURL))));
} else {
audience.sendMessage(Component.text().append(LegacyComponentSerializer.legacy('&').deserialize(log).clickEvent(ClickEvent.openUrl(pasteURL))));
component = Common.adventurise(log);
if (isPlayer) component = component.clickEvent(ClickEvent.openUrl(pasteURL));
}
audience.sendMessage(component);
if (!isPlayer) audience.sendMessage(Common.getLogPrefixAdventure().append(Component.text(pasteURL).color(NamedTextColor.GRAY)));
} catch (Exception e) {
Common.logPrefix("Failed to generate debug log!");
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Failed to generate debug log").color(NamedTextColor.RED)));
audience.sendMessage(Common.getLogPrefixAdventure().append(Component.text("Failed to generate debug log").color(NamedTextColor.RED)));
}
}

Expand Down
38 changes: 38 additions & 0 deletions src/main/java/dev/hypera/ultrastaffchat/utils/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class Common {

private static final String logPrefix = "&7[&c&lUltraStaffChat&7] &f";
private static final String errorPrefix = "&7[&4&lError&7] &4";
private static final Component logPrefixAdventure = adventurise(logPrefix);
private static final Component errorPrefixAdventure = adventurise(errorPrefix);

private static final int bStatsId = 5040;
private static final long resourceId = 68956;
Expand Down Expand Up @@ -164,6 +166,42 @@ public static Component message(String key) {
return adventurise(messageRaw(key));
}

/**
* Get the legacy ampersand log prefix
*
* @return (String) prefix.
*/
public static String getLogPrefix() {
return logPrefix;
}

/**
* Get the legacy ampersand error prefix
*
* @return (String) error prefix.
*/
public static String getErrorPrefix() {
return errorPrefix;
}

/**
* Get the component log prefix
*
* @return (Component) prefix.
*/
public static Component getLogPrefixAdventure() {
return logPrefixAdventure;
}

/**
* Get the component error prefix
*
* @return (Component) error prefix.
*/
public static Component getErrorPrefixAdventure() {
return errorPrefixAdventure;
}

/**
* Turns a message into an Adventure Component.
*
Expand Down
41 changes: 15 additions & 26 deletions src/main/java/dev/hypera/ultrastaffchat/utils/Discord.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import dev.hypera.ultrastaffchat.UltraStaffChat;
import dev.hypera.ultrastaffchat.utils.DiscordWebhook.EmbedObject;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
Expand All @@ -37,35 +36,25 @@ public class Discord {
private static String hookURL = "";

public static void setup() {
if(!UltraStaffChat.getConfig().getBoolean("discord-enabled").equals(true))
Configuration config = UltraStaffChat.getConfig().getConfiguration();
if(!config.getBoolean("discord-enabled"))
return;
if(UltraStaffChat.getConfig().getString("discord-webhook") == null || UltraStaffChat.getConfig().getString("discord-webhook").contains("XXXXXXXXXXXXXXXXXX")) {
if(config.getString("discord-webhook") == null || config.getString("discord-webhook").contains("XXXXXXXXXXXXXXXXXX")) {
Common.logPrefix("&cError: Discord messages are enabled but the webhook URL has not been configured!");
return;
}

Configuration config = UltraStaffChat.getConfig().getConfiguration();
if (config.getSection("discord-format.embed.fields").getKeys().size() > 25) {
Common.logPrefix("&cError: You can have a max of 25 fields in an embed.");
return;
} else if (config.getSection("discord-join-format.embed.fields").getKeys().size() > 25) {
Common.logPrefix("&cError: You can have a max of 25 fields in an embed.");
return;
} else if (config.getSection("discord-leave-format.embed.fields").getKeys().size() > 25) {
Common.logPrefix("&cError: You can have a max of 25 fields in an embed.");
return;
} else if (config.getSection("discord-switch-format.embed.fields").getKeys().size() > 25) {
Common.logPrefix("&cError: You can have a max of 25 fields in an embed.");
return;
} else if (config.getSection("discord-afk-enable-format.embed.fields").getKeys().size() > 25) {
Common.logPrefix("&cError: You can have a max of 25 fields in an embed.");
return;
} else if (config.getSection("discord-afk-disable-format.embed.fields").getKeys().size() > 25) {
if (config.getSection("discord-format.embed.fields").getKeys().size() > 25
|| config.getSection("discord-join-format.embed.fields").getKeys().size() > 25
|| config.getSection("discord-leave-format.embed.fields").getKeys().size() > 25
|| config.getSection("discord-switch-format.embed.fields").getKeys().size() > 25
|| config.getSection("discord-afk-enable-format.embed.fields").getKeys().size() > 25
|| config.getSection("discord-afk-disable-format.embed.fields").getKeys().size() > 25) {
Common.logPrefix("&cError: You can have a max of 25 fields in an embed.");
return;
}

hookURL = UltraStaffChat.getConfig().getString("discord-webhook");
hookURL = config.getString("discord-webhook");
enabled = true;
}

Expand All @@ -79,7 +68,7 @@ public static boolean isEnabled() {
}

public static void broadcastDiscordJoin(ProxiedPlayer p) {
if(!isEnabled())
if(!isEnabled() && UltraStaffChat.getConfig().getConfiguration().getBoolean("discord-join-messages"))
return;
ProxyServer.getInstance().getScheduler().runAsync(UltraStaffChat.getInstance(), () -> {
try {
Expand Down Expand Up @@ -113,7 +102,7 @@ public static void broadcastDiscordJoin(ProxiedPlayer p) {
}

public static void broadcastDiscordLeave(ProxiedPlayer p) {
if(!isEnabled())
if(!isEnabled() && UltraStaffChat.getConfig().getConfiguration().getBoolean("discord-leave-messages"))
return;
ProxyServer.getInstance().getScheduler().runAsync(UltraStaffChat.getInstance(), () -> {
try {
Expand Down Expand Up @@ -148,7 +137,7 @@ public static void broadcastDiscordLeave(ProxiedPlayer p) {
}

public static void broadcastDiscordSwitch(ProxiedPlayer p, String from, String to) {
if(!isEnabled())
if(!isEnabled() && UltraStaffChat.getConfig().getConfiguration().getBoolean("discord-switch-messages"))
return;
ProxyServer.getInstance().getScheduler().runAsync(UltraStaffChat.getInstance(), () -> {
try {
Expand Down Expand Up @@ -226,7 +215,7 @@ public static void broadcastDiscordStaffChatMessage(CommandSender s, String mess
}

public static void broadcastDiscordAFKEnable(ProxiedPlayer p) {
if(!isEnabled())
if(!isEnabled() && UltraStaffChat.getConfig().getConfiguration().getBoolean("discord-afk-enable-messages"))
return;
ProxyServer.getInstance().getScheduler().runAsync(UltraStaffChat.getInstance(), () -> {
try {
Expand Down Expand Up @@ -261,7 +250,7 @@ public static void broadcastDiscordAFKEnable(ProxiedPlayer p) {
}

public static void broadcastDiscordAFKDisable(ProxiedPlayer p) {
if(!isEnabled())
if(!isEnabled() && UltraStaffChat.getConfig().getConfiguration().getBoolean("discord-afk-disable-messages"))
return;
ProxyServer.getInstance().getScheduler().runAsync(UltraStaffChat.getInstance(), () -> {
try {
Expand Down

0 comments on commit 04a9581

Please sign in to comment.