block facing placement

This commit is contained in:
TheCrunchy committed 2023-07-29 10:34:25 +01:00
1 parent 3bea96a5fa
commit 72d3cdad85
8 files changed
+73 -15

No files matched your search

+1
View File
@@ -5,5 +5,6 @@
<classpathentry kind="lib" path="E:/4 1.19.4 test/spigot-api-1.19.4-R0.1-SNAPSHOT-shaded.jar"/>
<classpathentry kind="lib" path="E:/4 1.19.4 test/plugins/LibsDisguises-10.0.37-Free.jar"/>
<classpathentry kind="lib" path="E:/4 1.19.4 test/plugins/ProtocolLib (15).jar"/>
<classpathentry kind="lib" path="E:/4 1.19.4 test/plugins/Towny-0.99.5.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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;
+60 -13
View File
@@ -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<Block> 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<Block> sphere(final Location center, final int radius) {
ArrayList<Block> sphere = new ArrayList<Block>();
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<Block> 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;
+9 -2
View File
@@ -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);