Added private Minecraft chat, Discord login, show message pinning, Maven project check, some of #12 #39
4 changed files with 55 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.PlayerData;
|
||||
import buttondevteam.lib.player.UserClass;
|
||||
|
||||
@UserClass(foldername = "discord")
|
||||
|
@ -15,4 +16,8 @@ public class DiscordPlayer extends ChromaGamerBase {
|
|||
did = plugindata.getString(getFolder() + "_id");
|
||||
return did;
|
||||
}
|
||||
|
||||
public PlayerData<Boolean> minecraftChat() {
|
||||
return data();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,10 @@ import java.awt.Color;
|
|||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
@ -135,6 +138,16 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
setupProviders();
|
||||
TBMCCoreAPI.SendUnsentExceptions();
|
||||
TBMCCoreAPI.SendUnsentDebugMessages();
|
||||
final Calendar currentCal = Calendar.getInstance();
|
||||
final Calendar newCal = Calendar.getInstance();
|
||||
currentCal.set(currentCal.get(Calendar.YEAR), currentCal.get(Calendar.MONTH),
|
||||
currentCal.get(Calendar.DAY_OF_MONTH), 4, 10);
|
||||
if (currentCal.get(Calendar.DAY_OF_MONTH) % 9 == 0 && currentCal.before(newCal)) {
|
||||
Random rand = new Random();
|
||||
sendMessageToChannel(dc.getChannels().get(rand.nextInt(dc.getChannels().size())),
|
||||
"You could make a religion out of this");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while enabling DiscordPlugin!", e);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.lib.player.PlayerData;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
|
||||
public class MCChatCommand extends DiscordCommandBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "mcchat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(IMessage message, String args) {
|
||||
if (!message.getChannel().isPrivate()) {
|
||||
message.reply("This command can only be issued while DMing the bot.");
|
||||
return;
|
||||
}
|
||||
PlayerData<Boolean> mcchat = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)
|
||||
.minecraftChat();
|
||||
mcchat.set(!mcchat.get());
|
||||
message.reply("Minecraft chat " + (mcchat.get() ? "enabled." : "disabled."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getHelpText() {
|
||||
return new String[] { //
|
||||
"mcchat enables or disables the Minecraft chat in private messages.", //
|
||||
"It can be useful if you don't want your messages to be visible, for example when talking a private channel." //
|
||||
}; // TODO: Pin channel switching to indicate the current channel
|
||||
}
|
||||
|
||||
}
|
|
@ -59,21 +59,15 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
@EventHandler
|
||||
public void onChatPreprocess(TBMCChatPreprocessEvent event) {
|
||||
int start = -1;
|
||||
// System.out.println("A");
|
||||
while ((start = event.getMessage().indexOf('@', start + 1)) != -1) {
|
||||
// System.out.println("Start: " + start);
|
||||
int mid = event.getMessage().indexOf('#', start + 1);
|
||||
// System.out.println("Mid: " + mid);
|
||||
if (mid == -1)
|
||||
return;
|
||||
int end_ = event.getMessage().indexOf(' ', mid + 1);
|
||||
// System.out.println("End: " + end_);
|
||||
if (end_ == -1)
|
||||
end_ = event.getMessage().length();
|
||||
final int end = end_;
|
||||
final int startF = start;
|
||||
// System.out.println("Name: " + event.getMessage().substring(start, mid));
|
||||
// System.out.println("Disc: " + event.getMessage().substring(mid, end));
|
||||
DiscordPlugin.dc.getUsersByName(event.getMessage().substring(start + 1, mid)).stream()
|
||||
.filter(u -> u.getDiscriminator().equals(event.getMessage().substring(mid + 1, end))).findAny()
|
||||
.ifPresent(user -> event.setMessage(event.getMessage().substring(0, startF) + "@" + user.getName()
|
||||
|
@ -104,7 +98,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
public void handle(sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent event) {
|
||||
final IUser author = event.getMessage().getAuthor();
|
||||
if (!event.getMessage().getChannel().getStringID().equals(DiscordPlugin.chatchannel.getStringID())
|
||||
/* && !(event.getMessage().getChannel().isPrivate() && privatechat) */)
|
||||
&& !(event.getMessage().getChannel().isPrivate()
|
||||
&& DiscordPlayer.getUser(author.getStringID(), DiscordPlayer.class).minecraftChat().get()))
|
||||
return;
|
||||
lastmessage = null;
|
||||
lastlist++;
|
||||
|
@ -117,7 +112,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
try {
|
||||
DiscordPlayer dp = ChromaGamerBase.getUser(author.getStringID(), DiscordPlayer.class);
|
||||
final DiscordSenderBase dsender;
|
||||
Player mcp = null; // Offline players can't really run commands, or can they?
|
||||
Player mcp = null; // Offline players can't really run commands, or can they? No, they can't, really.
|
||||
final String cid;
|
||||
if ((cid = dp.getConnectedID(TBMCPlayer.class)) != null // Connected?
|
||||
&& (mcp = Bukkit.getPlayer(UUID.fromString(cid))) != null) { // Execute as ingame player
|
||||
|
|
Loading…
Reference in a new issue