Skip to content

Commit b738a9b

Browse files
committed
Clean some things up
1 parent f1e0d29 commit b738a9b

File tree

9 files changed

+67
-64
lines changed

9 files changed

+67
-64
lines changed

converters/chatchat/essentialschat.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Converter from "../converter";
22
import {EssentialsChatTypes} from "../types/essentialschat";
33
import {ChatChatFormat, ChatChatFormatsConfig, ChatChatSettingsConfig} from "../types/chatchat";
44
import MiniMessage from "../minimessage";
5-
import Placeholders from "../placeholders";
65

76
const schema = require('../types/essentialschat.json')
87

@@ -21,15 +20,15 @@ const ChatChatEssentialsChatConverter = new Converter<EssentialsChatTypes, { for
2120
},
2221
}
2322

24-
if (!essentialschatConfig.config) {
23+
if (!essentialschatConfig.config || !essentialschatConfig.config.chat) {
2524
return {
2625
error: true,
27-
message: 'EssentialsChat config is missing'
26+
message: 'must be object'
2827
}
2928
}
3029

31-
if (essentialschatConfig.config.format) {
32-
const format = essentialschatConfig.config.format;
30+
if (essentialschatConfig.config.chat.format) {
31+
const format = essentialschatConfig.config.chat.format;
3332
const ccFormat: ChatChatFormat = {
3433
priority: 1,
3534
parts: []
@@ -41,8 +40,8 @@ const ChatChatEssentialsChatConverter = new Converter<EssentialsChatTypes, { for
4140

4241
let formatCount = 1;
4342

44-
if (essentialschatConfig.config["group-formats"]) {
45-
const formats = essentialschatConfig.config["group-formats"]
43+
if (essentialschatConfig.config.chat["group-formats"]) {
44+
const formats = essentialschatConfig.config.chat["group-formats"]
4645
Object.keys(formats).forEach(name => {
4746
const ecFormat = formats[name]
4847
const ccFormat: ChatChatFormat = {
@@ -70,4 +69,26 @@ const ChatChatEssentialsChatConverter = new Converter<EssentialsChatTypes, { for
7069
inputSchema: schema,
7170
});
7271

72+
function Placeholders(input: string): string {
73+
const replacements: Record<string, string> = {
74+
'{MESSAGE}': "<message>",
75+
'{USERNAME}': "%player_name%",
76+
'{DISPLAYNAME}': "%player_display_name%",
77+
'{NICKNAME}': "%essentials_nickname%",
78+
'{PREFIX}': "%vault_prefix%",
79+
'{SUFFIX}': "%vault_suffix%",
80+
'{GROUP}': "%vault_groupprefix%",
81+
'{WORLDNAME}': "%player_world_name%"
82+
}
83+
84+
let out = input;
85+
86+
Object.keys(replacements).forEach(key => {
87+
out = out.replace(new RegExp(key, "ig"), replacements[key]);
88+
});
89+
90+
return out;
91+
}
92+
93+
7394
export default ChatChatEssentialsChatConverter;

converters/chatchat/venturechat.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Converter from '../converter';
2-
import {VentureChatConfig, VentureChatFormat, VentureChatJsonComponent} from "../types/venturechat";
2+
import {VentureChatConfig, VentureChatJsonComponent} from "../types/venturechat";
33
import {ChatChatFormat, ChatChatFormatsConfig, ChatChatSettingsConfig} from "../types/chatchat";
44
import MiniMessage from "../minimessage";
55

66
const schema = require('../types/venturechat.json');
77

8-
const ChatChatVentureChatConverter = new Converter<VentureChatConfig, {format: ChatChatFormatsConfig, settings: ChatChatSettingsConfig}>({
8+
const ChatChatVentureChatConverter = new Converter<VentureChatConfig, { format: ChatChatFormatsConfig, settings: ChatChatSettingsConfig }>({
99
Convert(venturechatConfig) {
1010
const chatchatFormatsConfig: ChatChatFormatsConfig = {
1111
"default-format": 'default',
@@ -29,26 +29,25 @@ const ChatChatVentureChatConverter = new Converter<VentureChatConfig, {format: C
2929
parts: []
3030
};
3131

32-
let key = 0;
32+
(["venturechat_channel_prefix", "vault_prefix", "player_displayname"]).forEach(key => {
33+
[vcFormat.json_attributes.venturechat_channel_prefix, vcFormat.json_attributes.vault_prefix, vcFormat.json_attributes.player_displayname]
34+
const part = `%${key}%`;
3335

34-
// todo get the possible key from the object?
35-
([vcFormat.json_attributes.venturechat_channel_prefix, vcFormat.json_attributes.vault_prefix, vcFormat.json_attributes.player_displayname]).forEach(section => {
36-
let part = "";
37-
switch(key) {
38-
case 0:
39-
part = "%venturechat_channel_prefix%";
36+
let section: VentureChatJsonComponent;
37+
switch (key) {
38+
case 'venturechat_channel_prefix':
39+
section = vcFormat.json_attributes.venturechat_channel_prefix
4040
break;
41-
case 1:
42-
part = "%vault_prefix%";
41+
case 'vault_prefix':
42+
section = vcFormat.json_attributes.vault_prefix
4343
break;
44-
case 2:
45-
part = "%player_displayname%";
44+
default:
45+
section = vcFormat.json_attributes.player_displayname
4646
break;
4747
}
48-
console.log(key);
49-
key++;
48+
5049
let formattedSection = part;
51-
switch(section.click_action) {
50+
switch (section.click_action) {
5251
case "suggest_command": {
5352
formattedSection = "<click:suggest_command:'" + section.click_text + "'>" + formattedSection + "</click>";
5453
break;
@@ -62,7 +61,7 @@ const ChatChatVentureChatConverter = new Converter<VentureChatConfig, {format: C
6261
break;
6362
}
6463
}
65-
let hover: string[] = (<string[]>section.hover_text).filter(s => s && s !== "")
64+
let hover = section.hover_text.filter(s => s && s !== "")
6665
if (hover && hover.length > 0) {
6766
formattedSection = "<hover:show_text:'" + hover.join("<newline>") + "'>" + formattedSection + "</hover>";
6867
}

converters/placeholders.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

converters/types/essentialschat.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// @ToolBox - EssentialsChatConfig
22

33
export interface EssentialsChatConfig {
4-
format?: string
5-
"group-formats"?: {
6-
[key: string]: string
4+
chat: {
5+
format?: string
6+
"group-formats"?: {
7+
[key: string]: string
8+
}
79
}
810
}
911

pages/_app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function Converter({Component, pageProps}: AppProps) {
2424
<p css={tw`hover:cursor-pointer`}>EssentialsChat</p>
2525
</Link>
2626
<Link href={'/converters/chatchat/venturechat'}>
27-
<p>VentureChat</p>
27+
<p css={tw`hover:cursor-pointer`}>VentureChat</p>
2828
</Link>
2929
</Collapsable>
3030
</Collapsable>

pages/converters/chatchat/deluxechat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const Home: NextPage = () => {
5050
max-width: calc(50vw - 6rem);
5151
`}>
5252
{
53-
error ? (<div css={tw`flex flex-col h-full w-full pt-1`}>
53+
error || !parsedConfig ? (<div css={tw`flex flex-col h-full w-full pt-1`}>
5454
<div css={tw`flex flex-row pl-2`}>
5555
<p css={tw`text-xl font-semibold mx-auto mb-2`}>YAML Validation Errors</p>
5656
</div>

pages/converters/chatchat/essentialschat.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ const Home: NextPage = () => {
2222
});
2323
propertiesList.forEach(properties => {
2424
if (!properties.key) return;
25-
propertiesConfig[properties.key] = properties.element ? unescape(properties.element) : "";
25+
propertiesConfig[properties.key] = properties.element ?? "";
2626
});
27-
console.log(propertiesConfig);
2827
} catch (e: any) {
2928
setError(e?.message ?? "Error parsing properties file");
3029
setParsedConfig(false);
@@ -37,7 +36,7 @@ const Home: NextPage = () => {
3736
setError(false);
3837
setParsedConfig(newConfig as { format: string, settings: string });
3938
}
40-
}, [config])
39+
}, [config, lang])
4140

4241
return (
4342
<div>
@@ -70,7 +69,7 @@ const Home: NextPage = () => {
7069
max-width: calc(50vw - 6rem);
7170
`}>
7271
{
73-
error ? (<div css={tw`flex flex-col h-full w-full pt-1`}>
72+
error || !parsedConfig ? (<div css={tw`flex flex-col h-full w-full pt-1`}>
7473
<div css={tw`flex flex-row pl-2`}>
7574
<p css={tw`text-xl font-semibold mx-auto mb-2`}>YAML Validation Errors</p>
7675
</div>

pages/converters/chatchat/venturechat.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const Home: NextPage = () => {
5050
max-width: calc(50vw - 6rem);
5151
`}>
5252
{
53-
error ? (<div css={tw`flex flex-col h-full w-full pt-1`}>
53+
error || !parsedConfig ? (<div css={tw`flex flex-col h-full w-full pt-1`}>
5454
<div css={tw`flex flex-row pl-2`}>
5555
<p css={tw`text-xl font-semibold mx-auto mb-2`}>YAML Validation Errors</p>
5656
</div>
@@ -65,15 +65,17 @@ const Home: NextPage = () => {
6565
</div>
6666
</div>) : (
6767
<>
68-
<div css={tw`flex flex-col md:flex-row flex-grow flex-shrink h-full max-w-full`}>
69-
<TextBox title={"ChatChat formats.yml"}
70-
code={!parsedConfig ? "" : parsedConfig.format}
71-
language={"yaml"}/>
72-
</div>
73-
<div css={tw`h-1/2`}>
74-
<TextBox title={"ChatChat settings.yml"}
75-
code={!parsedConfig ? "" : parsedConfig.settings}
76-
language={"yaml"}/>
68+
<div css={tw`flex flex-col flex-grow flex-shrink h-full max-w-full`}>
69+
<div css={tw`h-1/2`}>
70+
<TextBox title={"ChatChat formats.yml"}
71+
code={!parsedConfig ? "" : parsedConfig.format}
72+
language={"yaml"}/>
73+
</div>
74+
<div css={tw`h-1/2`}>
75+
<TextBox title={"ChatChat settings.yml"}
76+
code={!parsedConfig ? "" : parsedConfig.settings}
77+
language={"yaml"}/>
78+
</div>
7779
</div>
7880
</>
7981
)

pages/validators/yaml.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const Home: NextPage = () => {
7878
</div>
7979
<div css={css`${tw`rounded-md overflow-auto h-full`} background-color: #2a2734`}>
8080
<div css={tw` py-2 px-4`}>
81-
{!error ? <ReactJson src={parsedConfig} theme={{
81+
{!(error || !parsedConfig) ? <ReactJson src={parsedConfig} theme={{
8282
base00: duotoneDark.plain.backgroundColor ?? "",
8383
base01: duotoneDark.styles[2].style.color ?? "",
8484
base02: duotoneDark.styles[1].style.color ?? "",

0 commit comments

Comments
 (0)