added a crossbow check

This commit is contained in:
Richard Mikloš 2024-07-27 14:23:20 +02:00
parent 745c7df193
commit fc9378f422
5 changed files with 31 additions and 1 deletions

1
.gitignore vendored Normal file

@ -0,0 +1 @@
build

Binary file not shown.

Binary file not shown.

@ -9,6 +9,8 @@ import org.bukkit.entity.Firework;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileHitEvent; 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.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -16,6 +18,7 @@ public final class RocketJumping extends JavaPlugin implements Listener {
private double boostPower; private double boostPower;
private boolean damageShooter; private boolean damageShooter;
private boolean onlyCrossbow;
@Override @Override
public void onEnable() { public void onEnable() {
@ -23,6 +26,7 @@ public final class RocketJumping extends JavaPlugin implements Listener {
FileConfiguration config = getConfig(); FileConfiguration config = getConfig();
boostPower = config.getDouble("boostPower", 4.0); boostPower = config.getDouble("boostPower", 4.0);
damageShooter = config.getBoolean("damageShooter", false); damageShooter = config.getBoolean("damageShooter", false);
onlyCrossbow = config.getBoolean("onlyCrossbow", true);
Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(this, this);
} }
@ -37,6 +41,28 @@ public final class RocketJumping extends JavaPlugin implements Listener {
if (projectile instanceof Firework firework) { if (projectile instanceof Firework firework) {
Entity shooter = (Entity) firework.getShooter(); 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)) { for (Entity entity : firework.getNearbyEntities(5, 5, 5)) {
if (entity instanceof Player player) { if (entity instanceof Player player) {
Vector boostDirection = player.getLocation().toVector().subtract(firework.getLocation().toVector()).normalize(); Vector boostDirection = player.getLocation().toVector().subtract(firework.getLocation().toVector()).normalize();

@ -3,4 +3,7 @@
boostPower: 4.0 boostPower: 4.0
# damageShooter defines whether the shooter gets damages by their own fireworks (default: false) # damageShooter defines whether the shooter gets damages by their own fireworks (default: false)
damageShooter: false damageShooter: false
# onlyCrossbow defines whether the only fireworks shot from a crossbow should launch entities or if all fireworks (default: true)
onlyCrossbow: true