diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index 4adc397..f6982e5 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/build/libs/RocketJumping-1.2-1.21.jar b/build/libs/RocketJumping-1.2-1.21.jar new file mode 100644 index 0000000..7aba3fb Binary files /dev/null and b/build/libs/RocketJumping-1.2-1.21.jar differ diff --git a/src/main/java/org/twipnetwork/rocketJumping/RocketJumping.java b/src/main/java/org/twipnetwork/rocketJumping/RocketJumping.java index 071beb3..b17aafb 100644 --- a/src/main/java/org/twipnetwork/rocketJumping/RocketJumping.java +++ b/src/main/java/org/twipnetwork/rocketJumping/RocketJumping.java @@ -9,6 +9,8 @@ import org.bukkit.entity.Firework; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.CrossbowMeta; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -16,6 +18,7 @@ public final class RocketJumping extends JavaPlugin implements Listener { private double boostPower; private boolean damageShooter; + private boolean onlyCrossbow; @Override public void onEnable() { @@ -23,6 +26,7 @@ public final class RocketJumping extends JavaPlugin implements Listener { FileConfiguration config = getConfig(); boostPower = config.getDouble("boostPower", 4.0); damageShooter = config.getBoolean("damageShooter", false); + onlyCrossbow = config.getBoolean("onlyCrossbow", true); Bukkit.getPluginManager().registerEvents(this, this); } @@ -37,6 +41,28 @@ public final class RocketJumping extends JavaPlugin implements Listener { if (projectile instanceof Firework firework) { Entity shooter = (Entity) firework.getShooter(); + if (onlyCrossbow && shooter instanceof Player player) { + ItemStack itemInMainHand = player.getInventory().getItemInMainHand(); + ItemStack itemInOffHand = player.getInventory().getItemInOffHand(); + boolean shotFromCrossbow = false; + + if (itemInMainHand.getItemMeta() instanceof CrossbowMeta meta) { + if (meta.getChargedProjectiles().contains(firework)) { + shotFromCrossbow = true; + } + } + + if (itemInOffHand.getItemMeta() instanceof CrossbowMeta meta) { + if (meta.getChargedProjectiles().contains(firework)) { + shotFromCrossbow = true; + } + } + + if (!shotFromCrossbow) { + return; + } + } + for (Entity entity : firework.getNearbyEntities(5, 5, 5)) { if (entity instanceof Player player) { Vector boostDirection = player.getLocation().toVector().subtract(firework.getLocation().toVector()).normalize(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 47b5238..e1e7ceb 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,4 +3,7 @@ boostPower: 4.0 # damageShooter defines whether the shooter gets damages by their own fireworks (default: false) -damageShooter: false \ No newline at end of file +damageShooter: false + +# onlyCrossbow defines whether the only fireworks shot from a crossbow should launch entities or if all fireworks (default: true) +onlyCrossbow: true \ No newline at end of file