Skip to content

Commit 175276e

Browse files
committed
Feature: Add cooldown and bounds check to ArrowRefiller
- Added a configurable cooldown period to prevent frequent arrow refills. - Implemented a check to ensure arrow refilling only occurs when the player is within the defined strafing boundaries. - Modified ArrowRefiller to accept the StrafingScript instance for bounds checking. - Added command.
1 parent 3913577 commit 175276e

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/skyblock/ArrowRefiller.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Config from '../libs/Config';
22
import { CommandManager } from '../libs/CommandBuilderWrapper';
3+
import { StrafingScript } from './main'; // Import StrafingScript
34

45
enum RefillState {
56
IDLE,
@@ -15,26 +16,32 @@ enum RefillState {
1516
interface ArrowRefillerConfig {
1617
enabled: boolean;
1718
minArrows: number;
19+
cooldownSeconds: number; // New: Cooldown period in seconds
1820
}
1921

2022
export 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();

src/skyblock/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ const antiAFK = new AntiAFK((active) => {
580580
const phantomBlocks = new PhantomBlocks();
581581
const autoClicker = new AutoClicker();
582582
const triggerBot = new TriggerBot();
583-
const arrowRefiller = new ArrowRefiller();
583+
const arrowRefiller = new ArrowRefiller(strafer); // Pass strafer instance
584584
const fixHand = new FixHand();
585585

586586
(event as any).stopListener = JavaWrapper.methodToJava(() => strafer.stop());

0 commit comments

Comments
 (0)