Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
Call a code reviewer... but not for me!
Browse files Browse the repository at this point in the history
  • Loading branch information
YouHaveTrouble committed Aug 28, 2022
0 parents commit 9662462
Show file tree
Hide file tree
Showing 6 changed files with 380 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# User-specific stuff
.idea/

*.iml
*.ipr
*.iws

# IntelliJ
out/

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

target/

pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next

release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml

# Common working directory
run/
86 changes: 86 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>me.youhavetrouble</groupId>
<artifactId>JustChat</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>JustChat</name>

<description>Just a chat plugin.</description>
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>https://youhavetrouble.me</url>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories>
<repository>
<id>purpur</id>
<url>https://repo.purpurmc.org/snapshots</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.purpurmc.purpur</groupId>
<artifactId>purpur-api</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
32 changes: 32 additions & 0 deletions src/main/java/me/youhavetrouble/justchat/JustChat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package me.youhavetrouble.justchat;

import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

public final class JustChat extends JavaPlugin {

private static String chatFormat;

private static final MiniMessage miniMessage = MiniMessage.miniMessage();

@Override
public void onEnable() {
reloadPluginConfig();
getServer().getPluginManager().registerEvents(new JustChatListener(), this);
}

public void reloadPluginConfig() {
saveDefaultConfig();
FileConfiguration config = getConfig();
chatFormat = config.getString("format", "<%player_displayname%> %message%");
}

public static String getChatFormat() {
return chatFormat;
}

public static MiniMessage getMiniMessage() {
return miniMessage;
}
}
88 changes: 88 additions & 0 deletions src/main/java/me/youhavetrouble/justchat/JustChatListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package me.youhavetrouble.justchat;

import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
import io.papermc.paper.event.player.AsyncChatDecorateEvent;
import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.AsyncPlayerChatPreviewEvent;
import org.bukkit.permissions.Permission;


import java.util.HashMap;

public class JustChatListener implements Listener {

private final HashMap<Permission, TagResolver> formattingPerms = new HashMap<>();
private final PlainTextComponentSerializer plainTextComponentSerializer = PlainTextComponentSerializer.plainText();

public JustChatListener() {
formattingPerms.put(new Permission("justchat.color"), StandardTags.color());
formattingPerms.put(new Permission("justchat.bold"), StandardTags.decorations(TextDecoration.BOLD));
formattingPerms.put(new Permission("justchat.italic"), StandardTags.decorations(TextDecoration.ITALIC));
formattingPerms.put(new Permission("justchat.underlined"), StandardTags.decorations(TextDecoration.UNDERLINED));
formattingPerms.put(new Permission("justchat.strikethrough"), StandardTags.decorations(TextDecoration.STRIKETHROUGH));
formattingPerms.put(new Permission("justchat.obfuscated"), StandardTags.decorations(TextDecoration.OBFUSCATED));
formattingPerms.put(new Permission("justchat.gradient"), StandardTags.gradient());
formattingPerms.put(new Permission("justchat.font"), StandardTags.font());
formattingPerms.put(new Permission("justchat.rainbow"), StandardTags.rainbow());
formattingPerms.put(new Permission("justchat.hover"), StandardTags.hoverEvent());
formattingPerms.put(new Permission("justchat.click"), StandardTags.clickEvent());
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onjustChatDecorate(AsyncChatDecorateEvent event) {

if (event.player() == null) return;

String format = JustChat.getChatFormat();

format = PlaceholderAPI.setPlaceholders(event.player(), format);
Component formatComponent = JustChat.getMiniMessage().deserialize(format);

Component message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));

event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
}

@EventHandler
public void onAsyncChatPreviewEvent(AsyncPlayerChatPreviewEvent event) {
event.setFormat("%2$s");
}

@EventHandler
public void onAsyncChatEvent(AsyncPlayerChatEvent event) {
event.setFormat("%2$s");
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onjustChatCommandDecorate(AsyncChatCommandDecorateEvent event) {
if (event.player() == null) return;
event.result(parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage())));
}

private Component parseMessageContent(Player player, String rawMessage) {
TagResolver.Builder tagResolver = TagResolver.builder();

formattingPerms.forEach((perm, resolver) -> {
if (player.hasPermission(perm)) {
tagResolver.resolver(resolver);
}
});

MiniMessage messageParser = MiniMessage.builder().tags(tagResolver.build()).build();
return messageParser.deserialize(rawMessage);

}

}
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
format: "<%player_displayname%> %message%"
60 changes: 60 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: '${project.name}'
version: '${project.version}'
main: me.youhavetrouble.justchat.JustChat
api-version: 1.19
depend: [ PlaceholderAPI ]
authors: [ YouHaveTrouble ]
description: '${project.description}'
website: https://youhavetrouble.me
permissions:
justchat.color:
description: "Allows for usage of basic color tags"
default: op
justchat.bold:
description: "Allows for usage of <b>"
default: op
justchat.italic:
description: "Allows for usage of <i> tag"
default: op
justchat.underlined:
description: "Allows for usage of <u> tag"
default: op
justchat.strikethrough:
description: "Allows for usage of <st> tag"
default: op
justchat.obfuscated:
description: "Allows for usage of <obf> tag"
default: op
justchat.gradient:
description: "Allows for usage of <gradient> tag"
default: op
justchat.font:
description: "Allows for usage of <font> tag"
default: op
justchat.rainbow:
description: "Allows for usage of <rainbow> tag"
default: op
justchat.hover:
description: "Allows for usage of <hover> tag"
default: op
justchat.click:
description: "Allows for usage of <click> tag"
default: op
justchat.format:
description: "Allows for usage of <b>, <i>, <u> and <st> tags"
children:
justchat.bold: true
justchat.italic: true
justchat.underlined: true
justchat.strikethrough: true
justchat.colors:
description: "Allows for usage of basic color tags, <gradient> and <rainbow> tags"
children:
justchat.color: true
justchat.gradient: true
justchat.rainbow: true
justchat.actions:
description: "Allows for usage of <click> and <hover> tags"
children:
justchat.click: true
justchat.hover: true

0 comments on commit 9662462

Please sign in to comment.