Fixes, added game roles, commands in mcchat, smaller additions #26
7 changed files with 55 additions and 39 deletions
|
@ -1,13 +1,18 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
|
||||
public class DiscordPlayer extends TBMCPlayer {
|
||||
public class DiscordPlayer extends ChromaGamerBase {
|
||||
public String getDiscordID() {
|
||||
return getData();
|
||||
return plugindata.getString("id");
|
||||
}
|
||||
|
||||
public void setDiscordID(String id) {
|
||||
setData(id);
|
||||
plugindata.set("id", id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return "discord";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,17 @@ import sx.blah.discord.handle.obj.IUser;
|
|||
public class DiscordSender extends DiscordSenderBase implements CommandSender {
|
||||
private PermissibleBase perm = new PermissibleBase(this);
|
||||
|
||||
private String name = null;
|
||||
|
||||
public DiscordSender(IUser user, IChannel channel) {
|
||||
super(user, channel);
|
||||
}
|
||||
|
||||
public DiscordSender(IUser user, IChannel channel, String name) {
|
||||
super(user, channel);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(String name) {
|
||||
return perm.isPermissionSet(name);
|
||||
|
@ -92,7 +99,7 @@ public class DiscordSender extends DiscordSenderBase implements CommandSender {
|
|||
public String getName() {
|
||||
if (user == null)
|
||||
return "Discord user";
|
||||
return user.getDisplayName(DiscordPlugin.mainServer);
|
||||
return name == null ? user.getDisplayName(DiscordPlugin.mainServer) : name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.google.common.collect.HashBiMap;
|
|||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
|
||||
public class ConnectCommand extends DiscordCommandBase {
|
||||
|
@ -47,8 +47,8 @@ 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 (DiscordPlayer pl = ChromaGamerBase.getUser(message.getAuthor().getID(), DiscordPlayer.class)) {
|
||||
if (message.getAuthor().getID().equals(pl.getDiscordID())) {
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "You already have this account connected.");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@ 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;
|
||||
|
||||
|
@ -68,20 +69,13 @@ 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())) {
|
||||
StringBuilder uinfo = new StringBuilder("User info for ").append(target.getName()).append(":\n");
|
||||
uinfo.append(player.getInfo(InfoTarget.Discord));
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), uinfo.toString());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
try (DiscordPlayer dp = ChromaGamerBase.getUser(target.getID(), DiscordPlayer.class)) {
|
||||
StringBuilder uinfo = new StringBuilder("User info for ").append(target.getName()).append(":\n");
|
||||
uinfo.append(dp.getInfo(InfoTarget.Discord));
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), uinfo.toString());
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while getting info about " + target.getName() + "!", 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) {
|
||||
|
|
|
@ -13,6 +13,7 @@ import buttondevteam.discordplugin.*;
|
|||
import buttondevteam.lib.*;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import sx.blah.discord.api.events.IListener;
|
||||
import sx.blah.discord.api.internal.json.objects.EmbedObject;
|
||||
|
@ -83,20 +84,21 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
return;
|
||||
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());
|
||||
}).findAny();
|
||||
DiscordPlayer dp = ChromaGamerBase.getUser(author.getID(), DiscordPlayer.class);
|
||||
final DiscordSenderBase dsender;
|
||||
if (player.isPresent()) // Connected?
|
||||
{ // Execute as ingame player
|
||||
Player mcp = null; // Offline players can't really run commands
|
||||
final String cid;
|
||||
if ((cid = dp.getConnectedID(TBMCPlayer.class)) != null // Connected?
|
||||
&& (mcp = Bukkit.getPlayer(cid)) != null) { // Execute as ingame player, if online
|
||||
if (!ConnectedSenders.containsKey(author.getID()))
|
||||
ConnectedSenders.put(author.getID(),
|
||||
new DiscordPlayerSender(author, event.getMessage().getChannel(), player.get()));
|
||||
new DiscordPlayerSender(author, event.getMessage().getChannel(), mcp));
|
||||
dsender = ConnectedSenders.get(author.getID());
|
||||
} else {
|
||||
TBMCPlayer p = dp.getAs(TBMCPlayer.class);
|
||||
if (!UnconnectedSenders.containsKey(author.getID()))
|
||||
UnconnectedSenders.put(author.getID(), new DiscordSender(author, event.getMessage().getChannel()));
|
||||
UnconnectedSenders.put(author.getID(), new DiscordSender(author, event.getMessage().getChannel(),
|
||||
p == null ? null : p.getPlayerName())); // Display the playername, if found
|
||||
dsender = UnconnectedSenders.get(author.getID());
|
||||
}
|
||||
|
||||
|
@ -108,7 +110,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
|
||||
if (dmessage.startsWith("/")) {
|
||||
final String cmd = dmessage.substring(1).toLowerCase();
|
||||
if (!player.isPresent()
|
||||
if (mcp == null
|
||||
&& !Arrays.stream(UnconnectedCmds).anyMatch(s -> cmd.equals(s) || cmd.startsWith(s + " "))) {
|
||||
// Command not whitelisted
|
||||
DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), // TODO
|
||||
|
|
|
@ -11,17 +11,15 @@ import org.bukkit.event.server.ServerCommandEvent;
|
|||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.commands.ConnectCommand;
|
||||
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerQuitEvent;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import buttondevteam.lib.player.*;
|
||||
import net.ess3.api.events.*;
|
||||
import sx.blah.discord.handle.obj.IUser;
|
||||
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());
|
||||
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");
|
||||
|
@ -41,7 +39,7 @@ public class MCListener implements Listener {
|
|||
public void onGetInfo(TBMCPlayerGetInfoEvent e) {
|
||||
if (DiscordPlugin.SafeMode)
|
||||
return;
|
||||
DiscordPlayer dp = e.getPlayer().asPluginPlayer(DiscordPlayer.class);
|
||||
DiscordPlayer dp = e.getPlayer().getAs(DiscordPlayer.class);
|
||||
if (dp.getDiscordID() == null || dp.getDiscordID() == "")
|
||||
return;
|
||||
IUser user = DiscordPlugin.dc.getUserByID(dp.getDiscordID());
|
||||
|
@ -71,4 +69,9 @@ public class MCListener implements Listener {
|
|||
public void onServerCommand(ServerCommandEvent e) {
|
||||
DiscordPlugin.Restart = !e.getCommand().equalsIgnoreCase("stop"); // The variable is always true except if stopped
|
||||
}
|
||||
|
||||
/*@EventHandler
|
||||
public void onPlayerMute(MuteStatusChangeEvent e) {
|
||||
e.getAffected()
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ 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;
|
||||
|
||||
public class AcceptMCCommand extends DiscordMCCommandBase {
|
||||
|
@ -42,7 +43,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);
|
||||
final TBMCPlayer mcp = ChromaGamerBase.getUser(((Player) sender).getUniqueId().toString(), TBMCPlayer.class);
|
||||
final DiscordPlayer dp = ChromaGamerBase.getUser(did, DiscordPlayer.class);
|
||||
mcp.connectWith(dp);
|
||||
mcp.save();
|
||||
dp.save();
|
||||
ConnectCommand.WaitingToConnect.remove(sender.getName());
|
||||
MCChatListener.UnconnectedSenders.remove(did);
|
||||
sender.sendMessage("§bAccounts connected.");
|
||||
|
|
Loading…
Reference in a new issue