-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df6e83c
commit 9f61c54
Showing
4 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/me/metallicgoat/tweaksaddon/tweaks/explosives/TNTIgniteCountdown.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |