here
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const { sleep } = require('../../utils');
|
||||
|
||||
// Owner players who can run admin commands
|
||||
const owners = ['wmantly', 'useless666', 'tux4242'];
|
||||
// Team players who can use basic storage features
|
||||
const team = [...owners, 'pi_chef', 'Ethan', 'Vince_NL'];
|
||||
|
||||
const botSlots = [0, 1, 2, 3, 9, 10, 11, 12, 18, 19, 20, 21];
|
||||
const customerSlots = [5, 6, 7, 8, 14, 15, 16, 17, 23, 24, 25, 26];
|
||||
|
||||
module.exports = {
|
||||
'scan': {
|
||||
desc: 'Force chest area scan',
|
||||
@@ -28,14 +33,22 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
'withdraw': {
|
||||
desc: 'Withdraw items from storage',
|
||||
desc: 'Withdraw items from storage (use "3s" for 3 shulkers)',
|
||||
allowed: team,
|
||||
async function(from, itemName, countStr) {
|
||||
console.log(`Storage command 'withdraw' from ${from}: ${itemName} x${countStr}`);
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return this.whisper(from, 'Storage plugin not loaded');
|
||||
const count = parseInt(countStr) || 1;
|
||||
await storage.handleCommand(from, 'withdraw', itemName, count);
|
||||
|
||||
// Parse count — "3s" means 3 shulkers, "10" means 10 items
|
||||
const str = (countStr || '1').toString().trim();
|
||||
if (str.endsWith('s') || str.endsWith('S')) {
|
||||
const shulkerCount = parseInt(str) || 1;
|
||||
await storage.handleCommand(from, 'withdraw-shulkers', itemName, shulkerCount);
|
||||
} else {
|
||||
const count = parseInt(str) || 1;
|
||||
await storage.handleCommand(from, 'withdraw', itemName, count);
|
||||
}
|
||||
}
|
||||
},
|
||||
'find': {
|
||||
@@ -70,6 +83,17 @@ module.exports = {
|
||||
await storage.handleCommand(from, 'organize');
|
||||
}
|
||||
},
|
||||
'consolidate': {
|
||||
desc: 'Merge partially filled shulkers',
|
||||
allowed: owners,
|
||||
ignoreLock: true,
|
||||
async function(from) {
|
||||
console.log(`Storage command 'consolidate' from ${from}`);
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return this.whisper(from, 'Storage plugin not loaded');
|
||||
await storage.handleCommand(from, 'consolidate');
|
||||
}
|
||||
},
|
||||
'addplayer': {
|
||||
desc: 'Add player to storage',
|
||||
allowed: owners,
|
||||
@@ -103,4 +127,107 @@ module.exports = {
|
||||
await storage.handleCommand(from, 'players');
|
||||
}
|
||||
},
|
||||
'.trade': {
|
||||
desc: 'Handle trade deposits/withdrawals for storage',
|
||||
allowed: team,
|
||||
ignoreLock: true,
|
||||
async function(from) {
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return;
|
||||
|
||||
storage._busy = true;
|
||||
try {
|
||||
const pending = storage.pendingWithdrawals.get(from);
|
||||
|
||||
await this.say('/trade accept');
|
||||
let window = await this.once('windowOpen');
|
||||
|
||||
// If there's a pending withdrawal, place items in bot's trade slots
|
||||
if (pending) {
|
||||
console.log(`Storage trade: Withdrawal pickup for ${from} — ${pending.count}x ${pending.itemName} (mode: ${pending.mode})`);
|
||||
|
||||
let placed = 0;
|
||||
for (const slotNum of botSlots) {
|
||||
if (placed >= 12) break;
|
||||
|
||||
// Find matching item in bot inventory portion of trade window
|
||||
for (let i = window.inventoryStart; i < window.inventoryEnd; i++) {
|
||||
const item = window.slots[i];
|
||||
if (!item) continue;
|
||||
|
||||
if (pending.mode === 'shulkers') {
|
||||
if (!item.name.includes('shulker_box')) continue;
|
||||
} else {
|
||||
if (item.name !== pending.itemName) continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.bot.moveSlotItem(i, slotNum);
|
||||
await sleep(200);
|
||||
placed++;
|
||||
break;
|
||||
} catch (error) {
|
||||
console.log(`Storage trade: Could not move item to slot ${slotNum}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Storage trade: Placed ${placed} stack(s) in trade window`);
|
||||
}
|
||||
|
||||
// Poll for customer confirmation (lime_dye at slot 53)
|
||||
let timeoutCheck = setTimeout(() => {
|
||||
this.bot.closeWindow(window);
|
||||
this.whisper(from, 'Trade timed out.');
|
||||
}, 120000);
|
||||
|
||||
let confirmationCheck = setInterval(async () => {
|
||||
try {
|
||||
const indicator = window.slots[53];
|
||||
if (indicator && indicator.name === 'lime_dye') {
|
||||
this.bot.moveSlotItem(37, 37);
|
||||
}
|
||||
} catch (e) {
|
||||
// window may have closed
|
||||
}
|
||||
}, 500);
|
||||
|
||||
// Wait for trade to complete
|
||||
await this.once('windowClose');
|
||||
clearInterval(confirmationCheck);
|
||||
|
||||
if (timeoutCheck._destroyed) {
|
||||
storage._busy = false;
|
||||
return;
|
||||
}
|
||||
clearTimeout(timeoutCheck);
|
||||
|
||||
if (pending) {
|
||||
// Withdrawal complete — clear pending
|
||||
if (pending.timeoutId) clearTimeout(pending.timeoutId);
|
||||
storage.pendingWithdrawals.delete(from);
|
||||
this.whisper(from, `Withdrawal complete! Enjoy your ${pending.itemName}.`);
|
||||
} else {
|
||||
// Deposit — collect items from bot inventory and sort into storage
|
||||
await sleep(500);
|
||||
|
||||
const hotbarNames = new Set((storage.config.hotbarItems || []).map(h => h.name));
|
||||
const itemsReceived = [];
|
||||
for (const item of this.bot.inventory.items()) {
|
||||
if (hotbarNames.has(item.name)) continue;
|
||||
itemsReceived.push({ name: item.name, id: item.type, count: item.count, nbt: item.nbt });
|
||||
}
|
||||
|
||||
if (itemsReceived.length > 0) {
|
||||
this.whisper(from, `Received ${itemsReceived.length} item type(s). Sorting into storage.`);
|
||||
await storage.handleTrade(from, itemsReceived);
|
||||
} else {
|
||||
this.whisper(from, 'No items received.');
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
storage._busy = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user