Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/eternalcode.java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ repositories {
maven { url = uri("https://jitpack.io") }
maven { url = uri("https://repo.eternalcode.pl/releases") }
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/")
maven { url = uri("https://repo.minebench.de/") }
}

java {
Expand Down
4 changes: 4 additions & 0 deletions chatformatter-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ dependencies {
// GitCheck
implementation("com.eternalcode:gitcheck:1.0.0")

// MineDown
implementation("de.themoep:minedown-adventure:1.7.6-SNAPSHOT")

// JUnit 5
testImplementation(platform("org.junit:junit-bom:6.0.2"))
testImplementation("org.junit.jupiter:junit-jupiter-api")
Expand Down Expand Up @@ -72,6 +75,7 @@ tasks {
"net.kyori",
"org.bstats",
"org.json",
"de.themoep.minedown",
).forEach { pack ->
relocate(pack, "$prefix.$pack")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.eternalcode.formatter;

import com.eternalcode.formatter.adventure.AdventureUrlPostProcessor;
import de.themoep.minedown.adventure.MineDown;
import de.themoep.minedown.adventure.MineDownParser;
import java.util.Optional;
import net.kyori.adventure.text.serializer.json.JSONOptions;
import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection;
Expand Down Expand Up @@ -135,9 +137,30 @@ private TagResolver.Single namePlaceholder(Player sender) {
}

private TagResolver.Single messagePlaceholder(Player sender, String rawMessage) {
TagResolver permittedTags = this.providePermittedTags(sender);
rawMessage = Legacy.legacyToAdventure(rawMessage, permission -> sender.hasPermission(permission));
Component componentMessage = EMPTY_MESSAGE_DESERIALIZER.deserialize(rawMessage, permittedTags);
Component componentMessage;

if (this.settings.isMineDownEnabled()) {
MineDown mineDown = new MineDown(rawMessage);

if (!sender.hasPermission(PERMISSION_ALL)) {
if (!sender.hasPermission("chatformatter.decorations.*")) {
mineDown.disable(MineDownParser.Option.SIMPLE_FORMATTING);
}
if (!(sender.hasPermission("chatformatter.hover") && sender.hasPermission("chatformatter.click"))) {
mineDown.disable(MineDownParser.Option.ADVANCED_FORMATTING);
}
if (!sender.hasPermission("chatformatter.color.*")) {
mineDown.disable(MineDownParser.Option.LEGACY_COLORS);
}
}

componentMessage = mineDown.toComponent();
} else {
TagResolver permittedTags = this.providePermittedTags(sender);
rawMessage = Legacy.legacyToAdventure(rawMessage, permission -> sender.hasPermission(permission));
componentMessage = EMPTY_MESSAGE_DESERIALIZER.deserialize(rawMessage, permittedTags);
Comment on lines +142 to +161
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bez sensu czemu stara logika jest wykluczana

}

return Placeholder.component("message", componentMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public interface ChatSettings {

boolean isReceiveUpdates();

boolean isMineDownEnabled();

String getRawFormat(String rank);

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class PluginConfig implements ChatSettings, TemplateRepository {
@Description({ " ", "# Do you want to receive updates about new versions of ChatFormatter?" })
public boolean receiveUpdates = true;

@Description({ " ", "# Do you want to enable MineDown support? (Markdown-like formatting for Minecraft)",
"# See https://github.com/Phoenix616/MineDown for more information." })
public boolean mineDownSupport = false;


@Description({ " ", "# Chat format for ranks (Vault) Support mini-messages and legacy colors" })
@Description({ " ", "# We're recommending to use webui for mini-messages: https://webui.adventure.kyori.net/" })
Expand Down Expand Up @@ -89,6 +93,11 @@ public boolean isReceiveUpdates() {
return this.receiveUpdates;
}

@Override
public boolean isMineDownEnabled() {
return this.mineDownSupport;
}

@Override
public String getRawFormat(String rank) {
return this.format.getOrDefault(rank, this.defaultFormat);
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
Loading