Improve logging of error messages.

Allow the plugin to be disabled from our servers.
This commit is contained in:
Thijs Alders committed 2020-10-04 18:41:16 +02:00
1 parent 424c3d4358
commit 830b3794f3
10 files changed
+147 -63

No files matched your search

+9 -3
View File
@@ -58,9 +58,15 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-chat</artifactId>
<version>1.16-R0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -2,15 +2,15 @@ package net.craftingstore.bukkit.inventory.handlers;
import net.craftingstore.bukkit.inventory.CraftingStoreInventoryHolder;
import net.craftingstore.bukkit.inventory.InventoryItemHandler;
import net.craftingstore.bukkit.util.ChatColorUtil;
import net.craftingstore.core.models.api.inventory.types.InventoryItemMessage;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class MessageButtonHandler implements InventoryItemHandler<InventoryItemMessage> {
@Override
public void handle(Player p, InventoryItemMessage item, CraftingStoreInventoryHolder holder) {
for (String message : item.getMessages()) {
p.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
p.sendMessage(ChatColorUtil.translate(message));
}
if (item.shouldClose()) {
p.closeInventory();
@@ -0,0 +1,36 @@
package net.craftingstore.bukkit.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ChatColorUtil {
private static final Pattern HEX_PATTERN = Pattern.compile("&#(\\w{5}[0-9a-f])");
private static boolean hasHexAvailable = false;
static {
try {
Class.forName("net.md_5.bungee.api.ChatColor").getMethod("of", String.class);
hasHexAvailable = true;
} catch (NoSuchMethodException | ClassNotFoundException ignored) {
ignored.printStackTrace();
}
}
public static String translate(String textToTranslate) {
if (hasHexAvailable) {
return translateHexCodes(textToTranslate);
}
return org.bukkit.ChatColor.translateAlternateColorCodes('&', textToTranslate);
}
private static String translateHexCodes(String textToTranslate) {
Matcher matcher = HEX_PATTERN.matcher(textToTranslate);
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(buffer, net.md_5.bungee.api.ChatColor.of("#" + matcher.group(1)).toString());
}
return net.md_5.bungee.api.ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString());
}
}
@@ -20,4 +20,8 @@ public abstract class CraftingStoreLogger {
this.debug("Debug logging has been enabled!");
}
}
public boolean isDebugging() {
return this.debugging;
}
}
@@ -60,6 +60,14 @@ public class SocketProvider extends CraftingStoreProvider {
this.client.on(Socket.EVENT_CONNECT_ERROR, (Object... args) -> {
craftingStore.getLogger().debug("Socket server connect error event called");
this.disconnected();
if (!craftingStore.getLogger().isDebugging()) {
return;
}
for (Object arg : args) {
if (arg instanceof Exception) {
((Exception) arg).printStackTrace();
}
}
});
this.client.on("authenticated", (Object... args) -> {
craftingStore.getLogger().debug("Socket server authenticated");
@@ -70,8 +78,22 @@ public class SocketProvider extends CraftingStoreProvider {
this.craftingStore.executeQueue();
});
this.client.on("reload-plugin", (Object... args) -> this.craftingStore.reload());
this.client.on("disable-plugin", (Object... args) -> {
if (args.length > 0) {
craftingStore.getLogger().error(args[0].toString());
}
this.craftingStore.setEnabled(false);
});
this.client.on(Socket.EVENT_ERROR, (Object... args) -> {
craftingStore.getLogger().debug("Socket error event called");
if (!craftingStore.getLogger().isDebugging()) {
return;
}
for (Object arg : args) {
if (arg instanceof Exception) {
((Exception) arg).printStackTrace();
}
}
});
this.client.on(Socket.EVENT_RECONNECT, (Object... args) -> {
craftingStore.getLogger().debug("Socket reconnect event called");
@@ -26,7 +26,11 @@ public class DonationRunner {
Donation[] donationQueue = this.craftingStore.getApi().getDonationQueue().get();
new ExecuteDonationsJob(this.craftingStore, donationQueue);
} catch (CraftingStoreApiException | InterruptedException | ExecutionException e) {
e.printStackTrace();
if (craftingStore.getLogger().isDebugging()) {
e.printStackTrace();
} else {
craftingStore.getLogger().info("Failed to retrieve donation. The plugin will retry every 30 minutes.");
}
}
});
}
@@ -29,7 +29,11 @@ public class APICacheRenewer implements Runnable {
api.refreshPaymentsCache();
api.refreshTopDonatorsCache();
} catch (CraftingStoreApiException | ExecutionException | InterruptedException e) {
e.printStackTrace();
if (this.instance.getLogger().isDebugging()) {
e.printStackTrace();
} else {
instance.getLogger().error("Failed to renew API cache. If this issue persists, please contact support at https://craftingstore.net.");
}
}
}
}
@@ -33,7 +33,11 @@ public class DonationChecker implements Runnable {
Donation[] donationQueue = instance.getApi().getDonationQueue().get();
new ExecuteDonationsJob(instance, donationQueue);
} catch (CraftingStoreApiException | InterruptedException | ExecutionException e) {
e.printStackTrace();
if (instance.getLogger().isDebugging()) {
e.printStackTrace();
} else {
instance.getLogger().error("Failed to check for donations. If this issue persists, please contact support at https://craftingstore.net.");
}
}
}
}
@@ -27,7 +27,11 @@ public class InventoryRenewer implements Runnable {
try {
api.refreshGUICache();
} catch (CraftingStoreApiException | ExecutionException | InterruptedException e) {
e.printStackTrace();
if (instance.getLogger().isDebugging()) {
e.printStackTrace();
} else {
instance.getLogger().error("Failed to renew GUI cache. If this issue persists, please contact support at https://craftingstore.net.");
}
}
}
}
+54 -54
View File
@@ -1,55 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.craftingstore</groupId>
<artifactId>craftingstore</artifactId>
<packaging>pom</packaging>
<version>${revision}</version>
<properties>
<revision>${craftingstore-version}-RELEASE</revision>
<craftingstore-version>2.4.2</craftingstore-version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modules>
<module>core</module>
<module>bukkit</module>
<module>bungee</module>
<module>sponge</module>
<module>assembly</module>
<module>velocity</module>
</modules>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.craftingstore</groupId>
<artifactId>craftingstore</artifactId>
<packaging>pom</packaging>
<version>${revision}</version>
<properties>
<revision>${craftingstore-version}-RELEASE</revision>
<craftingstore-version>2.5.0</craftingstore-version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modules>
<module>core</module>
<module>bukkit</module>
<module>bungee</module>
<module>sponge</module>
<module>assembly</module>
<module>velocity</module>
</modules>
</project>