diff --git a/README.md b/README.md index 96a50f9..cd067aa 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ MBedwarsTweaks offers a large amount extra configuration, here are just a few tw - Explosive fall damage multiplier - Fireball block break whitelist - Fireball throw cool down and effects +- TNT Countdown Hologram #### 5. Spawner Configs - Prevent spawner pickup when AFK diff --git a/src/main/java/me/metallicgoat/tweaksaddon/MBedwarsTweaksAddon.java b/src/main/java/me/metallicgoat/tweaksaddon/MBedwarsTweaksAddon.java index 3d71f56..5191964 100644 --- a/src/main/java/me/metallicgoat/tweaksaddon/MBedwarsTweaksAddon.java +++ b/src/main/java/me/metallicgoat/tweaksaddon/MBedwarsTweaksAddon.java @@ -66,6 +66,7 @@ public void registerEvents() { manager.registerEvents(new FireballBlockBreakWhitelist(), plugin); manager.registerEvents(new FireballThrowEffects(), plugin); manager.registerEvents(new FireballUseCoolDown(), plugin); + manager.registerEvents(new TNTIgniteCountdown(), plugin); // Messages manager.registerEvents(new BuyMessage(), plugin); @@ -84,6 +85,7 @@ public void registerEvents() { manager.registerEvents(new PlayerLimitBypass(), plugin); manager.registerEvents(new RemoveInvisOnDamage(), plugin); manager.registerEvents(new SpecialItemCooldown(), plugin); + //manager.registerEvents(new TieBreaker(), plugin); // Spawners manager.registerEvents(new AFKSpawners(), plugin); diff --git a/src/main/java/me/metallicgoat/tweaksaddon/config/MainConfig.java b/src/main/java/me/metallicgoat/tweaksaddon/config/MainConfig.java index cde91d9..717a495 100644 --- a/src/main/java/me/metallicgoat/tweaksaddon/config/MainConfig.java +++ b/src/main/java/me/metallicgoat/tweaksaddon/config/MainConfig.java @@ -221,6 +221,15 @@ public class MainConfig { public static double tnt_fall_damage_multiplier = 1; @Config public static double fireball_fall_damage_multiplier = 1; + @Config( + description = { + "If enabled, TNT will display a countdown timer when ignited", + } + ) + public static boolean tnt_ignite_timer_enabled = false; + @Config public static String tnt_ignite_timer_title = "&c{seconds}"; + + // ===== MESSAGES @SectionTitle(title = "MESSAGES") @@ -346,6 +355,7 @@ public class MainConfig { @Config public static double lock_team_chest_range = 8; @Config public static String lock_team_chest_fail_open = "&cYou cannot open this chest until {team} &chas been eliminated."; + // MISCELLANEOUS @SectionTitle(title = "MISCELLANEOUS") diff --git a/src/main/java/me/metallicgoat/tweaksaddon/tweaks/explosives/TNTIgniteCountdown.java b/src/main/java/me/metallicgoat/tweaksaddon/tweaks/explosives/TNTIgniteCountdown.java new file mode 100644 index 0000000..1d1665f --- /dev/null +++ b/src/main/java/me/metallicgoat/tweaksaddon/tweaks/explosives/TNTIgniteCountdown.java @@ -0,0 +1,46 @@ +package me.metallicgoat.tweaksaddon.tweaks.explosives; + +import de.marcely.bedwars.api.message.Message; +import java.text.DecimalFormat; +import me.metallicgoat.tweaksaddon.MBedwarsTweaksPlugin; +import me.metallicgoat.tweaksaddon.config.MainConfig; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.scheduler.BukkitRunnable; + +public class TNTIgniteCountdown implements Listener { + + private static final DecimalFormat decimalFormat = new DecimalFormat("0.00"); + + // Place a countdown on TNT when it is ignited + @EventHandler + public void onEntitySpawnEvent(EntitySpawnEvent event) { + if (!MainConfig.tnt_ignite_timer_enabled || event.getEntity().getType() != EntityType.PRIMED_TNT) + return; + + final TNTPrimed entity = (TNTPrimed) event.getEntity(); + + entity.setCustomNameVisible(true); + + final BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + if (!entity.isValid() || entity.getFuseTicks() <= 0) { + cancel(); + return; + } + + // Second to two decimal places + final double seconds = ((double) entity.getFuseTicks()) / 20D; + final String secondsString = decimalFormat.format(seconds); + + entity.setCustomName(Message.build(MainConfig.tnt_ignite_timer_title).placeholder("seconds", secondsString).done()); + } + }; + + runnable.runTaskTimer(MBedwarsTweaksPlugin.getInstance(), 0L, 1L); + } +}