-
Notifications
You must be signed in to change notification settings - Fork 0
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
85dc760
commit f7022ac
Showing
26 changed files
with
244 additions
and
331 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
27 changes: 0 additions & 27 deletions
27
common/src/main/java/fi/fabianadrian/webhooklogger/common/event/ChatEventBuilder.java
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
common/src/main/java/fi/fabianadrian/webhooklogger/common/event/CommandEventBuilder.java
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
common/src/main/java/fi/fabianadrian/webhooklogger/common/event/DeathEventBuilder.java
This file was deleted.
Oops, something went wrong.
69 changes: 0 additions & 69 deletions
69
common/src/main/java/fi/fabianadrian/webhooklogger/common/event/EventBuilder.java
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
common/src/main/java/fi/fabianadrian/webhooklogger/common/event/JoinEventBuilder.java
This file was deleted.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
common/src/main/java/fi/fabianadrian/webhooklogger/common/event/PlaceholderFactory.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,102 @@ | ||
package fi.fabianadrian.webhooklogger.common.event; | ||
|
||
import fi.fabianadrian.webhooklogger.common.WebhookLogger; | ||
import fi.fabianadrian.webhooklogger.common.config.section.PlaceholderConfigSection; | ||
import fi.fabianadrian.webhooklogger.common.dependency.Dependency; | ||
import fi.fabianadrian.webhooklogger.common.platform.Player; | ||
import io.github.miniplaceholders.api.MiniPlaceholders; | ||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.identity.Identity; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.TranslatableComponent; | ||
import net.kyori.adventure.text.minimessage.MiniMessage; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; | ||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; | ||
|
||
import java.time.Instant; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public final class PlaceholderFactory { | ||
private final WebhookLogger webhookLogger; | ||
private final PlaceholderConfigSection config; | ||
private final PlainTextComponentSerializer plainTextSerializer = PlainTextComponentSerializer.plainText(); | ||
private final MiniMessage miniMessage = MiniMessage.miniMessage(); | ||
|
||
public PlaceholderFactory(WebhookLogger webhookLogger) { | ||
this.webhookLogger = webhookLogger; | ||
this.config = webhookLogger.mainConfig().placeholders(); | ||
} | ||
|
||
public TagResolver timestamp() { | ||
DateTimeFormatter formatter = DateTimeFormatter | ||
.ofPattern(config.timestampFormat()) | ||
.withZone(config.timestampTimezone()); | ||
return Placeholder.unparsed("timestamp", formatter.format(Instant.now())); | ||
} | ||
|
||
public TagResolver cancelled(boolean cancelled) { | ||
String cancelledString = cancelled ? config.cancelled() : ""; | ||
return Placeholder.unparsed("cancelled", cancelledString); | ||
} | ||
|
||
public TagResolver player(Player player) { | ||
List<TagResolver> resolvers = new ArrayList<>(); | ||
|
||
resolvers.add(audience(player)); | ||
|
||
String address = String.valueOf(player.address()); | ||
resolvers.add(Placeholder.unparsed("address", address)); | ||
|
||
Component location = miniMessage.deserialize( | ||
config.locationFormat(), | ||
Placeholder.unparsed("x", String.valueOf(player.location().x())), | ||
Placeholder.unparsed("y", String.valueOf(player.location().y())), | ||
Placeholder.unparsed("z", String.valueOf(player.location().z())) | ||
); | ||
resolvers.add(Placeholder.component("location", location)); | ||
|
||
return TagResolver.builder().resolvers(resolvers).build(); | ||
} | ||
|
||
public TagResolver audience(Audience audience) { | ||
List<TagResolver> resolvers = new ArrayList<>(); | ||
|
||
String name = audience.getOrDefault(Identity.NAME, "unknown"); | ||
resolvers.add(Placeholder.unparsed("name", name)); | ||
|
||
Component displayName = audience.getOrDefault(Identity.DISPLAY_NAME, Component.text(name)); | ||
resolvers.add(Placeholder.component("display_name", displayName)); | ||
|
||
String uuid = audience.get(Identity.UUID).map(UUID::toString).orElse("unknown"); | ||
resolvers.add(Placeholder.unparsed("uuid", uuid)); | ||
|
||
if (webhookLogger.dependencyManager().isPresent(Dependency.MINI_PLACEHOLDERS)) { | ||
resolvers.add(MiniPlaceholders.getAudienceGlobalPlaceholders(audience)); | ||
} | ||
|
||
return TagResolver.builder().resolvers(resolvers).build(); | ||
} | ||
|
||
public TagResolver message(Component message) { | ||
if (message == null) { | ||
return Placeholder.unparsed("placeholder", ""); | ||
} | ||
|
||
if (message instanceof TranslatableComponent) { | ||
message = Component.text(plainTextSerializer.serialize(message)); | ||
} | ||
|
||
return Placeholder.component("message", message); | ||
} | ||
|
||
public TagResolver command(String command) { | ||
if (!command.startsWith("/")) { | ||
command = "/" + command; | ||
} | ||
return Placeholder.unparsed("command", command); | ||
} | ||
} |
45 changes: 0 additions & 45 deletions
45
common/src/main/java/fi/fabianadrian/webhooklogger/common/event/QuitEventBuilder.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.