-
Notifications
You must be signed in to change notification settings - Fork 1
/
MessagingService.java
69 lines (59 loc) · 2.27 KB
/
MessagingService.java
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
package com.github.sanctum.labyrinth.api;
import com.github.sanctum.labyrinth.annotation.FieldsFrom;
import com.github.sanctum.labyrinth.data.LabyrinthPluginChannel;
import com.github.sanctum.labyrinth.data.LabyrinthPluginMessage;
import com.github.sanctum.labyrinth.data.LabyrinthPluginMessageEvent;
import com.github.sanctum.labyrinth.data.service.Constant;
import com.github.sanctum.labyrinth.event.custom.Vent;
import com.github.sanctum.labyrinth.formatting.Message;
import com.github.sanctum.labyrinth.library.Deployable;
import com.github.sanctum.labyrinth.library.Mailer;
import com.github.sanctum.labyrinth.library.TypeFlag;
import java.util.List;
import java.util.function.IntFunction;
import java.util.stream.Collectors;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
/**
* A service for default message creation.
*/
public interface MessagingService extends Service, Message.Factory {
/**
* Get a new object for sending numerous types of displayable messages!
*
* @return A new empty mailer instance.
*/
@NotNull Mailer getEmptyMailer();
/**
* Get a new object for sending numerous types of displayable messages!
*
* @return A new empty mailer instance.
*/
@NotNull Mailer getEmptyMailer(CommandSender sender);
/**
* Get a new object for sending numerous types of displayable messages!
*
* @return A new empty mailer instance.
*/
@NotNull Mailer getEmptyMailer(Plugin plugin);
default <T> Deployable<Object> sendPluginMessage(Plugin plugin, T object) {
return sendPluginMessage(plugin, object, LabyrinthPluginChannel.DEFAULT);
}
default <T> Deployable<Object> sendPluginMessage(Plugin plugin, T object, @FieldsFrom(LabyrinthPluginChannel.class) LabyrinthPluginChannel<?> channel) {
return Deployable.of(() -> new Vent.Call<>(new LabyrinthPluginMessageEvent(new LabyrinthPluginMessage<T>() {
@Override
public Plugin getPlugin() {
return plugin;
}
@Override
public T getMessage() {
return object;
}
}, channel)).run().getResponse());
}
default LabyrinthPluginChannel<?>[] getDefaultPluginChannels() {
TypeFlag<LabyrinthPluginChannel<?>> flag = TypeFlag.get();
return Constant.values(flag.getType(), flag.getType()).toArray(new LabyrinthPluginChannel[0]);
}
}