11import Config from '../libs/Config' ;
22import { CommandManager } from '../libs/CommandBuilderWrapper' ;
3+ import { StrafingScript } from './main' ; // Import StrafingScript
34
45enum RefillState {
56 IDLE ,
@@ -15,26 +16,32 @@ enum RefillState {
1516interface ArrowRefillerConfig {
1617 enabled : boolean ;
1718 minArrows : number ;
19+ cooldownSeconds : number ; // New: Cooldown period in seconds
1820}
1921
2022export class ArrowRefiller {
2123 private readonly configPath = './config/jayc331-config.json' ;
2224 private readonly scriptId = 'arrowRefiller' ;
2325 private readonly defaultConfig : ArrowRefillerConfig = {
2426 enabled : true ,
25- minArrows : 64
27+ minArrows : 64 ,
28+ cooldownSeconds : 300 // Default 5 minutes
2629 } ;
2730
2831 private config : ArrowRefillerConfig ;
2932 private refillState : RefillState = RefillState . IDLE ;
3033 private stateTickCounter : number = 0 ;
3134 private lastInventoryCheckTime = 0 ;
35+ private lastRefillTime = 0 ; // New: Timestamp of the last refill initiated
3236
3337 // Constants for delays
3438 private readonly MAX_SCREEN_WAIT_TICKS = 60 ; // 3 seconds
3539 private readonly CLICK_DELAY_TICKS = 5 ; // 250ms
3640
37- constructor ( ) {
41+ private strafer : StrafingScript ; // New: Reference to StrafingScript
42+
43+ constructor ( strafer : StrafingScript ) { // Modified constructor
44+ this . strafer = strafer ;
3845 this . config = Config . readConfig ( this . configPath , this . defaultConfig , this . scriptId ) ;
3946 this . registerListeners ( ) ;
4047 this . registerCommands ( ) ;
@@ -58,6 +65,16 @@ export class ArrowRefiller {
5865 if ( Date . now ( ) - this . lastInventoryCheckTime > 1000 ) {
5966 this . lastInventoryCheckTime = Date . now ( ) ;
6067 if ( ! Hud . getOpenScreen ( ) && ! this . hasEnoughArrows ( ) ) {
68+ // Check cooldown
69+ if ( Date . now ( ) - this . lastRefillTime < this . config . cooldownSeconds * 1000 ) {
70+ // Chat.log(`§eArrowRefiller: §7Cooldown active. Next refill in ${((this.config.cooldownSeconds * 1000 - (Date.now() - this.lastRefillTime)) / 1000).toFixed(0)}s`);
71+ return ;
72+ }
73+ // Check if player is within strafe bounds
74+ if ( this . strafer . outOfBounds ) {
75+ // Chat.log('§eArrowRefiller: §7Out of strafe bounds. Refill paused.');
76+ return ;
77+ }
6178 this . startRefillProcess ( ) ;
6279 }
6380 }
@@ -79,6 +96,7 @@ export class ArrowRefiller {
7996 Chat . say ( '/shop arrow' ) ;
8097 this . refillState = RefillState . WAIT_FOR_SCREEN ;
8198 this . stateTickCounter = 0 ; // Reset counter for new state
99+ this . lastRefillTime = Date . now ( ) ; // Record refill start time
82100 break ;
83101
84102 case RefillState . WAIT_FOR_SCREEN :
@@ -202,6 +220,15 @@ export class ArrowRefiller {
202220 this . saveConfig ( ) ;
203221 Chat . log ( `§7ArrowRefill threshold set to §a${ amt } ` ) ;
204222 } ) ;
223+
224+ cmd . literal ( 'cooldown' ) // New command to set cooldown
225+ . argument ( 'seconds' , 'int' )
226+ . executes ( ( ctx ) => {
227+ const seconds = ctx . getArg ( 'seconds' ) ;
228+ this . config . cooldownSeconds = seconds ;
229+ this . saveConfig ( ) ;
230+ Chat . log ( `§7ArrowRefill cooldown set to §a${ seconds } s` ) ;
231+ } ) ;
205232
206233 cmd . literal ( 'buy' ) . executes ( ( ) => {
207234 this . startRefillProcess ( ) ;
0 commit comments