Solved Help In Creating A Skill

Discussion in 'Plugin Development' started by IceHower, May 5, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    IceHower

    I recently tried to create a kit called witch who came from pvpdojo kits, but I can not make potions are automatically launch in a circle, please help me?

    My code

    Code:java
    1. @EventHandler
    2. public void onJagarPocao1(PlayerMoveEvent event) {
    3. final Player p = event.getPlayer();
    4. List<Entity> s = p.getNearbyEntities(2, 2, 2);
    5. for(Entity e : s) {
    6. if(e.getType().equals(EntityType.CREEPER)) {
    7. int time = 1;
    8. Potion potion = new Potion(PotionType.INSTANT_DAMAGE, time);
    9. potion.setSplash(true);
    10. final ItemStack itemStack = new ItemStack(Material.POTION);
    11. potion.apply(itemStack);
    12. final ThrownPotion thrownPotion = p.launchProjectile(ThrownPotion.class);
    13. thrownPotion.setItem(itemStack);
    14. Vector vector = p.getLocation().getDirection().setX(1).setZ(0);
    15. thrownPotion.getLocation().setDirection(vector);
    16. new BukkitRunnable() {
    17. public void run() {
    18. }
    19. }.runTaskTimer(Main.p, 0L, 50L);
    20.  
    21. }
    22. }
    23. }
    24. }


    Video Of Kit:
     
  2. Offline

    Onlineids

    First of all that music in that vid is awesome second of all heres the code I use,
    This will create a perfect square around a player like shown in the vid;
    Code:java
    1. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z), EntityType.SPLASH_POTION);
    2. entity1.setItem(potion);
    3. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z), EntityType.SPLASH_POTION);
    4. entity2.setItem(potion);
    5. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z-2), EntityType.SPLASH_POTION);
    6. entity3.setItem(potion);
    7. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z+2), EntityType.SPLASH_POTION);
    8. entity4.setItem(potion);
    9. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z+2), EntityType.SPLASH_POTION);
    10. entity5.setItem(potion);
    11. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z-2), EntityType.SPLASH_POTION);
    12. entity6.setItem(potion);
    13. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z-2), EntityType.SPLASH_POTION);
    14. entity7.setItem(potion);
    15. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z+2), EntityType.SPLASH_POTION);
    16. entity8.setItem(potion);
    17.  
     
  3. Offline

    IceHower

    Like that :

    Code:java
    1. @EventHandler
    2. public void onJagarPocao1(PlayerMoveEvent event) {
    3. final Player p = event.getPlayer();
    4. List<Entity> s = p.getNearbyEntities(2, 2, 2);
    5. for(Entity e : s) {
    6. if(e.getType().equals(EntityType.CREEPER)) {
    7. int time = 1;
    8. Potion potion = new Potion(PotionType.INSTANT_DAMAGE, time);
    9. potion.setSplash(true);
    10. final ItemStack itemStack = new ItemStack(Material.POTION);
    11. potion.apply(itemStack);
    12. World w = p.getWorld();
    13. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z), EntityType.SPLASH_POTION);
    14. entity1.setItem(itemStack);
    15. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z), EntityType.SPLASH_POTION);
    16. entity2.setItem(itemStack);
    17. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z-2), EntityType.SPLASH_POTION);
    18. entity3.setItem(itemStack);
    19. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z+2), EntityType.SPLASH_POTION);
    20. entity4.setItem(itemStack);
    21. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z+2), EntityType.SPLASH_POTION);
    22. entity5.setItem(itemStack);
    23. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z-2), EntityType.SPLASH_POTION);
    24. entity6.setItem(itemStack);
    25. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z-2), EntityType.SPLASH_POTION);
    26. entity7.setItem(itemStack);
    27. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z+2), EntityType.SPLASH_POTION);
    28. entity8.setItem(itemStack);
    29. }
    30. }
    31. }
    32. }
    33.  


    obs: This giving error, look: http://prntscr.com/3gmlhs
    obs2: I'm in New Encoding
     
  4. Offline

    Onlineids

    You have to define those variables:
    Code:java
    1. World w = p.getWorld();
    2. double x = p.getLocation().getX();
    3. double y = p.getLocation().getY();
    4. double z = p.getLocation().getZ();
     
  5. Offline

    IceHower

    Onlineids

    I tried to make a delay for power the potions were released again but it went wrong here is my code:

    Code:java
    1. @EventHandler
    2. public void onJagarPocao1(final PlayerMoveEvent event) {
    3. final Player p = event.getPlayer();
    4. List<Entity> s = p.getNearbyEntities(2, 2, 2);
    5. for(Entity e : s) {
    6. if(e.getType().equals(EntityType.CREEPER)) {
    7. int time = 1;
    8. final Potion potion = new Potion(PotionType.INSTANT_DAMAGE, time);
    9. potion.setSplash(true);
    10. final ItemStack itemStack = new ItemStack(Material.POTION);
    11. potion.apply(itemStack);
    12. World w = p.getWorld();
    13. double x = p.getLocation().getX();
    14. double y = p.getLocation().getY();
    15. double z = p.getLocation().getZ();
    16. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z), EntityType.SPLASH_POTION);
    17. entity1.setItem(itemStack);
    18. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z), EntityType.SPLASH_POTION);
    19. entity2.setItem(itemStack);
    20. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z-2), EntityType.SPLASH_POTION);
    21. entity3.setItem(itemStack);
    22. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z+2), EntityType.SPLASH_POTION);
    23. entity4.setItem(itemStack);
    24. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z+2), EntityType.SPLASH_POTION);
    25. entity5.setItem(itemStack);
    26. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z-2), EntityType.SPLASH_POTION);
    27. entity6.setItem(itemStack);
    28. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z-2), EntityType.SPLASH_POTION);
    29. entity7.setItem(itemStack);
    30. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z+2), EntityType.SPLASH_POTION);
    31. entity8.setItem(itemStack);
    32. Main.reload.add(p.getName());
    33. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.main, new Runnable() {
    34. public void run() {
    35. if (Main.kitfreeze.contains(event.getPlayer().getName())) {
    36. event.getPlayer().giveExp(2);
    37. event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.PISTON_EXTEND, 1.0F, 1.0F);
    38. final ItemStack itemStack = new ItemStack(Material.AIR);
    39. potion.apply(itemStack);
    40. World w = p.getWorld();
    41. double x = p.getLocation().getX();
    42. double y = p.getLocation().getY();
    43. double z = p.getLocation().getZ();
    44. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z), EntityType.SPLASH_POTION);
    45. entity1.setItem(itemStack);
    46. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z), EntityType.SPLASH_POTION);
    47. entity2.setItem(itemStack);
    48. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z-2), EntityType.SPLASH_POTION);
    49. entity3.setItem(itemStack);
    50. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z+2), EntityType.SPLASH_POTION);
    51. entity4.setItem(itemStack);
    52. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z+2), EntityType.SPLASH_POTION);
    53. entity5.setItem(itemStack);
    54. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z-2), EntityType.SPLASH_POTION);
    55. entity6.setItem(itemStack);
    56. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z-2), EntityType.SPLASH_POTION);
    57. entity7.setItem(itemStack);
    58. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z+2), EntityType.SPLASH_POTION);
    59. entity8.setItem(itemStack);
    60. }
    61. }
    62. }
    63. , 20L);
    64. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.main, new Runnable() {
    65. public void run() {
    66. if (Main.kitfreeze.contains(event.getPlayer().getName())) {
    67. event.getPlayer().giveExp(2);
    68. event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.PISTON_EXTEND, 1.0F, 1.0F);
    69. final ItemStack itemStack = new ItemStack(Material.AIR);
    70. potion.apply(itemStack);
    71. World w = p.getWorld();
    72. double x = p.getLocation().getX();
    73. double y = p.getLocation().getY();
    74. double z = p.getLocation().getZ();
    75. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z), EntityType.SPLASH_POTION);
    76. entity1.setItem(itemStack);
    77. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z), EntityType.SPLASH_POTION);
    78. entity2.setItem(itemStack);
    79. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z-2), EntityType.SPLASH_POTION);
    80. entity3.setItem(itemStack);
    81. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z+2), EntityType.SPLASH_POTION);
    82. entity4.setItem(itemStack);
    83. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z+2), EntityType.SPLASH_POTION);
    84. entity5.setItem(itemStack);
    85. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z-2), EntityType.SPLASH_POTION);
    86. entity6.setItem(itemStack);
    87. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z-2), EntityType.SPLASH_POTION);
    88. entity7.setItem(itemStack);
    89. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z+2), EntityType.SPLASH_POTION);
    90. entity8.setItem(itemStack);
    91. }
    92. }
    93. }
    94. , 40L);
    95. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.main, new Runnable() {
    96. public void run() {
    97. if (Main.kitfreeze.contains(event.getPlayer().getName())) {
    98. event.getPlayer().giveExp(2);
    99. event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.PISTON_EXTEND, 1.0F, 1.0F);
    100. final ItemStack itemStack = new ItemStack(Material.AIR);
    101. potion.apply(itemStack);
    102. World w = p.getWorld();
    103. double x = p.getLocation().getX();
    104. double y = p.getLocation().getY();
    105. double z = p.getLocation().getZ();
    106. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z), EntityType.SPLASH_POTION);
    107. entity1.setItem(itemStack);
    108. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z), EntityType.SPLASH_POTION);
    109. entity2.setItem(itemStack);
    110. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z-2), EntityType.SPLASH_POTION);
    111. entity3.setItem(itemStack);
    112. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z+2), EntityType.SPLASH_POTION);
    113. entity4.setItem(itemStack);
    114. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z+2), EntityType.SPLASH_POTION);
    115. entity5.setItem(itemStack);
    116. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z-2), EntityType.SPLASH_POTION);
    117. entity6.setItem(itemStack);
    118. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z-2), EntityType.SPLASH_POTION);
    119. entity7.setItem(itemStack);
    120. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z+2), EntityType.SPLASH_POTION);
    121. entity8.setItem(itemStack);
    122. }
    123. }
    124. }
    125. , 60L);
    126. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.main, new Runnable() {
    127. public void run() {
    128. if (Main.kitfreeze.contains(event.getPlayer().getName())) {
    129. event.getPlayer().giveExp(2);
    130. event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.PISTON_EXTEND, 1.0F, 1.0F);
    131. final ItemStack itemStack = new ItemStack(Material.AIR);
    132. potion.apply(itemStack);
    133. World w = p.getWorld();
    134. double x = p.getLocation().getX();
    135. double y = p.getLocation().getY();
    136. double z = p.getLocation().getZ();
    137. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z), EntityType.SPLASH_POTION);
    138. entity1.setItem(itemStack);
    139. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z), EntityType.SPLASH_POTION);
    140. entity2.setItem(itemStack);
    141. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z-2), EntityType.SPLASH_POTION);
    142. entity3.setItem(itemStack);
    143. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z+2), EntityType.SPLASH_POTION);
    144. entity4.setItem(itemStack);
    145. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z+2), EntityType.SPLASH_POTION);
    146. entity5.setItem(itemStack);
    147. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z-2), EntityType.SPLASH_POTION);
    148. entity6.setItem(itemStack);
    149. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z-2), EntityType.SPLASH_POTION);
    150. entity7.setItem(itemStack);
    151. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z+2), EntityType.SPLASH_POTION);
    152. entity8.setItem(itemStack);
    153. }
    154. }
    155. }
    156. , 80L);
    157. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.main, new Runnable() {
    158. public void run() {
    159. if (Main.kitfreeze.contains(event.getPlayer().getName())) {
    160. event.getPlayer().giveExp(2);
    161. event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.PISTON_EXTEND, 1.0F, 1.0F);
    162. final ItemStack itemStack = new ItemStack(Material.AIR);
    163. potion.apply(itemStack);
    164. World w = p.getWorld();
    165. double x = p.getLocation().getX();
    166. double y = p.getLocation().getY();
    167. double z = p.getLocation().getZ();
    168. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z), EntityType.SPLASH_POTION);
    169. entity1.setItem(itemStack);
    170. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z), EntityType.SPLASH_POTION);
    171. entity2.setItem(itemStack);
    172. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z-2), EntityType.SPLASH_POTION);
    173. entity3.setItem(itemStack);
    174. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z+2), EntityType.SPLASH_POTION);
    175. entity4.setItem(itemStack);
    176. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z+2), EntityType.SPLASH_POTION);
    177. entity5.setItem(itemStack);
    178. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z-2), EntityType.SPLASH_POTION);
    179. entity6.setItem(itemStack);
    180. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z-2), EntityType.SPLASH_POTION);
    181. entity7.setItem(itemStack);
    182. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z+2), EntityType.SPLASH_POTION);
    183. entity8.setItem(itemStack);
    184. }
    185. }
    186. }
    187. , 100L);
    188. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.main, new Runnable() {
    189. public void run() {
    190. if (Main.kitfreeze.contains(event.getPlayer().getName())) {
    191. event.getPlayer().giveExp(2);
    192. event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.PISTON_EXTEND, 1.0F, 1.0F);
    193. final ItemStack itemStack = new ItemStack(Material.AIR);
    194. potion.apply(itemStack);
    195. World w = p.getWorld();
    196. double x = p.getLocation().getX();
    197. double y = p.getLocation().getY();
    198. double z = p.getLocation().getZ();
    199. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z), EntityType.SPLASH_POTION);
    200. entity1.setItem(itemStack);
    201. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z), EntityType.SPLASH_POTION);
    202. entity2.setItem(itemStack);
    203. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z-2), EntityType.SPLASH_POTION);
    204. entity3.setItem(itemStack);
    205. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z+2), EntityType.SPLASH_POTION);
    206. entity4.setItem(itemStack);
    207. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z+2), EntityType.SPLASH_POTION);
    208. entity5.setItem(itemStack);
    209. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z-2), EntityType.SPLASH_POTION);
    210. entity6.setItem(itemStack);
    211. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z-2), EntityType.SPLASH_POTION);
    212. entity7.setItem(itemStack);
    213. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z+2), EntityType.SPLASH_POTION);
    214. entity8.setItem(itemStack);
    215. }
    216. }
    217. }
    218. , 120L);
    219. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.main, new Runnable() {
    220. public void run() {
    221. if (Main.kitfreeze.contains(event.getPlayer().getName())) {
    222. event.getPlayer().giveExp(2);
    223. event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.PISTON_EXTEND, 1.0F, 1.0F);
    224. final ItemStack itemStack = new ItemStack(Material.AIR);
    225. potion.apply(itemStack);
    226. World w = p.getWorld();
    227. double x = p.getLocation().getX();
    228. double y = p.getLocation().getY();
    229. double z = p.getLocation().getZ();
    230. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z), EntityType.SPLASH_POTION);
    231. entity1.setItem(itemStack);
    232. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z), EntityType.SPLASH_POTION);
    233. entity2.setItem(itemStack);
    234. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z-2), EntityType.SPLASH_POTION);
    235. entity3.setItem(itemStack);
    236. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+3, z+2), EntityType.SPLASH_POTION);
    237. entity4.setItem(itemStack);
    238. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z+2), EntityType.SPLASH_POTION);
    239. entity5.setItem(itemStack);
    240. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z-2), EntityType.SPLASH_POTION);
    241. entity6.setItem(itemStack);
    242. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-2, y+3, z-2), EntityType.SPLASH_POTION);
    243. entity7.setItem(itemStack);
    244. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+2, y+3, z+2), EntityType.SPLASH_POTION);
    245. entity8.setItem(itemStack);
    246. }
    247. }
    248. }
    249. , 140L);
    250. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.main, new Runnable() {
    251. public void run() {
    252. Main.reload.remove(event.getPlayer().getName());
    253. event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 1.0F);
    254. event.getPlayer().setExp(1.0F);
    255. }
    256. }
    257. , 160L);
    258. }
    259. }
    260. }
    261. }
     
  6. Offline

    Onlineids


    Code:java
    1. ItemStack potion = new ItemStack(Material.POTION, 1);
    2. PotionMeta pm = (PotionMeta) potion.getItemMeta();
    3. pm.addCustomEffect((new PotionEffect(PotionEffectType.HARM, TIME, AMPLIFIER)), true);
    4. potion.setItemMeta(pm);
     
  7. Offline

    geret13

    Code:
    Location loc = p.getLocation().clone().add(0,3,0);
    for (int xi = -2; xi <= 2; xi += 2) {
      for (int zi = -2; zi <=2; zi += 2) {
        ((ThrownPotion) w.spawnEntity(loc.clone().add(xi, 0, zi), EntityType.SPLASH_POTION)).setItem(itemStack);
      }
    }
     
  8. Offline

    IceHower

    Onlineids

    You do not understand my question, I would add a cooldown or delay, so we will not be throwing potion all the time

    could show me how I can do this with Bukkit Runnable?
     
  9. Offline

    Onlineids

  10. Offline

    IceHower

    Onlineids

    I did it! Still not working

    Code:java
    1. HashMap<String, Integer> map = new HashMap<String, Integer>();
    2. @EventHandler
    3. public void onJagarPocao1(final PlayerMoveEvent event) {
    4. final Player p = event.getPlayer();
    5. if (map.containsKey(p.getName())) {
    6. int time = 1;
    7. final Potion potion = new Potion(PotionType.INSTANT_DAMAGE, time);
    8. potion.setSplash(true);
    9. final ItemStack itemStack = new ItemStack(Material.POTION);
    10. potion.apply(itemStack);
    11. World w = p.getWorld();
    12. double x = p.getLocation().getX();
    13. double y = p.getLocation().getY();
    14. double z = p.getLocation().getZ();
    15. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-1, y+2, z), EntityType.SPLASH_POTION);
    16. entity1.setItem(itemStack);
    17. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+1, y+2, z), EntityType.SPLASH_POTION);
    18. entity2.setItem(itemStack);
    19. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+2, z-1), EntityType.SPLASH_POTION);
    20. entity3.setItem(itemStack);
    21. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+2, z+1), EntityType.SPLASH_POTION);
    22. entity4.setItem(itemStack);
    23. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-1, y+2, z+1), EntityType.SPLASH_POTION);
    24. entity5.setItem(itemStack);
    25. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+1, y+2, z-1), EntityType.SPLASH_POTION);
    26. entity6.setItem(itemStack);
    27. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-1, y+2, z-1), EntityType.SPLASH_POTION);
    28. entity7.setItem(itemStack);
    29. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+1, y+2, z+1), EntityType.SPLASH_POTION);
    30. entity8.setItem(itemStack);
    31. } else {
    32. Cooldown.setCooldownLength(p, 10, map);
    33. Cooldown.startCooldown(p, map);
    34. }
    35. }
    36. }
     
  11. Offline

    Onlineids

    Errors?
     
  12. Offline

    IceHower

    Onlineids

    The cooldown does not work, I need to launch when the potion once get 10 seconds without throwing!
     
  13. Offline

    Onlineids

    Try just waiting 10 seconds:
    Thread.sleep(10000);
     
  14. Offline

    IceHower

    Onlineids

    Not work, have another method of doing this delay?
     
  15. Offline

    Onlineids

    This works..... Just because you don't know how to use it doesn't mean it doesn't work, hover over it and surround it in try/catch
     
  16. Offline

    IceHower

  17. Offline

    Onlineids

    You put 10 in there when I said 10000 -_-, its in miliseconds 10 miliseconds sure isnt gonna stop anything
     
  18. Offline

    IceHower

    Onlineids

    I had put 10000, but no potion was launched
     
  19. Offline

    Onlineids

    Idk, like I said that works that waits 10 seconds I dont know your code and am not gonna spoonfeed you code.
     
  20. Offline

    xTigerRebornx

    Onlineids You should never call thread#sleep() on the main thread, it will completely lock it up.
    IceHower Instead of using PlayerMoveEvent, you could try using a BukkitRunnable/repeating task for the Player that either runs every second, and uses a counter to determine when every X seconds is, then spawn potions on that, or have the task run every X seconds, and spawn the potion then.
    Also, you should use a for loop to spawn the potions, instead of copy-pasting it so many times
     
  21. Offline

    Onlineids

    Was assuming he was using thread.sleep in the end which is when I use it before returning, where it works perfectly
     
  22. Offline

    xTigerRebornx

    Onlineids Thread#sleep won't work for delaying anything, as it will only lock up the entire main thread, it may delay the entire server, but it does not delay just your thing. It should never be called on the Bukkit server thread, as it locks up all server activity for the time you specified.
     
  23. Offline

    Onlineids

    k
     
  24. Offline

    IceHower

    Onlineids
    xTigerRebornx

    I did so, but my console crash and potions are thrown in one place

    my code:

    Code:java
    1. @EventHandler
    2. public void onJagarPocao1(final PlayerMoveEvent event) {
    3. final Player p = event.getPlayer();
    4. int time = 1;
    5. final Potion potion = new Potion(PotionType.INSTANT_DAMAGE, time);
    6. potion.setSplash(true);
    7. final ItemStack itemStack = new ItemStack(Material.POTION);
    8. potion.apply(itemStack);
    9. World w = p.getWorld();
    10. double x = p.getLocation().getX();
    11. double y = p.getLocation().getY();
    12. double z = p.getLocation().getZ();
    13. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-1, y+2, z), EntityType.SPLASH_POTION);
    14. entity1.setItem(itemStack);
    15. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+1, y+2, z), EntityType.SPLASH_POTION);
    16. entity2.setItem(itemStack);
    17. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+2, z-1), EntityType.SPLASH_POTION);
    18. entity3.setItem(itemStack);
    19. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+2, z+1), EntityType.SPLASH_POTION);
    20. entity4.setItem(itemStack);
    21. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-1, y+2, z+1), EntityType.SPLASH_POTION);
    22. entity5.setItem(itemStack);
    23. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+1, y+2, z-1), EntityType.SPLASH_POTION);
    24. entity6.setItem(itemStack);
    25. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-1, y+2, z-1), EntityType.SPLASH_POTION);
    26. entity7.setItem(itemStack);
    27. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+1, y+2, z+1), EntityType.SPLASH_POTION);
    28. entity8.setItem(itemStack);
    29. long l = 10000;
    30. try {
    31. Thread.sleep(l);
    32. } catch (InterruptedException e) {
    33. e.printStackTrace();
    34. }
    35. }
    36. }
    37.  
     
  25. Offline

    xTigerRebornx

    IceHower Read through everything I've posted to the other person, you do not want to use thread#sleep(), nor should you ever call it on the Bukkit server thread. read the suggestion I gave.
     
  26. Offline

    IceHower

    xTigerRebornx
    like that:
    Code:java
    1. @EventHandler
    2. public void onJagarPocao1(final PlayerMoveEvent event) {
    3. final Player p = event.getPlayer();
    4. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.main, new Runnable() {
    5. public void run() {
    6. }
    7. }
    8. , 80L);
    9. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.main, new Runnable() {
    10. public void run() {
    11. int time = 1;
    12. final Potion potion = new Potion(PotionType.INSTANT_DAMAGE, time);
    13. potion.setSplash(true);
    14. final ItemStack itemStack = new ItemStack(Material.POTION);
    15. potion.apply(itemStack);
    16. World w = p.getWorld();
    17. double x = p.getLocation().getX();
    18. double y = p.getLocation().getY();
    19. double z = p.getLocation().getZ();
    20. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-1, y+2, z), EntityType.SPLASH_POTION);
    21. entity1.setItem(itemStack);
    22. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+1, y+2, z), EntityType.SPLASH_POTION);
    23. entity2.setItem(itemStack);
    24. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+2, z-1), EntityType.SPLASH_POTION);
    25. entity3.setItem(itemStack);
    26. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+2, z+1), EntityType.SPLASH_POTION);
    27. entity4.setItem(itemStack);
    28. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-1, y+2, z+1), EntityType.SPLASH_POTION);
    29. entity5.setItem(itemStack);
    30. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+1, y+2, z-1), EntityType.SPLASH_POTION);
    31. entity6.setItem(itemStack);
    32. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-1, y+2, z-1), EntityType.SPLASH_POTION);
    33. entity7.setItem(itemStack);
    34. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+1, y+2, z+1), EntityType.SPLASH_POTION);
    35. entity8.setItem(itemStack);
    36. }
    37. }
    38. , 60L);
    39. }
    40. }


    You can make a model for me? I'm new to coding and would like to make these kits and other more pvpdojo, and all that I do I'll post on the bukkit!
     
  27. IceHower
    This should work.
    if you use this you can also make it so it doesnt work for every player.


    READ EVERYTHING BEFORE USING
    Event:
    Code:java
    1. private HashMap<String, Long> players = new HashMap<String, Long>();
    2. private int delay = 2 * 1000;
    3. @EventHandler
    4. public void onJagarPocao1(PlayerMoveEvent event) {
    5. Player p = event.getPlayer();
    6. if(players.containsKey(p.getName())){
    7. if(players.get(p.getName()) > System.currentTimeMillis()){
    8. return;
    9. }
    10. int time = 1;
    11. final Potion potion = new Potion(PotionType.INSTANT_DAMAGE, time);
    12. potion.setSplash(true);
    13. final ItemStack itemStack = new ItemStack(Material.POTION);
    14. potion.apply(itemStack);
    15. World w = p.getWorld();
    16. double x = p.getLocation().getX();
    17. double y = p.getLocation().getY();
    18. double z = p.getLocation().getZ();
    19. ThrownPotion entity1 = (ThrownPotion) w.spawnEntity(new Location(w, x-1, y+2, z), EntityType.SPLASH_POTION);
    20. entity1.setItem(itemStack);
    21. ThrownPotion entity2 = (ThrownPotion) w.spawnEntity(new Location(w, x+1, y+2, z), EntityType.SPLASH_POTION);
    22. entity2.setItem(itemStack);
    23. ThrownPotion entity3 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+2, z-1), EntityType.SPLASH_POTION);
    24. entity3.setItem(itemStack);
    25. ThrownPotion entity4 = (ThrownPotion) w.spawnEntity(new Location(w, x, y+2, z+1), EntityType.SPLASH_POTION);
    26. entity4.setItem(itemStack);
    27. ThrownPotion entity5 = (ThrownPotion) w.spawnEntity(new Location(w, x-1, y+2, z+1), EntityType.SPLASH_POTION);
    28. entity5.setItem(itemStack);
    29. ThrownPotion entity6 = (ThrownPotion) w.spawnEntity(new Location(w, x+1, y+2, z-1), EntityType.SPLASH_POTION);
    30. entity6.setItem(itemStack);
    31. ThrownPotion entity7 = (ThrownPotion) w.spawnEntity(new Location(w, x-1, y+2, z-1), EntityType.SPLASH_POTION);
    32. entity7.setItem(itemStack);
    33. ThrownPotion entity8 = (ThrownPotion) w.spawnEntity(new Location(w, x+1, y+2, z+1), EntityType.SPLASH_POTION);
    34. entity8.setItem(itemStack);
    35. players.put(p.getName(), System.currentTimeMillis() + delay);
    36. }
    37. }


    This wont work yet because you didnt add them to the "players" hashmap yet

    Set it for 1 player:
    Code:java
    1. players.put(player.getName(), 0);


    Set it for all online players:
    Code:java
    1. for(Player player : Bukkit.getOnlinePlayers()){
    2. players.put(player.getName(), System.currentTimeMillis() + delay);
    3. }


    Set it for all the players with a permission:
    Code:java
    1. for(Player player : Bukkit.getOnlinePlayers()){
    2. if(player.hasPermission("your.permission")){
    3. players.put(player.getName(), System.currentTimeMillis() + delay);
    4. }
    5. }



    Make sure to put player.getName not just player (player is ALOT of data that will be stored in your ram)
    (If you want to see how much it is just try Bukkit.BroadcastMessage(player + ""); :) )
    Have Fun with it.
     
Thread Status:
Not open for further replies.

Share This Page