forked from Nukkit/ExamplePlugin
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathExamplePlugin.java
More file actions
76 lines (63 loc) · 2.4 KB
/
ExamplePlugin.java
File metadata and controls
76 lines (63 loc) · 2.4 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package cn.nukkit.exampleplugin;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.Config;
import cn.nukkit.utils.TextFormat;
import cn.nukkit.utils.Utils;
import java.io.File;
import java.io.IOException;
import java.util.LinkedHashMap;
/**
* author: MagicDroidX
* NukkitExamplePlugin Project
*/
public class ExamplePlugin extends PluginBase {
@Override
public void onLoad() {
this.getLogger().info(TextFormat.WHITE + "I've been loaded!");
}
@Override
public void onEnable() {
this.getLogger().info(TextFormat.DARK_GREEN + "I've been enabled!");
this.getLogger().info(String.valueOf(this.getDataFolder().mkdirs()));
//Register the EventListener
this.getServer().getPluginManager().registerEvents(new EventListener(this), this);
//PluginTask
this.getServer().getScheduler().scheduleRepeatingTask(new BroadcastPluginTask(this), 200);
//Save resources
this.saveResource("string.txt");
//Config reading and writing
Config config = new Config(
new File(this.getDataFolder(), "config.yml"),
Config.YAML,
//Default values (not necessary)
new LinkedHashMap<String, Object>() {
{
put("this-is-a-key", "Hello! Config!");
put("another-key", true); //you can also put other standard objects!
}
});
//Now try to get the value, the default value will be given if the key isn't exist!
this.getLogger().info(String.valueOf(config.get("this-is-a-key", "this-is-default-value")));
//Don't forget to save it!
config.save();
}
@Override
public void onDisable() {
this.getLogger().info(TextFormat.DARK_RED + "I've been disabled!");
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (command.getName().toLowerCase()) {
case "example":
try {
this.getLogger().info(Utils.readFile(new File(this.getDataFolder(), "string.txt")) + " " + sender.getName());
} catch (IOException e) {
throw new RuntimeException(e);
}
break;
}
return true;
}
}