@Override public void onCommand(String command) { String[] parts = command.split(" "); if (parts[0].equalsIgnoreCase("blockid") && parts.length == 2 && StringTools.isInteger(parts[1])) { synchronized (lock) { blockID = Integer.parseInt(parts[1]); JTable list = ui.getList(); DefaultTableModel model = (DefaultTableModel) list.getModel(); Vector<?> dataVector = model.getDataVector(); dataVector.clear(); model.fireTableDataChanged(); displayText(ChatColor.GRAY + "Block ID for searching is now " + ChatColor.GOLD + blockID); } } else if (parts[0].equalsIgnoreCase("blockradius") && parts.length == 2 && StringTools.isInteger(parts[1])) { synchronized (lock) { radius = Integer.parseInt(parts[1]); displayText( ChatColor.GRAY + "Block radius for searching is now " + ChatColor.GOLD + radius); } } }
@Override public void onStop() { commandManager.unregisterListener("blockid"); commandManager.unregisterListener("blockradius"); ui.setVisible(false); synchronized (lock) { JTable list = ui.getList(); DefaultTableModel model = (DefaultTableModel) list.getModel(); Vector<?> dataVector = model.getDataVector(); dataVector.clear(); model.fireTableDataChanged(); } }
public void handle(Throwable exception) { try { if (exception instanceof NullPointerException) { synchronized (lock) { JTable table = ui.getList(); DefaultTableModel model = (DefaultTableModel) table.getModel(); Vector<?> data = model.getDataVector(); for (int i = 0; i < data.size(); i++) { Object row = data.get(i); if (row == null) data.remove(i); } } } exception.printStackTrace(); } catch (Throwable exception2) { exception.printStackTrace(); } }
@SuppressWarnings("unchecked") @Override public int loop() { synchronized (lock) { try { if (!ui.isVisible()) handler.stopMod(getName()); World world = minecraft.getWorld(); JTable list = ui.getList(); DefaultTableModel model = (DefaultTableModel) list.getModel(); TableRowSorter<TableModel> sorter = (TableRowSorter<TableModel>) list.getRowSorter(); if (world != null) { Player currentPlayer = minecraft.getPlayer(); int playerX = (int) java.lang.Math.round(currentPlayer.getX()); int playerY = (int) java.lang.Math.round(currentPlayer.getY()); int playerZ = (int) java.lang.Math.round(currentPlayer.getZ()); ArrayList<Block> blocks = new ArrayList<Block>(); for (int x = playerX - radius; x < playerX + radius; x++) for (int y = playerY - radius; y < playerY + radius; y++) for (int z = playerZ - radius; z < playerZ + radius; z++) if (world.getBlockIDAt(x, y, z) == blockID) blocks.add(new Block(x, y, z)); label: for (int row = 0; row < model.getRowCount(); row++) { int x = (Integer) model.getValueAt(row, 1); int y = (Integer) model.getValueAt(row, 2); int z = (Integer) model.getValueAt(row, 3); for (Block block : blocks) { if (x == block.getX() && y == block.getY() && z == block.getZ()) { model.setValueAt(getDistanceTo(x, y, z, currentPlayer), row, 0); continue label; } } model.removeRow(row); } label: for (Block block : blocks) { for (int row = 0; row < model.getRowCount(); row++) { int x = (Integer) model.getValueAt(row, 1); int y = (Integer) model.getValueAt(row, 2); int z = (Integer) model.getValueAt(row, 3); if (x == block.getX() && y == block.getY() && z == block.getZ()) continue label; } model.addRow( new Object[] { getDistanceTo(block.getX(), block.getY(), block.getZ(), minecraft.getPlayer()), block.getX(), block.getY(), block.getZ() }); } sorter.sort(); list.repaint(); } else { for (int i = model.getRowCount() - 1; i >= 0; i--) model.removeRow(i); } } catch (Exception exception) { } } return 500; }