Repository navigation
Expand file tree
/
Copy pathExamplePlugin.java
More file actions
60 lines (49 loc) · 1.68 KB
/
Copy pathExamplePlugin.java
File metadata and controls
60 lines (49 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package ru.example.newplugin;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
public final class ExamplePlugin extends JavaPlugin {
@Override
public void onEnable() {
new ExampleListener(this);
}
@Override
public void onDisable() {
getLogger().info("Plugin is Disabled");
}
}
class ExampleListener implements Listener {
private final ExamplePlugin plugin;
public ExampleListener(ExamplePlugin plugin) {
this.plugin = plugin;
this.plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
BukkitTask task = new ExampleSelfCancelingTask(this.plugin, 5).runTaskTimer(this.plugin, 10, 20);
}
}
class ExampleSelfCancelingTask extends BukkitRunnable {
private final JavaPlugin plugin;
private int counter;
public ExampleSelfCancelingTask(JavaPlugin plugin, int counter) {
this.plugin = plugin;
if (counter <= 0) {
throw new IllegalArgumentException("counter must be greater than 0");
} else {
this.counter = counter;
}
}
@Override
public void run() {
if (counter > 0) {
plugin.getServer().broadcastMessage("Commence greeting in " + counter--);
} else {
plugin.getServer().broadcastMessage("Welcome to my local server on Bukkit!");
this.cancel();
}
}
}