Skip to content

Commit

Permalink
Fixed issue#4
Browse files Browse the repository at this point in the history
  • Loading branch information
abc123me committed Dec 7, 2022
1 parent 0fb178f commit cb5f12e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class PermissionsHandler {
public static PermissionNode<Boolean> nickCommand =
ezyPermission("commands.nick", true, "Nickname", "Enables/Disables the \"/nick <nickname>\" command");
public static PermissionNode<Boolean> nickOthersCommand =
ezyPermission("commands.nick.others", true, "Modify nicknames", "Enables/Disables the \"/nick <username> <nickname>\" command");
ezyPermission("commands.nick.others", false, "Modify nicknames", "Enables/Disables the \"/nick <username> <nickname>\" command");

@SubscribeEvent public void registerPermissionNodes(Nodes pge) {
for(Field fld : PermissionsHandler.class.getDeclaredFields()) {
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/jeremiahbl/bfcmod/events/ChatEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Date;
import java.util.UUID;

import com.jeremiahbl.bfcmod.BetterForgeChat;
import com.jeremiahbl.bfcmod.MarkdownFormatter;
import com.jeremiahbl.bfcmod.TextFormatter;
import com.jeremiahbl.bfcmod.config.ConfigHandler;
Expand All @@ -14,12 +13,7 @@
import com.mojang.authlib.GameProfile;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.chat.*;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.event.ServerChatEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand All @@ -40,15 +34,19 @@ public void reloadConfigOptions() {
loaded = true;
}

public TextComponent getEventComponent(Component old) {
private Style getSpecialStyleComponents(Component old) {
if(old != null && old instanceof TranslatableComponent) {
TranslatableComponent tcmp = (TranslatableComponent) old;
Object[] args = tcmp.getArgs();
for(Object arg : args)
if(arg != null && arg instanceof TextComponent)
return (TextComponent) arg;
for(Object arg : args) {
if(arg != null && arg instanceof TextComponent) {
Style sty = ((TextComponent) arg).getStyle();
if(sty != null && sty.getHoverEvent() != null)
return sty;
}
}
}
return new TextComponent("");
return null;
}

@SubscribeEvent
Expand Down Expand Up @@ -81,7 +79,9 @@ public void onServerChat(ServerChatEvent e) {
if(markdownEnabled && enableStyle && PermissionsHandler.playerHasPermission(uuid, PermissionsHandler.markdownChatNode))
msg = MarkdownFormatter.markdownStringToFormattedString(msg);
TextComponent msgComp = TextFormatter.stringToFormattedText(msg, enableColor, enableStyle);
TextComponent eventComp = getEventComponent(e.getComponent());
e.setComponent(eventComp.append(beforeMsg.append(msgComp.append(afterMsg))));
Style sty = getSpecialStyleComponents(e.getComponent());
TextComponent pfx = new TextComponent("");
if(sty != null) pfx.setStyle(sty);
e.setComponent(pfx.append(beforeMsg.append(msgComp.append(afterMsg))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public void onTabListNameFormatEvent(TabListNameFormat e) {
if(ConfigHandler.config.enableTabListIntegration.get() && e.getPlayer() != null && e.getPlayer() instanceof ServerPlayer) {
GameProfile player = e.getPlayer().getGameProfile();
e.setDisplayName(BetterForgeChatUtilities.getFormattedPlayerName(player,
enableNicknamesInTabList && PermissionsHandler.playerHasPermission(player.getId(), PermissionsHandler.tabListNicknameNode),
enableMetadataInTabList && PermissionsHandler.playerHasPermission(player.getId(), PermissionsHandler.tabListMetadataNode)));
enableNicknamesInTabList &&
PermissionsHandler.playerHasPermission(player.getId(), PermissionsHandler.tabListNicknameNode),
enableMetadataInTabList &&
PermissionsHandler.playerHasPermission(player.getId(), PermissionsHandler.tabListMetadataNode)));
}
}
@SubscribeEvent
Expand Down

0 comments on commit cb5f12e

Please sign in to comment.