-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
161782c
commit 362cca5
Showing
22 changed files
with
334 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
api/src/main/java/com/mineaurion/aurionchat/api/AurionPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.mineaurion.aurionchat.api; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.annotations.SerializedName; | ||
import com.mineaurion.aurionchat.api.model.Named; | ||
import lombok.*; | ||
import lombok.Builder.Default; | ||
import lombok.experimental.FieldDefaults; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.Serializable; | ||
import java.util.Optional; | ||
|
||
import static net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson; | ||
|
||
@Value | ||
@Builder(toBuilder = true) | ||
@AllArgsConstructor // make public for gson | ||
public class AurionPacket implements Named, Serializable { | ||
public static Gson gson = new Gson(); | ||
|
||
public static AurionPacket parse(String json) { | ||
return gson.fromJson(json, AurionPacket.class); | ||
} | ||
|
||
public static Builder chat(AurionPlayer player, String message, Object tellRaw) { | ||
return AurionPacket.builder() | ||
.type(Type.CHAT) | ||
.source("ingame") | ||
.player(player) | ||
.detail(message) | ||
.tellRawData(tellRaw.toString()); | ||
} | ||
|
||
public static Builder autoMessage(String message, Object tellRaw) { | ||
return AurionPacket.builder() | ||
.type(Type.AUTO_MESSAGE) | ||
.source("automessage") | ||
.displayName("AutoMessage") | ||
.detail(message) | ||
.tellRawData(tellRaw.toString()); | ||
} | ||
|
||
/** packet type */ | ||
Type type; | ||
|
||
/** one of: servername, 'discord' or 'ingame' literal */ | ||
String source; | ||
|
||
/** related player */ | ||
@Default @Nullable AurionPlayer player = null; | ||
|
||
/** channel name */ | ||
@Default @Nullable String channel = null; | ||
|
||
/** display name of sender (one of: player name, automessage title) */ | ||
@Default @Nullable String displayName = null; | ||
|
||
/** detail data (one of: message text, join text, achievement text) */ | ||
@Default @Nullable String detail = null; | ||
|
||
/** what ingame players see */ | ||
@NotNull String tellRawData; | ||
|
||
/** what to display in plaintext environments */ | ||
@SuppressWarnings("ConstantValue") // false positive bcs of lombok | ||
public String getRawDisplay() { | ||
return displayName + ' ' + type.verb + (detail==null?"": ": " + detail); | ||
} | ||
|
||
public Component getComponent() { | ||
return gson().deserialize(tellRawData); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return gson.toJson(this); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings({"ConstantValue", "OptionalOfNullableMisuse"}) // false positive bcs of lombok | ||
public @Nullable String getName() { | ||
return Optional.ofNullable(player) | ||
.map(Named::getBestName) | ||
.orElse(null); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("ConstantValue") // false positive bcs of lombok | ||
public @Nullable String getDisplayName() { | ||
return displayName; | ||
} | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) | ||
public enum Type { | ||
@SerializedName("chat") CHAT("wrote"), | ||
@SerializedName("automessage") AUTO_MESSAGE("broadcasted"); | ||
|
||
String verb; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
api/src/main/java/com/mineaurion/aurionchat/api/AurionPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mineaurion.aurionchat.api; | ||
|
||
import com.mineaurion.aurionchat.api.model.Player; | ||
import lombok.Value; | ||
import lombok.experimental.NonFinal; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@Value @NonFinal | ||
public class AurionPlayer implements Player { | ||
UUID id; | ||
String name; | ||
@Nullable String prefix; | ||
@Nullable String suffix; | ||
@Nullable String displayName; | ||
|
||
public AurionPlayer(UUID id, String name, @Nullable String prefix, @Nullable String suffix) { | ||
this.id = id; | ||
this.name = name; | ||
this.prefix = prefix; | ||
this.suffix = suffix; | ||
this.displayName = Optional.ofNullable(prefix).orElse("") + name + Optional.ofNullable(suffix).orElse(""); | ||
} | ||
} |
53 changes: 0 additions & 53 deletions
53
api/src/main/java/com/mineaurion/aurionchat/api/RabbitMQMessage.java
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
api/src/main/java/com/mineaurion/aurionchat/api/model/Named.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.mineaurion.aurionchat.api.model; | ||
|
||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Optional; | ||
|
||
public interface Named { | ||
@Nullable String getName(); | ||
|
||
@Nullable String getDisplayName(); | ||
|
||
default String getBestName() { | ||
return getBestName(toString()); | ||
} | ||
|
||
@Contract("null -> _; !null -> !null") | ||
default String getBestName(String fallback) { | ||
return Optional.ofNullable(getDisplayName()) | ||
.orElseGet(() -> Optional.ofNullable(getName()) | ||
.orElse(fallback)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
api/src/main/java/com/mineaurion/aurionchat/api/model/Player.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mineaurion.aurionchat.api.model; | ||
|
||
import java.util.UUID; | ||
|
||
public interface Player extends Named { | ||
String getDisplayName(); | ||
|
||
UUID getId(); | ||
|
||
String getPrefix(); | ||
|
||
String getSuffix(); | ||
} |
9 changes: 9 additions & 0 deletions
9
api/src/main/java/com/mineaurion/aurionchat/api/model/ServerPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.mineaurion.aurionchat.api.model; | ||
|
||
import net.kyori.adventure.text.Component; | ||
|
||
public interface ServerPlayer extends Player { | ||
void sendMessage(Component message); | ||
|
||
boolean hasPermission(String permission); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.