12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package me.km.chatchannel;
- import java.util.function.BiConsumer;
- import java.util.function.Consumer;
- import java.util.function.Predicate;
- import me.km.KajetansMod;
- import net.minecraft.entity.player.ServerPlayerEntity;
- import net.minecraft.util.text.StringTextComponent;
- public class ChatChannel
- {
- // -------------------------------------------------------------------------
- // static stuff
- // -------------------------------------------------------------------------
-
- public static ChatChannel getDevChannel()
- {
- return DEV_CHANNEL;
- };
-
- private final static ChatChannel DEV_CHANNEL = new ChatChannel("Dev", TextColor.LIGHT_PURPLE,
- (cc, s) ->
- {
- StringTextComponent text = new StringTextComponent(s);
- cc.forEach(p -> p.sendMessage(text));
- }, p -> KajetansMod.perms.hasPermission(p, "script.error"));
-
- // -------------------------------------------------------------------------
- // chat channels
- // -------------------------------------------------------------------------
-
- private final Predicate<ServerPlayerEntity> filter;
- private final String prefix;
- private final String list;
- private final BiConsumer<ChatChannel, String> onSend;
-
- private ChatChannel(String name, TextColor tc,
- BiConsumer<ChatChannel, String> onSend, Predicate<ServerPlayerEntity> filter)
- {
- this.filter = filter;
- this.prefix = "[" + tc + name + TextColor.RESET + "] ";
- this.list = tc + " - ";
- this.onSend = onSend;
- }
-
- public void send(String msg)
- {
- onSend.accept(this, prefix + " " + msg);
- }
-
- public void sendWarning(String msg)
- {
- onSend.accept(this, prefix + " " + TextColor.RED + msg);
- }
-
- public void sendList(String msg)
- {
- onSend.accept(this, list + TextColor.RESET + msg);
- }
-
- public void sendList(String msg, String msg2)
- {
- onSend.accept(this, list + msg + TextColor.RESET + " " + msg2);
- }
-
- public void forEach(Consumer<ServerPlayerEntity> c)
- {
- KajetansMod.server.getPlayerList().getPlayers().stream().filter(filter).forEach(c);
- }
- }
|