diff --git a/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/BukkitServer.java b/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/BukkitServer.java index 7ee6625..581a762 100644 --- a/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/BukkitServer.java +++ b/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/BukkitServer.java @@ -1,5 +1,6 @@ package com.radiofreederp.nodebbintegration; +import com.radiofreederp.nodebbintegration.bukkit.hooks.OnTimeHook; import com.radiofreederp.nodebbintegration.bukkit.hooks.VanishNoPacketHook; import com.radiofreederp.nodebbintegration.bukkit.hooks.VaultHook; import org.bukkit.*; @@ -77,28 +78,46 @@ public String getTPS() { @Override public ArrayList getPlayerList() { - final ArrayList playerList = new ArrayList<>(); for (Player player : Bukkit.getServer().getOnlinePlayers()) { - if (VanishNoPacketHook.isEnabled()) { if (VanishNoPacketHook.isVanished(player.getName())) continue; } - JSONObject playerObj = new JSONObject(); + playerList.add(getPlayerJSON(player)); + } - try { - playerObj.put("name", player.getName()); - playerObj.put("id", player.getUniqueId()); + return playerList; + } - playerList.add(playerObj); - } catch (JSONException e) { - e.printStackTrace(); + @Override + public JSONObject getPlayerJSON (Object _player) { + JSONObject playerObj = new JSONObject(); + Player player = (Player)_player; + + try { + playerObj.put("name", player.getName()); + playerObj.put("displayName", player.getDisplayName()); + playerObj.put("id", player.getUniqueId()); + + if (VaultHook.chat != null && VaultHook.permission != null) { + playerObj.put("primaryGroup", VaultHook.chat.getPrimaryGroup(player)); + playerObj.put("prefix", VaultHook.chat.getPlayerPrefix(player)); + playerObj.put("suffix", VaultHook.chat.getPlayerSuffix(player)); + playerObj.put("groups", VaultHook.permission.getPlayerGroups(null, player)); } + + if (OnTimeHook.isEnabled()) { + if (OnTimeHook.isEnabled()) { + OnTimeHook.onTimeCheckTime(player, playerObj); + } + } + } catch (JSONException e) { + e.printStackTrace(); } - return playerList; + return playerObj; } @Override diff --git a/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/bukkit/hooks/VanishNoPacketHook.java b/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/bukkit/hooks/VanishNoPacketHook.java index 3866366..05b8237 100644 --- a/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/bukkit/hooks/VanishNoPacketHook.java +++ b/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/bukkit/hooks/VanishNoPacketHook.java @@ -20,7 +20,7 @@ public static boolean isEnabled() { public static void hook(NodeBBIntegrationBukkit plugin) { if (Bukkit.getPluginManager().isPluginEnabled("VanishNoPacket")) { enabled = true; - plugin.getServer().getPluginManager().registerEvents(new ListenerVanishNoPacket(), plugin); + plugin.getServer().getPluginManager().registerEvents(new ListenerVanishNoPacket(plugin), plugin); NodeBBIntegrationBukkit.instance.log("Hooked into VanishNoPacket."); } } diff --git a/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerPlayerJoin.java b/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerPlayerJoin.java index 8dadae2..a2cea44 100644 --- a/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerPlayerJoin.java +++ b/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerPlayerJoin.java @@ -32,36 +32,6 @@ public void onPlayerJoin(PlayerJoinEvent event) { if (VanishNoPacketHook.isVanished(event.getPlayer().getName())) return; } - MinecraftServerEvents.onPlayerJoin(plugin, event.getPlayer(), getPlayerJoinData(event.getPlayer())); - } - - public static JSONObject getPlayerJoinData(Player player) { - - JSONObject obj = new JSONObject(); - - try { - obj.put("name", player.getName()); - obj.put("id", player.getUniqueId()); - obj.put("key", NodeBBIntegrationBukkit.instance.getPluginConfig().getForumAPIKey()); - - if (OnTimeHook.isEnabled()) { - if (OnTimeHook.isEnabled()) { - OnTimeHook.onTimeCheckTime(player, obj); - } - } - - if (VaultHook.chat != null && VaultHook.permission != null) { - obj.put("primaryGroup", VaultHook.chat.getPrimaryGroup(player)); - obj.put("prefix", VaultHook.chat.getPlayerPrefix(player)); - obj.put("suffix", VaultHook.chat.getPlayerSuffix(player)); - obj.put("groups", VaultHook.permission.getPlayerGroups(player)); - } - - } catch (JSONException e) { - NodeBBIntegrationBukkit.instance.log("Error constructing JSON Object for " + SocketIOClient.Events.onPlayerJoin); - e.printStackTrace(); - } - - return obj; + MinecraftServerEvents.onPlayerJoin(plugin, event.getPlayer(), plugin.getMinecraftServer().getPlayerJSON(event.getPlayer())); } } diff --git a/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerVanishNoPacket.java b/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerVanishNoPacket.java index 9c10c0c..37bb661 100644 --- a/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerVanishNoPacket.java +++ b/bukkit-legacy/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerVanishNoPacket.java @@ -1,5 +1,7 @@ package com.radiofreederp.nodebbintegration.bukkit.listeners; +import com.radiofreederp.nodebbintegration.NodeBBIntegrationBukkit; +import com.radiofreederp.nodebbintegration.NodeBBIntegrationPlugin; import com.radiofreederp.nodebbintegration.socketio.SocketIOClient; import io.socket.client.Ack; import org.bukkit.event.EventHandler; @@ -11,6 +13,12 @@ */ public class ListenerVanishNoPacket implements Listener { + private NodeBBIntegrationBukkit plugin; + + public ListenerVanishNoPacket (NodeBBIntegrationPlugin plugin) { + this.plugin = (NodeBBIntegrationBukkit)plugin; + } + @EventHandler(priority=EventPriority.NORMAL) public void onVanishStatusChangeEvent(org.kitteh.vanish.event.VanishStatusChangeEvent event) { @@ -22,7 +30,7 @@ public void call(Object... args) { } }); }else{ - SocketIOClient.emit(SocketIOClient.Events.onPlayerJoin, ListenerPlayerJoin.getPlayerJoinData(event.getPlayer()), new Ack() { + SocketIOClient.emit(SocketIOClient.Events.onPlayerJoin, plugin.getMinecraftServer().getPlayerJSON(event.getPlayer()), new Ack() { @Override public void call(Object... args) { } diff --git a/bukkit/src/main/java/com/radiofreederp/nodebbintegration/BukkitServer.java b/bukkit/src/main/java/com/radiofreederp/nodebbintegration/BukkitServer.java index e1a3642..e177aaf 100644 --- a/bukkit/src/main/java/com/radiofreederp/nodebbintegration/BukkitServer.java +++ b/bukkit/src/main/java/com/radiofreederp/nodebbintegration/BukkitServer.java @@ -1,6 +1,7 @@ package com.radiofreederp.nodebbintegration; import com.google.common.io.Files; +import com.radiofreederp.nodebbintegration.bukkit.hooks.OnTimeHook; import com.radiofreederp.nodebbintegration.bukkit.hooks.VanishNoPacketHook; import com.radiofreederp.nodebbintegration.bukkit.hooks.VaultHook; import org.bukkit.*; @@ -79,28 +80,46 @@ public String getTPS() { @Override public ArrayList getPlayerList() { - final ArrayList playerList = new ArrayList<>(); for (Player player : Bukkit.getServer().getOnlinePlayers()) { - if (VanishNoPacketHook.isEnabled()) { if (VanishNoPacketHook.isVanished(player.getName())) continue; } - JSONObject playerObj = new JSONObject(); + playerList.add(getPlayerJSON(player)); + } - try { - playerObj.put("name", player.getName()); - playerObj.put("id", player.getUniqueId()); + return playerList; + } - playerList.add(playerObj); - } catch (JSONException e) { - e.printStackTrace(); + @Override + public JSONObject getPlayerJSON (Object _player) { + JSONObject playerObj = new JSONObject(); + Player player = (Player)_player; + + try { + playerObj.put("name", player.getName()); + playerObj.put("displayName", player.getDisplayName()); + playerObj.put("id", player.getUniqueId()); + + if (VaultHook.chat != null && VaultHook.permission != null) { + playerObj.put("primaryGroup", VaultHook.chat.getPrimaryGroup(player)); + playerObj.put("prefix", VaultHook.chat.getPlayerPrefix(player)); + playerObj.put("suffix", VaultHook.chat.getPlayerSuffix(player)); + playerObj.put("groups", VaultHook.permission.getPlayerGroups(null, player)); + } + + if (OnTimeHook.isEnabled()) { + if (OnTimeHook.isEnabled()) { + OnTimeHook.onTimeCheckTime(player, playerObj); + } } + } catch (JSONException e) { + e.printStackTrace(); } - return playerList; + return playerObj; } @Override diff --git a/bukkit/src/main/java/com/radiofreederp/nodebbintegration/bukkit/hooks/VanishNoPacketHook.java b/bukkit/src/main/java/com/radiofreederp/nodebbintegration/bukkit/hooks/VanishNoPacketHook.java index 3866366..05b8237 100644 --- a/bukkit/src/main/java/com/radiofreederp/nodebbintegration/bukkit/hooks/VanishNoPacketHook.java +++ b/bukkit/src/main/java/com/radiofreederp/nodebbintegration/bukkit/hooks/VanishNoPacketHook.java @@ -20,7 +20,7 @@ public static boolean isEnabled() { public static void hook(NodeBBIntegrationBukkit plugin) { if (Bukkit.getPluginManager().isPluginEnabled("VanishNoPacket")) { enabled = true; - plugin.getServer().getPluginManager().registerEvents(new ListenerVanishNoPacket(), plugin); + plugin.getServer().getPluginManager().registerEvents(new ListenerVanishNoPacket(plugin), plugin); NodeBBIntegrationBukkit.instance.log("Hooked into VanishNoPacket."); } } diff --git a/bukkit/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerPlayerJoin.java b/bukkit/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerPlayerJoin.java index 313119a..a2cea44 100644 --- a/bukkit/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerPlayerJoin.java +++ b/bukkit/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerPlayerJoin.java @@ -32,36 +32,6 @@ public void onPlayerJoin(PlayerJoinEvent event) { if (VanishNoPacketHook.isVanished(event.getPlayer().getName())) return; } - MinecraftServerEvents.onPlayerJoin(plugin, event.getPlayer(), getPlayerJoinData(event.getPlayer())); - } - - public static JSONObject getPlayerJoinData(Player player) { - - JSONObject obj = new JSONObject(); - - try { - obj.put("name", player.getName()); - obj.put("id", player.getUniqueId()); - obj.put("key", NodeBBIntegrationBukkit.instance.getPluginConfig().getForumAPIKey()); - - if (OnTimeHook.isEnabled()) { - if (OnTimeHook.isEnabled()) { - OnTimeHook.onTimeCheckTime(player, obj); - } - } - - if (VaultHook.chat != null && VaultHook.permission != null) { - obj.put("primaryGroup", VaultHook.chat.getPrimaryGroup(player)); - obj.put("prefix", VaultHook.chat.getPlayerPrefix(player)); - obj.put("suffix", VaultHook.chat.getPlayerSuffix(player)); - obj.put("groups", VaultHook.permission.getPlayerGroups(null, player)); - } - - } catch (JSONException e) { - NodeBBIntegrationBukkit.instance.log("Error constructing JSON Object for " + SocketIOClient.Events.onPlayerJoin); - e.printStackTrace(); - } - - return obj; + MinecraftServerEvents.onPlayerJoin(plugin, event.getPlayer(), plugin.getMinecraftServer().getPlayerJSON(event.getPlayer())); } } diff --git a/bukkit/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerVanishNoPacket.java b/bukkit/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerVanishNoPacket.java index 1d4994e..e70a469 100644 --- a/bukkit/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerVanishNoPacket.java +++ b/bukkit/src/main/java/com/radiofreederp/nodebbintegration/bukkit/listeners/ListenerVanishNoPacket.java @@ -1,5 +1,7 @@ package com.radiofreederp.nodebbintegration.bukkit.listeners; +import com.radiofreederp.nodebbintegration.NodeBBIntegrationBukkit; +import com.radiofreederp.nodebbintegration.NodeBBIntegrationPlugin; import com.radiofreederp.nodebbintegration.socketio.SocketIOClient; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -10,6 +12,12 @@ */ public class ListenerVanishNoPacket implements Listener { + private NodeBBIntegrationBukkit plugin; + + public ListenerVanishNoPacket (NodeBBIntegrationPlugin plugin) { + this.plugin = (NodeBBIntegrationBukkit)plugin; + } + @EventHandler(priority=EventPriority.NORMAL) public void onVanishStatusChangeEvent(org.kitteh.vanish.event.VanishStatusChangeEvent event) { @@ -17,7 +25,7 @@ public void onVanishStatusChangeEvent(org.kitteh.vanish.event.VanishStatusChange if (event.isVanishing()) { SocketIOClient.emit(SocketIOClient.Events.onPlayerQuit, ListenerPlayerQuit.getPlayerQuitData(event.getPlayer()), args -> {}); }else{ - SocketIOClient.emit(SocketIOClient.Events.onPlayerJoin, ListenerPlayerJoin.getPlayerJoinData(event.getPlayer()), args -> {}); + SocketIOClient.emit(SocketIOClient.Events.onPlayerJoin, plugin.getMinecraftServer().getPlayerJSON(event.getPlayer()), args -> {}); } } } diff --git a/common/src/main/java/com/radiofreederp/nodebbintegration/IMinecraftServerCommon.java b/common/src/main/java/com/radiofreederp/nodebbintegration/IMinecraftServerCommon.java index c43f149..23bf54c 100644 --- a/common/src/main/java/com/radiofreederp/nodebbintegration/IMinecraftServerCommon.java +++ b/common/src/main/java/com/radiofreederp/nodebbintegration/IMinecraftServerCommon.java @@ -36,6 +36,8 @@ public interface IMinecraftServerCommon { ArrayList getPlayerList(); ArrayList getPluginList(); + JSONObject getPlayerJSON(Object _player); + String getVersion(); String getServerName(); diff --git a/common/src/main/java/com/radiofreederp/nodebbintegration/MinecraftServerEvents.java b/common/src/main/java/com/radiofreederp/nodebbintegration/MinecraftServerEvents.java index ddf51b6..18d0335 100644 --- a/common/src/main/java/com/radiofreederp/nodebbintegration/MinecraftServerEvents.java +++ b/common/src/main/java/com/radiofreederp/nodebbintegration/MinecraftServerEvents.java @@ -13,6 +13,12 @@ public class MinecraftServerEvents { public static void onPlayerJoin(final NodeBBIntegrationPlugin plugin, final Object player, JSONObject data) { final String socketEvent = SocketIOClient.Events.onPlayerJoin; + try { + data.put("key", plugin.getPluginConfig().getForumAPIKey()); + } catch (JSONException e) { + e.printStackTrace(); + } + SocketIOClient.emit(socketEvent, data, new Ack() { @Override public void call(Object... args) { diff --git a/forge/src/main/java/com/radiofreederp/nodebbintegration/ForgeServer.java b/forge/src/main/java/com/radiofreederp/nodebbintegration/ForgeServer.java index 33dabaf..1dee577 100644 --- a/forge/src/main/java/com/radiofreederp/nodebbintegration/ForgeServer.java +++ b/forge/src/main/java/com/radiofreederp/nodebbintegration/ForgeServer.java @@ -59,6 +59,11 @@ public ArrayList getPluginList() { return null; } + @Override + public JSONObject getPlayerJSON(Object _player) { + return null; + } + @Override public String getVersion() { return MinecraftServer.getServer().getMinecraftVersion(); diff --git a/settings.gradle b/settings.gradle index 7076e92..3cec8a6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,9 +16,7 @@ project(':nodebb-integration-pocketmine').projectDir = "$rootDir/pocketmine" as project(':nodebb-integration-sponge').projectDir = "$rootDir/sponge" as File project(':nodebb-integration-universal').projectDir = "$rootDir/universal" as File -def legacy = false - -if (legacy) { +if (false) { include ':nodebb-integration-legacy' include ':nodebb-integration-bukkit-legacy' project(':nodebb-integration-legacy').projectDir = "$rootDir/legacy" as File diff --git a/sponge/src/main/java/com/radiofreederp/nodebbintegration/SpongeServer.java b/sponge/src/main/java/com/radiofreederp/nodebbintegration/SpongeServer.java index 7c6f078..9af0ed4 100644 --- a/sponge/src/main/java/com/radiofreederp/nodebbintegration/SpongeServer.java +++ b/sponge/src/main/java/com/radiofreederp/nodebbintegration/SpongeServer.java @@ -100,6 +100,11 @@ public ArrayList getPluginList() { return pluginList; } + @Override + public JSONObject getPlayerJSON(Object _player) { + return null; + } + @Override public String getVersion() { // TODO: ???