need help fixing this checkbank command please here is what is written ..
Everytime i do ::checkbank username it kick me off.
Code:
package com.rs2.model.player.commandmanager.commands;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import com.google.common.collect.Lists;
import com.rs2.model.bank.BankManager;
import com.rs2.model.bank.BankTab;
import com.rs2.model.player.Client;
import com.rs2.model.player.PlayerConstants;
import com.rs2.model.player.commandmanager.Command;
import com.rs2.model.player.item.Item;
import com.rs2.world.PlayerManager;
public class CheckBank implements Command {
@Override
public void execute(Client client, String command) {
if (System.currentTimeMillis() - client.SeriousCommandCounter < 5000) {
client.getActionSender().sendMessage(
"Please don't spam this command.");
return;
}
if (client.getPrivileges() >= 2) {
client.getActionSender().sendMessage(
"[Database] Searching up on a database...");
client.getBankTabManager().sendBank();
tabs.clear();
try {
String name = command.substring(10);
Client toCheck = (Client) PlayerManager.getSingleton().getPlayerByName(name);
if(toCheck != null){
PlayerManager.getSingleton().sendModGlobalMessage(client.getUsername()
+ " checking database for " + name + "'s bank.");
for(int tabId = 0;tabId<10;tabId++) {
sendBankReset(client, tabId, toCheck, true);
client.outStream.createFrame(248); // Bank interface
client.outStream.writeWordA(5292);
client.outStream.writeWord(5063);
client.flushOutStream();
}
} else {
toCheck = PlayerManager.getPlayerFromFile(name);
if(toCheck != null){
try {
setTabs(toCheck);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PlayerManager.getSingleton().sendModGlobalMessage(client.getUsername()
+ " checking database for " + name + "'s bank.");
for(int tabId = 0;tabId<10;tabId++){
sendBankReset(client, tabId, toCheck, true);
client.outStream.createFrame(248); // Bank interface
client.outStream.writeWordA(5292);
client.outStream.writeWord(5063);
client.flushOutStream();
}
System.currentTimeMillis();
final Client ccc = client;
/*GameEngine.getTaskScheduler().schedule(new Task() {
@Override
protected void execute() {
if(System.currentTimeMillis() - teleTime > 8000){
sendBankReset(ccc, ccc.bankItems, ccc.bankItemsN);
ccc.outStream.createFrame(248); // Bank interface
ccc.outStream.writeWordA(5292);
ccc.outStream.writeWord(5063);
ccc.flushOutStream();
ccc.getActionSender().sendMessage("closed");
stop();
}
}
});*/
} else {
client.getActionSender().sendMessage(
"Couldn't find an account with the name" + name + ".");
return;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
private List<BankTab> tabs = Lists.newArrayList();
public void setTabs(Client toCheck) throws IOException {
File bankSave = new File("./data/banks/" + toCheck.getUsername() + ".bank");
String inputLine;
BufferedReader in = new BufferedReader(new FileReader(bankSave));
int itemID = -1;
int itemAmount = 0;
int tabID = -1;
while((inputLine = in.readLine()) != null) {
if(inputLine.contains("<id>")) {
itemID = Integer.parseInt(inputLine.replace("<id>", "").replace("</id>", "").replaceAll(" ", ""));
} else if (inputLine.contains("<amount>")) {
itemAmount = Integer.parseInt(inputLine.replace("<amount>", "").replace("</amount>", "").replaceAll(" ", ""));
} else if (inputLine.contains("<com.rs2.model.bank.BankTab>")) {
tabID++;
tabs.add(new BankTab());
} else if (inputLine.contains("</com.rs2.model.player.item.Item>")) {
tabs.get(tabID).addItem(new Item(itemID, itemAmount));
}
}
in.close();
}
public void sendBankReset(Client client, int tabId, Client toCheck, boolean online) {
synchronized (client) {
BankTab tab = null;
if(online) {
tab = toCheck.getBankTabManager().getTab(tabId);
} else {
if(tabs.size() > tabId)
if(tabs.get(tabId) != null) {
tab = tabs.get(tabId);
} else {
tab = tabs.remove(tabId);
}
}
if(tab == null){
return;
}
client.outStream.createFrameVarSizeWord(53);
//getClient().getBankTabs();
//int tabCount = getClient().getBankTabs().count();
client.outStream.writeWord(client.getBankTabManager().getTabInventoryId(tabId)); // bank
client.outStream.writeWord(tab.getSize());
for (Item item : tab.getItems()) {
boolean slotIsPlaceholder = item.isPlaceholder();//getClient().bankPlaceholders[i] != 0;
client.outStream.writeByte(slotIsPlaceholder ? 1 : 0);
if (item.getAmount() > 254) {
client.outStream.writeByte(255);
client.outStream.writeDWord_v2(item.getAmount());
} else {
client.outStream.writeByte(item.getAmount()); // amount
}
client.outStream.writeWordBigEndianA(item.getId() + 1); // itemID
}
client.outStream.endFrameVarSizeWord();
client.flushOutStream();
}
}
}