Added messages on connect/disconnect and on leave
This commit is contained in:
parent
90bb05a4c5
commit
5875da50d4
4 changed files with 36 additions and 1 deletions
|
@ -18,7 +18,7 @@ import java.util.ArrayList;
|
|||
|
||||
public class MCTPAudioCmd implements CommandExecutor {
|
||||
|
||||
public String prefix = (ChatColor.GOLD + "[" + ChatColor.YELLOW + "MCTP" + ChatColor.GOLD + "] " + ChatColor.GRAY);
|
||||
public static String prefix = (ChatColor.GOLD + "[" + ChatColor.YELLOW + "MCTP" + ChatColor.GOLD + "] " + ChatColor.GRAY);
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
|
||||
if (cmd.getName().equalsIgnoreCase("mctpaudio")) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package me.mctp;
|
||||
|
||||
import me.mctp.listener.LogoutListener;
|
||||
import me.mctp.listener.WGListener;
|
||||
import me.mctp.socket.Client;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -33,6 +34,7 @@ public class Main extends JavaPlugin implements Listener {
|
|||
getCommand("mctpaudio").setExecutor(new MCTPAudioCmd());
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new WGListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new LogoutListener(), this);
|
||||
|
||||
Bukkit.getLogger().info(prefix + " __ __ ____ _____ ____ _ _ _ ");
|
||||
Bukkit.getLogger().info(prefix + " | \\/ |/ ___|_ _| _ \\ / \\ _ _ __| (_) ___ ");
|
||||
|
|
17
src/me/mctp/listener/LogoutListener.java
Normal file
17
src/me/mctp/listener/LogoutListener.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package me.mctp.listener;
|
||||
|
||||
import me.mctp.Main;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class LogoutListener implements Listener {
|
||||
@EventHandler
|
||||
public void onDisconnect(PlayerQuitEvent e) {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("task", "LOGOUT");
|
||||
data.put("uuid", e.getPlayer().getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
package me.mctp.socket;
|
||||
|
||||
import me.mctp.MCTPAudioCmd;
|
||||
import me.mctp.Main;
|
||||
import me.mctp.managers.PinManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
import org.json.simple.JSONObject;
|
||||
|
@ -69,11 +71,25 @@ public class Client {
|
|||
verified = PinManager.checkPin(pUUID, pin);
|
||||
}
|
||||
|
||||
Player p = Bukkit.getPlayer(pUUID);
|
||||
if (p != null && p.isOnline()) {
|
||||
p.sendMessage(MCTPAudioCmd.prefix + "You are now connected with the audioclient.");
|
||||
}
|
||||
|
||||
JSONObject reply = new JSONObject();
|
||||
reply.put("task", "AUTHENTICATION");
|
||||
reply.put("verified", verified);
|
||||
reply.put("uuid", uuid);
|
||||
this.send(reply.toJSONString());
|
||||
} else if (str.equals("DISCONNECTED")) {
|
||||
String uuid = JSONUtil.getValue(json, "uuid");
|
||||
if (uuid == null || uuid.isEmpty()) return;
|
||||
|
||||
UUID pUUID = JSONUtil.formatFromInput(uuid);
|
||||
Player p = Bukkit.getPlayer(pUUID);
|
||||
if (p != null && p.isOnline()) {
|
||||
p.sendMessage(MCTPAudioCmd.prefix + "You are now disconnected from the audioclient.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue