Skip to content

Commit

Permalink
add more player data to bukkit events.
Browse files Browse the repository at this point in the history
  • Loading branch information
yariplus committed Nov 3, 2016
1 parent 7cfd762 commit 5af5799
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -77,28 +78,46 @@ public String getTPS() {

@Override
public ArrayList<JSONObject> getPlayerList() {

final ArrayList<JSONObject> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
{
Expand All @@ -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) {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -79,28 +80,46 @@ public String getTPS() {

@Override
public ArrayList<JSONObject> getPlayerList() {

final ArrayList<JSONObject> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,14 +12,20 @@
*/
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)
{
// TODO: Make more options for handling vanished players.
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 -> {});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public interface IMinecraftServerCommon {
ArrayList<JSONObject> getPlayerList();
ArrayList<JSONObject> getPluginList();

JSONObject getPlayerJSON(Object _player);

String getVersion();
String getServerName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public ArrayList<JSONObject> getPluginList() {
return null;
}

@Override
public JSONObject getPlayerJSON(Object _player) {
return null;
}

@Override
public String getVersion() {
return MinecraftServer.getServer().getMinecraftVersion();
Expand Down
4 changes: 1 addition & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public ArrayList<JSONObject> getPluginList() {
return pluginList;
}

@Override
public JSONObject getPlayerJSON(Object _player) {
return null;
}

@Override
public String getVersion() {
// TODO: ???
Expand Down

0 comments on commit 5af5799

Please sign in to comment.