Skip to content

Commit

Permalink
Added a system to enable/disable Copy to Clipboard + Comment Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MeAlam1 committed Dec 8, 2024
1 parent 42956cd commit 0502d6d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* </ul>
*
* @author MeAlam
* @version 1.5.0
* @version 1.6.0
* @since 1.1.0
*/
public class MarkdownParser {
Expand Down Expand Up @@ -137,6 +137,7 @@ public static DisableMarkdownFor disableMarkdownFor() {
* <li>{@link #underline()} - Enables underline Markdown formatting.</li>
* <li>{@link #hyperlink()} - Enables hyperlink Markdown formatting.</li>
* <li>{@link #spoiler()} - Enables spoiler Markdown formatting.</li>
* <li>{@link #copyToClipboard()} - Enables copy to clipboard Markdown formatting.</li>
* </ul>
*
* @author MeAlam
Expand Down Expand Up @@ -222,6 +223,19 @@ public EnableMarkdownFor spoiler() {
BaseLogger.log(BaseLogLevel.INFO, "Enabled spoiler markdown", true);
return this;
}

/**
* A {@code public} method that enables CopyToClipboard Markdown formatting.
*
* @return The {@link EnableMarkdownFor} instance to allow method chaining.
* @author MeAlam
* @since 1.6.0
*/
public EnableMarkdownFor copyToClipboard() {
Spoiler.isSpoilerEnabled = true;
BaseLogger.log(BaseLogLevel.INFO, "Enabled CopyToClipboard markdown", true);
return this;
}
}

/**
Expand All @@ -237,6 +251,8 @@ public EnableMarkdownFor spoiler() {
* <li>{@link #strikethrough()} - Disables strikethrough Markdown formatting.</li>
* <li>{@link #underline()} - Disables underline Markdown formatting.</li>
* <li>{@link #hyperlink()} - Disables hyperlink Markdown formatting.</li>
* <li>{@link #spoiler()} - Disables spoiler Markdown formatting.</li>
* <li>{@link #copyToClipboard()} - Disables copy to clipboard Markdown formatting.</li>
* </ul>
*
* @author MeAlam
Expand Down Expand Up @@ -322,5 +338,18 @@ public DisableMarkdownFor spoiler() {
BaseLogger.log(BaseLogLevel.INFO, "Disabled spoiler markdown", true);
return this;
}

/**
* A {@code public} method that disables CopyToClipboard Markdown formatting.
*
* @return The {@link DisableMarkdownFor} instance to allow method chaining.
* @author MeAlam
* @since 1.6.0
*/
public DisableMarkdownFor copyToClipboard() {
Spoiler.isSpoilerEnabled = false;
BaseLogger.log(BaseLogLevel.INFO, "Disabled CopyToClipboard markdown", true);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* </ul>
*
* @author MeAlam
* @version 1.5.0
* @version 1.6.0
* @see MarkdownFeature
* @since 1.5.0
*/
Expand Down Expand Up @@ -61,18 +61,18 @@ protected String applyFormat(String pContent) {
* {@code textToCopy} parameter.
*
* @param pMessage {@link MutableComponent} - The input message to be formatted.
* @param textToCopy {@link String} - The text to copy to the clipboard.
* @param pTextToCopy {@link String} - The text to copy to the clipboard.
* @author MeAlam
* @since 1.5.0
*/
public MutableComponent applyCopyToClipboard(MutableComponent pMessage, String textToCopy) {
public MutableComponent applyCopyToClipboard(MutableComponent pMessage, String pTextToCopy) {
MutableComponent result = Component.literal("");

for (Component sibling : pMessage.getSiblings()) {
if (sibling instanceof MutableComponent mutableSibling) {
if (mutableSibling.getStyle().getClickEvent() == null) {
mutableSibling.setStyle(mutableSibling.getStyle()
.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, textToCopy)));
.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, pTextToCopy)));
}
result.append(mutableSibling);
} else {
Expand Down

0 comments on commit 0502d6d

Please sign in to comment.