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:
Norbi Peti 2017-04-02 02:06:00 +02:00
commit b95b9092f5
7 changed files with 36 additions and 24 deletions

View file

@ -1,18 +1,21 @@
package buttondevteam.discordplugin; package buttondevteam.discordplugin;
import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.ChromaGamerBase;
import buttondevteam.lib.player.UserClass;
@UserClass(foldername = "discord")
public class DiscordPlayer extends ChromaGamerBase { public class DiscordPlayer extends ChromaGamerBase {
public String getDiscordID() { private String did;
return plugindata.getString("id");
public DiscordPlayer() {
} }
public void setDiscordID(String id) { public String getDiscordID() {
plugindata.set("id", id); return did;
} }
@Override @Override
public String getFileName() { public String getFileName() {
return "discord"; return did;
} }
} }

View file

@ -96,7 +96,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
annchannel = botchannel; // bot-room annchannel = botchannel; // bot-room
genchannel = botchannel; // bot-room genchannel = botchannel; // bot-room
botroomchannel = botchannel;// bot-room botroomchannel = botchannel;// bot-room
chatchannel = devServer.getChannelByID("248185455508455424"); // minecraft_chat_test chatchannel = botchannel;// bot-room
officechannel = devServer.getChannelByID("219626707458457603"); // developers-office officechannel = devServer.getChannelByID("219626707458457603"); // developers-office
updatechannel = botchannel; updatechannel = botchannel;
dc.changeStatus(Status.game("testing")); dc.changeStatus(Status.game("testing"));

View file

@ -10,6 +10,8 @@ import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.ChromaGamerBase;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerBase;
import sx.blah.discord.handle.obj.IMessage; import sx.blah.discord.handle.obj.IMessage;
public class ConnectCommand extends DiscordCommandBase { 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"); DiscordPlugin.sendMessageToChannel(message.getChannel(), "The specified Minecraft player cannot be found");
return; return;
} }
try (DiscordPlayer pl = ChromaGamerBase.getUser(message.getAuthor().getID(), DiscordPlayer.class)) { try (TBMCPlayer pl = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class)) {
if (message.getAuthor().getID().equals(pl.getDiscordID())) { 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."); DiscordPlugin.sendMessageToChannel(message.getChannel(), "You already have this account connected.");
return; return;
} }

View file

@ -1,6 +1,7 @@
package buttondevteam.discordplugin.commands; package buttondevteam.discordplugin.commands;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -30,10 +31,10 @@ public class UserinfoCommand extends DiscordCommandBase {
if (args.length() == 0) if (args.length() == 0)
target = message.getAuthor(); target = message.getAuthor();
else { else {
final Stream<IUser> mentions = message.getMentions().stream() final Optional<IUser> firstmention = message.getMentions().stream()
.filter(m -> !m.getID().equals(DiscordPlugin.dc.getOurUser().getID())); .filter(m -> !m.getID().equals(DiscordPlugin.dc.getOurUser().getID())).findFirst();
if (mentions.findFirst().isPresent()) if (firstmention.isPresent())
target = mentions.findFirst().get(); target = firstmention.get();
else if (args.contains("#")) { else if (args.contains("#")) {
String[] targettag = args.split("#"); String[] targettag = args.split("#");
final List<IUser> targets = getUsers(message, targettag[0]); final List<IUser> targets = getUsers(message, targettag[0]);
@ -74,6 +75,7 @@ public class UserinfoCommand extends DiscordCommandBase {
uinfo.append(dp.getInfo(InfoTarget.Discord)); uinfo.append(dp.getInfo(InfoTarget.Discord));
DiscordPlugin.sendMessageToChannel(message.getChannel(), uinfo.toString()); DiscordPlugin.sendMessageToChannel(message.getChannel(), uinfo.toString());
} catch (Exception e) { } catch (Exception e) {
DiscordPlugin.sendMessageToChannel(message.getChannel(), "An error occured while getting the user!");
TBMCCoreAPI.SendException("Error while getting info about " + target.getName() + "!", e); TBMCCoreAPI.SendException("Error while getting info about " + target.getName() + "!", e);
} }
} }

View file

@ -54,9 +54,9 @@ public class CommandListener {
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);
boolean gotmention = checkanddeletemention(cmdwithargs, mention, message); 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) 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) { if (mentionedonly && !gotmention) {
message.getChannel().setTypingStatus(false); message.getChannel().setTypingStatus(false);
return false; return false;

View file

@ -20,19 +20,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().getPlayerName())) { if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().get())) {
p.sendMessage("§bTo connect with the Discord account " IUser user = DiscordPlugin.dc
+ ConnectCommand.WaitingToConnect.get(e.GetPlayer().getPlayerName()) + " do /discord accept"); .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"); p.sendMessage("§bIf it wasn't you, do /discord decline");
} }
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel, DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
e.GetPlayer().getPlayerName() + " joined the game"); e.GetPlayer().PlayerName().get() + " 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, e.GetPlayer().getPlayerName() + " left the game"); DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
e.GetPlayer().PlayerName().get() + " left the game");
} }
@EventHandler @EventHandler
@ -40,7 +43,7 @@ public class MCListener implements Listener {
if (DiscordPlugin.SafeMode) if (DiscordPlugin.SafeMode)
return; return;
DiscordPlayer dp = e.getPlayer().getAs(DiscordPlayer.class); DiscordPlayer dp = e.getPlayer().getAs(DiscordPlayer.class);
if (dp.getDiscordID() == null || dp.getDiscordID() == "") if (dp == null || dp.getDiscordID() == null || dp.getDiscordID() == "")
return; return;
IUser user = DiscordPlugin.dc.getUserByID(dp.getDiscordID()); IUser user = DiscordPlugin.dc.getUserByID(dp.getDiscordID());
e.addInfo("Discord tag: " + user.getName() + "#" + user.getDiscriminator()); e.addInfo("Discord tag: " + user.getName() + "#" + user.getDiscriminator());

View file

@ -8,6 +8,7 @@ import buttondevteam.discordplugin.commands.ConnectCommand;
import buttondevteam.discordplugin.listeners.MCChatListener; import buttondevteam.discordplugin.listeners.MCChatListener;
import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.ChromaGamerBase;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerBase;
public class AcceptMCCommand extends DiscordMCCommandBase { 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."); sender.sendMessage("§cYou don't have a pending connection to Discord.");
return true; return true;
} }
final TBMCPlayer mcp = ChromaGamerBase.getUser(((Player) sender).getUniqueId().toString(), TBMCPlayer.class); DiscordPlayer dp = ChromaGamerBase.getUser(did, DiscordPlayer.class);
final DiscordPlayer dp = ChromaGamerBase.getUser(did, DiscordPlayer.class); TBMCPlayer mcp = TBMCPlayerBase.getPlayer(((Player) sender).getUniqueId(), TBMCPlayer.class);
mcp.connectWith(dp); dp.connectWith(mcp); // TODO: Fix null.yml and empty playerinfos
mcp.save();
dp.save(); dp.save();
mcp.save();
ConnectCommand.WaitingToConnect.remove(sender.getName()); ConnectCommand.WaitingToConnect.remove(sender.getName());
MCChatListener.UnconnectedSenders.remove(did); MCChatListener.UnconnectedSenders.remove(did);
sender.sendMessage("§bAccounts connected."); sender.sendMessage("§bAccounts connected.");