Made last chat msg reset on sendMessage

This commit is contained in:
Norbi Peti 2016-12-26 22:33:38 +01:00
parent 9269e0fb19
commit 237559d663
3 changed files with 14 additions and 9 deletions

View file

@ -70,6 +70,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
public static IChannel botroomchannel;
public static IChannel officechannel;
public static IChannel coffeechannel;
public static IChannel updatechannel;
public static IGuild mainServer;
public static IGuild devServer;
@ -91,6 +92,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
botroomchannel = devServer.getChannelByID("239519012529111040"); // bot-room
officechannel = devServer.getChannelByID("219626707458457603"); // developers-office
coffeechannel = devServer.getChannelByID("219530035365675010"); // coffee-table
updatechannel = devServer.getChannelByID("233724163519414272"); // server-updates
dc.changeStatus(Status.game("on TBMC"));
} else {
botchannel = devServer.getChannelByID("239519012529111040"); // bot-room
@ -101,9 +103,10 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
chatchannel = devServer.getChannelByID("248185455508455424"); // minecraft_chat_test
officechannel = botchannel; // bot-room
coffeechannel = botchannel; // bot-room
updatechannel = botchannel;
dc.changeStatus(Status.game("testing"));
}
for (IListener<?> listener : CommandListener.getListeners())
dc.getDispatcher().registerListener(listener);
MCChatListener mcchat = new MCChatListener();
@ -113,7 +116,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
Bukkit.getPluginManager().registerEvents(new ExceptionListener(), this);
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this);
TBMCChatAPI.AddCommands(this, DiscordMCCommandBase.class);
Bukkit.getScheduler().runTaskAsynchronously(this, () -> sendMessageToChannel(chatchannel, "",
new EmbedBuilder().withColor(Color.GREEN).withTitle("Server started - chat connected.").build()));
Runnable r = new Runnable() {
@ -228,6 +231,8 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
e2.printStackTrace();
}
try {
if (TBMCCoreAPI.IsTestServer() && channel == chatchannel)
MCChatListener.resetLastMessage();
final String content = TBMCCoreAPI.IsTestServer() && channel != chatchannel
? "*The following message is from a test server*\n" + message : message;
return embed == null ? channel.sendMessage(content) : channel.sendMessage(content, embed, false);

View file

@ -26,7 +26,7 @@ public class AutoUpdaterListener implements IListener<MessageReceivedEvent> {
new DiscordSender(null,
TBMCCoreAPI.IsTestServer() //
? DiscordPlugin.chatchannel //
: DiscordPlugin.coffeechannel),
: DiscordPlugin.updatechannel),
branch)
&& (!TBMCCoreAPI.IsTestServer() || !branch.equals("master")))
try {

View file

@ -39,10 +39,6 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
if (lastmessage == null || lastmessage.isDeleted()
|| !authorPlayer.equals(lastmessage.getEmbedded().get(0).getAuthor().getName())
|| lastmsgtime / 1000000000f < nanoTime / 1000000000f - 120) {
/*System.out.println("lastmsgtime: " + lastmsgtime);
System.out.println("Current: " + nanoTime);
System.out.println("2 mins before: " + (nanoTime - 120 * 1000000000));
System.out.println("Diff: " + (nanoTime - (nanoTime - 120 * 1000000000)));*/
lastmessage = DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel, "", embedObject);
lastmsgtime = nanoTime;
} else
@ -65,15 +61,19 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
public static final HashMap<String, DiscordSender> UnconnectedSenders = new HashMap<>();
public static final HashMap<String, DiscordPlayerSender> ConnectedSenders = new HashMap<>();
public static void resetLastMessage() {
lastmessage = null;
}
@Override // Discord
public void handle(MessageReceivedEvent event) {
final IUser author = event.getMessage().getAuthor();
if (author.isBot())
return;
if (!event.getMessage().getChannel().getID().equals(DiscordPlugin.chatchannel.getID())
/* && !(event.getMessage().getChannel().isPrivate() && privatechat) */)
return;
lastmessage = null;
if (author.isBot())
return;
if (CommandListener.runCommand(event.getMessage(), true))
return;
String dmessage = event.getMessage().getContent();