Fixed and updated plugin to the new things
This commit is contained in:
parent
b7ef8f4048
commit
ffbb9a0a91
8 changed files with 58 additions and 41 deletions
|
@ -1,13 +1,21 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.UserClass;
|
||||
|
||||
public class DiscordPlayer extends TBMCPlayer {
|
||||
public String getDiscordID() {
|
||||
return getData();
|
||||
@UserClass(foldername = "discord")
|
||||
public class DiscordPlayer extends ChromaGamerBase {
|
||||
private String did;
|
||||
|
||||
public DiscordPlayer() {
|
||||
}
|
||||
|
||||
public void setDiscordID(String id) {
|
||||
setData(id);
|
||||
public String getDiscordID() {
|
||||
return did;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return did;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,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"));
|
||||
|
@ -120,6 +120,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
Bukkit.getPluginManager().registerEvents(new ExceptionListener(), this);
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this);
|
||||
TBMCChatAPI.AddCommands(this, DiscordMCCommandBase.class);
|
||||
TBMCCoreAPI.RegisterUserClass(DiscordPlayer.class);
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, () -> sendMessageToChannel(chatchannel, "",
|
||||
new EmbedBuilder().withColor(Color.GREEN).withTitle("Server started - chat connected.").build()));
|
||||
|
|
|
@ -10,6 +10,7 @@ import buttondevteam.discordplugin.DiscordPlayer;
|
|||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
|
||||
public class ConnectCommand extends DiscordCommandBase {
|
||||
|
@ -47,8 +48,9 @@ public class ConnectCommand extends DiscordCommandBase {
|
|||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "The specified Minecraft player cannot be found");
|
||||
return;
|
||||
}
|
||||
try (TBMCPlayer pl = TBMCPlayer.getPlayer(p)) {
|
||||
if (message.getAuthor().getID().equals(pl.asPluginPlayer(DiscordPlayer.class).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,13 +1,15 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayer.InfoTarget;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
import sx.blah.discord.handle.obj.IUser;
|
||||
|
||||
|
@ -29,10 +31,11 @@ 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]);
|
||||
|
@ -68,21 +71,15 @@ public class UserinfoCommand extends DiscordCommandBase {
|
|||
target = targets.get(0);
|
||||
}
|
||||
}
|
||||
boolean found = false;
|
||||
for (TBMCPlayer player : TBMCPlayer.getLoadedPlayers().values()) {
|
||||
DiscordPlayer dp = player.asPluginPlayer(DiscordPlayer.class);
|
||||
if (target.getID().equals(dp.getDiscordID())) {
|
||||
try (DiscordPlayer dp = ChromaGamerBase.getUser(target.getID(), DiscordPlayer.class)) {
|
||||
StringBuilder uinfo = new StringBuilder("User info for ").append(target.getName()).append(":\n");
|
||||
uinfo.append(player.getInfo(InfoTarget.Discord));
|
||||
uinfo.append(dp.getInfo(InfoTarget.Discord));
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), uinfo.toString());
|
||||
found = true;
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "An error occured while getting the user!");
|
||||
TBMCCoreAPI.SendException("Error while getting DiscordPlayer info!", e);
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "The user (" + target.getName()
|
||||
+ ") is not found in our system (player has to be on the MC server for now)!");
|
||||
}
|
||||
|
||||
private List<IUser> getUsers(IMessage message, String args) {
|
||||
final List<IUser> targets;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -84,8 +84,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
String dmessage = event.getMessage().getContent();
|
||||
try {
|
||||
Optional<? extends Player> player = Bukkit.getOnlinePlayers().stream().filter(p -> { // TODO: Support offline players
|
||||
DiscordPlayer dp = TBMCPlayer.getPlayerAs(p, DiscordPlayer.class); // Online player, already loaded
|
||||
return author.getID().equals(dp.getDiscordID());
|
||||
DiscordPlayer dp = TBMCPlayer.getPlayer(p.getUniqueId(), TBMCPlayer.class).getAs(DiscordPlayer.class); // Not changing any data, don't need to save
|
||||
return dp != null && author.getID().equals(dp.getDiscordID());
|
||||
}).findAny();
|
||||
final DiscordSenderBase dsender;
|
||||
if (player.isPresent()) // Connected?
|
||||
|
|
|
@ -21,28 +21,31 @@ import sx.blah.discord.handle.obj.Status.StatusType;
|
|||
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");
|
||||
final Player p = Bukkit.getPlayer(e.GetPlayer().getUUID());
|
||||
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
|
||||
public void onGetInfo(TBMCPlayerGetInfoEvent e) {
|
||||
if (DiscordPlugin.SafeMode)
|
||||
return;
|
||||
DiscordPlayer dp = e.getPlayer().asPluginPlayer(DiscordPlayer.class);
|
||||
if (dp.getDiscordID() == null || dp.getDiscordID() == "")
|
||||
DiscordPlayer dp = e.getPlayer().getAs(DiscordPlayer.class);
|
||||
if (dp == null || dp.getDiscordID() == null || dp.getDiscordID() == "")
|
||||
return;
|
||||
IUser user = DiscordPlugin.dc.getUserByID(dp.getDiscordID());
|
||||
e.addInfo("Discord tag: " + user.getName() + "#" + user.getDiscriminator());
|
||||
|
|
|
@ -6,7 +6,9 @@ import org.bukkit.entity.Player;
|
|||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
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 {
|
||||
|
||||
|
@ -42,7 +44,11 @@ public class AcceptMCCommand extends DiscordMCCommandBase {
|
|||
sender.sendMessage("§cYou don't have a pending connection to Discord.");
|
||||
return true;
|
||||
}
|
||||
TBMCPlayer.getPlayerAs((Player) sender, DiscordPlayer.class).setDiscordID(did);
|
||||
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