mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-06 02:42:05 +01:00
Bungee-Bukkit Plugin channel
This commit is contained in:
parent
bd83868094
commit
5506e66e35
@ -41,6 +41,7 @@ import main.java.com.djrapitops.plan.systems.cache.GeolocationCache;
|
||||
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
|
||||
import main.java.com.djrapitops.plan.systems.info.ImporterManager;
|
||||
import main.java.com.djrapitops.plan.systems.info.InformationManager;
|
||||
import main.java.com.djrapitops.plan.systems.info.pluginchannel.BukkitPluginChannelListener;
|
||||
import main.java.com.djrapitops.plan.systems.info.server.BukkitServerInfoManager;
|
||||
import main.java.com.djrapitops.plan.systems.listeners.*;
|
||||
import main.java.com.djrapitops.plan.systems.processing.Processor;
|
||||
@ -51,6 +52,7 @@ import main.java.com.djrapitops.plan.systems.webserver.PageCache;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.metrics.BStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -199,6 +201,10 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
|
||||
ImporterManager.registerImporter(new OfflinePlayerImporter());
|
||||
|
||||
if (Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isFalse()) {
|
||||
registerPluginChannelListener();
|
||||
}
|
||||
|
||||
BStats bStats = new BStats(this);
|
||||
bStats.registerMetrics();
|
||||
|
||||
@ -213,6 +219,11 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
}
|
||||
}
|
||||
|
||||
private void registerPluginChannelListener() {
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, "Plan", new BukkitPluginChannelListener(this));
|
||||
}
|
||||
|
||||
private void registerTasks() {
|
||||
RunnableFactory runnableFactory = getRunnableFactory();
|
||||
String bootAnalysisMsg = Locale.get(Msg.ENABLE_BOOT_ANALYSIS_INFO).toString();
|
||||
@ -423,6 +434,9 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
|
||||
public void addToProcessQueue(Processor... processors) {
|
||||
for (Processor processor : processors) {
|
||||
if (processor == null) {
|
||||
continue;
|
||||
}
|
||||
processingQueue.addToQueue(processor);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import main.java.com.djrapitops.plan.locale.Locale;
|
||||
import main.java.com.djrapitops.plan.locale.Msg;
|
||||
import main.java.com.djrapitops.plan.systems.info.BungeeInformationManager;
|
||||
import main.java.com.djrapitops.plan.systems.info.InformationManager;
|
||||
import main.java.com.djrapitops.plan.systems.info.pluginchannel.BungeePluginChannelListener;
|
||||
import main.java.com.djrapitops.plan.systems.info.server.BungeeServerInfoManager;
|
||||
import main.java.com.djrapitops.plan.systems.listeners.BungeePlayerListener;
|
||||
import main.java.com.djrapitops.plan.systems.processing.Processor;
|
||||
@ -85,6 +86,9 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
|
||||
return;
|
||||
}
|
||||
|
||||
getProxy().registerChannel("Plan");
|
||||
registerListener(new BungeePluginChannelListener(this));
|
||||
|
||||
processingQueue = new ProcessingQueue();
|
||||
|
||||
registerListener(new BungeePlayerListener(this));
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.info.pluginchannel;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BukkitPluginChannelListener implements PluginMessageListener {
|
||||
|
||||
private final Plan plugin;
|
||||
|
||||
public BukkitPluginChannelListener(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(message))) {
|
||||
String subChannel = in.readUTF();
|
||||
String address = in.readUTF();
|
||||
|
||||
if ("bungee_address".equals(subChannel)) {
|
||||
plugin.getServerInfoManager().saveBungeeConnectionAddress(address);
|
||||
Log.info("-----------------------------------");
|
||||
Log.info("Recieved Bungee WebServer address through plugin channel, restarting Plan.");
|
||||
Log.info("-----------------------------------");
|
||||
plugin.restart();
|
||||
notifyAll();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.info.pluginchannel;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.PlanBungee;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BungeePluginChannelListener implements Listener {
|
||||
|
||||
private final PlanBungee plugin;
|
||||
|
||||
public BungeePluginChannelListener(PlanBungee plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginMessage(PluginMessageEvent e) {
|
||||
if (!e.getTag().equalsIgnoreCase("BungeeCord")) {
|
||||
return;
|
||||
}
|
||||
|
||||
try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()))) {
|
||||
String channel = in.readUTF(); // channel we delivered
|
||||
if (channel.equals("bungee_address_get")) {
|
||||
ServerInfo server = plugin.getProxy().getPlayer(e.getReceiver().toString()).getServer().getInfo();
|
||||
sendToBukkit(server);
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void sendToBukkit(ServerInfo server) {
|
||||
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
|
||||
try (DataOutputStream out = new DataOutputStream(stream)) {
|
||||
out.writeUTF("bungee_address");
|
||||
out.writeUTF(plugin.getWebServer().getAccessAddress());
|
||||
}
|
||||
server.sendData("Return", stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,8 +2,10 @@ package main.java.com.djrapitops.plan.systems.listeners;
|
||||
|
||||
import com.djrapitops.plugin.utilities.player.Fetch;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
||||
import main.java.com.djrapitops.plan.systems.processing.info.BungeePluginChannelSenderProcessor;
|
||||
import main.java.com.djrapitops.plan.systems.processing.info.NetworkPageUpdateProcessor;
|
||||
import main.java.com.djrapitops.plan.systems.processing.player.*;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
@ -93,14 +95,16 @@ public class PlanPlayerListener implements Listener {
|
||||
|
||||
int playersOnline = plugin.getTpsCountTimer().getLatestPlayersOnline();
|
||||
|
||||
BungeePluginChannelSenderProcessor bungeePluginChannelSenderProcessor = null;
|
||||
if (!plugin.getInfoManager().isUsingAnotherWebServer() && Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isFalse()) {
|
||||
bungeePluginChannelSenderProcessor = new BungeePluginChannelSenderProcessor(player);
|
||||
}
|
||||
cache.cacheSession(uuid, Session.start(time, world, gm));
|
||||
|
||||
IPUpdateProcessor ipUpdateProcessor = new IPUpdateProcessor(uuid, ip);
|
||||
NameProcessor nameProcessor = new NameProcessor(uuid, playerName, displayName);
|
||||
plugin.addToProcessQueue(
|
||||
new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline,
|
||||
ipUpdateProcessor,
|
||||
nameProcessor
|
||||
new IPUpdateProcessor(uuid, ip),
|
||||
new NameProcessor(uuid, playerName, displayName),
|
||||
bungeePluginChannelSenderProcessor
|
||||
),
|
||||
new NetworkPageUpdateProcessor(plugin.getInfoManager())
|
||||
);
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.processing.info;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.systems.processing.Processor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BungeePluginChannelSenderProcessor extends Processor<Player> {
|
||||
|
||||
public BungeePluginChannelSenderProcessor(Player object) {
|
||||
super(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
try (ByteArrayOutputStream b = new ByteArrayOutputStream()) {
|
||||
try (DataOutputStream out = new DataOutputStream(b)) {
|
||||
out.writeUTF("bungee_address_get");
|
||||
object.sendPluginMessage(Plan.getInstance(), "BungeeCord", b.toByteArray());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user