diff --git a/.classpath b/.classpath index 728d38d..9eb919a 100644 --- a/.classpath +++ b/.classpath @@ -5,5 +5,6 @@ + diff --git a/bin/CrunchProjectiles/ExplosiveProjectile.class b/bin/CrunchProjectiles/ExplosiveProjectile.class index 7a2b03d..9da3950 100644 Binary files a/bin/CrunchProjectiles/ExplosiveProjectile.class and b/bin/CrunchProjectiles/ExplosiveProjectile.class differ diff --git a/bin/siegeCore/ClickHandler.class b/bin/siegeCore/ClickHandler.class index 221ef49..809fe07 100644 Binary files a/bin/siegeCore/ClickHandler.class and b/bin/siegeCore/ClickHandler.class differ diff --git a/bin/siegeCore/CrunchSiegeCore$SiegeCommand.class b/bin/siegeCore/CrunchSiegeCore$SiegeCommand.class index 70dad1c..784531f 100644 Binary files a/bin/siegeCore/CrunchSiegeCore$SiegeCommand.class and b/bin/siegeCore/CrunchSiegeCore$SiegeCommand.class differ diff --git a/bin/siegeCore/CrunchSiegeCore.class b/bin/siegeCore/CrunchSiegeCore.class index 37350fd..e86ad05 100644 Binary files a/bin/siegeCore/CrunchSiegeCore.class and b/bin/siegeCore/CrunchSiegeCore.class differ diff --git a/src/CrunchProjectiles/ExplosiveProjectile.java b/src/CrunchProjectiles/ExplosiveProjectile.java index a9e83c3..0d7b902 100644 --- a/src/CrunchProjectiles/ExplosiveProjectile.java +++ b/src/CrunchProjectiles/ExplosiveProjectile.java @@ -21,6 +21,9 @@ import siegeCore.CrunchSiegeCore; public class ExplosiveProjectile implements CrunchProjectile { public String ProjectileType = "Explosive"; + public Boolean PlaceBlocks = false; + public Material BlockToPlace = Material.COBWEB; + public int BlocksToPlaceAmount = 3; public int ExplodePower = 2; public float Inaccuracy = 0.3f; public int ProjectilesCount = 1; diff --git a/src/siegeCore/ClickHandler.java b/src/siegeCore/ClickHandler.java index 680c86d..65a5931 100644 --- a/src/siegeCore/ClickHandler.java +++ b/src/siegeCore/ClickHandler.java @@ -35,6 +35,7 @@ import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -48,6 +49,10 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.EulerAngle; +import com.palmergames.bukkit.towny.TownyAPI; +import com.palmergames.bukkit.towny.event.actions.TownyDestroyEvent; +import com.palmergames.bukkit.towny.object.TownBlock; + import CrunchProjectiles.ExplosiveProjectile; public class ClickHandler implements Listener { @@ -65,16 +70,58 @@ public class ClickHandler implements Listener { World world = event.getEntity().getWorld(); // world.createExplosion(loc, proj.Radius, proj.DoFire); Entity tnt = event.getEntity().getWorld().spawnEntity(loc, EntityType.PRIMED_TNT); - TNTPrimed tntEnt = (TNTPrimed) tnt; - tntEnt.setYield(proj.ExplodePower); - tntEnt.setFuseTicks(0); - - - + projectiles.remove(event.getEntity().getUniqueId()); + + if (proj.PlaceBlocks) { + TNTPrimed tntEnt = (TNTPrimed) tnt; + tntEnt.setYield(1); + tntEnt.setFuseTicks(0); + if (CrunchSiegeCore.towny != null) { + TownBlock block = TownyAPI.getInstance().getTownBlock(loc); + if (block != null) { + if (block.hasTown()) { + if (!block.getTownBlockOwner().getPermissions().explosion) { + return; + } + } + } + List Blocks = sphere(loc, proj.ExplodePower); + for (int i = 0; i < proj.BlocksToPlaceAmount; i++) { + Block replace = getRandomElement(Blocks); + replace.setType(Material.COBWEB); + } + } + } + else { + TNTPrimed tntEnt = (TNTPrimed) tnt; + tntEnt.setYield(proj.ExplodePower); + tntEnt.setFuseTicks(0); + } + } } + public ArrayList sphere(final Location center, final int radius) { + ArrayList sphere = new ArrayList(); + for (int Y = -radius; Y < radius; Y++) + for (int X = -radius; X < radius; X++) + for (int Z = -radius; Z < radius; Z++) + if (Math.sqrt((X * X) + (Y * Y) + (Z * Z)) <= radius) { + final Block block = center.getWorld().getBlockAt(X + center.getBlockX(), Y + center.getBlockY(), Z + center.getBlockZ()); + if (block.getType() == Material.AIR) { + sphere.add(block); + } + } + return sphere; + } + + public Block getRandomElement(List list) + { + Random rand = new Random(); + return list.get(rand.nextInt(list.size())); + } + @EventHandler(priority = EventPriority.HIGHEST) public void BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent event) { Player thePlayer = event.getPlayer(); @@ -341,27 +388,27 @@ public class ClickHandler implements Listener { if (ent.isDead()) { continue; } - + SiegeEquipment equipment = CrunchSiegeCore.equipment.get(ent.getUniqueId()); if (equipment != null) { equipment.LoadFuel(player); } } } - + public void LoadCannonsWithProjectile(Player player, ItemStack projectile) { for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) { if (ent.isDead()) { continue; } - + SiegeEquipment equipment = CrunchSiegeCore.equipment.get(ent.getUniqueId()); if (equipment != null) { equipment.LoadProjectile(player, projectile); } } } - + @EventHandler public void onPlayerClickSign(PlayerInteractEvent event){ Player player = event.getPlayer(); @@ -393,13 +440,13 @@ public class ClickHandler implements Listener { if (itemInHand == null) { return; } - - + + LoadCannonsWithProjectile(player, player.getInventory().getItemInMainHand()); return; } } - + if(sign.getLine(0).equalsIgnoreCase( "[Aim]")){ if (!CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) { return; diff --git a/src/siegeCore/CrunchSiegeCore.java b/src/siegeCore/CrunchSiegeCore.java index 7f8e706..bed5f34 100644 --- a/src/siegeCore/CrunchSiegeCore.java +++ b/src/siegeCore/CrunchSiegeCore.java @@ -50,6 +50,9 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; +import com.comphenix.protocol.wrappers.EnumWrappers.Direction; +import com.palmergames.bukkit.towny.Towny; + import CrunchProjectiles.EntityProjectile; import CrunchProjectiles.CrunchProjectile; import CrunchProjectiles.ExplosiveProjectile; @@ -61,6 +64,7 @@ public class CrunchSiegeCore extends JavaPlugin { public static Random random = new Random(); private static String Path; + public static Towny towny; @SuppressWarnings("deprecation") @Override @@ -101,6 +105,7 @@ public class CrunchSiegeCore extends JavaPlugin { DefinedEquipment.clear(); } LoadConfigs(); + towny = (Towny) Bukkit.getServer().getPluginManager().getPlugin("Towny"); } public static void LoadConfigs() { @@ -299,7 +304,8 @@ public class CrunchSiegeCore extends JavaPlugin { } l.setY(l.getY() + 1); l.setY(l.getY() + equip.PlacementOffsetY); - l.setDirection(player.getLocation().getDirection()); + l.setDirection(player.getFacing().getDirection()); + Entity entity2 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND); ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); @@ -313,10 +319,11 @@ public class CrunchSiegeCore extends JavaPlugin { meta.setLore(Lore); item.setItemMeta(meta); - + LivingEntity ent = (LivingEntity) entity2; ArmorStand stand = (ArmorStand) ent; equip.Entity = entity2; + equip.EntityId = entity2.getUniqueId(); stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING); stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING);