Made all channels configurable

Removed Vault repo, was unused and errors now
Removed all channel fields from main class
This commit is contained in:
Norbi Peti 2019-02-13 15:21:57 +01:00
parent 9ba57fd989
commit 13b168d238
7 changed files with 415 additions and 409 deletions

502
pom.xml
View file

@ -1,251 +1,251 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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"> 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> <modelVersion>4.0.0</modelVersion>
<groupId>com.github.TBMCPlugins</groupId> <groupId>com.github.TBMCPlugins</groupId>
<artifactId>DiscordPlugin</artifactId> <artifactId>DiscordPlugin</artifactId>
<version>master-SNAPSHOT</version> <version>master-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>DiscordPlugin</name> <name>DiscordPlugin</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<build> <build>
<!-- <sourceDirectory>target/generated-sources/delombok</sourceDirectory> <!-- <sourceDirectory>target/generated-sources/delombok</sourceDirectory>
<testSourceDirectory>target/generated-test-sources/delombok</testSourceDirectory> --> <testSourceDirectory>target/generated-test-sources/delombok</testSourceDirectory> -->
<sourceDirectory>src/main/java</sourceDirectory> <sourceDirectory>src/main/java</sourceDirectory>
<resources> <resources>
<resource> <resource>
<directory>src</directory> <directory>src</directory>
<excludes> <excludes>
<exclude>**/*.java</exclude> <exclude>**/*.java</exclude>
</excludes> </excludes>
</resource> </resource>
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<includes> <includes>
<include>*.properties</include> <include>*.properties</include>
<include>*.yml</include> <include>*.yml</include>
<include>*.csv</include> <include>*.csv</include>
<include>*.txt</include> <include>*.txt</include>
</includes> </includes>
<filtering>true</filtering> <filtering>true</filtering>
</resource> </resource>
</resources> </resources>
<finalName>DiscordPlugin</finalName> <finalName>DiscordPlugin</finalName>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version> <version>3.6.2</version>
<configuration> <configuration>
<source>1.8</source> <source>1.8</source>
<target>1.8</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version> <version>2.4.2</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
<goals> <goals>
<goal>shade</goal> <goal>shade</goal>
</goals> </goals>
<configuration> <configuration>
<artifactSet> <artifactSet>
<excludes> <excludes>
<exclude>org.spigotmc:spigot-api</exclude> <exclude>org.spigotmc:spigot-api</exclude>
<exclude>com.github.TBMCPlugins.ButtonCore:ButtonCore</exclude> <exclude>com.github.TBMCPlugins.ButtonCore:ButtonCore</exclude>
<exclude>net.ess3:Essentials</exclude> <exclude>net.ess3:Essentials</exclude>
</excludes> <!-- http://stackoverflow.com/questions/28458058/maven-shade-plugin-exclude-a-dependency-and-all-its-transitive-dependencies --> </excludes> <!-- http://stackoverflow.com/questions/28458058/maven-shade-plugin-exclude-a-dependency-and-all-its-transitive-dependencies -->
</artifactSet> </artifactSet>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version> <version>3.0.1</version>
<executions> <executions>
<execution> <execution>
<id>copy</id> <id>copy</id>
<phase>compile</phase> <phase>compile</phase>
<goals> <goals>
<goal>copy-resources</goal> <goal>copy-resources</goal>
</goals> </goals>
<configuration> <configuration>
<outputDirectory>target</outputDirectory> <outputDirectory>target</outputDirectory>
<resources> <resources>
<resource> <resource>
<directory>resources</directory> <directory>resources</directory>
</resource> </resource>
</resources> </resources>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!-- <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <!-- <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId>
<version>1.16.16.0</version> <executions> <execution> <id>delombok</id> <phase>generate-sources</phase> <version>1.16.16.0</version> <executions> <execution> <id>delombok</id> <phase>generate-sources</phase>
<goals> <goal>delombok</goal> </goals> <configuration> <addOutputDirectory>false</addOutputDirectory> <goals> <goal>delombok</goal> </goals> <configuration> <addOutputDirectory>false</addOutputDirectory>
<sourceDirectory>src/main/java</sourceDirectory> <verbose>true</verbose> <sourceDirectory>src/main/java</sourceDirectory> <verbose>true</verbose>
</configuration> </execution> <execution> <id>test-delombok</id> <phase>generate-test-sources</phase> </configuration> </execution> <execution> <id>test-delombok</id> <phase>generate-test-sources</phase>
<goals> <goal>testDelombok</goal> </goals> <configuration> <addOutputDirectory>false</addOutputDirectory> <goals> <goal>testDelombok</goal> </goals> <configuration> <addOutputDirectory>false</addOutputDirectory>
<sourceDirectory>src/test/java</sourceDirectory> </configuration> </execution> <sourceDirectory>src/test/java</sourceDirectory> </configuration> </execution>
</executions> </plugin> --> </executions> </plugin> -->
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<useSystemClassLoader>false <useSystemClassLoader>false
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 --> </useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<branch> <branch>
master master
</branch> <!-- Should be master if building ButtonCore locally - the CI will overwrite it (see below) --> </branch> <!-- Should be master if building ButtonCore locally - the CI will overwrite it (see below) -->
</properties> </properties>
<repositories> <repositories>
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository> </repository>
<repository> <!-- This repo fixes issues with transitive dependencies --> <repository> <!-- This repo fixes issues with transitive dependencies -->
<id>jcenter</id> <id>jcenter</id>
<url>http://jcenter.bintray.com</url> <url>http://jcenter.bintray.com</url>
</repository> </repository>
<repository> <repository>
<id>jitpack.io</id> <id>jitpack.io</id>
<url>https://jitpack.io</url> <url>https://jitpack.io</url>
</repository> </repository>
<repository> <!-- <repository>
<id>vault-repo</id> <id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url> <url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository> </repository> -->
<repository> <repository>
<id>Essentials</id> <id>Essentials</id>
<url>http://repo.ess3.net/content/repositories/essrel/</url> <url>http://repo.ess3.net/content/repositories/essrel/</url>
</repository> </repository>
<repository> <repository>
<id>projectlombok.org</id> <id>projectlombok.org</id>
<url>http://projectlombok.org/mavenrepo</url> <url>http://projectlombok.org/mavenrepo</url>
</repository> </repository>
<!-- <repository> <!-- <repository>
<id>pex-repo</id> <id>pex-repo</id>
<url>http://pex-repo.aoeu.xyz</url> <url>http://pex-repo.aoeu.xyz</url>
</repository> --> </repository> -->
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.12-R0.1-SNAPSHOT</version> <version>1.12-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version> <version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.discord4j/Discord4J --> <!-- https://mvnrepository.com/artifact/com.discord4j/Discord4J -->
<!-- <dependency> <!-- <dependency>
<groupId>com.discord4j</groupId> <groupId>com.discord4j</groupId>
<artifactId>Discord4J</artifactId> <artifactId>Discord4J</artifactId>
<version>2.10.1</version> <version>2.10.1</version>
</dependency> --> </dependency> -->
<dependency> <dependency>
<groupId>com.github.SizableShrimp</groupId> <groupId>com.github.SizableShrimp</groupId>
<artifactId>Discord4J</artifactId> <artifactId>Discord4J</artifactId>
<version>httprequestchange-SNAPSHOT</version> <version>httprequestchange-SNAPSHOT</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 --> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId> <artifactId>slf4j-jdk14</artifactId>
<version>1.7.21</version> <version>1.7.21</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.TBMCPlugins.ButtonCore</groupId> <groupId>com.github.TBMCPlugins.ButtonCore</groupId>
<artifactId>ButtonCore</artifactId> <artifactId>ButtonCore</artifactId>
<version>${branch}-SNAPSHOT</version> <version>${branch}-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.milkbowl</groupId> <!-- net.milkbowl.vault --> <groupId>com.github.milkbowl</groupId> <!-- net.milkbowl.vault -->
<artifactId>VaultAPI</artifactId> <artifactId>VaultAPI</artifactId>
<version>master-SNAPSHOT</version> <!-- 1.6 --> <version>master-SNAPSHOT</version> <!-- 1.6 -->
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.ess3</groupId> <groupId>net.ess3</groupId>
<artifactId>Essentials</artifactId> <artifactId>Essentials</artifactId>
<version>2.13.1</version> <version>2.13.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.xaanit</groupId> <groupId>com.github.xaanit</groupId>
<artifactId>D4J-OAuth</artifactId> <artifactId>D4J-OAuth</artifactId>
<version>master-SNAPSHOT</version> <version>master-SNAPSHOT</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.16.16</version> <version>1.16.16</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- <dependency> <!-- <dependency>
<groupId>ru.tehkode</groupId> <groupId>ru.tehkode</groupId>
<artifactId>PermissionsEx</artifactId> <artifactId>PermissionsEx</artifactId>
<version>1.23.1</version> <version>1.23.1</version>
<scope>provided</scope> <scope>provided</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> --> </dependency> -->
<!-- https://mvnrepository.com/artifact/org.objenesis/objenesis --> <!-- https://mvnrepository.com/artifact/org.objenesis/objenesis -->
<dependency> <dependency>
<groupId>org.objenesis</groupId> <groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId> <artifactId>objenesis</artifactId>
<version>2.6</version> <version>2.6</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.vdurmont</groupId> <groupId>com.vdurmont</groupId>
<artifactId>emoji-java</artifactId> <artifactId>emoji-java</artifactId>
<version>4.0.0</version> <version>4.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
<profiles> <profiles>
<profile> <profile>
<id>ci</id> <id>ci</id>
<activation> <activation>
<property> <property>
<name>env.TRAVIS_BRANCH</name> <name>env.TRAVIS_BRANCH</name>
</property> </property>
</activation> </activation>
<properties> <properties>
<!-- Override only if necessary --> <!-- Override only if necessary -->
<branch>${env.TRAVIS_BRANCH}</branch> <branch>${env.TRAVIS_BRANCH}</branch>
</properties> </properties>
</profile> </profile>
</profiles> </profiles>
</project> </project>

View file

@ -5,6 +5,7 @@ import buttondevteam.discordplugin.commands.Command2DC;
import buttondevteam.discordplugin.commands.DiscordCommandBase; import buttondevteam.discordplugin.commands.DiscordCommandBase;
import buttondevteam.discordplugin.commands.VersionCommand; import buttondevteam.discordplugin.commands.VersionCommand;
import buttondevteam.discordplugin.exceptions.ExceptionListenerModule; import buttondevteam.discordplugin.exceptions.ExceptionListenerModule;
import buttondevteam.discordplugin.fun.FunModule;
import buttondevteam.discordplugin.listeners.CommonListeners; import buttondevteam.discordplugin.listeners.CommonListeners;
import buttondevteam.discordplugin.listeners.MCListener; import buttondevteam.discordplugin.listeners.MCListener;
import buttondevteam.discordplugin.mcchat.MCChatPrivate; import buttondevteam.discordplugin.mcchat.MCChatPrivate;
@ -89,18 +90,6 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
} }
} }
public static IChannel botchannel; //Can be removed
public static IChannel annchannel;
public static IChannel genchannel;
public static IChannel chatchannel;
public static IChannel botroomchannel;
public static IChannel modlogchannel;
/**
* Don't send messages, just receive, the same channel is used when testing
*/
public static IChannel officechannel;
public static IChannel updatechannel;
public static IChannel devofficechannel;
public static IGuild mainServer; public static IGuild mainServer;
public static IGuild devServer; public static IGuild devServer;
@ -119,31 +108,10 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
if (mainServer == null || devServer == null) if (mainServer == null || devServer == null)
return; // Retry return; // Retry
if (!TBMCCoreAPI.IsTestServer()) { //Don't change conditions here, see mainServer=devServer=null in onDisable() if (!TBMCCoreAPI.IsTestServer()) { //Don't change conditions here, see mainServer=devServer=null in onDisable()
botchannel = mainServer.getChannelByID(209720707188260864L); // bot
annchannel = mainServer.getChannelByID(126795071927353344L); // announcements
genchannel = mainServer.getChannelByID(125813020357165056L); // general
chatchannel = mainServer.getChannelByID(249663564057411596L); // minecraft_chat
botroomchannel = devServer.getChannelByID(239519012529111040L); // bot-room
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
updatechannel = devServer.getChannelByID(233724163519414272L); // server-updates
devofficechannel = officechannel; // developers-office
modlogchannel = mainServer.getChannelByID(283840717275791360L); // modlog
dc.changePresence(StatusType.ONLINE, ActivityType.PLAYING, "Chromacraft"); dc.changePresence(StatusType.ONLINE, ActivityType.PLAYING, "Chromacraft");
} else { } else {
botchannel = devServer.getChannelByID(239519012529111040L); // bot-room
annchannel = botchannel; // bot-room
genchannel = botchannel; // bot-room
botroomchannel = botchannel;// bot-room
chatchannel = botchannel;// bot-room
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
updatechannel = botchannel;
devofficechannel = botchannel;// bot-room
modlogchannel = botchannel; // bot-room
dc.changePresence(StatusType.ONLINE, ActivityType.PLAYING, "testing"); dc.changePresence(StatusType.ONLINE, ActivityType.PLAYING, "testing");
} }
if (botchannel == null || annchannel == null || genchannel == null || botroomchannel == null
|| chatchannel == null || officechannel == null || updatechannel == null)
return; // Retry
SafeMode = false; SafeMode = false;
if (task != null) if (task != null)
task.cancel(); task.cancel();
@ -153,6 +121,7 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
Component.registerComponent(this, new ExceptionListenerModule()); Component.registerComponent(this, new ExceptionListenerModule());
Component.registerComponent(this, new GameRoleModule()); //Needs the mainServer to be set Component.registerComponent(this, new GameRoleModule()); //Needs the mainServer to be set
Component.registerComponent(this, new AnnouncerModule()); Component.registerComponent(this, new AnnouncerModule());
Component.registerComponent(this, new FunModule());
new ChromaBot(this).updatePlayerList(); //Initialize ChromaBot - The MCCHatModule is tested to be enabled new ChromaBot(this).updatePlayerList(); //Initialize ChromaBot - The MCCHatModule is tested to be enabled
DiscordCommandBase.registerCommands(); DiscordCommandBase.registerCommands();

View file

@ -1,31 +1,32 @@
package buttondevteam.discordplugin.exceptions; package buttondevteam.discordplugin.exceptions;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.core.ComponentManager;
import buttondevteam.lib.TBMCDebugMessageEvent; import buttondevteam.discordplugin.DiscordPlugin;
import org.bukkit.event.EventHandler; import buttondevteam.lib.TBMCDebugMessageEvent;
import org.bukkit.event.Listener; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class DebugMessageListener implements Listener{
@EventHandler public class DebugMessageListener implements Listener{
public void onDebugMessage(TBMCDebugMessageEvent e) { @EventHandler
SendMessage(e.getDebugMessage()); public void onDebugMessage(TBMCDebugMessageEvent e) {
e.setSent(); SendMessage(e.getDebugMessage());
} e.setSent();
}
private static void SendMessage(String message) {
if (DiscordPlugin.SafeMode) private static void SendMessage(String message) {
return; if (DiscordPlugin.SafeMode || !ComponentManager.isEnabled(ExceptionListenerModule.class))
try { return;
StringBuilder sb = new StringBuilder(); try {
sb.append("```").append("\n"); StringBuilder sb = new StringBuilder();
if (message.length() > 2000) sb.append("```").append("\n");
message = message.substring(0, 2000); if (message.length() > 2000)
sb.append(message).append("\n"); message = message.substring(0, 2000);
sb.append("```"); sb.append(message).append("\n");
DiscordPlugin.sendMessageToChannel(DiscordPlugin.botroomchannel, sb.toString()); sb.append("```");
} catch (Exception ex) { DiscordPlugin.sendMessageToChannel(ExceptionListenerModule.getChannel(), sb.toString());
ex.printStackTrace(); } catch (Exception ex) {
} ex.printStackTrace();
} }
}
}
}

View file

@ -1,76 +1,92 @@
package buttondevteam.discordplugin.exceptions; package buttondevteam.discordplugin.exceptions;
import buttondevteam.core.ComponentManager; import buttondevteam.core.ComponentManager;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DPUtils;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.lib.TBMCExceptionEvent; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.Component; import buttondevteam.lib.TBMCExceptionEvent;
import org.apache.commons.lang.exception.ExceptionUtils; import buttondevteam.lib.architecture.Component;
import org.bukkit.Bukkit; import buttondevteam.lib.architecture.ConfigData;
import org.bukkit.event.EventHandler; import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.event.Listener; import org.bukkit.Bukkit;
import sx.blah.discord.handle.obj.IRole; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import java.util.ArrayList; import sx.blah.discord.handle.obj.IChannel;
import java.util.Arrays; import sx.blah.discord.handle.obj.IRole;
import java.util.List;
import java.util.stream.Collectors; import java.util.ArrayList;
import java.util.Arrays;
public class ExceptionListenerModule extends Component implements Listener { import java.util.List;
private List<Throwable> lastthrown = new ArrayList<>(); import java.util.stream.Collectors;
private List<String> lastsourcemsg = new ArrayList<>();
public class ExceptionListenerModule extends Component implements Listener {
@EventHandler private List<Throwable> lastthrown = new ArrayList<>();
public void onException(TBMCExceptionEvent e) { private List<String> lastsourcemsg = new ArrayList<>();
if (DiscordPlugin.SafeMode || !ComponentManager.isEnabled(getClass()))
return; @EventHandler
if (lastthrown.stream() public void onException(TBMCExceptionEvent e) {
.anyMatch(ex -> Arrays.equals(e.getException().getStackTrace(), ex.getStackTrace()) if (DiscordPlugin.SafeMode || !ComponentManager.isEnabled(getClass()))
&& (e.getException().getMessage() == null ? ex.getMessage() == null return;
: e.getException().getMessage().equals(ex.getMessage()))) // e.Exception.Message==ex.Message if (lastthrown.stream()
&& lastsourcemsg.contains(e.getSourceMessage())) .anyMatch(ex -> Arrays.equals(e.getException().getStackTrace(), ex.getStackTrace())
return; && (e.getException().getMessage() == null ? ex.getMessage() == null
SendException(e.getException(), e.getSourceMessage()); : e.getException().getMessage().equals(ex.getMessage()))) // e.Exception.Message==ex.Message
if (lastthrown.size() >= 10) && lastsourcemsg.contains(e.getSourceMessage()))
lastthrown.remove(0); return;
if (lastsourcemsg.size() >= 10) SendException(e.getException(), e.getSourceMessage());
lastsourcemsg.remove(0); if (lastthrown.size() >= 10)
lastthrown.add(e.getException()); lastthrown.remove(0);
lastsourcemsg.add(e.getSourceMessage()); if (lastsourcemsg.size() >= 10)
e.setHandled(); lastsourcemsg.remove(0);
} lastthrown.add(e.getException());
lastsourcemsg.add(e.getSourceMessage());
private static IRole coderRole; e.setHandled();
}
private static void SendException(Throwable e, String sourcemessage) {
try { private static IRole coderRole;
if (coderRole == null)
coderRole = DiscordPlugin.devServer.getRolesByName("Coder").get(0); private static void SendException(Throwable e, String sourcemessage) {
StringBuilder sb = TBMCCoreAPI.IsTestServer() ? new StringBuilder() if (instance == null) return;
: new StringBuilder(coderRole.mention()).append("\n"); try {
sb.append(sourcemessage).append("\n"); if (coderRole == null)
sb.append("```").append("\n"); coderRole = DiscordPlugin.devServer.getRolesByName("Coder").get(0);
String stackTrace = Arrays.stream(ExceptionUtils.getStackTrace(e).split("\\n")) StringBuilder sb = TBMCCoreAPI.IsTestServer() ? new StringBuilder()
.filter(s -> !s.contains("\tat ") || s.contains("\tat buttondevteam.")) : new StringBuilder(coderRole.mention()).append("\n");
.collect(Collectors.joining("\n")); sb.append(sourcemessage).append("\n");
if (stackTrace.length() > 1800) sb.append("```").append("\n");
stackTrace = stackTrace.substring(0, 1800); String stackTrace = Arrays.stream(ExceptionUtils.getStackTrace(e).split("\\n"))
sb.append(stackTrace).append("\n"); .filter(s -> !s.contains("\tat ") || s.contains("\tat buttondevteam."))
sb.append("```"); .collect(Collectors.joining("\n"));
DiscordPlugin.sendMessageToChannel(DiscordPlugin.botroomchannel, sb.toString()); if (stackTrace.length() > 1800)
} catch (Exception ex) { stackTrace = stackTrace.substring(0, 1800);
ex.printStackTrace(); sb.append(stackTrace).append("\n");
} sb.append("```");
} DiscordPlugin.sendMessageToChannel(getChannel(), sb.toString()); //Instance isn't null here
} catch (Exception ex) {
@Override ex.printStackTrace();
protected void enable() { }
Bukkit.getPluginManager().registerEvents(new ExceptionListenerModule(), getPlugin()); }
TBMCCoreAPI.RegisterEventsForExceptions(new DebugMessageListener(), getPlugin());
} private static ExceptionListenerModule instance;
@Override public static IChannel getChannel() {
protected void disable() { if (instance != null) return instance.channel().get();
return null;
} }
}
private ConfigData<IChannel> channel() {
return DPUtils.channelData(getConfig(), "channel", 239519012529111040L);
}
@Override
protected void enable() {
instance = this;
Bukkit.getPluginManager().registerEvents(new ExceptionListenerModule(), getPlugin());
TBMCCoreAPI.RegisterEventsForExceptions(new DebugMessageListener(), getPlugin());
}
@Override
protected void disable() {
instance = null;
}
}

View file

@ -1,6 +1,7 @@
package buttondevteam.discordplugin.fun; package buttondevteam.discordplugin.fun;
import buttondevteam.core.ComponentManager; import buttondevteam.core.ComponentManager;
import buttondevteam.discordplugin.DPUtils;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.Component;
@ -12,6 +13,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent; import sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage; import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IRole; import sx.blah.discord.handle.obj.IRole;
import sx.blah.discord.handle.obj.StatusType; import sx.blah.discord.handle.obj.StatusType;
@ -123,6 +125,11 @@ public class FunModule extends Component implements Listener {
}, IRole::getName); }, IRole::getName);
} }
private ConfigData<IChannel> fullHouseChannel() {
return DPUtils.channelData(getConfig(), "fullHouseChannel", 219626707458457603L);
}
private static long lasttime = 0; private static long lasttime = 0;
public static void handleFullHouse(PresenceUpdateEvent event) { public static void handleFullHouse(PresenceUpdateEvent event) {
@ -138,7 +145,7 @@ public class FunModule extends Component implements Listener {
.noneMatch(u -> u.getPresence().getStatus().equals(StatusType.OFFLINE)) .noneMatch(u -> u.getPresence().getStatus().equals(StatusType.OFFLINE))
&& lasttime + 10 < TimeUnit.NANOSECONDS.toHours(System.nanoTime()) && lasttime + 10 < TimeUnit.NANOSECONDS.toHours(System.nanoTime())
&& Calendar.getInstance().get(Calendar.DAY_OF_MONTH) % 5 == 0) { && Calendar.getInstance().get(Calendar.DAY_OF_MONTH) % 5 == 0) {
DiscordPlugin.sendMessageToChannel(DiscordPlugin.devofficechannel, "Full house!", DiscordPlugin.sendMessageToChannel(mod.fullHouseChannel().get(), "Full house!",
new EmbedBuilder() new EmbedBuilder()
.withImage( .withImage(
"https://cdn.discordapp.com/attachments/249295547263877121/249687682618359808/poker-hand-full-house-aces-kings-playing-cards-15553791.png") "https://cdn.discordapp.com/attachments/249295547263877121/249687682618359808/poker-hand-full-house-aces-kings-playing-cards-15553791.png")

View file

@ -3,8 +3,10 @@ package buttondevteam.discordplugin.mcchat;
import buttondevteam.discordplugin.*; import buttondevteam.discordplugin.*;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.TBMCSystemChatEvent;
import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.player.*; import buttondevteam.lib.player.*;
import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.CommandSource;
import lombok.RequiredArgsConstructor;
import lombok.val; import lombok.val;
import net.ess3.api.events.AfkStatusChangeEvent; import net.ess3.api.events.AfkStatusChangeEvent;
import net.ess3.api.events.MuteStatusChangeEvent; import net.ess3.api.events.MuteStatusChangeEvent;
@ -26,14 +28,17 @@ import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.util.DiscordException; import sx.blah.discord.util.DiscordException;
import sx.blah.discord.util.MissingPermissionsException; import sx.blah.discord.util.MissingPermissionsException;
@RequiredArgsConstructor
class MCListener implements Listener { class MCListener implements Listener {
private final MinecraftChatModule module;
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent e) { public void onPlayerLogin(PlayerLoginEvent e) {
if (e.getResult() != Result.ALLOWED) if (e.getResult() != Result.ALLOWED)
return; return;
MCChatUtils.ConnectedSenders.values().stream().flatMap(v -> v.values().stream()) //Only private mcchat should be in ConnectedSenders MCChatUtils.ConnectedSenders.values().stream().flatMap(v -> v.values().stream()) //Only private mcchat should be in ConnectedSenders
.filter(s -> s.getUniqueId().equals(e.getPlayer().getUniqueId())).findAny() .filter(s -> s.getUniqueId().equals(e.getPlayer().getUniqueId())).findAny()
.ifPresent(dcp -> buttondevteam.discordplugin.listeners.MCListener.callEventExcludingSome(new PlayerQuitEvent(dcp, ""))); .ifPresent(dcp -> buttondevteam.discordplugin.listeners.MCListener.callEventExcludingSome(new PlayerQuitEvent(dcp, "")));
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
@ -46,9 +51,9 @@ class MCListener implements Listener {
if (dp != null) { if (dp != null) {
val user = DiscordPlugin.dc.getUserByID(Long.parseLong(dp.getDiscordID())); val user = DiscordPlugin.dc.getUserByID(Long.parseLong(dp.getDiscordID()));
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(), MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
new DiscordPlayerSender(user, user.getOrCreatePMChannel(), p)); new DiscordPlayerSender(user, user.getOrCreatePMChannel(), p));
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(), MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
new DiscordPlayerSender(user, DiscordPlugin.chatchannel, p)); //Stored per-channel new DiscordPlayerSender(user, module.chatChannel().get(), p)); //Stored per-channel
} }
final String message = e.GetPlayer().PlayerName().get() + " joined the game"; final String message = e.GetPlayer().PlayerName().get() + " joined the game";
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(message), e.getPlayer(), ChannelconBroadcast.JOINLEAVE, true); MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(message), e.getPlayer(), ChannelconBroadcast.JOINLEAVE, true);
@ -61,13 +66,13 @@ class MCListener implements Listener {
if (e.getPlayer() instanceof DiscordConnectedPlayer) if (e.getPlayer() instanceof DiscordConnectedPlayer)
return; // Only care about real users return; // Only care about real users
MCChatUtils.OnlineSenders.entrySet() MCChatUtils.OnlineSenders.entrySet()
.removeIf(entry -> entry.getValue().entrySet().stream().anyMatch(p -> p.getValue().getUniqueId().equals(e.getPlayer().getUniqueId()))); .removeIf(entry -> entry.getValue().entrySet().stream().anyMatch(p -> p.getValue().getUniqueId().equals(e.getPlayer().getUniqueId())));
Bukkit.getScheduler().runTask(DiscordPlugin.plugin, Bukkit.getScheduler().runTask(DiscordPlugin.plugin,
() -> MCChatUtils.ConnectedSenders.values().stream().flatMap(v -> v.values().stream()) () -> MCChatUtils.ConnectedSenders.values().stream().flatMap(v -> v.values().stream())
.filter(s -> s.getUniqueId().equals(e.getPlayer().getUniqueId())).findAny() .filter(s -> s.getUniqueId().equals(e.getPlayer().getUniqueId())).findAny()
.ifPresent(dcp -> buttondevteam.discordplugin.listeners.MCListener.callEventExcludingSome(new PlayerJoinEvent(dcp, "")))); .ifPresent(dcp -> buttondevteam.discordplugin.listeners.MCListener.callEventExcludingSome(new PlayerJoinEvent(dcp, ""))));
Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin,
ChromaBot.getInstance()::updatePlayerList, 5); ChromaBot.getInstance()::updatePlayerList, 5);
final String message = e.GetPlayer().PlayerName().get() + " left the game"; final String message = e.GetPlayer().PlayerName().get() + " left the game";
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(message), e.getPlayer(), ChannelconBroadcast.JOINLEAVE, true); MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(message), e.getPlayer(), ChannelconBroadcast.JOINLEAVE, true);
} }
@ -90,32 +95,36 @@ class MCListener implements Listener {
if (e.isCancelled() || !base.isOnline()) if (e.isCancelled() || !base.isOnline())
return; return;
final String msg = base.getDisplayName() final String msg = base.getDisplayName()
+ " is " + (e.getValue() ? "now" : "no longer") + " AFK."; + " is " + (e.getValue() ? "now" : "no longer") + " AFK.";
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(msg), base, ChannelconBroadcast.AFK, false); MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(msg), base, ChannelconBroadcast.AFK, false);
} }
private ConfigData<IRole> muteRole() {
return DPUtils.roleData(module.getConfig(), "muteRole", "Muted");
}
@EventHandler @EventHandler
public void onPlayerMute(MuteStatusChangeEvent e) { public void onPlayerMute(MuteStatusChangeEvent e) {
try { try {
DPUtils.performNoWait(() -> { DPUtils.performNoWait(() -> {
final IRole role = DiscordPlugin.dc.getRoleByID(164090010461667328L); //TODO: Config final IRole role = muteRole().get();
final CommandSource source = e.getAffected().getSource(); final CommandSource source = e.getAffected().getSource();
if (!source.isPlayer()) if (!source.isPlayer())
return; return;
final DiscordPlayer p = TBMCPlayerBase.getPlayer(source.getPlayer().getUniqueId(), TBMCPlayer.class) final DiscordPlayer p = TBMCPlayerBase.getPlayer(source.getPlayer().getUniqueId(), TBMCPlayer.class)
.getAs(DiscordPlayer.class); .getAs(DiscordPlayer.class);
if (p == null) return; if (p == null) return;
final IUser user = DiscordPlugin.dc.getUserByID( final IUser user = DiscordPlugin.dc.getUserByID(
Long.parseLong(p.getDiscordID())); Long.parseLong(p.getDiscordID()));
if (e.getValue()) if (e.getValue())
user.addRole(role); user.addRole(role);
else else
user.removeRole(role); user.removeRole(role);
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, (e.getValue() ? "M" : "Unm") + "uted user: " + user.getName()); DiscordPlugin.sendMessageToChannel(module.modlogChannel().get(), (e.getValue() ? "M" : "Unm") + "uted user: " + user.getName());
}); });
} catch (DiscordException | MissingPermissionsException ex) { } catch (DiscordException | MissingPermissionsException ex) {
TBMCCoreAPI.SendException("Failed to give/take Muted role to player " + e.getAffected().getName() + "!", TBMCCoreAPI.SendException("Failed to give/take Muted role to player " + e.getAffected().getName() + "!",
ex); ex);
} }
} }
@ -132,7 +141,7 @@ class MCListener implements Listener {
@EventHandler @EventHandler
public void onYEEHAW(TBMCYEEHAWEvent event) { //TODO: Inherit from the chat event base to have channel support public void onYEEHAW(TBMCYEEHAWEvent event) { //TODO: Inherit from the chat event base to have channel support
String name = event.getSender() instanceof Player ? ((Player) event.getSender()).getDisplayName() String name = event.getSender() instanceof Player ? ((Player) event.getSender()).getDisplayName()
: event.getSender().getName(); : event.getSender().getName();
//Channel channel = ChromaGamerBase.getFromSender(event.getSender()).channel().get(); - TODO //Channel channel = ChromaGamerBase.getFromSender(event.getSender()).channel().get(); - TODO
MCChatUtils.forAllMCChat(MCChatUtils.send(name + " <:YEEHAW:" + DiscordPlugin.mainServer.getEmojiByName("YEEHAW").getStringID() + ">s")); MCChatUtils.forAllMCChat(MCChatUtils.send(name + " <:YEEHAW:" + DiscordPlugin.mainServer.getEmojiByName("YEEHAW").getStringID() + ">s"));
} }

View file

@ -32,12 +32,16 @@ public class MinecraftChatModule extends Component {
return DPUtils.channelData(getConfig(), "chatChannel", 239519012529111040L); return DPUtils.channelData(getConfig(), "chatChannel", 239519012529111040L);
} }
public ConfigData<IChannel> modlogChannel() {
return DPUtils.channelData(getConfig(), "modlogChannel", 283840717275791360L);
}
@Override @Override
protected void enable() { protected void enable() {
listener = new MCChatListener(this); listener = new MCChatListener(this);
DiscordPlugin.dc.getDispatcher().registerListener(listener); DiscordPlugin.dc.getDispatcher().registerListener(listener);
TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin()); TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin());
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(this), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled
val chcons = getConfig().getConfig().getConfigurationSection("chcons"); val chcons = getConfig().getConfig().getConfigurationSection("chcons");
if (chcons == null) //Fallback to old place if (chcons == null) //Fallback to old place