diff --git a/src/main/java/me/lukyn76/imagefireworkspro/ImageFireworksPro.java b/src/main/java/me/lukyn76/imagefireworkspro/ImageFireworksPro.java index 93fac66..156fcb9 100644 --- a/src/main/java/me/lukyn76/imagefireworkspro/ImageFireworksPro.java +++ b/src/main/java/me/lukyn76/imagefireworkspro/ImageFireworksPro.java @@ -1,17 +1,42 @@ package me.lukyn76.imagefireworkspro; +import me.lukyn76.imagefireworkspro.listeners.FireworkExplodeListener; import org.bukkit.plugin.java.JavaPlugin; +import java.io.File; + public final class ImageFireworksPro extends JavaPlugin { + private static ImageFireworksPro instance; + @Override public void onEnable() { - // Plugin startup logic + instance = this; + createFoldersAndFiles(); + registerListeners(); + getLogger().info("Plugin has been loaded!"); } @Override public void onDisable() { - // Plugin shutdown logic + getLogger().info("Plugin has been unloaded!"); + } + + private void createFoldersAndFiles() { + saveDefaultConfig(); + if (!new File(getDataFolder(), "images").exists()) { + new File(getDataFolder(), "images").mkdir(); + } + } + + + private void registerListeners() { + getServer().getPluginManager().registerEvents(new FireworkExplodeListener(), this); + getLogger().info("Listeners registered!"); + } + + public static ImageFireworksPro getInstance() { + return instance; } } diff --git a/src/main/java/me/lukyn76/imagefireworkspro/core/ImageFirework.java b/src/main/java/me/lukyn76/imagefireworkspro/core/ImageFirework.java new file mode 100644 index 0000000..a4d6654 --- /dev/null +++ b/src/main/java/me/lukyn76/imagefireworkspro/core/ImageFirework.java @@ -0,0 +1,87 @@ +package me.lukyn76.imagefireworkspro.core; + +import me.lukyn76.imagefireworkspro.ImageFireworksPro; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.scheduler.BukkitTask; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +public class ImageFirework { + + private String name; + private String imageName; + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getImageName() { + return imageName; + } + + public void setImageName(String imageName) { + this.imageName = imageName; + } + + public void explode(Location location, double playerViewRotation) throws IOException { + displayImage(location, playerViewRotation); + } + + + + private void displayImage(Location explodeLocation, double playerViewRotation) throws IOException { + ImageFireworksPro plugin = ImageFireworksPro.getInstance(); + + File imageFile = new File(plugin.getDataFolder(), "images/"+imageName); + if (!imageFile.exists()) { + plugin.getLogger().warning("Image file not found: " + imageName); + return; + } + + + BufferedImage image = ImageIO.read(imageFile); + int width = image.getWidth(); + int height = image.getHeight(); + + double yawRadians = Math.toRadians(playerViewRotation); + + BukkitTask taskId = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> { + for(int x = 0; x < width; x++) { + for(int y = 0; y < height; y++) { + int color = image.getRGB(x, y); + int alpha = (color >> 24) & 0xff; + if(alpha != 0) { + int red = (color >> 16) & 0xff; + int green = (color >> 8) & 0xff; + int blue = color & 0xff; + + double offsetX = x / 10.0 - width / 20.0; + double offsetY = -y / 10.0 + height / 10.0 / 4.0; + double offsetZ = 0.0; + + double rotatedX = offsetX * Math.cos(yawRadians) - offsetZ * Math.sin(yawRadians); + double rotatedZ = offsetX * Math.sin(yawRadians) + offsetZ * Math.cos(yawRadians); + + Location location = explodeLocation.clone().add(rotatedX, offsetY, rotatedZ); + Particle.DustOptions dust = new Particle.DustOptions(Color.fromRGB(red, green, blue), 1); + explodeLocation.getWorld().spawnParticle(Particle.REDSTONE, location, 0, 0, 0, 0, dust); + } + } + } + }, 0L, 3L); + + Bukkit.getScheduler().runTaskLater(plugin, taskId::cancel, 3 * 20L); + + } +} diff --git a/src/main/java/me/lukyn76/imagefireworkspro/listeners/FireworkExplodeListener.java b/src/main/java/me/lukyn76/imagefireworkspro/listeners/FireworkExplodeListener.java new file mode 100644 index 0000000..b27e2f6 --- /dev/null +++ b/src/main/java/me/lukyn76/imagefireworkspro/listeners/FireworkExplodeListener.java @@ -0,0 +1,36 @@ +package me.lukyn76.imagefireworkspro.listeners; + +import me.lukyn76.imagefireworkspro.ImageFireworksPro; +import me.lukyn76.imagefireworkspro.core.ImageFirework; +import me.lukyn76.imagefireworkspro.util.ConfigManager; +import org.bukkit.Location; +import org.bukkit.entity.Firework; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.FireworkExplodeEvent; +import org.bukkit.inventory.meta.FireworkMeta; + +import java.io.IOException; + +public class FireworkExplodeListener implements Listener { + + + @EventHandler + public void onFireworkExplode(FireworkExplodeEvent event) throws IOException { + Firework firework = event.getEntity(); + FireworkMeta fireworkMeta = firework.getFireworkMeta(); + if (!fireworkMeta.hasCustomModelData()) return; + int customModelData = fireworkMeta.getCustomModelData(); + + ImageFirework imageFirework = ConfigManager.getImageFirework(customModelData); + ImageFireworksPro.getInstance().getServer().getPlayer("lukyn76").sendMessage("Firework: " + imageFirework); + if (imageFirework == null) return; + + Location explodeLocation = event.getEntity().getLocation(); + Player shooter = (Player) event.getEntity().getShooter(); + double playerViewRotation = shooter.getLocation().getYaw(); + + imageFirework.explode(explodeLocation, playerViewRotation); + } +} diff --git a/src/main/java/me/lukyn76/imagefireworkspro/util/ConfigManager.java b/src/main/java/me/lukyn76/imagefireworkspro/util/ConfigManager.java new file mode 100644 index 0000000..3d78937 --- /dev/null +++ b/src/main/java/me/lukyn76/imagefireworkspro/util/ConfigManager.java @@ -0,0 +1,29 @@ +package me.lukyn76.imagefireworkspro.util; + +import me.lukyn76.imagefireworkspro.ImageFireworksPro; +import me.lukyn76.imagefireworkspro.core.ImageFirework; +import org.bukkit.configuration.ConfigurationSection; + +public class ConfigManager { + + static ImageFireworksPro plugin = ImageFireworksPro.getInstance(); + + + public static ImageFirework getImageFirework(int customModelData) { + ConfigurationSection fireworksSection = plugin.getConfig().getConfigurationSection("Fireworks"); + if (fireworksSection == null) return null; // No fireworks configuration found + + for (String key : fireworksSection.getKeys(false)) { + ConfigurationSection fireworkSection = fireworksSection.getConfigurationSection(key); + + if (fireworkSection != null && fireworkSection.getInt("customModelData") == customModelData) { + ImageFirework firework = new ImageFirework(); + firework.setName(fireworkSection.getString("name")); + firework.setImageName(fireworkSection.getString("imageName")); + + return firework; + } + } + return null; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..ac11cbb --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,5 @@ +Fireworks: + dog: + name: "Dog" + imageName: "dog.png" + customModelData: 4444 \ No newline at end of file