Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.34 KB | None | 0 0
  1. import org.rsbot.script.Script;
  2. import org.rsbot.script.ScriptManifest;
  3. import org.rsbot.script.wrappers.RSTile;
  4.  
  5.  
  6. @ScriptManifest(authors = {"Issues"}, keywords = "deve", name = "Path Maker", version = 0.1, description = ("Create paths for your script in seconds."))
  7. public class PathMaker extends Script {
  8.  
  9.     private String PATH;
  10.     private PathMakerGUI GUI;
  11.     private boolean autoAddPos;
  12.  
  13.     private RSTile lastTile = null;
  14.  
  15.     @Override
  16.     public boolean onStart() {
  17.         GUI = new PathMakerGUI();
  18.         GUI.setVisible(true);
  19.         return true;
  20.     }
  21.    
  22.     @Override
  23.     public int loop() {
  24.         if (GUI.isVisible()) {
  25.            
  26.             if (autoAddPos) {
  27.                
  28.                 if (lastTile == null || calc.distanceBetween(lastTile, getMyPlayer().getLocation()) >= 8) {
  29.                    
  30.                     GUI.nodeListModel.add(GUI.nodeList.getModel().getSize(), "" + getMyPlayer().getLocation() + "");
  31.                     lastTile = getMyPlayer().getLocation();
  32.                     GUI.nodeList.setSelectedIndex(GUI.nodeList.getModel().getSize());
  33.                 }
  34.                
  35.             }
  36.         } else {
  37.            
  38.             stopScript();
  39.         }
  40.         return 1000;
  41.     }
  42.  
  43.     @SuppressWarnings("serial")
  44.     public class PathMakerGUI extends javax.swing.JFrame {
  45.  
  46.         public PathMakerGUI() {
  47.             initComponents();
  48.         }
  49.  
  50.         private void initComponents() {
  51.  
  52.             nodeListModel = new javax.swing.DefaultListModel();
  53.  
  54.             pathArea = new javax.swing.JTextArea();
  55.             pathLabel = new javax.swing.JLabel();
  56.             importLabel = new javax.swing.JLabel();
  57.             importScroll = new javax.swing.JScrollPane();
  58.             importArea = new javax.swing.JTextArea();
  59.             nodeScroll = new javax.swing.JScrollPane();
  60.             nodeList = new javax.swing.JList(nodeListModel);
  61.             addPPos = new javax.swing.JButton();
  62.             genCode = new javax.swing.JButton();
  63.             autoAdd = new javax.swing.JCheckBox();
  64.             autoAddS = new javax.swing.JSpinner();
  65.             tilesLable = new javax.swing.JLabel();
  66.             nodeLabel = new javax.swing.JLabel();
  67.             deleteSelected = new javax.swing.JButton();
  68.  
  69.             pathArea.setColumns(20);
  70.             pathArea.setEditable(false);
  71.             pathArea.setFont(new java.awt.Font("NSimSun", 0, 11)); // NOI18N
  72.             pathArea.setRows(5);
  73.  
  74.             pathLabel.setFont(new java.awt.Font("NSimSun", 0, 11)); // NOI18N
  75.             pathLabel.setText("Path:");
  76.  
  77.             importLabel.setFont(new java.awt.Font("NSimSun", 0, 11)); // NOI18N
  78.             importLabel.setText("Import needed:");
  79.  
  80.             importScroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  81.             importScroll.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
  82.  
  83.             importArea.setColumns(1);
  84.             importArea.setEditable(false);
  85.             importArea.setFont(new java.awt.Font("NSimSun", 0, 11)); // NOI18N
  86.             importArea.setRows(5);
  87.             importArea.setText("import org.rsbot.script.wrappers.RSTile;");
  88.             importScroll.setViewportView(importArea);
  89.  
  90.             setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
  91.             setResizable(false);
  92.             setTitle("Path Maker");
  93.            
  94.             nodeList.setFont(new java.awt.Font("NSimSun", 0, 11)); // NOI18N
  95.             nodeScroll.setViewportView(nodeList);
  96.  
  97.             addPPos.setFont(new java.awt.Font("NSimSun", 0, 11)); // NOI18N
  98.             addPPos.setText("Add Players Position");
  99.             addPPos.addActionListener(new java.awt.event.ActionListener() {
  100.                 public void actionPerformed(java.awt.event.ActionEvent evt) {
  101.                     addPPosActionPerformed(evt);
  102.                 }
  103.             });
  104.  
  105.             genCode.setFont(new java.awt.Font("NSimSun", 0, 11)); // NOI18N
  106.             genCode.setText("Generate Code");
  107.             genCode.addActionListener(new java.awt.event.ActionListener() {
  108.                 public void actionPerformed(java.awt.event.ActionEvent evt) {
  109.                     genCodeActionPerformed(evt);
  110.                 }
  111.             });
  112.  
  113.             autoAdd.setFont(new java.awt.Font("NSimSun", 0, 11)); // NOI18N
  114.             autoAdd.setText("Auto Add Every");
  115.             autoAdd.addActionListener(new java.awt.event.ActionListener() {
  116.                 public void actionPerformed(java.awt.event.ActionEvent evt) {
  117.                     autoAddActionPerformed(evt);
  118.                 }
  119.             });
  120.  
  121.             autoAddS.setFont(new java.awt.Font("NSimSun", 0, 11)); // NOI18N
  122.             autoAddS.setModel(new javax.swing.SpinnerNumberModel(8, 1, 40, 1));
  123.             autoAddS.setEnabled(false);
  124.  
  125.             tilesLable.setFont(new java.awt.Font("NSimSun", 0, 11)); // NOI18N
  126.             tilesLable.setText(" Tiles.");
  127.  
  128.             nodeLabel.setFont(new java.awt.Font("NSimSun", 0, 11)); // NOI18N
  129.             nodeLabel.setText("Current Nodes:");
  130.  
  131.             deleteSelected.setFont(new java.awt.Font("NSimSun", 0, 11)); // NOI18N
  132.             deleteSelected.setText("Delete Selected");
  133.             deleteSelected.addActionListener(new java.awt.event.ActionListener() {
  134.                 public void actionPerformed(java.awt.event.ActionEvent evt) {
  135.                     deleteSelectedActionPerformed(evt);
  136.                 }
  137.             });
  138.  
  139.             javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  140.             getContentPane().setLayout(layout);
  141.             layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(nodeScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(autoAdd) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(autoAddS, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(tilesLable)) .addComponent(nodeLabel) .addGroup(layout.createSequentialGroup() .addComponent(addPPos) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(deleteSelected) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(genCode))) .addContainerGap()) );
  142.             layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(nodeLabel) .addGap(5, 5, 5) .addComponent(nodeScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(autoAddS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(tilesLable) .addComponent(autoAdd)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(addPPos) .addComponent(deleteSelected) .addComponent(genCode)) .addContainerGap()) );
  143.             pack();
  144.             setLocationRelativeTo(getOwner());
  145.         }
  146.  
  147.         private void addPPosActionPerformed(java.awt.event.ActionEvent evt) {
  148.             nodeListModel.add(nodeList.getModel().getSize(), "" + getMyPlayer().getLocation() + "");
  149.             nodeList.setSelectedIndex(nodeList.getModel().getSize());
  150.         }
  151.  
  152.         private void deleteSelectedActionPerformed(java.awt.event.ActionEvent evt) {
  153.             if (nodeList.getSelectedIndex() == -1)
  154.                 return;
  155.  
  156.             int lastSelected = nodeList.getSelectedIndex();
  157.  
  158.             nodeListModel.remove(nodeList.getSelectedIndex());
  159.             nodeList.setSelectedIndex(lastSelected);
  160.         }
  161.  
  162.         private void genCodeActionPerformed(java.awt.event.ActionEvent evt) {
  163.            
  164.             PATH = "private RSTile[] path = {";
  165.            
  166.             for(int i = 0; i < nodeList.getModel().getSize(); i++) {
  167.  
  168.                 String node = (String) nodeList.getModel().getElementAt(i);
  169.  
  170.                 if ( i != nodeList.getModel().getSize() - 1) {
  171.                     PATH += " new RSTile" + node + ", ";
  172.                 } else {
  173.                     PATH += " new RSTile" + node + " ";
  174.                 }
  175.             }
  176.            
  177.             PATH += "};";
  178.            
  179.             pathArea.setText(PATH);
  180.            
  181.             pathArea.selectAll();
  182.             pathArea.copy();
  183.            
  184.             javax.swing.JOptionPane.showMessageDialog(null, "Path has been generated and copied to clipboard.");
  185.         }
  186.  
  187.         private void autoAddActionPerformed(java.awt.event.ActionEvent evt) {
  188.  
  189.             if (autoAdd.isSelected()) {
  190.                 addPPos.setEnabled(false);
  191.                 autoAddS.setEnabled(true);
  192.                 autoAddPos = true;
  193.             } else {
  194.                 addPPos.setEnabled(true);
  195.                 autoAddS.setEnabled(false);
  196.                 autoAddPos = true;
  197.             }
  198.         }
  199.  
  200.         private javax.swing.DefaultListModel nodeListModel;
  201.         private javax.swing.JButton addPPos;
  202.         private javax.swing.JCheckBox autoAdd;
  203.         private javax.swing.JSpinner autoAddS;
  204.         private javax.swing.JButton deleteSelected;
  205.         private javax.swing.JButton genCode;
  206.         private javax.swing.JTextArea importArea;
  207.         private javax.swing.JLabel importLabel;
  208.         private javax.swing.JScrollPane importScroll;
  209.         private javax.swing.JLabel nodeLabel;
  210.         private javax.swing.JList nodeList;
  211.         private javax.swing.JScrollPane nodeScroll;
  212.         private javax.swing.JTextArea pathArea;
  213.         private javax.swing.JLabel pathLabel;
  214.         private javax.swing.JLabel tilesLable;
  215.  
  216.     }
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement