1010import dev .objz .commandbridge .net .payloads .cmd .InvokedCommand ;
1111import dev .objz .commandbridge .net .payloads .cmd .SenderContext ;
1212import dev .objz .commandbridge .scripting .model .Script ;
13- import dev .objz .commandbridge .scripting .model .enums .Location ;
1413import dev .objz .commandbridge .scripting .model .records .mapping .ArgMapping ;
1514import dev .objz .commandbridge .scripting .model .records .mapping .CmdMapping ;
1615import dev .objz .commandbridge .scripting .model .records .mapping .IdMapping ;
@@ -37,11 +36,11 @@ public final class CommandEntry {
3736
3837 private final ProxyServer proxy ;
3938 private final Object plugin ;
40- private final SessionHub sessions ;
4139 private final ScheduleManager scheduler ;
4240 private final VelocityExecutor velocityExecutor ;
4341 private final CommandDispatcher dispatcher ;
4442 private final CooldownManager cooldowns ;
43+ private final PlayerTracker playerTracker ;
4544 private final List <Pipeline > pipelineStages ;
4645
4746 public CommandEntry (
@@ -56,13 +55,14 @@ public CommandEntry(
5655
5756 this .proxy = Objects .requireNonNull (proxy );
5857 this .plugin = Objects .requireNonNull (plugin );
59- this .sessions = Objects .requireNonNull (sessions );
60-
61- this .scheduler = new ScheduleManager (proxy , plugin , dataDir , scriptManager );
62- this .scheduler .setExecutionCallback (this ::resumeTask );
58+ this .playerTracker = Objects .requireNonNull (playerTracker );
6359
6460 this .velocityExecutor = new VelocityExecutor (proxy , Objects .requireNonNull (localServerId ));
6561
62+ this .scheduler = new ScheduleManager (proxy , plugin , dataDir , scriptManager ,
63+ playerTracker , localServerId );
64+ this .scheduler .setExecutionCallback (this ::resumeTask );
65+
6666 this .dispatcher = new CommandDispatcher (sessions , outNode , velocityExecutor , playerTracker );
6767
6868 this .cooldowns = new CooldownManager ();
@@ -169,7 +169,7 @@ private void resumeTask(ExecutionContext ctx) {
169169 private void scheduleAndExecute (ExecutionContext ctx , Runnable continuation ) {
170170 var cmd = ctx .currentCommand ();
171171
172- if (shouldSchedule (cmd )) {
172+ if (shouldSchedule (ctx , cmd )) {
173173 scheduler .queueTask (ctx , cmd , ctx .commandIndex ());
174174 return ;
175175 }
@@ -189,7 +189,7 @@ private void scheduleAndExecute(ExecutionContext ctx, Runnable continuation) {
189189 }
190190 }
191191
192- private boolean shouldSchedule (CmdMapping cmd ) {
192+ private boolean shouldSchedule (ExecutionContext ctx , CmdMapping cmd ) {
193193 if (cmd .server () == null || !cmd .server ().scheduleOnline ()) {
194194 return false ;
195195 }
@@ -198,23 +198,28 @@ private boolean shouldSchedule(CmdMapping cmd) {
198198 return false ;
199199 }
200200
201+ UUID playerUuid = ctx .getPlayerUuid ();
202+ if (playerUuid == null ) {
203+ Log .warn ("schedule-online: cannot schedule for non-player source (no player UUID available)" );
204+ return false ;
205+ }
206+
201207 for (IdMapping target : cmd .execute ()) {
202- if ( target . location () == Location . BACKEND ) {
203- boolean online = sessions . findSession ( target .id (), Location . BACKEND ). isPresent ();
204- if (! online ) {
205- return true ;
206- }
208+ boolean playerOnTarget = playerTracker . isPlayerOnTarget (
209+ playerUuid , target .id (), target . location (),
210+ velocityExecutor . getLocalServerId ());
211+ if (! playerOnTarget ) {
212+ return true ;
207213 }
208214 }
209215
210216 return false ;
211217 }
212218
213- // ──────────────────────────────────────────────────────────────────────────────
214-
215219 private ExecutionContext createInitialContext (InvokedCommand invoked , ClientSession session ,
216220 CommandSource source ) {
217- return new ExecutionContext (invoked , session , source , null , Map .of (), null , -1 );
221+ UUID playerUuid = source instanceof Player p ? p .getUniqueId () : null ;
222+ return new ExecutionContext (invoked , session , source , playerUuid , null , Map .of (), null , -1 );
218223 }
219224
220225 private Optional <CommandSource > resolveSource (SenderContext sender ) {
0 commit comments