summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-01-29 18:54:53 +0800
committerkeuin <[email protected]>2021-01-29 18:54:53 +0800
commit602fb9e88685041abac73f868cb697123e15865c (patch)
treefab97907433b15ab88a55af03c88f6f22ce90676 /src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java
parentb0208136e0dab098d8270b56b65521e13ff3d732 (diff)
Add Op login hint in the next start after restoring
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java b/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java
new file mode 100644
index 0000000..b44bfce
--- /dev/null
+++ b/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java
@@ -0,0 +1,45 @@
+package com.keuin.kbackupfabric.notification;
+
+import net.minecraft.network.MessageType;
+import net.minecraft.server.network.ServerPlayerEntity;
+import net.minecraft.text.Text;
+
+/**
+ * Decouple from ServerPlayerEntity, in case further migration to other APIs.
+ */
+public interface DistinctNotifiable {
+
+ /**
+ * Does the receiver has privilege to receive some special message.
+ */
+ boolean isPrivileged();
+
+ void notify(Text text);
+
+ /**
+ * Get an unique, non-null object that identifies this notifiable instance.
+ * The identifier must be immutable and implement their own equals method.
+ *
+ * @return the identifier.
+ */
+ Object getIdentifier();
+
+ static DistinctNotifiable fromServerPlayerEntity(ServerPlayerEntity serverPlayerEntity) {
+ return new DistinctNotifiable() {
+ @Override
+ public boolean isPrivileged() {
+ return serverPlayerEntity.server.getPermissionLevel(serverPlayerEntity.getGameProfile()) >= serverPlayerEntity.server.getOpPermissionLevel();
+ }
+
+ @Override
+ public void notify(Text text) {
+ serverPlayerEntity.sendChatMessage(text, MessageType.SYSTEM);
+ }
+
+ @Override
+ public Object getIdentifier() {
+ return serverPlayerEntity.getUuid();
+ }
+ };
+ }
+}