Skip to content

Commit

Permalink
Added ChatColors Pack
Browse files Browse the repository at this point in the history
  • Loading branch information
teakivy committed Nov 2, 2021
1 parent ceb485d commit 55a5619
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package me.teakivy.teakstweaks.Packs.TeaksTweaks.ChatColors;

import me.teakivy.teakstweaks.Main;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class ChatColors implements Listener {

Main main = Main.getPlugin(Main.class);

@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
if (!main.getConfig().getBoolean("packs.chat-colors.chat")) return;
event.setMessage(ChatColor.translateAlternateColorCodes('&', event.getMessage()));
}

@EventHandler
private void onAnvil(PrepareAnvilEvent event) {
if (!main.getConfig().getBoolean("packs.chat-colors.items")) return;
ItemStack result = event.getResult();
if (result == null) return;
if (!result.hasItemMeta()) return;

ItemMeta meta = result.getItemMeta();
if (meta == null) return;
if (!meta.hasDisplayName()) return;

meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', meta.getDisplayName()));
result.setItemMeta(meta);
event.setResult(result);
}

@EventHandler
public void onSign(SignChangeEvent event) {
if (!main.getConfig().getBoolean("packs.chat-colors.signs")) return;
for (int i = 0; i < event.getLines().length; i++) {
if (event.getLine(i) == null) continue;
event.setLine(i, ChatColor.translateAlternateColorCodes('&', event.getLine(i)));
}
}

public void unregister() {
HandlerList.unregisterAll(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import me.teakivy.teakstweaks.Packs.Survival.TrackStatistics.StatTracker;
import me.teakivy.teakstweaks.Packs.Survival.UnlockAllRecipes.UnlockRecipes;
import me.teakivy.teakstweaks.Packs.Survival.WorkstationHighlights.Highlighter;
import me.teakivy.teakstweaks.Packs.TeaksTweaks.ChatColors.ChatColors;
import me.teakivy.teakstweaks.Packs.TeaksTweaks.KeepSmall.KeepSmall;
import me.teakivy.teakstweaks.Packs.Teleportation.Back.Back;
import me.teakivy.teakstweaks.Packs.Utilities.CustomVillagerShops.CustomVillager;
Expand Down Expand Up @@ -98,6 +99,7 @@ public class Register {
public static CustomVillager customVillager = new CustomVillager();
public static Sphere sphere = new Sphere();
public static KeepSmall keepSmall = new KeepSmall();
public static ChatColors chatColors = new ChatColors();

public static void registerAll() {
for (String pack : main.getConfig().getConfigurationSection("packs").getKeys(false)) {
Expand Down Expand Up @@ -159,7 +161,7 @@ public static void unregisterPack(String pack) {
}

if (pack.equalsIgnoreCase("multiplayer-sleep")) {
// multiplayerSleep.unregister();
multiplayerSleep.unregister();
}

if (pack.equalsIgnoreCase("player-head-drops")) {
Expand Down Expand Up @@ -281,6 +283,10 @@ public static void unregisterPack(String pack) {
if (pack.equalsIgnoreCase("keep-small")) {
keepSmall.unregister();
}

if (pack.equalsIgnoreCase("chat-colors")) {
chatColors.unregister();
}
}

public static void registerPack(String pack) {
Expand Down Expand Up @@ -461,6 +467,10 @@ public static void registerPack(String pack) {
if (pack.equalsIgnoreCase("keep-small")) {
main.getServer().getPluginManager().registerEvents(keepSmall, main);
}

if (pack.equalsIgnoreCase("chat-colors")) {
main.getServer().getPluginManager().registerEvents(chatColors, main);
}
}
public static void registerCommands() {

Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ packs:
# Allow the mob to be set in its adult form (By Naming a mob 'grow')
grow: true

# Chat Colors
# Use Chat Colors to make your messages, signs, and items look better (Using '&' for color codes)
chat-colors:
enabled: false
# Enable Colors in the chat
chat: true
# Enable Colors on signs
signs: true
# Enable Colors on items (Using anvils)
items: true

# Vanilla Tweaks:

# Survival:
Expand Down

0 comments on commit 55a5619

Please sign in to comment.