Advertisement
deww1

Untitled

Jun 15th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.23 KB | None | 0 0
  1. /**
  2. * Copy everything in the following tag..
  3. *
  4. * //COPY
  5. * this is what you will copy..
  6. * //ENDCOPY
  7. */
  8.  
  9.  
  10. import java.awt.*;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.io.IOException;
  14. import java.net.MalformedURLException;
  15. import java.net.URL;
  16. import java.util.LinkedList;
  17. import javax.imageio.ImageIO;
  18. import org.rsbot.event.listeners.PaintListener;
  19. import org.rsbot.script.*;
  20. import org.rsbot.script.methods.Skills;
  21.  
  22. @ScriptManifest(authors = {"Dew"}, keywords = {"Paint"}, name = "FuserPAINT", description = "Demo Paint - To Be Edited", version = 1.0)
  23.  
  24. public class paintforubuntu extends Script implements PaintListener, MouseListener {
  25. //COPY - these are needed variables
  26. public long startTime = 0, millis = 0, hours = 0, minutes = 0, seconds = 0;
  27.  
  28. public Double ver = getClass().getAnnotation(ScriptManifest.class).version();
  29. Point p;
  30.  
  31. private int startXP = 0;
  32. private int XPGained = 0;
  33.  
  34. public boolean showPaint = true;
  35.  
  36. private String Status = "Setting up";
  37.  
  38. public MousePaint mousePaint = new MousePaint();
  39.  
  40. public Image fuserScriptsLogo, userLogo, paintBackGround, closeButton, openButton, Avatar;
  41. //ENDCOPY
  42.  
  43. //COPY
  44. Color Color1 = new Color(255, 255, 255),
  45. Transparent = new Color(255, 255, 255, 0);
  46.  
  47. Font Font1 = new Font("Calibri", 1, 14),
  48. Font2 = new Font("Calibri", 0, 14),
  49. Font3 = new Font("Calibri", 0, 9);
  50. //ENDCOPY
  51.  
  52. //COPY -These are needed to make the image links work
  53. Rectangle fuserScriptsLogoRectangle = new Rectangle(4, 276, 207, 69),
  54. userLogoRectangle = new Rectangle(9, 347, 124, 28),
  55. closeButtonRectangle = new Rectangle(426, 345, 22, 22),
  56. openButtonRectangle = new Rectangle(474, 345, 22, 22),
  57. avatarRectangle = new Rectangle(448, 345, 65, 65);
  58. //ENDCOPY
  59. @Override
  60. public boolean onStart() {
  61. //COPY -these are the images to load
  62. // (CHANGE}url to the user avatar spot - Your Avatar HERE - MAKE
  63. // SURE the pixel ratio is 65x65px
  64. Avatar = getImage("http://i.imgur.com/XaXmd.png");
  65. // (CHANGE)URL to the user logo spot - Your Logo HERE - MAKE
  66. // SURE the pixel ratio is 124x28px
  67. userLogo = getImage("http://i.imgur.com/yzKFM.png");
  68.  
  69. fuserScriptsLogo = getImage("http://i.imgur.com/yzKFM.png");
  70. paintBackGround = getImage("http://i.imgur.com/9vt7j.png");
  71. closeButton = getImage("http://i.imgur.com/RqFu8.png");
  72. openButton = getImage("http://i.imgur.com/OPMSU.png");
  73. //ENDCOPY
  74. return true;
  75. }
  76.  
  77. //COPY
  78. private Image getImage(final String url) {
  79. try {
  80. return ImageIO.read(new URL(url));
  81. } catch (final IOException e) {
  82. return null;
  83. }
  84. }
  85. //ENDCOPY
  86.  
  87. //COPY -- this is the actual paint itself
  88. // <editor-fold defaultstate="collapsed" desc="Paint">
  89. private final RenderingHints renderHints = new RenderingHints(
  90. RenderingHints.KEY_TEXT_ANTIALIASING,
  91. RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  92.  
  93. public void mainPaint(Graphics g) {
  94. Graphics2D g2 = (Graphics2D) g;
  95.  
  96. // (CHANGE) Change the skill.
  97. if ((skills.getCurrentExp(Skills.CONSTRUCTION) - startExperience) > 0
  98. && startExperience > 0) {
  99. experienceGained = skills.getCurrentExp(Skills.CONSTRUCTION)
  100. - startExperience;
  101. }
  102.  
  103. long millis = System.currentTimeMillis() - startTime;
  104. long totalseconds = millis / 1000;
  105. long hours = millis / (1000 * 60 * 60);
  106. millis -= hours * 1000 * 60 * 60;
  107. long minutes = millis / (1000 * 60);
  108. millis -= minutes * 1000 * 60;
  109. long seconds = millis / 1000;
  110.  
  111. if (showPaint) {
  112.  
  113. g2.drawImage(fuserScriptsLogo, 4, 276, null);
  114. g2.drawImage(paintBackGround, -1, 328, null);
  115. g2.drawImage(userLogo, 9, 347, null);
  116. g2.drawImage(closeButton, 426, 345, null);
  117. g2.drawImage(Avatar, 448, 345, null);
  118.  
  119. g2.setColor(Constants.Transparent);
  120. g2.draw(Constants.fuserScriptsLogoRectangle);
  121. g2.draw(Constants.closeButtonRectangle);
  122. g2.draw(Constants.userLogoRectangle);
  123.  
  124. g2.setColor(Constants.Color1);
  125.  
  126. // START - current script version text
  127. g2.setFont(Constants.Font1);
  128. g2.drawString("Current Script Version:", 197, 358);
  129. g2.setFont(Constants.Font2);
  130. g2.drawString(
  131. ""
  132. + getClass().getAnnotation(ScriptManifest.class).version(), 335, 358);
  133. // END - current script version text
  134.  
  135. // EDIT - Close Button Text - Remove or leave
  136. //g2.setFont(Constants.Font3);
  137. //g2.drawString("Close Button:", 373, 353);
  138. // EDIT - End of Close Button Text
  139.  
  140. // START - Run Time
  141. g2.setFont(Constants.Font1);
  142. g2.drawString("Run Time:", 14, 400);
  143. g2.setFont(Constants.Font2);
  144. if (startTime != 0) {
  145. g2.drawString(hours + " Hours " + minutes + " Minutes "
  146. + seconds + " Seconds", 121, 400);
  147. } else {
  148. g2.drawString("Script loading...", 121, 400);
  149. }
  150. // END - Run Time
  151.  
  152. // START - Experience
  153. if (experienceGained > 0 && totalseconds > 0) {
  154. g2.setFont(Constants.Font1);
  155. g2.drawString("Total Xp Gained:", 12, 431);
  156. g2.setFont(Constants.Font2);
  157. g2.drawString("" + experienceGained, 120, 431);
  158.  
  159. g2.setFont(Constants.Font1);
  160. g2.drawString("Xp/hr:", 10, 462);
  161. g2.setFont(Constants.Font2);
  162. experiencePerHour = (int) (3600 * experienceGained / totalseconds);
  163. g2.drawString("" + experiencePerHour, 119, 464);
  164.  
  165. //CHANGE, uncomment calculations if needed
  166. // runesPerHour = (int) (3600*runesMade/totalseconds);
  167. // essensePerHour = (int)
  168. // (3600*((int)((expGained)/runeExp))/totalseconds);
  169. // totalProfit = (long)
  170. // ((runesMade*runePrice)-(essenceCount*essencePrice));
  171. // profitPerHour = (long) (3600*totalProfit/totalseconds);
  172. }
  173. // END - Experience
  174.  
  175. // START - Time to Next Level
  176. long timeToLevel = 0;
  177. g2.setFont(Constants.Font1);
  178. g2.drawString("Time to Next Level:", 340, 454);
  179. g2.setFont(Constants.Font2);
  180. String timeToLevel2 = "Calculating...";
  181. g2.drawString(timeToLevel2, 454, 454);
  182. if (experiencePerHour > 0) {
  183. g2.setFont(Constants.Font2);
  184. timeToLevel = (skills.getExpToNextLevel(Skills.CONSTRUCTION) * 60 / experiencePerHour);
  185. if (timeToLevel >= 60) {
  186. long thours = (int) timeToLevel / 60;
  187. long tmin = (timeToLevel - (thours * 60));
  188. timeToLevel2 = thours + " Hours, " + tmin + " Minutes";
  189. } else {
  190. timeToLevel2 = timeToLevel + " Minutes";
  191. }
  192. }
  193. // END - Time to Next Level
  194.  
  195. // START - Script Status
  196. g2.setFont(Constants.Font1);
  197. g2.drawString("Script Status:", 200, 473);
  198. g2.setFont(Constants.Font2);
  199. g2.drawString(Status, 283, 474);
  200. // END - Script Status
  201.  
  202. } else {
  203. g2.setColor(Constants.Transparent);
  204. g2.draw(Constants.openButtonRectangle);
  205. g2.drawImage(openButton, 474, 345, null);
  206. }
  207.  
  208. }
  209. @Override
  210. public void onRepaint(Graphics g) {
  211. Graphics2D g2 = (Graphics2D) g;
  212. g2.setRenderingHints(renderHints);
  213. mainPaint(g2);
  214. mousePaint.Draw(g2);
  215. }
  216. // </editor-fold>
  217. //END
  218.  
  219. //COPY -- this is needed to make links work
  220. // <editor-fold defaultstate="collapsed" desc="mouseClicked">
  221. @Override
  222. public void mouseClicked(MouseEvent mouseEvent) {
  223. Point mousePoint = mouseEvent.getPoint();
  224. if (Constants.fuserScriptsLogoRectangle.contains(mousePoint)
  225. && showPaint) {
  226. sendToURL("http://fuserscripts.cz.cc/community/");
  227. } else if (Constants.userLogoRectangle.contains(mousePoint)
  228. && showPaint) {
  229. log("Currently, the Thread is not active! Please wait until I update this.");
  230. // sendToURL("http://fuserscripts.cz.cc/community/index.php?/topic/76-fuserpaint-skeleton/");
  231. } else if (Constants.avatarRectangle.contains(mousePoint) && showPaint) {
  232. sendToURL("http://fuserscripts.cz.cc/community/index.php?/user/19-dew/");
  233. } else if (Constants.closeButtonRectangle.contains(mousePoint)
  234. && showPaint) {
  235. showPaint = false;
  236. } else if (Constants.openButtonRectangle.contains(mousePoint)
  237. && !showPaint) {
  238. showPaint = true;
  239. }
  240. }
  241.  
  242. public void sendToURL(String url) {
  243. try {
  244. java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
  245. } catch (Exception exception) {
  246. log("[ERROR]SendToURL: " + exception.getLocalizedMessage());
  247. }
  248. }
  249.  
  250. @Override
  251. public void mouseEntered(MouseEvent e) {
  252. }
  253.  
  254. @Override
  255. public void mouseExited(MouseEvent e) {
  256. }
  257.  
  258. @Override
  259. public void mousePressed(MouseEvent e) {
  260. }
  261.  
  262. @Override
  263. public void mouseReleased(MouseEvent e) {
  264. }
  265. // </editor-fold>
  266. //ENDCOPY
  267.  
  268. //COPY -- this is the mouse stuff.
  269. // <editor-fold defaultstate="collapsed" desc="MousePaint">
  270. public class MousePaint {
  271.  
  272. public int waveSize = 0;
  273.  
  274. @SuppressWarnings({"serial"})
  275. public class mousePathPoint extends Point {
  276.  
  277. private long finishTime;
  278. private double lastingTime;
  279.  
  280. public mousePathPoint(int x, int y, int lastingTime) {
  281. super(x, y);
  282. this.lastingTime = lastingTime;
  283. finishTime = System.currentTimeMillis() + lastingTime;
  284. }
  285.  
  286. public boolean isUp() {
  287. return System.currentTimeMillis() > finishTime;
  288. }
  289. }
  290.  
  291. public double getRot(int ticks) {
  292. return (System.currentTimeMillis() % (360 * ticks)) / ticks;
  293. }
  294. public LinkedList<mousePathPoint> mousePath = new LinkedList<mousePathPoint>();
  295.  
  296. public void drawTrail(Graphics g) {
  297. Graphics2D g2 = (Graphics2D) g;
  298. g2.setStroke(new BasicStroke(1));
  299. while (!mousePath.isEmpty() && mousePath.peek().isUp()) {
  300. mousePath.remove();
  301. }
  302. Point clientCursor = mouse.getLocation();
  303. mousePathPoint mpp = new mousePathPoint(clientCursor.x,
  304. clientCursor.y, 250);
  305. if (mousePath.isEmpty() || !mousePath.getLast().equals(mpp)) {
  306. mousePath.add(mpp);
  307. }
  308. mousePathPoint lastPoint = null;
  309. for (mousePathPoint a : mousePath) {
  310. if (lastPoint != null) {
  311. long mpt = System.currentTimeMillis()
  312. - mouse.getPressTime();
  313. if (mouse.getPressTime() == -1 || mpt >= 250) {
  314. g2.setColor(Color.GREEN);
  315. }
  316. if (mpt < 250) {
  317. g2.setColor(Color.RED);
  318. }
  319. g2.drawLine(a.x, a.y, lastPoint.x, lastPoint.y);
  320. }
  321. lastPoint = a;
  322. }
  323. }
  324.  
  325. public void drawMouse(Graphics g) {
  326. Graphics2D g2 = (Graphics2D) g;
  327. g2.setRenderingHints(new RenderingHints(
  328. RenderingHints.KEY_ANTIALIASING,
  329. RenderingHints.VALUE_ANTIALIAS_ON));
  330. g2.setStroke(new BasicStroke(3));
  331. g2.setColor(Color.BLACK);
  332. g2.drawOval(mouse.getLocation().x - 13, mouse.getLocation().y - 13,
  333. 25, 25);
  334. g2.setStroke(new BasicStroke(1));
  335. g2.setColor(new Color(0, 0, 0, 114));
  336. g2.fillOval(mouse.getLocation().x - 13, mouse.getLocation().y - 13,
  337. 25, 25);
  338. Point MouseLocation = mouse.getLocation();
  339. long mpt = System.currentTimeMillis() - mouse.getPressTime();
  340. g2.rotate(Math.toRadians(getRot(5)), mouse.getLocation().x,
  341. mouse.getLocation().y);
  342. if (mouse.getPressTime() == -1 || mpt >= 250) {
  343. g2.setColor(Color.GREEN);
  344. g2.drawLine(MouseLocation.x - 5, MouseLocation.y,
  345. MouseLocation.x + 5, MouseLocation.y);
  346. g2.drawLine(MouseLocation.x, MouseLocation.y - 5,
  347. MouseLocation.x, MouseLocation.y + 5);
  348. }
  349. if (mpt < 250) {
  350. g2.setColor(Color.RED);
  351. g2.drawLine(MouseLocation.x - 5, MouseLocation.y,
  352. MouseLocation.x + 5, MouseLocation.y);
  353. g2.drawLine(MouseLocation.x, MouseLocation.y - 5,
  354. MouseLocation.x, MouseLocation.y + 5);
  355. }
  356. }
  357.  
  358. public void drawWave(Graphics g, Color color) {
  359. Graphics2D g2 = (Graphics2D) g;
  360. Point MouseLoc = mouse.getPressLocation();
  361. long mpt = System.currentTimeMillis() - mouse.getPressTime();
  362. g2.setRenderingHints(new RenderingHints(
  363. RenderingHints.KEY_ANTIALIASING,
  364. RenderingHints.VALUE_ANTIALIAS_ON));
  365. g2.setColor(color);
  366. if (mpt < 1000) {
  367. waveSize = (int) (mpt / 7.5);
  368. } else {
  369. waveSize = 0;
  370. }
  371. g2.setStroke(new BasicStroke(3));
  372. g2.drawOval(MouseLoc.x - (waveSize / 2), MouseLoc.y
  373. - (waveSize / 2), waveSize, waveSize);
  374. g2.drawOval(MouseLoc.x - ((waveSize / 2) / 2), MouseLoc.y
  375. - ((waveSize / 2) / 2), waveSize / 2, waveSize / 2);
  376. }
  377.  
  378. public void Draw(Graphics g) {
  379. Graphics2D g2 = (Graphics2D) g;
  380. g2.setRenderingHints(new RenderingHints(
  381. RenderingHints.KEY_ANTIALIASING,
  382. RenderingHints.VALUE_ANTIALIAS_ON));
  383. drawWave(g2, Color.BLACK);
  384. drawTrail(g2);
  385. drawMouse(g2);
  386. }
  387. }
  388. // </editor-fold>
  389. //ENDCOPY
  390. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement