Added messages

This commit is contained in:
Norbi Peti 2016-10-31 18:07:53 +01:00
parent b2e9503a02
commit f60a5205de
2 changed files with 38 additions and 0 deletions

View file

@ -1,9 +1,14 @@
package buttondevteam.discordplugin;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerCommandEvent;
import buttondevteam.discordplugin.commands.ConnectCommand;
import buttondevteam.lib.TBMCPlayerJoinEvent;
public class MCListener implements Listener {
@EventHandler
public void onServerCommandPreprocess(ServerCommandEvent e) {
@ -18,4 +23,12 @@ public class MCListener implements Listener {
ex.printStackTrace();
}
}
@EventHandler
public void onPlayerJoin(TBMCPlayerJoinEvent e) {
final Player p = Bukkit.getPlayer(e.GetPlayer().getUuid());
p.sendMessage("§bTo connect with the Discord account "
+ ConnectCommand.WaitingToConnect.get(e.GetPlayer().getPlayerName()) + " do /discord accept");
p.sendMessage("§bIf it wasn't you, do /discord decline");
}
}

View file

@ -1,8 +1,15 @@
package buttondevteam.discordplugin.commands;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.google.common.collect.HashBiMap;
import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.TBMCDiscordAPI;
import buttondevteam.lib.TBMCPlayer;
import sx.blah.discord.handle.obj.IMessage;
public class ConnectCommand extends DiscordCommandBase {
@ -34,10 +41,28 @@ public class ConnectCommand extends DiscordCommandBase {
"Replacing " + WaitingToConnect.inverse().get(message.getAuthor().getID()) + " with " + args);
WaitingToConnect.inverse().remove(message.getAuthor().getID());
}
@SuppressWarnings("deprecation")
OfflinePlayer p = Bukkit.getOfflinePlayer(args);
if (p == null) {
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())) {
DiscordPlugin.sendMessageToChannel(message.getChannel(), "You already have this account connected.");
return;
}
} catch (Exception e) {
TBMCDiscordAPI.SendException(e, "An error occured while connecting a Discord account!");
DiscordPlugin.sendMessageToChannel(message.getChannel(), "An internal error occured!\n" + e);
}
WaitingToConnect.put(args, message.getAuthor().getID());
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"Pending connection - accept connection in Minecraft from the account " + args
+ " before the server gets restarted.");
if (p.isOnline())
((Player) p).sendMessage(
"§bTo connect with the Discord account " + message.getAuthor().getName() + " do /discord accept");
}
}