From 389da943855cdb3c88bf279b2d1b51e5a6841f5c Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sat, 5 Oct 2024 11:46:31 +0200 Subject: [PATCH] getting altcontrol peers now possible --- .../remote/events/RemoteDataRequestEvent.java | 19 ++++++++++++++ .../feature/modules/client/AltControl.java | 26 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Client/src/main/java/de/com/baseband/client/event/remote/events/RemoteDataRequestEvent.java diff --git a/Client/src/main/java/de/com/baseband/client/event/remote/events/RemoteDataRequestEvent.java b/Client/src/main/java/de/com/baseband/client/event/remote/events/RemoteDataRequestEvent.java new file mode 100644 index 0000000..18e0f71 --- /dev/null +++ b/Client/src/main/java/de/com/baseband/client/event/remote/events/RemoteDataRequestEvent.java @@ -0,0 +1,19 @@ +package de.com.baseband.client.event.remote.events; + +import com.mojang.authlib.GameProfile; +import de.com.baseband.client.BaseBand; +import de.com.baseband.client.event.remote.RemoteEvent; +import de.tudbut.obj.Save; + +public class RemoteDataRequestEvent extends RemoteEvent { + + public static class Request extends RemoteDataRequestEvent {} + + public static class Response extends RemoteDataRequestEvent { + @Save + public int id = BaseBand.REMOTE_EVENT_BUS.getID(); + + @Save + public GameProfile profile = BaseBand.mc.getSession().getProfile(); + } +} diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/client/AltControl.java b/Client/src/main/java/de/com/baseband/client/feature/modules/client/AltControl.java index 59c6ddd..271467b 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/client/AltControl.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/client/AltControl.java @@ -1,8 +1,10 @@ package de.com.baseband.client.feature.modules.client; +import com.mojang.authlib.GameProfile; import de.com.baseband.client.BaseBand; import de.com.baseband.client.event.Listen; import de.com.baseband.client.event.remote.events.RemoteConfigEvent; +import de.com.baseband.client.event.remote.events.RemoteDataRequestEvent; import de.com.baseband.client.event.remote.events.RemoteSendMessageEvent; import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.Features; @@ -16,6 +18,8 @@ import de.com.baseband.client.registry.annotation.Trigger; import de.com.baseband.client.util.adapt.Marker; import de.com.baseband.client.util.interact.Chat; +import java.util.ArrayList; + @ClientCategory public class AltControl extends Feature { @@ -30,6 +34,12 @@ public class AltControl extends Feature { BaseBand.publish(new RemoteConfigEvent()); } + @Trigger("Who is connected?") + @Gate(M_ENABLED) + public void requestData() { + BaseBand.publish(new RemoteDataRequestEvent.Request()); + } + @Marker(1) boolean notEnabled = true; @@ -64,6 +74,22 @@ public class AltControl extends Feature { this.ip = ip; } + ArrayList peers = new ArrayList<>(); + + @Listen + public void onRequestData(RemoteDataRequestEvent.Request event) { + peers.clear(); + BaseBand.publish(new RemoteDataRequestEvent.Response()); + } + + @Listen + public void onDataResponse(RemoteDataRequestEvent.Response event) { + peers.add(event.profile); + if(peers.size() == BaseBand.REMOTE_EVENT_BUS.getPeers()) { + BaseBand.notifyAll("§a§lPeers: §r" + String.join(", ", (Iterable) peers.stream().map(GameProfile::getName))); + } + } + @Override public void onCommand(String[] args) { if(!enabled)