@@ -56,6 +56,7 @@ public final class CommandEntry {
5656 private final UserCache userCache ;
5757 private final List <Pipeline > pipelineStages ;
5858 private final PlatformFeatures platformFeatures ;
59+ private final PlaceholderStage placeholderStage ;
5960
6061 public CommandEntry (
6162 ProxyServer proxy ,
@@ -84,6 +85,7 @@ public CommandEntry(
8485 this .dispatcher = new CommandDispatcher (sessions , outNode , velocityExecutor , playerTracker );
8586
8687 this .cooldowns = new CooldownManager ();
88+ this .placeholderStage = new PlaceholderStage (platformFeatures );
8789 this .pipelineStages = List .of (
8890 new ScriptResolutionStage (scriptManager ),
8991 new ArgumentMappingStage (),
@@ -138,6 +140,12 @@ private void runPipelineStages(Iterator<Pipeline> stages, ExecutionContext ctx,
138140 }
139141
140142 private void executeCommands (ExecutionContext ctx ) {
143+ if (ctx .script () != null && ctx .source () instanceof Player player ) {
144+ Duration scriptCooldown = ctx .script ().defaults ().cooldown ();
145+ if (scriptCooldown != null && !scriptCooldown .isZero ()) {
146+ cooldowns .setCooldown (ctx .script ().name (), player .getUniqueId (), scriptCooldown );
147+ }
148+ }
141149 Optional .ofNullable (ctx .script ())
142150 .map (Script ::commands )
143151 .filter (Predicate .not (List ::isEmpty ))
@@ -161,15 +169,16 @@ private void processCommandAt(ExecutionContext ctx, List<CmdMapping> commands, i
161169 }
162170 }
163171
164- new PlaceholderStage ( platformFeatures ) .process (nextCtx , result -> {
172+ placeholderStage .process (nextCtx , result -> {
165173 if (result instanceof ExecutionResult .Continue c ) {
166- if (ctx .source () instanceof Player player && cmd .cooldown () != null
167- && !cmd .cooldown ().isZero () && !cmd .cooldown ().isNegative ()) {
168- String cooldownKey = ctx .script ().name () + ":" + index ;
169- cooldowns .setCooldown (cooldownKey , player .getUniqueId (), cmd .cooldown ());
170- }
171- resolvePlayerArg (c .context ()).thenAccept (resolved ->
172- scheduleAndExecute (resolved , () -> processCommandAt (ctx , commands , index + 1 )));
174+ resolvePlayerArg (c .context ()).thenAccept (resolved -> {
175+ if (ctx .source () instanceof Player player && cmd .cooldown () != null
176+ && !cmd .cooldown ().isZero () && !cmd .cooldown ().isNegative ()) {
177+ String cooldownKey = ctx .script ().name () + ":" + index ;
178+ cooldowns .setCooldown (cooldownKey , player .getUniqueId (), cmd .cooldown ());
179+ }
180+ scheduleAndExecute (resolved , () -> processCommandAt (ctx , commands , index + 1 ));
181+ });
173182 }
174183 });
175184 }
0 commit comments