Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Feel free to change/modify this if you know how,
- * but please don't distribute it without giving me credit!
- * Do the right thing!
- *
- * Creator: dankydrank
- * Jan 11, 2014
- */
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.datatransfer.*;
- public class CommandCompressor implements KeyListener, ActionListener
- {
- private JFrame frame;
- private JTextArea input, output;
- public static void main(String[]args)
- {
- //call CommandCompressor's constructor
- new CommandCompressor();
- }
- public CommandCompressor()
- {
- //instructions
- JLabel instructions = new JLabel("Press the Button to Convert Your Text and Copy It. Place each command on a new line.");
- JLabel outputLabel = new JLabel("Output:");
- //button
- JButton copy = new JButton("Convert and Copy to Clipboard");
- //frame
- frame = new JFrame("Command Compressor");
- //Just the sizes I found best
- input = new JTextArea(13, 31);
- output = new JTextArea(13, 23);
- //turn JTextAreas into JScrollPanes for window scrolling
- JScrollPane outPane = new JScrollPane(output);
- JScrollPane inPane = new JScrollPane(input);
- //add Key Listeners
- input.addKeyListener(this);
- output.addKeyListener(this);
- //user can't edit output pane
- output.setEditable(false);
- //output text wraps within the pane
- output.setLineWrap(true);
- //add listener to button
- copy.addActionListener(this);
- //FlowLayout works best
- frame.setLayout(new FlowLayout());
- //add components
- frame.add(instructions);
- frame.add(inPane);
- frame.add(outputLabel);
- frame.add(outPane);
- frame.add(copy);
- //set frame size and visibility
- frame.setSize(675, 325);
- frame.setVisible(true);
- //set default close operation
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- public void keyPressed(KeyEvent e) {
- //I updated the app so you no longer need to press F3, but it still works. F3's key code is 114
- int key = e.getKeyCode();
- //check for F3
- if(key==114)
- generateAndCopy();
- }
- public void actionPerformed(ActionEvent e)
- {
- generateAndCopy();
- }
- public void generateAndCopy()
- {
- //instantiate string
- String s = "summon MinecartCommandBlock ~ ~1 ~ {";
- //split text from input window into array--each element is one line of input
- String[] lines = input.getText().split("\n");
- //for each command the player entered, add "Riding:}id:MinecartCommandBlock," to the output string
- for(int i = 0; i < lines.length; i++)
- s+= "Riding:{id:MinecartCommandBlock,";
- //rail
- s+= "Riding:{id:FallingSand,TileID:157,Time:1}";
- //loop over output string and add commands from lines[]
- for(String temp : lines)
- {
- if(temp != null)
- s+= ",Command:" + temp + "}";
- }
- //add lava to the end
- s+= ",Command:/kill @e[type=MinecartCommandBlock,r=3]}";
- //set text in window to the output string
- output.setText(s);
- //copy text to clipboard
- StringSelection selection = new StringSelection(output.getText());
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
- clipboard.setContents(selection, selection);
- }
- public void keyReleased(KeyEvent e)
- {
- //Do nothing
- }
- public void keyTyped(KeyEvent e)
- {
- //Do nothing
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement