From 26d0756960a2a32fe2cc90e563b2e639cdd01768 Mon Sep 17 00:00:00 2001 From: heyxmirko Date: Thu, 9 May 2024 09:38:38 +0200 Subject: [PATCH] feat: Add a new `flightDuration` option in the config.yml --- pom.xml | 2 +- .../commands/CommandHandler.java | 19 +++++++++++++++---- .../imagefireworkspro/core/ImageFirework.java | 10 +++++++++- .../imagefireworkspro/util/ConfigManager.java | 7 +++---- src/main/resources/config.yml | 5 +++-- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 2618299..531fcfa 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.lukyn76 ImageFireworksPro - 1.1.4 + 1.1.5 jar ImageFireworksPro diff --git a/src/main/java/me/lukyn76/imagefireworkspro/commands/CommandHandler.java b/src/main/java/me/lukyn76/imagefireworkspro/commands/CommandHandler.java index 459913b..09f1345 100644 --- a/src/main/java/me/lukyn76/imagefireworkspro/commands/CommandHandler.java +++ b/src/main/java/me/lukyn76/imagefireworkspro/commands/CommandHandler.java @@ -4,6 +4,8 @@ import me.lukyn76.imagefireworkspro.core.ImageFirework; import me.lukyn76.imagefireworkspro.util.ConfigManager; import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.FireworkEffect; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -11,7 +13,7 @@ import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.FireworkMeta; import java.util.ArrayList; import java.util.List; @@ -43,17 +45,26 @@ public boolean onCommand(CommandSender sender, Command command, String s, String ImageFirework imageFirework = ConfigManager.getImageFirework(fireworkName); if (imageFirework != null) { - - // Give firework int amount = 1; if (args.length == 4) { amount = Integer.parseInt(args[3]); } ItemStack firework = new ItemStack(Material.FIREWORK_ROCKET, amount); - ItemMeta fireworkMeta = firework.getItemMeta(); + FireworkMeta fireworkMeta = (FireworkMeta) firework.getItemMeta(); fireworkMeta.setDisplayName(imageFirework.getName()); fireworkMeta.setCustomModelData(imageFirework.getCustomModelData()); + + FireworkEffect effect = FireworkEffect.builder() + .with(FireworkEffect.Type.BURST) + .withColor(Color.BLACK) + .build(); + fireworkMeta.addEffect(effect); + + if (imageFirework.getFlightDuration() > 0) { + fireworkMeta.setPower(imageFirework.getFlightDuration()); + } + firework.setItemMeta(fireworkMeta); player.getInventory().addItem(firework); diff --git a/src/main/java/me/lukyn76/imagefireworkspro/core/ImageFirework.java b/src/main/java/me/lukyn76/imagefireworkspro/core/ImageFirework.java index eb48049..b744095 100644 --- a/src/main/java/me/lukyn76/imagefireworkspro/core/ImageFirework.java +++ b/src/main/java/me/lukyn76/imagefireworkspro/core/ImageFirework.java @@ -16,6 +16,7 @@ public class ImageFirework { private String imageName; private int customModelData; private int displayTime; + private int flightDuration; public String getName() { @@ -50,8 +51,15 @@ public void setDisplayTime(int displayTime) { this.displayTime = displayTime; } + public int getFlightDuration() { + return flightDuration; + } + + public void setFlightDuration(int flightDuration) { + this.flightDuration = flightDuration; + } + public void explode(Location location, double yawRotation) throws IOException { - location.getWorld().playSound(location, Sound.ENTITY_FIREWORK_ROCKET_BLAST_FAR, 10F, 1F); displayImage(location, yawRotation); } diff --git a/src/main/java/me/lukyn76/imagefireworkspro/util/ConfigManager.java b/src/main/java/me/lukyn76/imagefireworkspro/util/ConfigManager.java index 33ee11a..25e233c 100644 --- a/src/main/java/me/lukyn76/imagefireworkspro/util/ConfigManager.java +++ b/src/main/java/me/lukyn76/imagefireworkspro/util/ConfigManager.java @@ -2,9 +2,9 @@ import me.lukyn76.imagefireworkspro.ImageFireworksPro; import me.lukyn76.imagefireworkspro.core.ImageFirework; +import org.bukkit.Color; import org.bukkit.configuration.ConfigurationSection; -import java.util.List; import java.util.Set; public class ConfigManager { @@ -25,11 +25,9 @@ public static ImageFirework getImageFirework(int customModelData) { firework.setImageName(fireworkSection.getString("imageName")); firework.setCustomModelData(fireworkSection.getInt("customModelData")); firework.setDisplayTime(fireworkSection.getInt("displayTime", 3)); + firework.setFlightDuration(fireworkSection.getInt("flightDuration", 1)); return firework; - - // help me write a commit message under this line that I added a new option displaytime to the config - // Add a new option displayTime to the config that allows to set the display time of the firework } } return null; @@ -46,6 +44,7 @@ public static ImageFirework getImageFirework(String id) { firework.setImageName(fireworkSection.getString("imageName")); firework.setCustomModelData(fireworkSection.getInt("customModelData")); firework.setDisplayTime(fireworkSection.getInt("displayTime")); + firework.setFlightDuration(fireworkSection.getInt("flightDuration", 1)); return firework; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c790fe0..5bc2f6d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -2,5 +2,6 @@ Fireworks: dog: name: "Dog" imageName: "dog.png" - customModelData: 1000 - displayTime: 3 # in seconds \ No newline at end of file + customModelData: 1234 + flightDuration: 1 # 0-3 + displayTime: 3 # in seconds