Testing autoupdate with this commit

- Finished autoupdate
- Made DiscordSender work with no Discord user
- Made the DiscordPlayerSender return the player's name on getName()
This commit is contained in:
Norbi Peti 2016-12-22 21:56:26 +01:00
parent c3cc559b61
commit ab90f935fa
4 changed files with 22 additions and 12 deletions

View file

@ -106,7 +106,7 @@ public class DiscordPlayerSender extends DiscordSenderBase implements Player {
@Override @Override
public String getName() { 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();" // Find: " (\w+)\(\) \{\s+\/\/ TO\DO Auto-generated method stub\s+return null;" - Replace: " $1() { return player.$1();"

View file

@ -90,6 +90,8 @@ public class DiscordSender extends DiscordSenderBase implements CommandSender {
@Override @Override
public String getName() { public String getName() {
if (user == null)
return "Discord user";
return user.getDisplayName(DiscordPlugin.mainServer); return user.getDisplayName(DiscordPlugin.mainServer);
} }

View file

@ -14,6 +14,9 @@ import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
public abstract class DiscordSenderBase implements IDiscordSender { public abstract class DiscordSenderBase implements IDiscordSender {
/**
* May be null.
*/
protected IUser user; protected IUser user;
protected IChannel channel; protected IChannel channel;
@ -27,6 +30,11 @@ public abstract class DiscordSenderBase implements IDiscordSender {
private volatile String msgtosend = ""; private volatile String msgtosend = "";
private volatile BukkitTask sendtask; private volatile BukkitTask sendtask;
/**
* Returns the user. May be null.
*
* @return The user or null.
*/
public IUser getUser() { public IUser getUser() {
return user; return user;
} }
@ -51,7 +59,7 @@ public abstract class DiscordSenderBase implements IDiscordSender {
if (sendtask == null) if (sendtask == null)
sendtask = Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> { sendtask = Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
DiscordPlugin.sendMessageToChannel(channel, DiscordPlugin.sendMessageToChannel(channel,
(!broadcast ? user.mention() + "\n" : "") + msgtosend.trim()); (!broadcast && user != null ? user.mention() + "\n" : "") + msgtosend.trim());
sendtask = null; sendtask = null;
msgtosend = ""; msgtosend = "";
}, 10); // Waits a half second to gather all/most of the different messages }, 10); // Waits a half second to gather all/most of the different messages

View file

@ -1,6 +1,8 @@
package buttondevteam.discordplugin.listeners; package buttondevteam.discordplugin.listeners;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.DiscordSender;
import buttondevteam.lib.TBMCCoreAPI;
import sx.blah.discord.api.events.IListener; import sx.blah.discord.api.events.IListener;
import sx.blah.discord.handle.impl.events.MessageReceivedEvent; import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
@ -9,18 +11,16 @@ public class AutoUpdaterListener implements IListener<MessageReceivedEvent> {
public void handle(MessageReceivedEvent event) { public void handle(MessageReceivedEvent event) {
if (!event.getMessage().getChannel().getID().equals(DiscordPlugin.officechannel.getID())) if (!event.getMessage().getChannel().getID().equals(DiscordPlugin.officechannel.getID()))
return; return;
if (event.getMessage().getWebhookID() == null) if (!"239123781401051138".equals(event.getMessage().getWebhookID()))
return; return;
System.out.println(event.getMessage().getWebhookID()); if (event.getMessage().getEmbedded().size() == 0)
if (event.getMessage().getEmbedded().size() == 0) {
System.out.println("No embed");
return; return;
}
final String title = event.getMessage().getEmbedded().get(0).getTitle(); final String title = event.getMessage().getEmbedded().get(0).getTitle();
System.out.println(title); if (!title.contains("new commit"))
System.out.println(title.indexOf(':')); return;
System.out.println(title.indexOf(']')); String branch = title.substring(title.indexOf(':') + 1, title.indexOf(']'));
System.out.println(title.substring(title.indexOf(':') + 1, title.indexOf(']'))); String project = title.substring(title.indexOf('[') + 1, title.indexOf(':'));
System.out.println(title.contains("new commit")); if (branch.equals("master") || (TBMCCoreAPI.IsTestServer() && branch.equals("dev")))
TBMCCoreAPI.UpdatePlugin(project, new DiscordSender(null, DiscordPlugin.officechannel));
} }
} }