Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.88 KB | None | 0 0
  1. package lf.survival.listeners;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Random;
  7.  
  8. import org.bukkit.Location;
  9. import org.bukkit.Material;
  10. import org.bukkit.World;
  11. import org.bukkit.block.Beacon;
  12. import org.bukkit.block.Block;
  13. import org.bukkit.block.Chest;
  14. import org.bukkit.block.Dispenser;
  15. import org.bukkit.block.Dropper;
  16. import org.bukkit.block.Furnace;
  17. import org.bukkit.block.Hopper;
  18. import org.bukkit.block.Sign;
  19. import org.bukkit.entity.Entity;
  20. import org.bukkit.entity.EntityType;
  21. import org.bukkit.entity.FallingBlock;
  22. import org.bukkit.entity.TNTPrimed;
  23. import org.bukkit.event.entity.EntityExplodeEvent;
  24. import org.bukkit.event.entity.ExplosionPrimeEvent;
  25. import org.bukkit.inventory.ItemStack;
  26. import org.bukkit.scheduler.BukkitRunnable;
  27. import org.bukkit.util.Vector;
  28.  
  29. import lf.survival.pack.ToxSurvival;
  30. import lf.survival.particles.PlayEffects;
  31. import net.minecraft.server.v1_12_R1.EnumParticle;
  32. /**
  33. *
  34. * @author &copy; Luis Falkenhan || ToxicCSN00B<p><b>Das entfernen dieser Auskommentierung, sowie allgemein das verändern dieser Klasse ist untersagt!</b>
  35. *
  36. * @category <b>Bukkit |=> Explosion Manager 1.7- 1.8</b>
  37. *
  38. * @important <b>How to Use this Class:</b>
  39. *
  40. *
  41. * <b>Put the following code in the <b>ExplosionPrimeEvent</b>:</b><p>
  42. * &emsp;&emsp;if(!LFExplosions.hasExplosion(event)){<p>
  43. * &emsp;&emsp;&emsp;event.setCancelled(true);<p>
  44. * &emsp;&emsp;&emsp;LFExplosions.createExplosion(event.getEntity().getLocation(), 20.0f, true, true, 20.0f, 1, 2L);<p>
  45. * &emsp;&emsp;}<p>
  46. * &emsp;&emsp;LFExplosions.prime(event);<p>
  47. *
  48. *<b>Put the following code in the <b>EntityExplodeEvent</b>:</b><p>
  49. * &emsp;&emsp;if(!LFExplosions.hasExplosion(event)){<p>
  50. * &emsp;&emsp;&emsp;event.setCancelled(true);<p>
  51. * &emsp;&emsp;&emsp;LFExplosions.createExplosion(event.getEntity().getLocation(), 20.0f, true, true, 20.0f, 1, 2L);<p>
  52. * &emsp;&emsp;}<p>
  53. * &emsp;&emsp;LFExplosions.explode(event);<p>
  54. *
  55. *
  56. * TODO: REQUIRE-LIST finshen!
  57. */
  58. public class LFExplosions {
  59. private static HashMap<Entity, Explosion> rad=new HashMap<>();
  60. /**
  61. *
  62. * @param loc = Location
  63. * @param yield = Yield of the Explosion
  64. * @param regBlocks = Regenerate Blocks after Explosion
  65. * @param bounce = Bounce Blocks after Explosion
  66. * @param radius = Explosion Radius
  67. * @param fuseTicks = Explosion (TNT) Fuse Ticks
  68. * @param timer = Regenerate Timer between blocks (normal is 6)
  69. * @return TNTPrimed = the Spawned TNT
  70. */
  71. public static TNTPrimed createExplosion(Location loc, float yield, boolean regBlocks, boolean bounce, float radius, int fuseTicks, long timer){
  72. World w = loc.getWorld();
  73. Entity e = w.spawnEntity(loc, EntityType.PRIMED_TNT);
  74. TNTPrimed tnt = (TNTPrimed)e;
  75. tnt.setYield(yield);
  76. tnt.setFuseTicks(fuseTicks);
  77. rad.put(e, new Explosion(loc, yield, regBlocks, bounce, radius, timer));
  78. return tnt;
  79. }
  80. /**
  81. *
  82. * @param loc = Location
  83. * @param rad = Explosion Radius
  84. * @param fuseTicks = Explosion (TNT) Fuse Ticks
  85. * @param timer = Regenerate Timer between blocks (normal is 6)
  86. * @return TNTPrimed = the Spawned TNT
  87. */
  88. public static TNTPrimed createExplosion(Location loc, float rad, int fuseTicks, long timer){
  89. return createExplosion(loc, 20f, true, true, rad, fuseTicks, timer);
  90. }
  91. /**
  92. *
  93. * @param loc = Location
  94. * @param yield = Yield of the Explosion
  95. * @param rad = Explosion Radius
  96. * @param fuseTicks = Explosion (TNT) Fuse Ticks
  97. * @param timer = Regenerate Timer between blocks (normal is 6)
  98. * @return TNTPrimed = the Spawned TNT
  99. */
  100. public static TNTPrimed createExplosion(Location loc, float yield, float rad, int fuseTicks, long timer){
  101. return createExplosion(loc, yield, true, true, rad, fuseTicks, timer);
  102. }
  103. /**
  104. *
  105. * @param loc = Location
  106. * @param regBlocks = Regenerate Blocks after Explosion
  107. * @param bounce = Bounce Blocks after Explosion
  108. * @param rad = Explosion Radius
  109. * @param fuseTicks = Explosion (TNT) Fuse Ticks
  110. * @param timer = Regenerate Timer between blocks (normal is 6)
  111. * @return TNTPrimed = the Spawned TNT
  112. */
  113. public static TNTPrimed createExplosion(Location loc, boolean regBlocks, boolean bounce, float rad, int fuseTicks, long timer){
  114. return createExplosion(loc, 20f, regBlocks, bounce, rad, fuseTicks, timer);
  115. }
  116. /**
  117. *
  118. * @param e = EntityExplodeEvent
  119. * @return is the Explosion generated by {@link LFExplosion}
  120. */
  121. public static boolean hasExplosion(EntityExplodeEvent e){
  122. return rad.get(e.getEntity())!=null;
  123. }
  124. /**
  125. *
  126. * @param e = ExplosionPrimeEvent
  127. * @return is the Explosion generated by {@link LFExplosion}
  128. */
  129. public static boolean hasExplosion(ExplosionPrimeEvent e){
  130. return rad.get(e.getEntity())!=null;
  131. }
  132. /**
  133. *
  134. * @param e = ExplosionPrimeEvent
  135. */
  136. public static void prime(ExplosionPrimeEvent e){
  137. if(e.getEntity() instanceof TNTPrimed){
  138. if(rad.containsKey(e.getEntity())){
  139. e.setRadius(rad.get(e.getEntity()).radius);
  140. }
  141. }
  142. }
  143. /**
  144. *
  145. * @param e = EntityExplodeEvent
  146. */
  147. public static void explode(EntityExplodeEvent e){
  148. List<Block> blocks = e.blockList();
  149. if(e.getEntity() instanceof TNTPrimed){
  150. Explosion ex = rad.get(e.getEntity());
  151. if(ex.bounce){blocks=bounceBlocks(blocks);}
  152. if(ex.regBlocks){new Replacer(blocks, ex.timer);}
  153. }
  154. }
  155. /**
  156. *
  157. * @param block = List of Blocks to Bounce
  158. * @return ArrayList of Blocks [=>input]
  159. */
  160. @SuppressWarnings("deprecation")
  161. private static ArrayList<Block> bounceBlocks(List<Block> block){
  162. HashMap<Location, Material> type = new HashMap<>();
  163. HashMap<Location, Byte> data = new HashMap<>();
  164. for(int i = 0; i<block.size();i++){
  165. type.put(block.get(i).getLocation(), block.get(i).getType());
  166. data.put(block.get(i).getLocation(), block.get(i).getData());
  167. Location blocklc = block.get(i).getLocation();
  168. blocklc.setY(blocklc.getY()+1);
  169. FallingBlock fb = block.get(i).getWorld().spawnFallingBlock(blocklc, block.get(i).getType(), block.get(i).getData());
  170. fb.setDropItem(false);
  171. Random rd = new Random();
  172. double x = (rd.nextInt(8)-2)*0.1D;
  173. double y = 03D+rd.nextInt(2)*0.1D;
  174. double z = (rd.nextInt(11)- -2)*- 0.1D;
  175. fb.setVelocity(new Vector(x, y, z));
  176. new BukkitRunnable(){
  177. @Override
  178. public void run() {
  179. if(fb.isOnGround()){
  180. fb.getLocation().getBlock().setType(Material.AIR);
  181. this.cancel();
  182. }
  183. }
  184. }.runTaskTimer(ToxSurvival.pl, 0L, 1L);
  185. }
  186. return (ArrayList<Block>) block;
  187. }
  188. /**
  189. *
  190. * @author &copy; Luis Falkenhan || ToxicCSN00B<p><b>Das entfernen dieser Auskommentierung, sowie allgemein das verändern dieser Klasse ist untersagt!</b>
  191. *
  192. * @category <b>Bukkit |=> Explosion Manager || SubClass [Replacer]</b>
  193. *
  194. * @important <b>Replace- Agent for the Exploded Blocks</b>
  195. */
  196. public static class Replacer{
  197.  
  198. private static ArrayList<Location> l1=new ArrayList<>();
  199. private static ArrayList<Material> m1=new ArrayList<>();
  200. private static ArrayList<Byte> d1=new ArrayList<>();
  201.  
  202. private static ArrayList<Location> l2=new ArrayList<>();
  203. private static ArrayList<Material> m2=new ArrayList<>();
  204. private static ArrayList<Byte> d2=new ArrayList<>();
  205.  
  206. private static HashMap<Location, ItemStack[]> invs=new HashMap<>();
  207.  
  208. private static HashMap<Location, String[]> lines=new HashMap<>();
  209.  
  210. private static ArrayList<Material> require=new ArrayList<>();
  211. /**
  212. * @param blocks = List of the Block's
  213. * @param timer = Regenerate Timer between blocks (normal is 6)
  214. */
  215. @SuppressWarnings("deprecation")
  216. public Replacer(List<Block> blocks, long timer){
  217. init();
  218. for(int i=0;i<blocks.size(); i++){
  219. Block b = blocks.get(i);
  220. if(require.contains(b.getType())){
  221. l2.add(b.getLocation());
  222. m2.add(b.getType());
  223. d2.add(b.getData());
  224. }else{
  225. l1.add(b.getLocation());
  226. m1.add(b.getType());
  227. d1.add(b.getData());
  228. }
  229. if(b.getType()==Material.SIGN||
  230. b.getType()==Material.WALL_SIGN||
  231. b.getType()==Material.SIGN_POST){
  232. Sign sign = (Sign)b.getState();
  233. lines.put(b.getLocation(), sign.getLines());
  234. }
  235. if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.TRAPPED_CHEST|| b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.CHEST){
  236. final Chest block = (Chest)b.getState();
  237. final ItemStack[] inv = block.getInventory().getContents();
  238. block.getInventory().clear();
  239. invs.put(b.getLocation(), inv);
  240. }
  241. if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.FURNACE||
  242. b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.BURNING_FURNACE){
  243. final Furnace block = (Furnace)b.getState();
  244. final ItemStack[] inv = block.getInventory().getContents();
  245. block.getInventory().clear();
  246. invs.put(b.getLocation(), inv);
  247. }
  248. if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.DROPPER){
  249. final Dropper block = (Dropper)b.getState();
  250. final ItemStack[] inv = block.getInventory().getContents();
  251. block.getInventory().clear();
  252. invs.put(b.getLocation(), inv);
  253. }
  254. if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.DISPENSER){
  255. final Dispenser block = (Dispenser)b.getState();
  256. final ItemStack[] inv = block.getInventory().getContents();
  257. block.getInventory().clear();
  258. invs.put(b.getLocation(), inv);
  259. }
  260. if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.HOPPER){
  261. final Hopper block = (Hopper)b.getState();
  262. final ItemStack[] inv = block.getInventory().getContents();
  263. block.getInventory().clear();
  264. invs.put(b.getLocation(), inv);
  265. }
  266. if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.BEACON){
  267. final Beacon block = (Beacon)b.getState();
  268. final ItemStack[] inv = block.getInventory().getContents();
  269. block.getInventory().clear();
  270. invs.put(b.getLocation(), inv);
  271. }
  272. b.getDrops().clear();
  273. b.setType(Material.AIR);
  274. }
  275. new BukkitRunnable() {
  276. int counter=0;
  277. boolean fin=false;
  278. @Override
  279. public void run(){
  280. if(m1.size()>counter){
  281. Material tempMat = m1.get(counter);
  282. Byte tempData = d1.get(counter);
  283. Location tempLoc = l1.get(counter);
  284. if(tempMat!=Material.TNT){
  285. tempLoc.getBlock().setType(tempMat);
  286. PlayEffects.sendPacket(EnumParticle.FLAME, new Location(tempLoc.getBlock().getLocation().getWorld(), tempLoc.getBlock().getLocation().getX(), tempLoc.getBlock().getLocation().getY()+1, tempLoc.getBlock().getLocation().getZ()), 15D);
  287. tempLoc.getBlock().setData(tempData);
  288. }else{
  289. PlayEffects.sendPacket(EnumParticle.EXPLOSION_LARGE, new Location(tempLoc.getBlock().getLocation().getWorld(), tempLoc.getBlock().getLocation().getX(), tempLoc.getBlock().getLocation().getY()+1, tempLoc.getBlock().getLocation().getZ()), 15D);
  290. }
  291. m1.remove(counter);
  292. d1.remove(counter);
  293. l1.remove(counter);
  294. counter++;
  295. }else{
  296. counter=0;
  297. if(m2.size()>counter){
  298. Material tempMat = m2.get(counter);
  299. Byte tempData = d2.get(counter);
  300. Location tempLoc = l2.get(counter);
  301. tempLoc.getBlock().setType(tempMat);
  302. tempLoc.getBlock().setData(tempData);
  303. PlayEffects.sendPacket(EnumParticle.FLAME, new Location(tempLoc.getBlock().getLocation().getWorld(), tempLoc.getBlock().getLocation().getX(), tempLoc.getBlock().getLocation().getY()+1, tempLoc.getBlock().getLocation().getZ()), 15D);
  304. //tempLoc.getWorld().playSound(tempLoc.getBlock().getLocation(), Sound.ANVIL_LAND, 1F, 1F);
  305. m2.remove(counter);
  306. d2.remove(counter);
  307. l2.remove(counter);
  308. counter++;
  309. }else{fin=true;}
  310. }
  311. if(fin){
  312. counter=0;
  313. setInventory();
  314. setLines();
  315. this.cancel();
  316. }
  317. }
  318. }.runTaskTimer(ToxSurvival.pl, 1*10L, timer);
  319. }
  320. /**
  321. * Initialize ArrayList require
  322. */
  323. private static void init(){
  324. require.clear();
  325. require.add(Material.WOODEN_DOOR);
  326. require.add(Material.IRON_DOOR);
  327. require.add(Material.IRON_DOOR_BLOCK);
  328. require.add(Material.TRAP_DOOR);
  329. require.add(Material.LADDER);
  330. require.add(Material.VINE);
  331. require.add(Material.LEVER);
  332. require.add(Material.REDSTONE);
  333. require.add(Material.REDSTONE_COMPARATOR);
  334. require.add(Material.REDSTONE_COMPARATOR_OFF);
  335. require.add(Material.REDSTONE_COMPARATOR_ON);
  336. require.add(Material.REDSTONE_WIRE);
  337. require.add(Material.WOOD_BUTTON);
  338. require.add(Material.STONE_BUTTON);
  339. require.add(Material.WOOD_PLATE);
  340. require.add(Material.STONE_PLATE);
  341. require.add(Material.TORCH);
  342. require.add(Material.REDSTONE_TORCH_ON);
  343. require.add(Material.REDSTONE_TORCH_OFF);
  344. require.add(Material.WALL_SIGN);
  345. require.add(Material.SIGN_POST);
  346. require.add(Material.SIGN);
  347. require.add(Material.GRASS);
  348. require.add(Material.LONG_GRASS);
  349. require.add(Material.PAINTING);
  350. require.add(Material.YELLOW_FLOWER);
  351. require.add(Material.DOUBLE_PLANT);
  352. }
  353. /**
  354. * ReSet Lines of all InventoryHolders
  355. */
  356. private static void setInventory(){
  357. for(Location l : invs.keySet()){
  358. ItemStack[] i = invs.get(l);
  359. Block b = l.getWorld().getBlockAt(l);
  360. if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.TRAPPED_CHEST|| b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.CHEST){
  361. final Chest block = (Chest)b.getState();
  362. try{
  363. block.getInventory().setContents(i);
  364. block.update();
  365. }catch(IllegalArgumentException e){
  366. int iii=0;
  367. for(int ii=0; ii<block.getInventory().getSize(); ii++){
  368. block.getInventory().addItem(i[ii]);
  369. iii=ii;
  370. }
  371. for(int ii=0; ii<iii; ii++){
  372. l.getWorld().dropItem(l, i[ii]);
  373. }
  374. }
  375. }
  376. if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.FURNACE||
  377. b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.BURNING_FURNACE){
  378. final Furnace block = (Furnace)b.getState();
  379. block.getInventory().setContents(i);
  380. block.update();
  381. }
  382. if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.DROPPER){
  383. final Dropper block = (Dropper)b.getState();
  384. block.getInventory().setContents(i);
  385. block.update();
  386. }
  387. if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.DISPENSER){
  388. final Dispenser block = (Dispenser)b.getState();
  389. block.getInventory().setContents(i);
  390. block.update();
  391. }
  392. if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.HOPPER){
  393. final Hopper block = (Hopper)b.getState();
  394. block.getInventory().setContents(i);
  395. block.update();
  396. }
  397. if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.BEACON){
  398. final Beacon block = (Beacon)b.getState();
  399. block.getInventory().setContents(i);
  400. block.update();
  401. }
  402. }
  403. }
  404. /**
  405. * ReSet Lines of all Signs
  406. */
  407. private static void setLines(){
  408. for(Location l : lines.keySet()){
  409. String[] s = lines.get(l);
  410. if(l.getWorld().getBlockAt(l).getType()==Material.SIGN||
  411. l.getWorld().getBlockAt(l).getType()==Material.WALL_SIGN||
  412. l.getWorld().getBlockAt(l).getType()==Material.SIGN_POST){
  413. Sign sign = (Sign)l.getBlock().getState();
  414. sign.setLine(0, s[0]);
  415. sign.setLine(1, s[1]);
  416. sign.setLine(2, s[2]);
  417. sign.setLine(3, s[3]);
  418. sign.update();
  419. }
  420. }
  421. }
  422. }
  423. /**
  424. *
  425. * @author &copy; Luis Falkenhan || ToxicCSN00B<p><b>Das entfernen dieser Auskommentierung, sowie allgemein das verändern dieser Klasse ist untersagt!</b>
  426. *
  427. * @category <b>Bukkit |=> Explosion Manager || SubClass [Explosion]</b>
  428. *
  429. * @important <b>You'll never use this Class</b>
  430. */
  431. public static class Explosion{
  432. public Location loc;
  433. public float yield;
  434. public boolean regBlocks;
  435. public boolean bounce;
  436. public float radius;
  437. public long timer;
  438. /**
  439. *
  440. * @param loc = Location
  441. * @param yield = Yield of the Explosion
  442. * @param regBlocks = Regenerate Blocks after Explosion
  443. * @param bounce = Bounce Blocks after Explosion
  444. * @param radius = Explosion Radius
  445. * @param timer = Regenerate Timer between blocks (normal is 6)
  446. * @return New instance of Explosion with initialized variables
  447. */
  448. public Explosion(Location loc, float yield, boolean regBlocks, boolean bounce, float radius, long timer){
  449. this.loc=loc;
  450. this.yield=yield;
  451. this.regBlocks=regBlocks;
  452. this.bounce=bounce;
  453. this.radius=radius;
  454. this.timer=timer;
  455. }
  456. }
  457. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement