Fixes, channel con work
Connecting channels is WIP
This commit is contained in:
parent
b60bf36864
commit
fba5c5b49a
5 changed files with 96 additions and 3 deletions
|
@ -58,8 +58,8 @@ public class ConnectCommand extends DiscordCommandBase {
|
|||
}
|
||||
WaitingToConnect.put(p.getName(), message.getAuthor().getStringID());
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||
"Pending connection - accept connection in Minecraft from the account " + args
|
||||
+ " before the server gets restarted. You can also adjust the Minecraft name you want to connect to with the same command.");
|
||||
"Alright! Now accept the connection in Minecraft from the account " + args
|
||||
+ " before the next server restart. You can also adjust the Minecraft name you want to connect to with the same command.");
|
||||
if (p.isOnline())
|
||||
((Player) p).sendMessage("§bTo connect with the Discord account " + message.getAuthor().getName() + "#"
|
||||
+ message.getAuthor().getDiscriminator() + " do /discord accept");
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.mccommands.ChannelconMCCommand;
|
||||
import lombok.val;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
|
||||
public class HereCommand extends DiscordCommandBase {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "here";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(IMessage message, String args) {
|
||||
val chgroup = ChannelconMCCommand.PendingConnections.get(message.getAuthor().getStringID());
|
||||
if (chgroup == null) {
|
||||
message.reply("no pending connection found! "); //TODO
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getHelpText() {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
|
@ -46,6 +46,12 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
private LinkedBlockingQueue<AbstractMap.SimpleEntry<TBMCChatEvent, Instant>> sendevents = new LinkedBlockingQueue<>();
|
||||
private Runnable sendrunnable;
|
||||
|
||||
public static void addCustomChat(IChannel channel, String groupid, Channel mcchannel) {
|
||||
val lmd = new LastMsgData(channel, null, null);
|
||||
lmd.mcchannel = mcchannel;
|
||||
lastmsgCustom.put(groupid, lmd);
|
||||
}
|
||||
|
||||
@EventHandler // Minecraft
|
||||
public void onMCChat(TBMCChatEvent ev) {
|
||||
if (ev.isCancelled())
|
||||
|
@ -177,6 +183,10 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
* Used for messages in PMs (mcchat).
|
||||
*/
|
||||
private static ArrayList<LastMsgData> lastmsgPerUser = new ArrayList<LastMsgData>();
|
||||
/**
|
||||
* Used for town or nation chats or anything else
|
||||
*/
|
||||
private static HashMap<String, LastMsgData> lastmsgCustom = new HashMap<>();
|
||||
|
||||
public static boolean privateMCChat(IChannel channel, boolean start, IUser user, DiscordPlayer dp) {
|
||||
TBMCPlayer mcp = dp.getAs(TBMCPlayer.class);
|
||||
|
|
|
@ -93,7 +93,7 @@ public class MCListener implements Listener {
|
|||
if (DiscordPlugin.SafeMode)
|
||||
return;
|
||||
DiscordPlayer dp = e.getPlayer().getAs(DiscordPlayer.class);
|
||||
if (dp == null || dp.getDiscordID() == null || dp.getDiscordID() == "")
|
||||
if (dp == null || dp.getDiscordID() == null || dp.getDiscordID().equals(""))
|
||||
return;
|
||||
IUser user = DiscordPlugin.dc.getUserByID(Long.parseLong(dp.getDiscordID()));
|
||||
e.addInfo("Discord tag: " + user.getName() + "#" + user.getDiscriminator());
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package buttondevteam.discordplugin.mccommands;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.lib.TBMCChannelConnectEvent;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
@CommandClass(modOnly = false, path = "channelcon")
|
||||
public class ChannelconMCCommand extends DiscordMCCommandBase {
|
||||
@Override //TODO: Since we require connecting the accounts, it can be done entirely on Discord.
|
||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
val chan = Channel.getChannels().stream().filter(ch -> ch.ID.equalsIgnoreCase(args[0]) || (ch.IDs != null && Arrays.stream(ch.IDs).anyMatch(cid -> cid.equalsIgnoreCase(args[0])))).findAny();
|
||||
if (!chan.isPresent()) {
|
||||
player.sendMessage("§cChannel with ID '" + args[0] + "' not found! The ID is the command for it without the /.");
|
||||
return true;
|
||||
}
|
||||
val dp = TBMCPlayer.getPlayer(player.getUniqueId(), TBMCPlayer.class).getAs(DiscordPlayer.class);
|
||||
if (dp == null) {
|
||||
player.sendMessage("§cYou need to connect your Discord account. In #bot do @ChromaBot connect " + player.getName());
|
||||
return true;
|
||||
}
|
||||
val ev = new TBMCChannelConnectEvent(player, chan.get());
|
||||
Bukkit.getPluginManager().callEvent(ev);
|
||||
if (ev.isCancelled() || ev.getGroupid() == null) {
|
||||
player.sendMessage("§cSorry, that didn't work. You cannot use that channel.");
|
||||
return true;
|
||||
}
|
||||
//MCChatListener.addCustomChat() - TODO: Call in Discord cmd
|
||||
PendingConnections.put(dp.getDiscordID(), new AbstractMap.SimpleEntry<>(ev.getChannel(), ev.getGroupid()));
|
||||
player.sendMessage("§bAlright! Now invite me to your server then show me the channel to use (@ChromaBot here).");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String s) {
|
||||
return new String[]{//
|
||||
"§6---- Channel connect ---", //
|
||||
"This command allows you to connect a Minecraft channel to a Discord channel.", //
|
||||
"You need to have access to the MC channel and have manage permissions on the Discord channel." //
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Key: Discord ID
|
||||
* Value of value. Channel Group ID
|
||||
*/
|
||||
public static HashMap<String, AbstractMap.SimpleEntry<Channel, String>> PendingConnections = new HashMap<>();
|
||||
}
|
Loading…
Reference in a new issue