Merge branch 'master' into dev
Conflicts: src/main/java/buttondevteam/discordplugin/DiscordPlayer.java src/main/java/buttondevteam/discordplugin/DiscordPlugin.java src/main/java/buttondevteam/discordplugin/commands/ConnectCommand.java src/main/java/buttondevteam/discordplugin/commands/UserinfoCommand.java src/main/java/buttondevteam/discordplugin/listeners/MCChatListener.java src/main/java/buttondevteam/discordplugin/listeners/MCListener.java src/main/java/buttondevteam/discordplugin/mccommands/AcceptMCCommand.java
This commit is contained in:
commit
b95b9092f5
7 changed files with 36 additions and 24 deletions
|
@ -1,18 +1,21 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.UserClass;
|
||||
|
||||
@UserClass(foldername = "discord")
|
||||
public class DiscordPlayer extends ChromaGamerBase {
|
||||
public String getDiscordID() {
|
||||
return plugindata.getString("id");
|
||||
private String did;
|
||||
|
||||
public DiscordPlayer() {
|
||||
}
|
||||
|
||||
public void setDiscordID(String id) {
|
||||
plugindata.set("id", id);
|
||||
public String getDiscordID() {
|
||||
return did;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return "discord";
|
||||
return did;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
annchannel = botchannel; // bot-room
|
||||
genchannel = botchannel; // bot-room
|
||||
botroomchannel = botchannel;// bot-room
|
||||
chatchannel = devServer.getChannelByID("248185455508455424"); // minecraft_chat_test
|
||||
chatchannel = botchannel;// bot-room
|
||||
officechannel = devServer.getChannelByID("219626707458457603"); // developers-office
|
||||
updatechannel = botchannel;
|
||||
dc.changeStatus(Status.game("testing"));
|
||||
|
|
|
@ -10,6 +10,8 @@ import buttondevteam.discordplugin.DiscordPlayer;
|
|||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
|
||||
public class ConnectCommand extends DiscordCommandBase {
|
||||
|
@ -47,8 +49,9 @@ public class ConnectCommand extends DiscordCommandBase {
|
|||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "The specified Minecraft player cannot be found");
|
||||
return;
|
||||
}
|
||||
try (DiscordPlayer pl = ChromaGamerBase.getUser(message.getAuthor().getID(), DiscordPlayer.class)) {
|
||||
if (message.getAuthor().getID().equals(pl.getDiscordID())) {
|
||||
try (TBMCPlayer pl = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class)) {
|
||||
DiscordPlayer dp = pl.getAs(DiscordPlayer.class);
|
||||
if (dp != null && message.getAuthor().getID().equals(dp.getDiscordID())) {
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "You already have this account connected.");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -30,10 +31,10 @@ public class UserinfoCommand extends DiscordCommandBase {
|
|||
if (args.length() == 0)
|
||||
target = message.getAuthor();
|
||||
else {
|
||||
final Stream<IUser> mentions = message.getMentions().stream()
|
||||
.filter(m -> !m.getID().equals(DiscordPlugin.dc.getOurUser().getID()));
|
||||
if (mentions.findFirst().isPresent())
|
||||
target = mentions.findFirst().get();
|
||||
final Optional<IUser> firstmention = message.getMentions().stream()
|
||||
.filter(m -> !m.getID().equals(DiscordPlugin.dc.getOurUser().getID())).findFirst();
|
||||
if (firstmention.isPresent())
|
||||
target = firstmention.get();
|
||||
else if (args.contains("#")) {
|
||||
String[] targettag = args.split("#");
|
||||
final List<IUser> targets = getUsers(message, targettag[0]);
|
||||
|
@ -74,6 +75,7 @@ public class UserinfoCommand extends DiscordCommandBase {
|
|||
uinfo.append(dp.getInfo(InfoTarget.Discord));
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), uinfo.toString());
|
||||
} catch (Exception e) {
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "An error occured while getting the user!");
|
||||
TBMCCoreAPI.SendException("Error while getting info about " + target.getName() + "!", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,9 +54,9 @@ public class CommandListener {
|
|||
final String mention = DiscordPlugin.dc.getOurUser().mention(false);
|
||||
final String mentionNick = DiscordPlugin.dc.getOurUser().mention(true);
|
||||
boolean gotmention = checkanddeletemention(cmdwithargs, mention, message);
|
||||
gotmention = checkanddeletemention(cmdwithargs, mentionNick, message);
|
||||
gotmention = checkanddeletemention(cmdwithargs, mentionNick, message) || gotmention;
|
||||
for (String mentionRole : (Iterable<String>) message.getRoleMentions().stream().map(r -> r.mention())::iterator)
|
||||
gotmention = checkanddeletemention(cmdwithargs, mentionRole, message);
|
||||
gotmention = checkanddeletemention(cmdwithargs, mentionRole, message) || gotmention; // Delete all mentions
|
||||
if (mentionedonly && !gotmention) {
|
||||
message.getChannel().setTypingStatus(false);
|
||||
return false;
|
||||
|
|
|
@ -20,19 +20,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().getPlayerName())) {
|
||||
p.sendMessage("§bTo connect with the Discord account "
|
||||
+ ConnectCommand.WaitingToConnect.get(e.GetPlayer().getPlayerName()) + " do /discord accept");
|
||||
if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().get())) {
|
||||
IUser user = DiscordPlugin.dc
|
||||
.getUserByID(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().get()));
|
||||
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().getPlayerName() + " joined the game");
|
||||
e.GetPlayer().PlayerName().get() + " joined the game");
|
||||
MCChatListener.ListC = 0;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(TBMCPlayerQuitEvent e) {
|
||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel, e.GetPlayer().getPlayerName() + " left the game");
|
||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
||||
e.GetPlayer().PlayerName().get() + " left the game");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -40,7 +43,7 @@ public class MCListener implements Listener {
|
|||
if (DiscordPlugin.SafeMode)
|
||||
return;
|
||||
DiscordPlayer dp = e.getPlayer().getAs(DiscordPlayer.class);
|
||||
if (dp.getDiscordID() == null || dp.getDiscordID() == "")
|
||||
if (dp == null || dp.getDiscordID() == null || dp.getDiscordID() == "")
|
||||
return;
|
||||
IUser user = DiscordPlugin.dc.getUserByID(dp.getDiscordID());
|
||||
e.addInfo("Discord tag: " + user.getName() + "#" + user.getDiscriminator());
|
||||
|
|
|
@ -8,6 +8,7 @@ import buttondevteam.discordplugin.commands.ConnectCommand;
|
|||
import buttondevteam.discordplugin.listeners.MCChatListener;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
|
||||
public class AcceptMCCommand extends DiscordMCCommandBase {
|
||||
|
||||
|
@ -43,11 +44,11 @@ public class AcceptMCCommand extends DiscordMCCommandBase {
|
|||
sender.sendMessage("§cYou don't have a pending connection to Discord.");
|
||||
return true;
|
||||
}
|
||||
final TBMCPlayer mcp = ChromaGamerBase.getUser(((Player) sender).getUniqueId().toString(), TBMCPlayer.class);
|
||||
final DiscordPlayer dp = ChromaGamerBase.getUser(did, DiscordPlayer.class);
|
||||
mcp.connectWith(dp);
|
||||
mcp.save();
|
||||
DiscordPlayer dp = ChromaGamerBase.getUser(did, DiscordPlayer.class);
|
||||
TBMCPlayer mcp = TBMCPlayerBase.getPlayer(((Player) sender).getUniqueId(), TBMCPlayer.class);
|
||||
dp.connectWith(mcp); // TODO: Fix null.yml and empty playerinfos
|
||||
dp.save();
|
||||
mcp.save();
|
||||
ConnectCommand.WaitingToConnect.remove(sender.getName());
|
||||
MCChatListener.UnconnectedSenders.remove(did);
|
||||
sender.sendMessage("§bAccounts connected.");
|
||||
|
|
Loading…
Reference in a new issue