Skip to content

Commit

Permalink
feat: Add a new flightDuration option in the config.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
heyxmirko committed May 9, 2024
1 parent 6f0e9df commit 26d0756
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.lukyn76</groupId>
<artifactId>ImageFireworksPro</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
<packaging>jar</packaging>

<name>ImageFireworksPro</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
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;
import org.bukkit.command.CommandSender;
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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ImageFirework {
private String imageName;
private int customModelData;
private int displayTime;
private int flightDuration;


public String getName() {
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ Fireworks:
dog:
name: "Dog"
imageName: "dog.png"
customModelData: 1000
displayTime: 3 # in seconds
customModelData: 1234
flightDuration: 1 # 0-3
displayTime: 3 # in seconds

0 comments on commit 26d0756

Please sign in to comment.