Full house cooldown, reset last msg in PM

Plus test account enforced
This commit is contained in:
Norbi Peti 2017-08-18 03:12:33 +02:00
parent 6d40949ddd
commit e4382bbcd2
3 changed files with 34 additions and 9 deletions

View file

@ -136,6 +136,13 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
}
});
sent = true;
if (TBMCCoreAPI.IsTestServer() && !dc.getOurUser().getName().toLowerCase().contains("test")) {
TBMCCoreAPI.SendException(
"Won't load because we're in testing mode and not using the separate account.",
new Exception(
"The plugin refuses to load until you change the token to the testing account."));
Bukkit.getPluginManager().disablePlugin(this);
}
}
}, 0, 10);
for (IListener<?> listener : CommandListener.getListeners())
@ -284,9 +291,9 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
try {
if (channel == chatchannel)
MCChatListener.resetLastMessage(); // If this is a chat message, it'll be set again
final String content = TBMCCoreAPI.IsTestServer() && (channel != chatchannel || channel == botroomchannel // Both are the same for testing
|| channel.isPrivate()) //
? "*The following message is from a test server*\n" + message : message;
else if (channel.isPrivate())
MCChatListener.resetLastMessage(channel);
final String content = message;
return perform(
() -> embed == null ? channel.sendMessage(content) : channel.sendMessage(content, embed, false));
} catch (Exception e) {

View file

@ -3,6 +3,7 @@ package buttondevteam.discordplugin.listeners;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.discordplugin.DiscordPlugin;
@ -54,6 +55,8 @@ public class CommandListener {
list.add(i);
}
private static long lasttime = 0;
public static IListener<?>[] getListeners() {
return new IListener[] { new IListener<MentionEvent>() {
@Override
@ -102,12 +105,15 @@ public class CommandListener {
&& event.getUser().getRolesForGuild(DiscordPlugin.devServer).stream()
.anyMatch(r -> r.getLongID() == devrole.getLongID())
&& DiscordPlugin.devServer.getUsersByRole(devrole).stream()
.noneMatch(u -> u.getPresence().getStatus().equals(StatusType.OFFLINE)))
.noneMatch(u -> u.getPresence().getStatus().equals(StatusType.OFFLINE))
&& lasttime + 10 < TimeUnit.NANOSECONDS.toHours(System.nanoTime())) {
DiscordPlugin.sendMessageToChannel(DiscordPlugin.devofficechannel, "Full house!",
new EmbedBuilder()
.withImage(
"https://cdn.discordapp.com/attachments/249295547263877121/249687682618359808/poker-hand-full-house-aces-kings-playing-cards-15553791.png")
.build());
lasttime = TimeUnit.NANOSECONDS.toHours(System.nanoTime());
}
}
} };
}

View file

@ -190,6 +190,12 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
: lastmsgdata).message = null;
} // Don't set the whole object to null, the player and channel information should be preserved
public static void resetLastMessage(IChannel channel) {
for (LastMsgData data : lastmsgPerUser)
if (data.channel.getLongID() == channel.getLongID())
data.message = null; // Since only private channels are stored, only those will work anyways
}
/**
* This overload sends it to the global chat.
*/
@ -215,7 +221,10 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
&& !(event.getMessage().getChannel().isPrivate() && user.isMinecraftChatEnabled()
&& !DiscordPlugin.checkIfSomeoneIsTestingWhileWeArent()))
return;
if (!event.getMessage().getChannel().isPrivate())
resetLastMessage();
else
resetLastMessage(event.getMessage().getChannel());
lastlist++;
if (author.isBot())
return;
@ -284,9 +293,12 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
val oldch = dsender.getMcchannel();
if (oldch instanceof ChatRoom)
((ChatRoom) oldch).leaveRoom(dsender);
if (!oldch.ID.equals(chc.ID)) {
dsender.setMcchannel(chc);
if (chc instanceof ChatRoom)
((ChatRoom) chc).joinRoom(dsender);
} else
dsender.setMcchannel(Channel.GlobalChat);
dsender.sendMessage("You're now talking in: "
+ DiscordPlugin.sanitizeString(dsender.getMcchannel().DisplayName));
} else { // Send single message