Skip to content
Open
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 LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALL RIGHTS RESERVED.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# LPC
A chat formatting plugin for LuckPerms.
# LPC-Color
A chat formatting plugin for LuckPerms with support for color and formatting permissions.


# Permissions
> /lpc reload `lpc.reload`

>ColorCodes `lpc.colorcodes`

>Reset `lpc.reset`

>Italics `lpc.italics`

>Strikethrough `lpc.strikethrough`

>Underline `lpc.underline`

>Bold `lpc.bold`

>Magic `lpc.magic`

>RGB Color Codes `lpc.rgbcodes`

24 changes: 0 additions & 24 deletions UNLICENSE

This file was deleted.

20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.wikmor</groupId>
<artifactId>lpc</artifactId>
<name>LPC</name>
<description>A chat formatting plugin for LuckPerms.</description>
<version>3.6.0</version>
<groupId>dev.noah</groupId>
<artifactId>lpc-color</artifactId>
<name>LPC-color</name>
<description>A chat formatting plugin for LuckPerms with support for color and formatting permissions.</description>
<version>4.0.0</version>
<packaging>jar</packaging>

<properties>
<author>wikmor</author>
<main.class>me.wikmor.lpc.LPC</main.class>
<author>wikmor, noah</author>
<main.class>dev.noah.lpc.LPC</main.class>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand All @@ -38,7 +38,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -75,8 +75,8 @@
https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<version>3.10.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<target>8</target>
<source>8</source>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.wikmor.lpc;
package dev.noah.lpc;

import me.clip.placeholderapi.PlaceholderAPI;
import net.luckperms.api.LuckPerms;
Expand Down Expand Up @@ -40,7 +40,7 @@ public boolean onCommand(final CommandSender sender, final Command command, fina
if (args.length == 1 && "reload".equals(args[0])) {
reloadConfig();

sender.sendMessage(colorize("&aLPC has been reloaded."));
sender.sendMessage(unsafeColorize("&aLPC has been reloaded."));
return true;
}

Expand All @@ -55,6 +55,7 @@ public List<String> onTabComplete(final CommandSender sender, final Command comm
return new ArrayList<>();
}


@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(final AsyncPlayerChatEvent event) {
final String message = event.getMessage();
Expand All @@ -75,17 +76,90 @@ public void onChat(final AsyncPlayerChatEvent event) {
.replace("{username-color}", metaData.getMetaValue("username-color") != null ? metaData.getMetaValue("username-color") : "")
.replace("{message-color}", metaData.getMetaValue("message-color") != null ? metaData.getMetaValue("message-color") : "");

format = colorize(translateHexColorCodes(getServer().getPluginManager().isPluginEnabled("PlaceholderAPI") ? PlaceholderAPI.setPlaceholders(player, format) : format));
format = unsafeColorize(translateHexColorCodes(getServer().getPluginManager().isPluginEnabled("PlaceholderAPI") ? PlaceholderAPI.setPlaceholders(player, format) : format));

event.setFormat(format.replace("{message}", player.hasPermission("lpc.colorcodes") && player.hasPermission("lpc.rgbcodes")
? colorize(translateHexColorCodes(message)) : player.hasPermission("lpc.colorcodes") ? colorize(message) : player.hasPermission("lpc.rgbcodes")
? translateHexColorCodes(message) : message).replace("%", "%%"));
event.setFormat(format.replace("{message}", colorize(message,player)).replace("%", "%%"));
}

private String colorize(final String message) {
// Old colorize method without any checks
private String unsafeColorize(final String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}

private String colorize(final String message, Player player) {
String output = message;
//do each step / color on its own and check for permissions for each step
if (player.hasPermission("lpc.colorcodes")) {
//translate each color individually
output = output.replace("&0", ChatColor.BLACK.toString());
output = output.replace("&1", ChatColor.DARK_BLUE.toString());
output = output.replace("&2", ChatColor.DARK_GREEN.toString());
output = output.replace("&3", ChatColor.DARK_AQUA.toString());
output = output.replace("&4", ChatColor.DARK_RED.toString());
output = output.replace("&5", ChatColor.DARK_PURPLE.toString());
output = output.replace("&6", ChatColor.GOLD.toString());
output = output.replace("&7", ChatColor.GRAY.toString());
output = output.replace("&8", ChatColor.DARK_GRAY.toString());
output = output.replace("&9", ChatColor.BLUE.toString());

output = output.replace("&a", ChatColor.GREEN.toString());
output = output.replace("&A", ChatColor.GREEN.toString());

output = output.replace("&b", ChatColor.AQUA.toString());
output = output.replace("&B", ChatColor.AQUA.toString());

output = output.replace("&c", ChatColor.RED.toString());
output = output.replace("&C", ChatColor.RED.toString());

output = output.replace("&d", ChatColor.LIGHT_PURPLE.toString());
output = output.replace("&D", ChatColor.LIGHT_PURPLE.toString());

output = output.replace("&e", ChatColor.YELLOW.toString());
output = output.replace("&E", ChatColor.YELLOW.toString());

output = output.replace("&f", ChatColor.WHITE.toString());
output = output.replace("&F", ChatColor.WHITE.toString());
}

if (player.hasPermission("lpc.magic")) {
//translate magic
output = output.replace("&k", ChatColor.MAGIC.toString());
output = output.replace("&K", ChatColor.MAGIC.toString());
}
if(player.hasPermission("lpc.bold")) {
//translate bold
output = output.replace("&l", ChatColor.BOLD.toString());
output = output.replace("&L", ChatColor.BOLD.toString());
}
if(player.hasPermission("lpc.underline")) {
//translate underline
output = output.replace("&n", ChatColor.UNDERLINE.toString());
output = output.replace("&N", ChatColor.UNDERLINE.toString());
}
if(player.hasPermission("lpc.italics")) {
//translate italics
output = output.replace("&o", ChatColor.ITALIC.toString());
output = output.replace("&O", ChatColor.ITALIC.toString());
}
if(player.hasPermission("lpc.strikethrough")) {
//translate strikethrough
output = output.replace("&m", ChatColor.STRIKETHROUGH.toString());
output = output.replace("&M", ChatColor.STRIKETHROUGH.toString());

}
if(player.hasPermission("lpc.reset")){
//translate reset
output = output.replace("&r", ChatColor.RESET.toString());
output = output.replace("&R", ChatColor.RESET.toString());
}

if(player.hasPermission("lpc.rgbcodes")){
output = translateHexColorCodes(output);
}

return output;
}

private String translateHexColorCodes(final String message) {
final char colorChar = ChatColor.COLOR_CHAR;

Expand Down
31 changes: 30 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,33 @@ commands:
lpc:
description: Reload the configuration.
permission: lpc.reload
usage: "Usage: /lpc reload"
usage: "Usage: /lpc reload"

permissions:
lpc.reload:
description: Allows the player to reload the configuration.
default: op
lpc.colorcodes:
description: Allows the player to use color codes. (e.g. &a, &b, &c, &d, &e, &f, &0, &1, &2, &3, &4, &5, &6, &7, &8, &9)
default: op
lpc.reset:
description: Allows the player to reset the chat format. (e.g. &r)
default: op
lpc.bold:
description: Allows the player to use bold text. (e.g. &l)
default: op
lpc.italic:
description: Allows the player to use italic text. (e.g. &o)
default: op
lpc.underline:
description: Allows the player to use underline text. (e.g. &n)
default: op
lpc.strikethrough:
description: Allows the player to use strikethrough text. (e.g. &m)
default: op
lpc.magic:
description: Allows the player to use magic text. (e.g. &k)
default: op
lpc.rgbcodes:
description: Allows the player to use RGB color codes. (e.g. &#ff0000)
default: op