-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPossiExamplePlugin.java
More file actions
72 lines (58 loc) · 2.13 KB
/
PossiExamplePlugin.java
File metadata and controls
72 lines (58 loc) · 2.13 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
package rip.hippo.possi.spigot.example;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import rip.hippo.possi.Property;
import rip.hippo.possi.spigot.SpigotString;
import rip.hippo.possi.spigot.source.YAMLPropertySource;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
/**
* @author Hippo
*/
public final class PossiExamplePlugin extends JavaPlugin {
private final YAMLPropertySource propertySource = new YAMLPropertySource(this);
private final Property<SpigotString> greetingProperty = Property.of(SpigotString.of("&cHello world!").color())
.withBind(propertySource.bindSpigotString("messages.greeting"));
private final Property<List<Integer>> numberProperty = Property.of(Arrays.asList(1, 2, 3, 4, 5))
.withBind(propertySource.bindIntegerList("number-list"));
@Override
public void onEnable() {
saveDefaultConfig();
propertySource.load();
Objects.requireNonNull(Bukkit.getPluginCommand("possi")).setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) {
greetingProperty.get()
.copy()
.color()
.replace("%name%", sender.getName())
.send(sender);
for (Integer integer : numberProperty.get()) {
sender.sendMessage(integer.toString());
}
return true;
}
if (args.length == 1 && args[0].equals("reload")) {
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
reloadConfig();
propertySource.load();
sender.sendMessage("Reloaded!");
});
return true;
}
StringBuilder stringBuilder = new StringBuilder();
for (String arg : args) {
stringBuilder.append(arg).append(" ");
}
String newGreeting = stringBuilder.toString().trim();
greetingProperty.set(SpigotString.of(newGreeting));
SpigotString.of("&aGreeting set to: &e" + newGreeting).color().send(sender);
Bukkit.getScheduler().runTaskAsynchronously(this, propertySource::save);
return true;
}
}