Skip to content

Commit

Permalink
Add TNT countdown timer
Browse files Browse the repository at this point in the history
  • Loading branch information
MetallicGoat committed Dec 19, 2024
1 parent df6e83c commit 9f61c54
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/me/metallicgoat/tweaksaddon/config/MainConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 9f61c54

Please sign in to comment.