Skip to content

Commit 1173dde

Browse files
committed
Update VentureChat to not hardcode parts
1 parent 3fa12d5 commit 1173dde

File tree

3 files changed

+36
-63
lines changed

3 files changed

+36
-63
lines changed

converters/chatchat/venturechat.ts

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,50 +29,39 @@ const ChatChatVentureChatConverter = new Converter<VentureChatConfig, { format:
2929
parts: []
3030
};
3131

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}%`;
35-
36-
let section: VentureChatJsonComponent;
37-
switch (key) {
38-
case 'venturechat_channel_prefix':
39-
section = vcFormat.json_attributes.venturechat_channel_prefix
40-
break;
41-
case 'vault_prefix':
42-
section = vcFormat.json_attributes.vault_prefix
43-
break;
44-
default:
45-
section = vcFormat.json_attributes.player_displayname
46-
break;
47-
}
48-
49-
let formattedSection = part;
50-
switch (section.click_action) {
51-
case "suggest_command": {
52-
formattedSection = "<click:suggest_command:'" + section.click_text + "'>" + formattedSection + "</click>";
53-
break;
32+
if (vcFormat.json_attributes) {
33+
const innerFormat = vcFormat.json_attributes;
34+
Object.keys(innerFormat).forEach(key => {
35+
const part = `%${key}%`;
36+
const section = innerFormat[key];
37+
let formattedSection = part;
38+
switch (section.click_action) {
39+
case "suggest_command": {
40+
formattedSection = "<click:suggest_command:'" + section.click_text + "'>" + formattedSection + "</click>";
41+
break;
42+
}
43+
case "run_command": {
44+
formattedSection = "<click:run_command:'" + section.click_text + "'>" + formattedSection + "</click>";
45+
break;
46+
}
47+
case "open_url": {
48+
formattedSection = "<click:open_url:'" + section.click_text + "'>" + formattedSection + "</click>";
49+
break;
50+
}
5451
}
55-
case "run_command": {
56-
formattedSection = "<click:run_command:'" + section.click_text + "'>" + formattedSection + "</click>";
57-
break;
52+
let hover = section.hover_text.filter(s => s && s !== "")
53+
if (hover && hover.length > 0) {
54+
formattedSection = "<hover:show_text:'" + hover.join("<newline>") + "'>" + formattedSection + "</hover>";
5855
}
59-
case "open_url": {
60-
formattedSection = "<click:open_url:'" + section.click_text + "'>" + formattedSection + "</click>";
61-
break;
62-
}
63-
}
64-
let hover = section.hover_text.filter(s => s && s !== "")
65-
if (hover && hover.length > 0) {
66-
formattedSection = "<hover:show_text:'" + hover.join("<newline>") + "'>" + formattedSection + "</hover>";
67-
}
6856

69-
if (formattedSection !== "") {
70-
ccFormat.parts.push(MiniMessage(formattedSection));
71-
}
72-
})
73-
ccFormat.parts.push("<message>")
74-
chatchatFormatsConfig.formats[name] = ccFormat;
75-
})
57+
if (formattedSection !== "") {
58+
ccFormat.parts.push(MiniMessage(formattedSection));
59+
}
60+
})
61+
ccFormat.parts.push("<message>")
62+
chatchatFormatsConfig.formats[name] = ccFormat;
63+
}
64+
});
7665
}
7766

7867

converters/types/venturechat.json

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,13 @@
3131
},
3232
"json_attributes": {
3333
"type": "object",
34-
"properties": {
35-
"player_displayname": {
36-
"$ref": "#/definitions/VentureChatJsonComponent"
37-
},
38-
"vault_prefix": {
39-
"$ref": "#/definitions/VentureChatJsonComponent"
40-
},
41-
"venturechat_channel_prefix": {
42-
"$ref": "#/definitions/VentureChatJsonComponent"
43-
}
44-
},
45-
"required": [
46-
"player_displayname",
47-
"vault_prefix",
48-
"venturechat_channel_prefix"
49-
]
34+
"additionalProperties": {
35+
"$ref": "#/definitions/VentureChatJsonComponent"
36+
}
5037
}
5138
},
5239
"required": [
53-
"priority",
54-
"json_attributes"
40+
"priority"
5541
]
5642
},
5743
"VentureChatJsonComponent": {

converters/types/venturechat.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ export interface VentureChatConfig {
1010

1111
export interface VentureChatFormat {
1212
priority: number;
13-
json_attributes: {
14-
player_displayname: VentureChatJsonComponent
15-
vault_prefix: VentureChatJsonComponent
16-
venturechat_channel_prefix: VentureChatJsonComponent
13+
json_attributes?: {
14+
[key : string]: VentureChatJsonComponent
1715
}
1816
}
1917

0 commit comments

Comments
 (0)