예제 #1
0
 @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;
 }
예제 #2
0
 @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();
   }
 }
예제 #3
0
 @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);
     }
   }
 }
예제 #4
0
 @Override
 public void onStart() {
   commandManager.registerListener(
       new Command("blockid", "/blockid <id>", "Sets the ID for block searching"), this);
   commandManager.registerListener(
       new Command("blockradius", "/blockradius <radius>", "Sets the radius for block searching"),
       this);
   ui.setVisible(true);
 }