Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lf.survival.listeners;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Random;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.block.Beacon;
- import org.bukkit.block.Block;
- import org.bukkit.block.Chest;
- import org.bukkit.block.Dispenser;
- import org.bukkit.block.Dropper;
- import org.bukkit.block.Furnace;
- import org.bukkit.block.Hopper;
- import org.bukkit.block.Sign;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.FallingBlock;
- import org.bukkit.entity.TNTPrimed;
- import org.bukkit.event.entity.EntityExplodeEvent;
- import org.bukkit.event.entity.ExplosionPrimeEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.util.Vector;
- import lf.survival.pack.ToxSurvival;
- import lf.survival.particles.PlayEffects;
- import net.minecraft.server.v1_12_R1.EnumParticle;
- /**
- *
- * @author © Luis Falkenhan || ToxicCSN00B<p><b>Das entfernen dieser Auskommentierung, sowie allgemein das verändern dieser Klasse ist untersagt!</b>
- *
- * @category <b>Bukkit |=> Explosion Manager 1.7- 1.8</b>
- *
- * @important <b>How to Use this Class:</b>
- *
- *
- * <b>Put the following code in the <b>ExplosionPrimeEvent</b>:</b><p>
- *   if(!LFExplosions.hasExplosion(event)){<p>
- *    event.setCancelled(true);<p>
- *    LFExplosions.createExplosion(event.getEntity().getLocation(), 20.0f, true, true, 20.0f, 1, 2L);<p>
- *   }<p>
- *   LFExplosions.prime(event);<p>
- *
- *<b>Put the following code in the <b>EntityExplodeEvent</b>:</b><p>
- *   if(!LFExplosions.hasExplosion(event)){<p>
- *    event.setCancelled(true);<p>
- *    LFExplosions.createExplosion(event.getEntity().getLocation(), 20.0f, true, true, 20.0f, 1, 2L);<p>
- *   }<p>
- *   LFExplosions.explode(event);<p>
- *
- *
- * TODO: REQUIRE-LIST finshen!
- */
- public class LFExplosions {
- private static HashMap<Entity, Explosion> rad=new HashMap<>();
- /**
- *
- * @param loc = Location
- * @param yield = Yield of the Explosion
- * @param regBlocks = Regenerate Blocks after Explosion
- * @param bounce = Bounce Blocks after Explosion
- * @param radius = Explosion Radius
- * @param fuseTicks = Explosion (TNT) Fuse Ticks
- * @param timer = Regenerate Timer between blocks (normal is 6)
- * @return TNTPrimed = the Spawned TNT
- */
- public static TNTPrimed createExplosion(Location loc, float yield, boolean regBlocks, boolean bounce, float radius, int fuseTicks, long timer){
- World w = loc.getWorld();
- Entity e = w.spawnEntity(loc, EntityType.PRIMED_TNT);
- TNTPrimed tnt = (TNTPrimed)e;
- tnt.setYield(yield);
- tnt.setFuseTicks(fuseTicks);
- rad.put(e, new Explosion(loc, yield, regBlocks, bounce, radius, timer));
- return tnt;
- }
- /**
- *
- * @param loc = Location
- * @param rad = Explosion Radius
- * @param fuseTicks = Explosion (TNT) Fuse Ticks
- * @param timer = Regenerate Timer between blocks (normal is 6)
- * @return TNTPrimed = the Spawned TNT
- */
- public static TNTPrimed createExplosion(Location loc, float rad, int fuseTicks, long timer){
- return createExplosion(loc, 20f, true, true, rad, fuseTicks, timer);
- }
- /**
- *
- * @param loc = Location
- * @param yield = Yield of the Explosion
- * @param rad = Explosion Radius
- * @param fuseTicks = Explosion (TNT) Fuse Ticks
- * @param timer = Regenerate Timer between blocks (normal is 6)
- * @return TNTPrimed = the Spawned TNT
- */
- public static TNTPrimed createExplosion(Location loc, float yield, float rad, int fuseTicks, long timer){
- return createExplosion(loc, yield, true, true, rad, fuseTicks, timer);
- }
- /**
- *
- * @param loc = Location
- * @param regBlocks = Regenerate Blocks after Explosion
- * @param bounce = Bounce Blocks after Explosion
- * @param rad = Explosion Radius
- * @param fuseTicks = Explosion (TNT) Fuse Ticks
- * @param timer = Regenerate Timer between blocks (normal is 6)
- * @return TNTPrimed = the Spawned TNT
- */
- public static TNTPrimed createExplosion(Location loc, boolean regBlocks, boolean bounce, float rad, int fuseTicks, long timer){
- return createExplosion(loc, 20f, regBlocks, bounce, rad, fuseTicks, timer);
- }
- /**
- *
- * @param e = EntityExplodeEvent
- * @return is the Explosion generated by {@link LFExplosion}
- */
- public static boolean hasExplosion(EntityExplodeEvent e){
- return rad.get(e.getEntity())!=null;
- }
- /**
- *
- * @param e = ExplosionPrimeEvent
- * @return is the Explosion generated by {@link LFExplosion}
- */
- public static boolean hasExplosion(ExplosionPrimeEvent e){
- return rad.get(e.getEntity())!=null;
- }
- /**
- *
- * @param e = ExplosionPrimeEvent
- */
- public static void prime(ExplosionPrimeEvent e){
- if(e.getEntity() instanceof TNTPrimed){
- if(rad.containsKey(e.getEntity())){
- e.setRadius(rad.get(e.getEntity()).radius);
- }
- }
- }
- /**
- *
- * @param e = EntityExplodeEvent
- */
- public static void explode(EntityExplodeEvent e){
- List<Block> blocks = e.blockList();
- if(e.getEntity() instanceof TNTPrimed){
- Explosion ex = rad.get(e.getEntity());
- if(ex.bounce){blocks=bounceBlocks(blocks);}
- if(ex.regBlocks){new Replacer(blocks, ex.timer);}
- }
- }
- /**
- *
- * @param block = List of Blocks to Bounce
- * @return ArrayList of Blocks [=>input]
- */
- @SuppressWarnings("deprecation")
- private static ArrayList<Block> bounceBlocks(List<Block> block){
- HashMap<Location, Material> type = new HashMap<>();
- HashMap<Location, Byte> data = new HashMap<>();
- for(int i = 0; i<block.size();i++){
- type.put(block.get(i).getLocation(), block.get(i).getType());
- data.put(block.get(i).getLocation(), block.get(i).getData());
- Location blocklc = block.get(i).getLocation();
- blocklc.setY(blocklc.getY()+1);
- FallingBlock fb = block.get(i).getWorld().spawnFallingBlock(blocklc, block.get(i).getType(), block.get(i).getData());
- fb.setDropItem(false);
- Random rd = new Random();
- double x = (rd.nextInt(8)-2)*0.1D;
- double y = 03D+rd.nextInt(2)*0.1D;
- double z = (rd.nextInt(11)- -2)*- 0.1D;
- fb.setVelocity(new Vector(x, y, z));
- new BukkitRunnable(){
- @Override
- public void run() {
- if(fb.isOnGround()){
- fb.getLocation().getBlock().setType(Material.AIR);
- this.cancel();
- }
- }
- }.runTaskTimer(ToxSurvival.pl, 0L, 1L);
- }
- return (ArrayList<Block>) block;
- }
- /**
- *
- * @author © Luis Falkenhan || ToxicCSN00B<p><b>Das entfernen dieser Auskommentierung, sowie allgemein das verändern dieser Klasse ist untersagt!</b>
- *
- * @category <b>Bukkit |=> Explosion Manager || SubClass [Replacer]</b>
- *
- * @important <b>Replace- Agent for the Exploded Blocks</b>
- */
- public static class Replacer{
- private static ArrayList<Location> l1=new ArrayList<>();
- private static ArrayList<Material> m1=new ArrayList<>();
- private static ArrayList<Byte> d1=new ArrayList<>();
- private static ArrayList<Location> l2=new ArrayList<>();
- private static ArrayList<Material> m2=new ArrayList<>();
- private static ArrayList<Byte> d2=new ArrayList<>();
- private static HashMap<Location, ItemStack[]> invs=new HashMap<>();
- private static HashMap<Location, String[]> lines=new HashMap<>();
- private static ArrayList<Material> require=new ArrayList<>();
- /**
- * @param blocks = List of the Block's
- * @param timer = Regenerate Timer between blocks (normal is 6)
- */
- @SuppressWarnings("deprecation")
- public Replacer(List<Block> blocks, long timer){
- init();
- for(int i=0;i<blocks.size(); i++){
- Block b = blocks.get(i);
- if(require.contains(b.getType())){
- l2.add(b.getLocation());
- m2.add(b.getType());
- d2.add(b.getData());
- }else{
- l1.add(b.getLocation());
- m1.add(b.getType());
- d1.add(b.getData());
- }
- if(b.getType()==Material.SIGN||
- b.getType()==Material.WALL_SIGN||
- b.getType()==Material.SIGN_POST){
- Sign sign = (Sign)b.getState();
- lines.put(b.getLocation(), sign.getLines());
- }
- if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.TRAPPED_CHEST|| b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.CHEST){
- final Chest block = (Chest)b.getState();
- final ItemStack[] inv = block.getInventory().getContents();
- block.getInventory().clear();
- invs.put(b.getLocation(), inv);
- }
- if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.FURNACE||
- b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.BURNING_FURNACE){
- final Furnace block = (Furnace)b.getState();
- final ItemStack[] inv = block.getInventory().getContents();
- block.getInventory().clear();
- invs.put(b.getLocation(), inv);
- }
- if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.DROPPER){
- final Dropper block = (Dropper)b.getState();
- final ItemStack[] inv = block.getInventory().getContents();
- block.getInventory().clear();
- invs.put(b.getLocation(), inv);
- }
- if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.DISPENSER){
- final Dispenser block = (Dispenser)b.getState();
- final ItemStack[] inv = block.getInventory().getContents();
- block.getInventory().clear();
- invs.put(b.getLocation(), inv);
- }
- if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.HOPPER){
- final Hopper block = (Hopper)b.getState();
- final ItemStack[] inv = block.getInventory().getContents();
- block.getInventory().clear();
- invs.put(b.getLocation(), inv);
- }
- if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.BEACON){
- final Beacon block = (Beacon)b.getState();
- final ItemStack[] inv = block.getInventory().getContents();
- block.getInventory().clear();
- invs.put(b.getLocation(), inv);
- }
- b.getDrops().clear();
- b.setType(Material.AIR);
- }
- new BukkitRunnable() {
- int counter=0;
- boolean fin=false;
- @Override
- public void run(){
- if(m1.size()>counter){
- Material tempMat = m1.get(counter);
- Byte tempData = d1.get(counter);
- Location tempLoc = l1.get(counter);
- if(tempMat!=Material.TNT){
- tempLoc.getBlock().setType(tempMat);
- PlayEffects.sendPacket(EnumParticle.FLAME, new Location(tempLoc.getBlock().getLocation().getWorld(), tempLoc.getBlock().getLocation().getX(), tempLoc.getBlock().getLocation().getY()+1, tempLoc.getBlock().getLocation().getZ()), 15D);
- tempLoc.getBlock().setData(tempData);
- }else{
- 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);
- }
- m1.remove(counter);
- d1.remove(counter);
- l1.remove(counter);
- counter++;
- }else{
- counter=0;
- if(m2.size()>counter){
- Material tempMat = m2.get(counter);
- Byte tempData = d2.get(counter);
- Location tempLoc = l2.get(counter);
- tempLoc.getBlock().setType(tempMat);
- tempLoc.getBlock().setData(tempData);
- PlayEffects.sendPacket(EnumParticle.FLAME, new Location(tempLoc.getBlock().getLocation().getWorld(), tempLoc.getBlock().getLocation().getX(), tempLoc.getBlock().getLocation().getY()+1, tempLoc.getBlock().getLocation().getZ()), 15D);
- //tempLoc.getWorld().playSound(tempLoc.getBlock().getLocation(), Sound.ANVIL_LAND, 1F, 1F);
- m2.remove(counter);
- d2.remove(counter);
- l2.remove(counter);
- counter++;
- }else{fin=true;}
- }
- if(fin){
- counter=0;
- setInventory();
- setLines();
- this.cancel();
- }
- }
- }.runTaskTimer(ToxSurvival.pl, 1*10L, timer);
- }
- /**
- * Initialize ArrayList require
- */
- private static void init(){
- require.clear();
- require.add(Material.WOODEN_DOOR);
- require.add(Material.IRON_DOOR);
- require.add(Material.IRON_DOOR_BLOCK);
- require.add(Material.TRAP_DOOR);
- require.add(Material.LADDER);
- require.add(Material.VINE);
- require.add(Material.LEVER);
- require.add(Material.REDSTONE);
- require.add(Material.REDSTONE_COMPARATOR);
- require.add(Material.REDSTONE_COMPARATOR_OFF);
- require.add(Material.REDSTONE_COMPARATOR_ON);
- require.add(Material.REDSTONE_WIRE);
- require.add(Material.WOOD_BUTTON);
- require.add(Material.STONE_BUTTON);
- require.add(Material.WOOD_PLATE);
- require.add(Material.STONE_PLATE);
- require.add(Material.TORCH);
- require.add(Material.REDSTONE_TORCH_ON);
- require.add(Material.REDSTONE_TORCH_OFF);
- require.add(Material.WALL_SIGN);
- require.add(Material.SIGN_POST);
- require.add(Material.SIGN);
- require.add(Material.GRASS);
- require.add(Material.LONG_GRASS);
- require.add(Material.PAINTING);
- require.add(Material.YELLOW_FLOWER);
- require.add(Material.DOUBLE_PLANT);
- }
- /**
- * ReSet Lines of all InventoryHolders
- */
- private static void setInventory(){
- for(Location l : invs.keySet()){
- ItemStack[] i = invs.get(l);
- Block b = l.getWorld().getBlockAt(l);
- if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.TRAPPED_CHEST|| b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.CHEST){
- final Chest block = (Chest)b.getState();
- try{
- block.getInventory().setContents(i);
- block.update();
- }catch(IllegalArgumentException e){
- int iii=0;
- for(int ii=0; ii<block.getInventory().getSize(); ii++){
- block.getInventory().addItem(i[ii]);
- iii=ii;
- }
- for(int ii=0; ii<iii; ii++){
- l.getWorld().dropItem(l, i[ii]);
- }
- }
- }
- if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.FURNACE||
- b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.BURNING_FURNACE){
- final Furnace block = (Furnace)b.getState();
- block.getInventory().setContents(i);
- block.update();
- }
- if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.DROPPER){
- final Dropper block = (Dropper)b.getState();
- block.getInventory().setContents(i);
- block.update();
- }
- if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.DISPENSER){
- final Dispenser block = (Dispenser)b.getState();
- block.getInventory().setContents(i);
- block.update();
- }
- if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.HOPPER){
- final Hopper block = (Hopper)b.getState();
- block.getInventory().setContents(i);
- block.update();
- }
- if(b.getLocation().getWorld().getBlockAt(b.getLocation()).getType()==Material.BEACON){
- final Beacon block = (Beacon)b.getState();
- block.getInventory().setContents(i);
- block.update();
- }
- }
- }
- /**
- * ReSet Lines of all Signs
- */
- private static void setLines(){
- for(Location l : lines.keySet()){
- String[] s = lines.get(l);
- if(l.getWorld().getBlockAt(l).getType()==Material.SIGN||
- l.getWorld().getBlockAt(l).getType()==Material.WALL_SIGN||
- l.getWorld().getBlockAt(l).getType()==Material.SIGN_POST){
- Sign sign = (Sign)l.getBlock().getState();
- sign.setLine(0, s[0]);
- sign.setLine(1, s[1]);
- sign.setLine(2, s[2]);
- sign.setLine(3, s[3]);
- sign.update();
- }
- }
- }
- }
- /**
- *
- * @author © Luis Falkenhan || ToxicCSN00B<p><b>Das entfernen dieser Auskommentierung, sowie allgemein das verändern dieser Klasse ist untersagt!</b>
- *
- * @category <b>Bukkit |=> Explosion Manager || SubClass [Explosion]</b>
- *
- * @important <b>You'll never use this Class</b>
- */
- public static class Explosion{
- public Location loc;
- public float yield;
- public boolean regBlocks;
- public boolean bounce;
- public float radius;
- public long timer;
- /**
- *
- * @param loc = Location
- * @param yield = Yield of the Explosion
- * @param regBlocks = Regenerate Blocks after Explosion
- * @param bounce = Bounce Blocks after Explosion
- * @param radius = Explosion Radius
- * @param timer = Regenerate Timer between blocks (normal is 6)
- * @return New instance of Explosion with initialized variables
- */
- public Explosion(Location loc, float yield, boolean regBlocks, boolean bounce, float radius, long timer){
- this.loc=loc;
- this.yield=yield;
- this.regBlocks=regBlocks;
- this.bounce=bounce;
- this.radius=radius;
- this.timer=timer;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement