parent
b7c8e9dfa6
commit
a6244b7f9f
5 changed files with 34 additions and 46 deletions
|
@ -21,9 +21,10 @@ public class MCChatCommand extends DiscordCommandBase {
|
||||||
try (final DiscordPlayer user = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)) {
|
try (final DiscordPlayer user = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)) {
|
||||||
PlayerData<Boolean> mcchat = user.minecraftChat();
|
PlayerData<Boolean> mcchat = user.minecraftChat();
|
||||||
mcchat.set(!mcchat.getOrDefault(false));
|
mcchat.set(!mcchat.getOrDefault(false));
|
||||||
message.reply(
|
message.reply("Minecraft chat " + (mcchat.getOrDefault(false) //
|
||||||
"Minecraft chat " + (mcchat.get() ? "enabled. Use '" + message.getClient().getOurUser().mention()
|
? "enabled. Use '" + message.getClient().getOurUser().mention()
|
||||||
+ " mcchat' (with the mention) to disable." : "disabled."));
|
+ " mcchat' (with the mention) to disable." //
|
||||||
|
: "disabled."));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("Error while setting mcchat for user" + message.getAuthor().getName(), e);
|
TBMCCoreAPI.SendException("Error while setting mcchat for user" + message.getAuthor().getName(), e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,13 @@ public class CommandListener {
|
||||||
"Once the server stops screaming.", // Ali
|
"Once the server stops screaming.", // Ali
|
||||||
"After HL3 comes out", // Ali
|
"After HL3 comes out", // Ali
|
||||||
"Next time you ask", // 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",
|
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 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 Random serverReadyRandom = new Random();
|
||||||
private static final ArrayList<Short> usableServerReadyStrings = new ArrayList<Short>(serverReadyStrings.length) {
|
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()
|
if (DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat()
|
||||||
.getOrDefault(false)) // Let the MCChatListener handle it
|
.getOrDefault(false)) // Let the MCChatListener handle it
|
||||||
return;
|
return;
|
||||||
|
event.getMessage().getChannel().setTypingStatus(true); // Fun
|
||||||
runCommand(event.getMessage(), true);
|
runCommand(event.getMessage(), true);
|
||||||
}
|
}
|
||||||
}, new IListener<MessageReceivedEvent>() {
|
}, new IListener<MessageReceivedEvent>() {
|
||||||
|
@ -102,7 +104,6 @@ public class CommandListener {
|
||||||
public static boolean runCommand(IMessage message, boolean mentionedonly) {
|
public static boolean runCommand(IMessage message, boolean mentionedonly) {
|
||||||
if (DiscordPlugin.SafeMode)
|
if (DiscordPlugin.SafeMode)
|
||||||
return true;
|
return true;
|
||||||
message.getChannel().setTypingStatus(true);
|
|
||||||
final StringBuilder cmdwithargs = new StringBuilder(message.getContent());
|
final StringBuilder cmdwithargs = new StringBuilder(message.getContent());
|
||||||
final String mention = DiscordPlugin.dc.getOurUser().mention(false);
|
final String mention = DiscordPlugin.dc.getOurUser().mention(false);
|
||||||
final String mentionNick = DiscordPlugin.dc.getOurUser().mention(true);
|
final String mentionNick = DiscordPlugin.dc.getOurUser().mention(true);
|
||||||
|
@ -114,6 +115,7 @@ public class CommandListener {
|
||||||
message.getChannel().setTypingStatus(false);
|
message.getChannel().setTypingStatus(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
message.getChannel().setTypingStatus(true);
|
||||||
int index = cmdwithargs.indexOf(" ");
|
int index = cmdwithargs.indexOf(" ");
|
||||||
String cmd;
|
String cmd;
|
||||||
String args;
|
String args;
|
||||||
|
|
|
@ -34,24 +34,26 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
? ((Player) e.getSender()).getDisplayName() //
|
? ((Player) e.getSender()).getDisplayName() //
|
||||||
: e.getSender().getName());
|
: e.getSender().getName());
|
||||||
final EmbedBuilder embed = new EmbedBuilder().withAuthorName(authorPlayer).withDescription(e.getMessage());
|
final EmbedBuilder embed = new EmbedBuilder().withAuthorName(authorPlayer).withDescription(e.getMessage());
|
||||||
final EmbedObject embedObject = e.getSender() instanceof Player
|
if (e.getSender() instanceof Player)
|
||||||
? embed.withAuthorIcon(
|
embed.withAuthorIcon("https://minotar.net/avatar/" + ((Player) e.getSender()).getName() + "/32.png");
|
||||||
"https://minotar.net/avatar/" + ((Player) e.getSender()).getName() + "/32.png").build()
|
|
||||||
: embed.build();
|
|
||||||
final long nanoTime = System.nanoTime();
|
final long nanoTime = System.nanoTime();
|
||||||
Consumer<LastMsgData> doit = lastmsgdata -> {
|
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()
|
if (lastmsgdata.message == null || lastmsgdata.message.isDeleted()
|
||||||
|| !authorPlayer.equals(lastmsgdata.message.getEmbeds().get(0).getAuthor().getName())
|
|| !authorPlayer.equals(lastmsgdata.message.getEmbeds().get(0).getAuthor().getName())
|
||||||
|| lastmsgdata.time / 1000000000f < nanoTime / 1000000000f - 120) {
|
|| lastmsgdata.time / 1000000000f < nanoTime / 1000000000f - 120
|
||||||
lastmsgdata.message = DiscordPlugin.sendMessageToChannel(lastmsgdata.channel,
|
|| !lastmsgdata.mcchannel.ID.equals(e.getChannel().ID)) {
|
||||||
lastmsgdata.channel.isPrivate() ? e.getChannel().DisplayName : "", embedObject);
|
lastmsgdata.message = DiscordPlugin.sendMessageToChannel(lastmsgdata.channel, msg, embedObject);
|
||||||
lastmsgdata.time = nanoTime;
|
lastmsgdata.time = nanoTime;
|
||||||
|
lastmsgdata.mcchannel = e.getChannel();
|
||||||
} else
|
} else
|
||||||
try {
|
try {
|
||||||
lastmsgdata.content = embedObject.description = lastmsgdata.content + "\n"
|
lastmsgdata.content = embedObject.description = lastmsgdata.content + "\n"
|
||||||
+ embedObject.description;// The message object doesn't get updated
|
+ embedObject.description;// The message object doesn't get updated
|
||||||
final LastMsgData _lastmsgdata = lastmsgdata;
|
final LastMsgData _lastmsgdata = lastmsgdata;
|
||||||
DiscordPlugin.perform(() -> _lastmsgdata.message.edit("", embedObject));
|
DiscordPlugin.perform(() -> _lastmsgdata.message.edit(msg, embedObject));
|
||||||
} catch (MissingPermissionsException | DiscordException e1) {
|
} catch (MissingPermissionsException | DiscordException e1) {
|
||||||
TBMCCoreAPI.SendException("An error occured while editing chat message!", 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 long time;
|
||||||
public String content;
|
public String content;
|
||||||
public IChannel channel;
|
public IChannel channel;
|
||||||
|
public Channel mcchannel;
|
||||||
|
|
||||||
public LastMsgData(IChannel channel) {
|
public LastMsgData(IChannel channel) {
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
|
@ -112,6 +115,14 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
*/
|
*/
|
||||||
private static ArrayList<LastMsgData> lastmsgPerUser = new ArrayList<LastMsgData>();
|
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, DiscordSender> UnconnectedSenders = new HashMap<>();
|
||||||
public static final HashMap<String, DiscordPlayerSender> ConnectedSenders = new HashMap<>();
|
public static final HashMap<String, DiscordPlayerSender> ConnectedSenders = new HashMap<>();
|
||||||
public static short ListC = 0;
|
public static short ListC = 0;
|
||||||
|
@ -214,7 +225,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
TBMCPlayer p = dp.getAs(TBMCPlayer.class);
|
TBMCPlayer p = dp.getAs(TBMCPlayer.class);
|
||||||
if (!UnconnectedSenders.containsKey(author.getStringID()))
|
if (!UnconnectedSenders.containsKey(author.getStringID()))
|
||||||
UnconnectedSenders.put(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());
|
dsender = UnconnectedSenders.get(author.getStringID());
|
||||||
}
|
}
|
||||||
return dsender;
|
return dsender;
|
||||||
|
|
|
@ -25,22 +25,22 @@ public class MCListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(TBMCPlayerJoinEvent e) {
|
public void onPlayerJoin(TBMCPlayerJoinEvent e) {
|
||||||
final Player p = Bukkit.getPlayer(e.GetPlayer().getUUID());
|
final Player p = Bukkit.getPlayer(e.GetPlayer().getUUID());
|
||||||
if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().get())) {
|
if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().getOrDefault(null))) {
|
||||||
IUser user = DiscordPlugin.dc
|
IUser user = DiscordPlugin.dc.getUserByID(
|
||||||
.getUserByID(Long.parseLong(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().get())));
|
Long.parseLong(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().getOrDefault(null))));
|
||||||
p.sendMessage("§bTo connect with the Discord account @" + user.getName() + "#" + user.getDiscriminator()
|
p.sendMessage("§bTo connect with the Discord account @" + user.getName() + "#" + user.getDiscriminator()
|
||||||
+ " do /discord accept");
|
+ " do /discord accept");
|
||||||
p.sendMessage("§bIf it wasn't you, do /discord decline");
|
p.sendMessage("§bIf it wasn't you, do /discord decline");
|
||||||
}
|
}
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
||||||
e.GetPlayer().PlayerName().get() + " joined the game");
|
e.GetPlayer().PlayerName().getOrDefault(null) + " joined the game");
|
||||||
MCChatListener.ListC = 0;
|
MCChatListener.ListC = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLeave(TBMCPlayerQuitEvent e) {
|
public void onPlayerLeave(TBMCPlayerQuitEvent e) {
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
||||||
e.GetPlayer().PlayerName().get() + " left the game");
|
e.GetPlayer().PlayerName().getOrDefault(null) + " left the game");
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
package buttondevteam.DiscordPlugin;
|
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.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
@ -35,26 +29,6 @@ public class AppTest extends TestCase {
|
||||||
* Rigourous Test :-)
|
* Rigourous Test :-)
|
||||||
*/
|
*/
|
||||||
public void testApp() {
|
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);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue