Added private Minecraft chat, Discord login, show message pinning, Maven project check, some of #12 #39

Merged
NorbiPeti merged 21 commits from dev into master 2017-07-04 16:14:01 +00:00
5 changed files with 34 additions and 46 deletions
Showing only changes of commit a6244b7f9f - Show all commits

View file

@ -21,9 +21,10 @@ public class MCChatCommand extends DiscordCommandBase {
try (final DiscordPlayer user = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)) {
PlayerData<Boolean> mcchat = user.minecraftChat();
mcchat.set(!mcchat.getOrDefault(false));
message.reply(
"Minecraft chat " + (mcchat.get() ? "enabled. Use '" + message.getClient().getOurUser().mention()
+ " mcchat' (with the mention) to disable." : "disabled."));
message.reply("Minecraft chat " + (mcchat.getOrDefault(false) //
? "enabled. Use '" + message.getClient().getOurUser().mention()
+ " mcchat' (with the mention) to disable." //
: "disabled."));
} catch (Exception e) {
TBMCCoreAPI.SendException("Error while setting mcchat for user" + message.getAuthor().getName(), e);
}

View file

@ -28,12 +28,13 @@ public class CommandListener {
"Once the server stops screaming.", // Ali
"After HL3 comes out", // Ali
"Next time you ask", // Ali
"When will *you* be open?" //Ali
"When will *you* be open?" // Ali
};
private static final String[] serverReadyQuestions = new String[] { "when will the server be open",
"when will the server be ready", "when will the server be done", "when will the server be complete",
"when will the server be finished", "when's the server ready", "when's the server open", "Vhen vill ze server be open?" };
"when will the server be finished", "when's the server ready", "when's the server open",
"Vhen vill ze server be open?" };
private static final Random serverReadyRandom = new Random();
private static final ArrayList<Short> usableServerReadyStrings = new ArrayList<Short>(serverReadyStrings.length) {
@ -64,6 +65,7 @@ public class CommandListener {
if (DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat()
.getOrDefault(false)) // Let the MCChatListener handle it
return;
event.getMessage().getChannel().setTypingStatus(true); // Fun
runCommand(event.getMessage(), true);
}
}, new IListener<MessageReceivedEvent>() {
@ -102,7 +104,6 @@ public class CommandListener {
public static boolean runCommand(IMessage message, boolean mentionedonly) {
if (DiscordPlugin.SafeMode)
return true;
message.getChannel().setTypingStatus(true);
final StringBuilder cmdwithargs = new StringBuilder(message.getContent());
final String mention = DiscordPlugin.dc.getOurUser().mention(false);
final String mentionNick = DiscordPlugin.dc.getOurUser().mention(true);
@ -114,6 +115,7 @@ public class CommandListener {
message.getChannel().setTypingStatus(false);
return false;
}
message.getChannel().setTypingStatus(true);
int index = cmdwithargs.indexOf(" ");
String cmd;
String args;

View file

@ -34,24 +34,26 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
? ((Player) e.getSender()).getDisplayName() //
: e.getSender().getName());
final EmbedBuilder embed = new EmbedBuilder().withAuthorName(authorPlayer).withDescription(e.getMessage());
final EmbedObject embedObject = e.getSender() instanceof Player
? embed.withAuthorIcon(
"https://minotar.net/avatar/" + ((Player) e.getSender()).getName() + "/32.png").build()
: embed.build();
if (e.getSender() instanceof Player)
embed.withAuthorIcon("https://minotar.net/avatar/" + ((Player) e.getSender()).getName() + "/32.png");
final long nanoTime = System.nanoTime();
Consumer<LastMsgData> doit = lastmsgdata -> {
final EmbedObject embedObject = embed.build();
String msg = lastmsgdata.channel.isPrivate() ? DiscordPlugin.sanitizeString(e.getChannel().DisplayName)
: "";
if (lastmsgdata.message == null || lastmsgdata.message.isDeleted()
|| !authorPlayer.equals(lastmsgdata.message.getEmbeds().get(0).getAuthor().getName())
|| lastmsgdata.time / 1000000000f < nanoTime / 1000000000f - 120) {
lastmsgdata.message = DiscordPlugin.sendMessageToChannel(lastmsgdata.channel,
lastmsgdata.channel.isPrivate() ? e.getChannel().DisplayName : "", embedObject);
|| lastmsgdata.time / 1000000000f < nanoTime / 1000000000f - 120
|| !lastmsgdata.mcchannel.ID.equals(e.getChannel().ID)) {
lastmsgdata.message = DiscordPlugin.sendMessageToChannel(lastmsgdata.channel, msg, embedObject);
lastmsgdata.time = nanoTime;
lastmsgdata.mcchannel = e.getChannel();
} else
try {
lastmsgdata.content = embedObject.description = lastmsgdata.content + "\n"
+ embedObject.description;// The message object doesn't get updated
final LastMsgData _lastmsgdata = lastmsgdata;
DiscordPlugin.perform(() -> _lastmsgdata.message.edit("", embedObject));
DiscordPlugin.perform(() -> _lastmsgdata.message.edit(msg, embedObject));
} catch (MissingPermissionsException | DiscordException e1) {
TBMCCoreAPI.SendException("An error occured while editing chat message!", e1);
}
@ -74,6 +76,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
public long time;
public String content;
public IChannel channel;
public Channel mcchannel;
public LastMsgData(IChannel channel) {
this.channel = channel;
@ -112,6 +115,14 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
*/
private static ArrayList<LastMsgData> lastmsgPerUser = new ArrayList<LastMsgData>();
public static boolean startPrivateMCChat(IChannel channel) {
return lastmsgPerUser.add(new LastMsgData(channel));
}
public static boolean stopPrivateMCChat(IChannel channel) {
return lastmsgPerUser.removeIf(lmd -> lmd.channel.getLongID() == channel.getLongID());
}
public static final HashMap<String, DiscordSender> UnconnectedSenders = new HashMap<>();
public static final HashMap<String, DiscordPlayerSender> ConnectedSenders = new HashMap<>();
public static short ListC = 0;
@ -214,7 +225,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
TBMCPlayer p = dp.getAs(TBMCPlayer.class);
if (!UnconnectedSenders.containsKey(author.getStringID()))
UnconnectedSenders.put(author.getStringID(),
new DiscordSender(author, channel, p == null ? null : p.PlayerName().get())); // Display the playername, if found
new DiscordSender(author, channel, p == null ? null : p.PlayerName().getOrDefault(null))); // Display the playername, if found
dsender = UnconnectedSenders.get(author.getStringID());
}
return dsender;

View file

@ -25,22 +25,22 @@ public class MCListener implements Listener {
@EventHandler
public void onPlayerJoin(TBMCPlayerJoinEvent e) {
final Player p = Bukkit.getPlayer(e.GetPlayer().getUUID());
if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().get())) {
IUser user = DiscordPlugin.dc
.getUserByID(Long.parseLong(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().get())));
if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().getOrDefault(null))) {
IUser user = DiscordPlugin.dc.getUserByID(
Long.parseLong(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().getOrDefault(null))));
p.sendMessage("§bTo connect with the Discord account @" + user.getName() + "#" + user.getDiscriminator()
+ " do /discord accept");
p.sendMessage("§bIf it wasn't you, do /discord decline");
}
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
e.GetPlayer().PlayerName().get() + " joined the game");
e.GetPlayer().PlayerName().getOrDefault(null) + " joined the game");
MCChatListener.ListC = 0;
}
@EventHandler
public void onPlayerLeave(TBMCPlayerQuitEvent e) {
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
e.GetPlayer().PlayerName().get() + " left the game");
e.GetPlayer().PlayerName().getOrDefault(null) + " left the game");
}
@EventHandler

View file

@ -1,11 +1,5 @@
package buttondevteam.DiscordPlugin;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.apache.commons.lang.exception.ExceptionUtils;
import buttondevteam.lib.TBMCCoreAPI;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@ -35,26 +29,6 @@ public class AppTest extends TestCase {
* Rigourous Test :-)
*/
public void testApp() {
/*String sourcemessage = "Test message";
Exception e = new Exception("Test exception");
StringBuilder sb = TBMCCoreAPI.IsTestServer() ? new StringBuilder()
: new StringBuilder("Coder role").append("\n");
sb.append(sourcemessage).append("\n");
sb.append("```").append("\n");
String stackTrace = Arrays.stream(ExceptionUtils.getStackTrace(e).split("\\n"))
.filter(s -> !(s.contains("\tat ") && ( //
s.contains("java.util") //
|| s.contains("java.lang") //
|| s.contains("net.minecraft.server") //
|| s.contains("sun.reflect") //
|| s.contains("org.bukkit") //
))).collect(Collectors.joining("\n"));
if (stackTrace.length() > 1800)
stackTrace = stackTrace.substring(0, 1800);
sb.append(stackTrace).append("\n");
sb.append("```");
System.out.println(sb.toString());
assertTrue(sb.toString().contains("Coder role"));*/
assertTrue(true);
}
}