Undid delegate, mcchat fixes, testing check

It checks if it's running in production and another copy is testing at
the moment
This commit is contained in:
Norbi Peti 2017-07-04 18:04:01 +02:00
parent 9d0525571b
commit cf5aaa53fb
5 changed files with 1246 additions and 52 deletions

43
pom.xml
View file

@ -11,8 +11,9 @@
<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>
<resources> <resources>
<resource> <resource>
<directory>src</directory> <directory>src</directory>
@ -90,36 +91,14 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin> <!-- <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId>
<groupId>org.projectlombok</groupId> <version>1.16.16.0</version> <executions> <execution> <id>delombok</id> <phase>generate-sources</phase>
<artifactId>lombok-maven-plugin</artifactId> <goals> <goal>delombok</goal> </goals> <configuration> <addOutputDirectory>false</addOutputDirectory>
<version>1.16.16.0</version> <sourceDirectory>src/main/java</sourceDirectory> <verbose>true</verbose>
<executions> </configuration> </execution> <execution> <id>test-delombok</id> <phase>generate-test-sources</phase>
<execution> <goals> <goal>testDelombok</goal> </goals> <configuration> <addOutputDirectory>false</addOutputDirectory>
<id>delombok</id> <sourceDirectory>src/test/java</sourceDirectory> </configuration> </execution>
<phase>generate-sources</phase> </executions> </plugin> -->
<goals>
<goal>delombok</goal>
</goals>
<configuration>
<addOutputDirectory>false</addOutputDirectory>
<sourceDirectory>src/main/java</sourceDirectory>
<verbose>true</verbose>
</configuration>
</execution>
<execution>
<id>test-delombok</id>
<phase>generate-test-sources</phase>
<goals>
<goal>testDelombok</goal>
</goals>
<configuration>
<addOutputDirectory>false</addOutputDirectory>
<sourceDirectory>src/test/java</sourceDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>

View file

@ -318,4 +318,9 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
return null; return null;
return RequestBuffer.request(action).get(); // Let the pros handle this return RequestBuffer.request(action).get(); // Let the pros handle this
} }
public static boolean checkIfSomeoneIsTestingWhileWeArent() {
return !TBMCCoreAPI.IsTestServer()
&& dc.getOurUser().getPresence().getPlayingText().orElse("").equals("testing");
}
} }

View file

@ -59,7 +59,8 @@ public class CommandListener {
if (event.getMessage().getAuthor().isBot()) if (event.getMessage().getAuthor().isBot())
return; return;
final IChannel channel = event.getMessage().getChannel(); final IChannel channel = event.getMessage().getChannel();
if (!channel.getStringID().equals(DiscordPlugin.botchannel.getStringID()) && !channel.isPrivate()) if (!channel.getStringID().equals(DiscordPlugin.botchannel.getStringID())
&& (!channel.isPrivate() || DiscordPlugin.checkIfSomeoneIsTestingWhileWeArent()))
return; return;
if (channel.getStringID().equals(DiscordPlugin.chatchannel.getStringID())) if (channel.getStringID().equals(DiscordPlugin.chatchannel.getStringID()))
return; // The chat code already handles this - Right now while testing botchannel is the same as chatchannel return; // The chat code already handles this - Right now while testing botchannel is the same as chatchannel
@ -82,8 +83,10 @@ public class CommandListener {
next = usableServerReadyStrings.remove(serverReadyRandom.nextInt(usableServerReadyStrings.size())); next = usableServerReadyStrings.remove(serverReadyRandom.nextInt(usableServerReadyStrings.size()));
DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), serverReadyStrings[next]); DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), serverReadyStrings[next]);
} }
if (!event.getMessage().getChannel().isPrivate() || DiscordPlayer if (!event.getMessage().getChannel().isPrivate() //
.getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat().get()) || DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat()
.get()
|| DiscordPlugin.checkIfSomeoneIsTestingWhileWeArent())
return; return;
if (event.getMessage().getAuthor().isBot()) if (event.getMessage().getAuthor().isBot())
return; return;

View file

@ -17,6 +17,7 @@ import buttondevteam.lib.*;
import buttondevteam.lib.chat.Channel; import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
import lombok.val;
import sx.blah.discord.api.events.IListener; import sx.blah.discord.api.events.IListener;
import sx.blah.discord.api.internal.json.objects.EmbedObject; import sx.blah.discord.api.internal.json.objects.EmbedObject;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent; import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
@ -62,7 +63,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
} }
}; };
if (e.getChannel().equals(Channel.GlobalChat)) if (e.getChannel().equals(Channel.GlobalChat))
doit.accept(lastmsgdata); doit.accept(
lastmsgdata == null ? lastmsgdata = new LastMsgData(DiscordPlugin.chatchannel) : lastmsgdata);
for (LastMsgData data : lastmsgPerUser) { for (LastMsgData data : lastmsgPerUser) {
final IUser iUser = data.channel.getUsersHere().stream() final IUser iUser = data.channel.getUsersHere().stream()
@ -110,7 +112,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
private static final String[] UnconnectedCmds = new String[] { "list", "u", "shrug", "tableflip", "unflip", "mwiki", private static final String[] UnconnectedCmds = new String[] { "list", "u", "shrug", "tableflip", "unflip", "mwiki",
"yeehaw" }; "yeehaw" };
private static LastMsgData lastmsgdata = new LastMsgData(DiscordPlugin.chatchannel); private static LastMsgData lastmsgdata;
private static short lastlist = 0; private static short lastlist = 0;
private static short lastlistp = 0; private static short lastlistp = 0;
/** /**
@ -128,15 +130,16 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
public static short ListC = 0; public static short ListC = 0;
public static void resetLastMessage() { public static void resetLastMessage() {
lastmsgdata.message = null; // Don't set the whole object to null, the player and channel information should be preserved (lastmsgdata == null ? lastmsgdata = new LastMsgData(DiscordPlugin.chatchannel) : lastmsgdata).message = null; // Don't set the whole object to null, the player and channel information should
} } // be preserved
@Override // Discord @Override // Discord
public void handle(MessageReceivedEvent event) { public void handle(MessageReceivedEvent event) {
final IUser author = event.getMessage().getAuthor(); val author = event.getMessage().getAuthor();
final DiscordPlayer user = DiscordPlayer.getUser(author.getStringID(), DiscordPlayer.class); val user = DiscordPlayer.getUser(author.getStringID(), DiscordPlayer.class);
if (!event.getMessage().getChannel().getStringID().equals(DiscordPlugin.chatchannel.getStringID()) if (!event.getMessage().getChannel().getStringID().equals(DiscordPlugin.chatchannel.getStringID())
&& !(event.getMessage().getChannel().isPrivate() && user.minecraftChat().get())) && !(event.getMessage().getChannel().isPrivate() && user.minecraftChat().get()
&& !DiscordPlugin.checkIfSomeoneIsTestingWhileWeArent()))
return; return;
resetLastMessage(); resetLastMessage();
lastlist++; lastlist++;