├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
└── src
└── main
├── java
└── net
│ └── badlion
│ └── timers
│ ├── TimerPlugin.java
│ ├── api
│ ├── Timer.java
│ ├── TimerApi.java
│ └── TimerApiImpl.java
│ ├── impl
│ ├── NmsManager.java
│ └── TimerImpl.java
│ └── listeners
│ └── TimerListener.java
└── resources
└── plugin.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .idea/
3 | target/
4 | .project
5 | .classpath
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018-2020 ESL Gaming Online, Inc
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
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 | ```
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | net.badlion
8 | timer-api
9 | 1.2.2
10 |
11 | jar
12 |
13 |
14 |
15 | spigot-repo
16 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
17 |
18 |
19 |
20 |
21 |
22 | org.spigotmc
23 | spigot-api
24 | 1.8.8-R0.1-SNAPSHOT
25 | provided
26 |
27 |
28 |
29 |
30 | clean install
31 | badlionclienttimerapi
32 | src/main/java
33 |
34 |
35 | .
36 | true
37 | src/main/resources/
38 |
39 | *.yml
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.apache.maven.plugins
47 | maven-compiler-plugin
48 | 3.8.0
49 |
50 |
51 | 1.7
52 | 1.7
53 | UTF-8
54 |
55 |
56 |
57 |
58 | org.apache.maven.plugins
59 | maven-resources-plugin
60 | 3.1.0
61 |
62 |
63 | UTF-8
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/src/main/java/net/badlion/timers/TimerPlugin.java:
--------------------------------------------------------------------------------
1 | package net.badlion.timers;
2 |
3 | import net.badlion.timers.api.TimerApiImpl;
4 | import net.badlion.timers.impl.NmsManager;
5 | import net.badlion.timers.listeners.TimerListener;
6 | import org.bukkit.plugin.java.JavaPlugin;
7 |
8 | import java.nio.charset.Charset;
9 |
10 | public class TimerPlugin extends JavaPlugin {
11 |
12 | public static final String CHANNEL_NAME = "badlion:timers";
13 | public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8"); // Do not use Guava because of 1.7
14 |
15 | private TimerApiImpl timerApi;
16 |
17 | @Override
18 | public void onEnable() {
19 |
20 | NmsManager.init(this);
21 |
22 | this.timerApi = new TimerApiImpl(this);
23 |
24 | this.getServer().getMessenger().registerOutgoingPluginChannel(this, TimerPlugin.CHANNEL_NAME);
25 |
26 | this.getServer().getPluginManager().registerEvents(new TimerListener(this), this);
27 |
28 | this.getServer().getScheduler().runTaskTimer(this, new Runnable() {
29 | @Override
30 | public void run() {
31 | TimerPlugin.this.timerApi.tickTimers();
32 | }
33 | }, 1L, 1L);
34 |
35 | this.getServer().getScheduler().runTaskTimer(this, new Runnable() {
36 | @Override
37 | public void run() {
38 | TimerPlugin.this.timerApi.syncTimers();
39 | }
40 | }, 60L, 60L);
41 | }
42 |
43 | @Override
44 | public void onDisable() {
45 |
46 | }
47 |
48 | public TimerApiImpl getTimerApi() {
49 | return this.timerApi;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/net/badlion/timers/api/Timer.java:
--------------------------------------------------------------------------------
1 | package net.badlion.timers.api;
2 |
3 | import org.bukkit.entity.Player;
4 | import org.bukkit.inventory.ItemStack;
5 |
6 | import java.util.Collection;
7 | import java.util.concurrent.TimeUnit;
8 |
9 | public interface Timer {
10 |
11 | // Getters and setters
12 |
13 | /**
14 | * Get the timer's id
15 | *
16 | * @return Id as unique long value
17 | */
18 | long getId();
19 |
20 | /**
21 | * Get the timer's name
22 | *
23 | * @return Name as string
24 | */
25 | String getName();
26 |
27 | /**
28 | * Set the timer's name
29 | * Will be the text displayed in the client
30 | *
31 | * @param name Name as string
32 | */
33 | void setName(String name);
34 |
35 | /**
36 | * Get the item displayed in the client
37 | *
38 | * @return Item as a Bukkit ItemStack
39 | */
40 | ItemStack getItem();
41 |
42 | /**
43 | * Set the item displayed in the client
44 | * Cannot be a null value
45 | *
46 | * Note : Item metas are currently not implemented,
47 | * but enchantments should work fine
48 | *
49 | * @param item Item as a Bukkit ItemStack
50 | */
51 | void setItem(ItemStack item);
52 |
53 | /**
54 | * Get if the timer is repeating or not
55 | *
56 | * @return Repeating value as a boolean
57 | */
58 | boolean isRepeating();
59 |
60 | /**
61 | * Set whether the timer should repeat when reaching 0 or not
62 | *
63 | * @param repeating {@code true} if repeating, {@code false} otherwise
64 | */
65 | void setRepeating(boolean repeating);
66 |
67 | /**
68 | * Get the timer countdown time
69 | *
70 | * @return Timer countdown time as a long number of ticks
71 | */
72 | long getTime();
73 |
74 | /**
75 | * Set the timer countdown time
76 | * Note : This implies a call to {@link Timer#reset()}
77 | *
78 | * @param time Timer countdown time as a long number of ticks
79 | */
80 | void setTime(long time);
81 |
82 | /**
83 | * Get the timer countdown time
84 | *
85 | * @return Timer countdown time in milliseconds
86 | */
87 | long getMillis();
88 |
89 | /**
90 | * Set the timer countdown time
91 | * Note : This implies a call to {@link Timer#reset()}
92 | *
93 | * @param time Timer countdown time
94 | * @param timeUnit Timer countdown time unit
95 | */
96 | void setTime(long time, TimeUnit timeUnit);
97 |
98 | // Player functions
99 |
100 | /**
101 | * Add a receiver to the timer
102 | * Note : A disconnecting player will automatically
103 | * be removed from the timer
104 | *
105 | * @param player Player instance to add
106 | */
107 | void addReceiver(Player player);
108 |
109 | /**
110 | * Manually remove a receiver form the timer
111 | *
112 | * @param player Player instance to remove
113 | */
114 | void removeReceiver(Player player);
115 |
116 | /**
117 | * Clear all players receiving this timer
118 | */
119 | void clearReceivers();
120 |
121 | /**
122 | * Get all the players that are receiving this timer
123 | *
124 | * @return Collection of receivers as a thread-safe collection
125 | */
126 | Collection getReceivers();
127 |
128 | // Other functions
129 |
130 | /**
131 | * Reset the current countdown to the {@link Timer#getTime()} value
132 | */
133 | void reset();
134 | }
135 |
--------------------------------------------------------------------------------
/src/main/java/net/badlion/timers/api/TimerApi.java:
--------------------------------------------------------------------------------
1 | package net.badlion.timers.api;
2 |
3 | import org.bukkit.entity.Player;
4 | import org.bukkit.inventory.ItemStack;
5 |
6 | import java.util.concurrent.TimeUnit;
7 |
8 | public abstract class TimerApi {
9 | static TimerApi instance;
10 |
11 | /**
12 | * Get the API instance.
13 | *
14 | * @return The API instance
15 | */
16 | public static TimerApi getInstance() {
17 | return TimerApi.instance;
18 | }
19 |
20 | /**
21 | * Create a new timer and register it into the API.
22 | *
23 | * A timer will automatically handle synchronizing with its receivers,
24 | * and will repeat itself if it's mark as repeating. If not, it'll be
25 | * automatically removed from the API.
26 | *
27 | * @param item Item to show in the client
28 | * @param repeating {@code true} if the timer is repeating, {@code false} otherwise
29 | * @param time Countdown time, in ticks (20 per seconds)
30 | * @return The new timer instance
31 | */
32 | public abstract Timer createTickTimer(ItemStack item, boolean repeating, long time);
33 |
34 | /**
35 | * Create a new timer and register it into the API.
36 | *
37 | * A timer will automatically handle synchronizing with its receivers,
38 | * and will repeat itself if it's mark as repeating. If not, it'll be
39 | * automatically removed from the API.
40 | *
41 | * @param name Name to show in the client
42 | * @param item Item to show in the client
43 | * @param repeating {@code true} if the timer is repeating, {@code false} otherwise
44 | * @param time Countdown time, in ticks (20 per seconds)
45 | * @return The new timer instance
46 | */
47 | public abstract Timer createTickTimer(String name, ItemStack item, boolean repeating, long time);
48 |
49 | /**
50 | * Create a new timer and register it into the API.
51 | *
52 | * A timer will automatically handle synchronizing with its receivers,
53 | * and will repeat itself if it's mark as repeating. If not, it'll be
54 | * automatically removed from the API.
55 | *
56 | * @param item Item to show in the client
57 | * @param repeating {@code true} if the timer is repeating, {@code false} otherwise
58 | * @param time Countdown time
59 | * @param timeUnit Countdown time unit
60 | * @return The new timer instance
61 | */
62 | public abstract Timer createTimeTimer(ItemStack item, boolean repeating, long time, TimeUnit timeUnit);
63 |
64 | /**
65 | * Create a new timer and register it into the API.
66 | *