|
| 1 | +# Badlion Client Timer API |
| 2 | + |
| 3 | +This repository explains how to use Badlion Client Timer Api. |
| 4 | + |
| 5 | +It allows the server to display timers in the Badlion Client. |
| 6 | +This plugin is an API and you need to call it from your own plugins for it to work. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +### Installation |
| 11 | + |
| 12 | +How to install the Badlion Client Timer API on your server. |
| 13 | + |
| 14 | +#### Quick Installation |
| 15 | + |
| 16 | +1. Download the latest bukkit plugin from our releases : https://github.com/BadlionNetwork/BadlionClientTimerAPI/releases |
| 17 | +2. Place the downloaded plugin into your `plugins` directory on your server. |
| 18 | +3. Turn on the Bukkit server |
| 19 | + |
| 20 | +### API Usage |
| 21 | + |
| 22 | +Below is an example plugin with the four different timers types implemented. |
| 23 | + |
| 24 | +```java |
| 25 | +import net.badlion.timers.api.Timer; |
| 26 | +import net.badlion.timers.api.TimerApi; |
| 27 | +import org.bukkit.Material; |
| 28 | +import org.bukkit.event.EventHandler; |
| 29 | +import org.bukkit.event.Listener; |
| 30 | +import org.bukkit.event.player.PlayerJoinEvent; |
| 31 | +import org.bukkit.event.player.PlayerQuitEvent; |
| 32 | +import org.bukkit.inventory.ItemStack; |
| 33 | +import org.bukkit.plugin.java.JavaPlugin; |
| 34 | + |
| 35 | +import java.util.concurrent.TimeUnit; |
| 36 | + |
| 37 | +public class ExamplePlugin extends JavaPlugin implements Listener { |
| 38 | + |
| 39 | + private TimerApi timerApi; |
| 40 | + |
| 41 | + private Timer tickTimer; // 1 minute tick timer |
| 42 | + private Timer repeatingTickTimer; // 1 minute repeating tick timer |
| 43 | + private Timer timeTimer; // 1 minute time timer |
| 44 | + private Timer repeatingTimeTimer; // 1 minute repeating time timer |
| 45 | + |
| 46 | + @Override |
| 47 | + public void onEnable() { |
| 48 | + |
| 49 | + // Get the timer api instancce |
| 50 | + this.timerApi = TimerApi.getInstance(); |
| 51 | + |
| 52 | + // Create the timers |
| 53 | + this.tickTimer = this.timerApi.createTickTimer("Tick Timer", new ItemStack(Material.IRON_INGOT), false, 1200L); |
| 54 | + this.repeatingTickTimer = this.timerApi.createTickTimer("Repeating Tick Timer", new ItemStack(Material.GOLD_INGOT), true, 1200L); |
| 55 | + this.timeTimer = this.timerApi.createTimeTimer("Time Timer", new ItemStack(Material.DIAMOND), false, 1L, TimeUnit.MINUTES); |
| 56 | + this.repeatingTimeTimer = this.timerApi.createTimeTimer("Repeating Tick Timer", new ItemStack(Material.EMERALD), true, 1L, TimeUnit.MINUTES); |
| 57 | + |
| 58 | + // Register the listener |
| 59 | + this.getServer().getPluginManager().registerEvents(this, this); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public void onDisable() { |
| 64 | + |
| 65 | + // Remove the timers |
| 66 | + this.timerApi.removeTimer(this.tickTimer); |
| 67 | + this.timerApi.removeTimer(this.repeatingTickTimer); |
| 68 | + this.timerApi.removeTimer(this.timeTimer); |
| 69 | + this.timerApi.removeTimer(this.repeatingTimeTimer); |
| 70 | + } |
| 71 | + |
| 72 | + @EventHandler |
| 73 | + public void onLogin(PlayerJoinEvent event) { |
| 74 | + |
| 75 | + // Add the player to the timers |
| 76 | + this.tickTimer.addReceiver(event.getPlayer()); |
| 77 | + this.repeatingTickTimer.addReceiver(event.getPlayer()); |
| 78 | + this.timeTimer.addReceiver(event.getPlayer()); |
| 79 | + this.repeatingTimeTimer.addReceiver(event.getPlayer()); |
| 80 | + } |
| 81 | + |
| 82 | + @EventHandler |
| 83 | + public void onLogout(PlayerQuitEvent event) { |
| 84 | + |
| 85 | + // Remove the player from the timers |
| 86 | + this.tickTimer.removeReceiver(event.getPlayer()); |
| 87 | + this.repeatingTickTimer.removeReceiver(event.getPlayer()); |
| 88 | + this.timeTimer.removeReceiver(event.getPlayer()); |
| 89 | + this.repeatingTimeTimer.removeReceiver(event.getPlayer()); |
| 90 | + } |
| 91 | +} |
| 92 | +``` |
0 commit comments