Merge pull request #21 from TBMCPlugins/dev
Added automatic plugin updater and a few smaller changes
This commit is contained in:
commit
46182fc4ec
7 changed files with 58 additions and 18 deletions
|
@ -106,7 +106,7 @@ public class DiscordPlayerSender extends DiscordSenderBase implements Player {
|
|||
|
||||
@Override
|
||||
public String getName() {
|
||||
return user.getDisplayName(DiscordPlugin.mainServer);
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
// Find: " (\w+)\(\) \{\s+\/\/ TO\DO Auto-generated method stub\s+return null;" - Replace: " $1() { return player.$1();"
|
||||
|
|
|
@ -47,7 +47,6 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
} else {
|
||||
lastannouncementtime = getConfig().getLong("lastannouncementtime");
|
||||
lastseentime = getConfig().getLong("lastseentime");
|
||||
Test = getConfig().getBoolean("test", true);
|
||||
saveConfig();
|
||||
}
|
||||
ClientBuilder cb = new ClientBuilder();
|
||||
|
@ -59,6 +58,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
MCChatListener mcchat = new MCChatListener();
|
||||
dc.getDispatcher().registerListener(mcchat);
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(mcchat, this);
|
||||
dc.getDispatcher().registerListener(new AutoUpdaterListener());
|
||||
Bukkit.getPluginManager().registerEvents(new ExceptionListener(), this);
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this);
|
||||
TBMCChatAPI.AddCommands(this, DiscordMCCommandBase.class);
|
||||
|
@ -74,11 +74,10 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
public static IChannel chatchannel;
|
||||
public static IChannel issuechannel;
|
||||
public static IChannel botroomchannel;
|
||||
public static IChannel officechannel;
|
||||
public static IGuild mainServer;
|
||||
public static IGuild devServer;
|
||||
|
||||
public static boolean Test = true;
|
||||
|
||||
@Override
|
||||
public void handle(ReadyEvent event) {
|
||||
try {
|
||||
|
@ -88,13 +87,14 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
devServer = event.getClient().getGuildByID("219529124321034241");
|
||||
Thread.sleep(100);
|
||||
} while ((mainServer == null || devServer == null) && retryc++ < 10);
|
||||
if (!Test) {
|
||||
if (!TBMCCoreAPI.IsTestServer()) {
|
||||
botchannel = mainServer.getChannelByID("209720707188260864"); // bot
|
||||
annchannel = mainServer.getChannelByID("126795071927353344"); // announcements
|
||||
genchannel = mainServer.getChannelByID("125813020357165056"); // general
|
||||
chatchannel = mainServer.getChannelByID("249663564057411596"); // minecraft_chat
|
||||
issuechannel = devServer.getChannelByID("219643416496046081"); // server-issues
|
||||
botroomchannel = devServer.getChannelByID("239519012529111040");// bot-room
|
||||
botroomchannel = devServer.getChannelByID("239519012529111040"); // bot-room
|
||||
officechannel = devServer.getChannelByID("219626707458457603"); // developers-office
|
||||
dc.changeStatus(Status.game("on TBMC"));
|
||||
} else {
|
||||
botchannel = devServer.getChannelByID("239519012529111040"); // bot-room
|
||||
|
@ -103,6 +103,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
botroomchannel = botchannel;// bot-room
|
||||
issuechannel = botchannel; // bot-room
|
||||
chatchannel = devServer.getChannelByID("248185455508455424"); // minecraft_chat_test
|
||||
officechannel = devServer.getChannelByID("219626707458457603"); // developers-office
|
||||
dc.changeStatus(Status.game("testing"));
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this,
|
||||
|
@ -143,6 +144,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
|
||||
private long lastannouncementtime = 0;
|
||||
private long lastseentime = 0;
|
||||
public static final String DELIVERED_REACTION = "✅";
|
||||
|
||||
private void AnnouncementGetterThreadMethod() {
|
||||
while (!stop) {
|
||||
|
@ -208,8 +210,8 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
e2.printStackTrace();
|
||||
}
|
||||
try {
|
||||
return channel
|
||||
.sendMessage(Test ? "*The following message is from a test server*\n" + message : message);
|
||||
return channel.sendMessage(TBMCCoreAPI.IsTestServer() && channel != chatchannel
|
||||
? "*The following message is from a test server*\n" + message : message);
|
||||
} catch (RateLimitException e) {
|
||||
try {
|
||||
Thread.sleep(e.getRetryDelay());
|
||||
|
|
|
@ -90,6 +90,8 @@ public class DiscordSender extends DiscordSenderBase implements CommandSender {
|
|||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (user == null)
|
||||
return "Discord user";
|
||||
return user.getDisplayName(DiscordPlugin.mainServer);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,9 @@ import sx.blah.discord.handle.obj.IChannel;
|
|||
import sx.blah.discord.handle.obj.IUser;
|
||||
|
||||
public abstract class DiscordSenderBase implements IDiscordSender {
|
||||
/**
|
||||
* May be null.
|
||||
*/
|
||||
protected IUser user;
|
||||
protected IChannel channel;
|
||||
|
||||
|
@ -27,6 +30,11 @@ public abstract class DiscordSenderBase implements IDiscordSender {
|
|||
private volatile String msgtosend = "";
|
||||
private volatile BukkitTask sendtask;
|
||||
|
||||
/**
|
||||
* Returns the user. May be null.
|
||||
*
|
||||
* @return The user or null.
|
||||
*/
|
||||
public IUser getUser() {
|
||||
return user;
|
||||
}
|
||||
|
@ -51,7 +59,7 @@ public abstract class DiscordSenderBase implements IDiscordSender {
|
|||
if (sendtask == null)
|
||||
sendtask = Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
|
||||
DiscordPlugin.sendMessageToChannel(channel,
|
||||
(!broadcast ? user.mention() + "\n" : "") + msgtosend.trim());
|
||||
(!broadcast && user != null ? user.mention() + "\n" : "") + msgtosend.trim());
|
||||
sendtask = null;
|
||||
msgtosend = "";
|
||||
}, 10); // Waits a half second to gather all/most of the different messages
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package buttondevteam.discordplugin.listeners;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.DiscordSender;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import sx.blah.discord.api.events.IListener;
|
||||
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
||||
import sx.blah.discord.util.RateLimitException;
|
||||
|
||||
public class AutoUpdaterListener implements IListener<MessageReceivedEvent> {
|
||||
@Override
|
||||
public void handle(MessageReceivedEvent event) {
|
||||
if (!event.getMessage().getChannel().getID().equals(DiscordPlugin.officechannel.getID()))
|
||||
return;
|
||||
if (!"239123781401051138".equals(event.getMessage().getWebhookID()))
|
||||
return;
|
||||
if (event.getMessage().getEmbedded().size() == 0)
|
||||
return;
|
||||
final String title = event.getMessage().getEmbedded().get(0).getTitle();
|
||||
if (!title.contains("new commit"))
|
||||
return;
|
||||
String branch = title.substring(title.indexOf(':') + 1, title.indexOf(']'));
|
||||
String project = title.substring(title.indexOf('[') + 1, title.indexOf(':'));
|
||||
if (branch.equals("master") || (TBMCCoreAPI.IsTestServer() && branch.equals("dev")))
|
||||
if (TBMCCoreAPI.UpdatePlugin(project, new DiscordSender(null, DiscordPlugin.chatchannel), branch))
|
||||
try {
|
||||
event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION);
|
||||
} catch (RateLimitException e) { // TODO: Handle
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while reacting to plugin update!", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,14 +19,9 @@ import sx.blah.discord.api.events.IListener;
|
|||
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
||||
import sx.blah.discord.handle.obj.IReaction;
|
||||
import sx.blah.discord.handle.obj.IUser;
|
||||
import sx.blah.discord.util.DiscordException;
|
||||
import sx.blah.discord.util.EmbedBuilder;
|
||||
import sx.blah.discord.util.MissingPermissionsException;
|
||||
import sx.blah.discord.util.RateLimitException;
|
||||
|
||||
public class MCChatListener implements Listener, IListener<MessageReceivedEvent> {
|
||||
private static final String DELIVERED_REACTION = "✅";
|
||||
|
||||
@EventHandler // Minecraft
|
||||
public void onMCChat(TBMCChatEvent e) {
|
||||
if (e.isCancelled())
|
||||
|
@ -100,10 +95,10 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
dmessage + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage()
|
||||
.getAttachments().stream().map(a -> a.getUrl()).collect(Collectors.joining("\n"))
|
||||
: ""));
|
||||
event.getMessage().addReaction(DELIVERED_REACTION);
|
||||
event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION);
|
||||
event.getMessage().getChannel().getMessages().stream().forEach(m -> {
|
||||
try {
|
||||
final IReaction reaction = m.getReactionByName(DELIVERED_REACTION);
|
||||
final IReaction reaction = m.getReactionByName(DiscordPlugin.DELIVERED_REACTION);
|
||||
if (reaction != null) {
|
||||
while (true)
|
||||
try {
|
||||
|
@ -111,7 +106,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
Thread.sleep(100);
|
||||
break;
|
||||
} catch (RateLimitException e) {
|
||||
Thread.sleep(e.getRetryDelay());
|
||||
if (e.getRetryDelay() > 0)
|
||||
Thread.sleep(e.getRetryDelay());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -12,7 +12,6 @@ import buttondevteam.discordplugin.commands.ConnectCommand;
|
|||
import buttondevteam.lib.TBMCPlayerGetInfoEvent;
|
||||
import buttondevteam.lib.TBMCPlayerJoinEvent;
|
||||
import buttondevteam.lib.TBMCPlayerQuitEvent;
|
||||
import buttondevteam.lib.TBMCYEEHAWEvent;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import sx.blah.discord.handle.obj.IUser;
|
||||
import sx.blah.discord.handle.obj.Status.StatusType;
|
||||
|
|
Loading…
Reference in a new issue