From 3c57e9e48fe8e1716034934de3b2349121229633 Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Mon, 7 Jul 2025 03:42:21 -0400 Subject: Allow for fireballs to have a power level dictating their yield --- .../net/cflems/mc/sandbox/commands/Fireball.java | 27 +++++++++++++++++++--- src/main/resources/plugin.yml | 7 ++++-- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/java/net/cflems/mc/sandbox/commands/Fireball.java b/src/main/java/net/cflems/mc/sandbox/commands/Fireball.java index 47f5e0c..049c554 100644 --- a/src/main/java/net/cflems/mc/sandbox/commands/Fireball.java +++ b/src/main/java/net/cflems/mc/sandbox/commands/Fireball.java @@ -4,17 +4,18 @@ import net.cflems.mc.sandbox.CommandUtils; import net.cflems.mc.sandbox.Sandbox; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; public final class Fireball implements CommandExecutor { private static final String PERMISSION = Sandbox.PERMISSION_NAMESPACE + ".fireball"; + private static final String CUSTOM_PERMISSION = PERMISSION + ".custom"; + private static final float DEFAULT_POWER = 5.0f; @SuppressWarnings("NullableProblems") @Override public boolean onCommand( CommandSender sender, org.bukkit.command.Command _command, String _label, String[] args) { - if (args.length > 0) return false; + if (args.length > 1) return false; if (!(sender instanceof Player player)) { CommandUtils.respond(sender, "Only players can use fireballs."); return true; @@ -23,7 +24,27 @@ public final class Fireball implements CommandExecutor { CommandUtils.respond(sender, "You do not have permission to use fireballs."); return true; } - player.getWorld().spawnEntity(player.getEyeLocation().subtract(0, 1, 0), EntityType.FIREBALL); + + float yield = DEFAULT_POWER; + if (args.length > 0) { + if (!sender.hasPermission(CUSTOM_PERMISSION)) { + CommandUtils.respond( + sender, "You do not have permission to use fireballs of custom power."); + return true; + } + try { + yield = Float.parseFloat(args[0]); + } catch (NumberFormatException _e) { + yield = -1.0f; + } + } + if (yield < 0.0f) { + CommandUtils.respond(sender, "Fireball power must be a non-negative decimal number."); + return true; + } + + org.bukkit.entity.Fireball fireball = player.launchProjectile(org.bukkit.entity.Fireball.class); + fireball.setYield(yield); return true; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ec4a04a..3011fe1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -18,8 +18,8 @@ commands: usage: /repair [player] description: Repairs the item in your main hand. fireball: - usage: /fireball - description: Shoots a fireball. + usage: /fireball [power] + description: Shoots a fireball, optionally with the desired power. powertool: aliases: [ "pt" ] usage: /powertool [command...] @@ -36,6 +36,7 @@ permissions: sandbox.fly: true sandbox.fly.others: true sandbox.fireball: true + sandbox.fireball.custom: true sandbox.powertool: true sandbox.powertool.use: true sandbox.powertool.reload: true @@ -53,6 +54,8 @@ permissions: description: Permission to repair other people's items. sandbox.fireball: description: Permission to use fireballs. + sandbox.fireball.custom: + description: Permission to use fireballs with custom power. sandbox.powertool: description: Permission to modify power tools. sandbox.powertool.use: -- cgit v1.2.3