Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
CreatureChat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Public
CreatureChat
Commits
1c6ddbae
Commit
1c6ddbae
authored
May 09, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Output red error if config commands fail to save config file
- Updated save-related error message text
parent
50d27268
Pipeline
#12158
passed with stage
in 1 minute 51 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
6 deletions
+21
-6
CHANGELOG.md
CHANGELOG.md
+2
-1
ChatDataManager.java
src/main/java/com/owlmaddie/chat/ChatDataManager.java
+1
-1
ConfigurationHandler.java
...ain/java/com/owlmaddie/commands/ConfigurationHandler.java
+10
-2
CreatureChatCommands.java
...ain/java/com/owlmaddie/commands/CreatureChatCommands.java
+8
-2
No files found.
CHANGELOG.md
View file @
1c6ddbae
...
...
@@ -8,7 +8,8 @@ All notable changes to **CreatureChat** are documented in this file. The format
### Changed
-
Simplified saving of chat data (no more renaming files)
-
Send message to all ops when saving chat data errors (first auto-save happens at 1 minute after launching)
-
If chat data fails to save, send message to all ops (first auto-save happens at 1 minute after launching)
-
If /creaturechat commands fail to save, send message to all ops (fail loudly) and display RED error message
## [1.0.2] - 2024-05-07
...
...
src/main/java/com/owlmaddie/chat/ChatDataManager.java
View file @
1c6ddbae
...
...
@@ -485,7 +485,7 @@ public class ChatDataManager {
try
(
Writer
writer
=
new
OutputStreamWriter
(
new
FileOutputStream
(
saveFile
),
StandardCharsets
.
UTF_8
))
{
GSON
.
toJson
(
this
.
entityChatDataMap
,
writer
);
}
catch
(
Exception
e
)
{
String
errorMessage
=
"Error saving
chat data to file system. No chat history will be saved. Check file permissions.
"
+
e
.
getMessage
();
String
errorMessage
=
"Error saving
`chatdata.json`. No CreatureChat chat history was saved!
"
+
e
.
getMessage
();
LOGGER
.
error
(
errorMessage
,
e
);
ServerPackets
.
sendMessageToAllOps
(
server
,
errorMessage
);
}
...
...
src/main/java/com/owlmaddie/commands/ConfigurationHandler.java
View file @
1c6ddbae
...
...
@@ -2,8 +2,11 @@ package com.owlmaddie.commands;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.owlmaddie.network.ServerPackets
;
import
net.minecraft.server.MinecraftServer
;
import
net.minecraft.util.WorldSavePath
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.io.Reader
;
...
...
@@ -19,6 +22,7 @@ import java.nio.file.Paths;
*/
public
class
ConfigurationHandler
{
public
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
"creaturechat"
);
private
static
final
Gson
gson
=
new
GsonBuilder
().
setPrettyPrinting
().
create
();
private
final
Path
serverConfigPath
;
private
final
Path
defaultConfigPath
;
...
...
@@ -36,12 +40,16 @@ public class ConfigurationHandler {
return
config
!=
null
?
config
:
new
Config
();
// Return new config if both are null
}
public
void
saveConfig
(
Config
config
,
boolean
useServerConfig
)
{
public
boolean
saveConfig
(
Config
config
,
boolean
useServerConfig
)
{
Path
path
=
useServerConfig
?
serverConfigPath
:
defaultConfigPath
;
try
(
Writer
writer
=
Files
.
newBufferedWriter
(
path
))
{
gson
.
toJson
(
config
,
writer
);
return
true
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
String
errorMessage
=
"Error saving `creaturechat.json`. CreatureChat config was not saved. "
+
e
.
getMessage
();
LOGGER
.
error
(
errorMessage
,
e
);
ServerPackets
.
sendMessageToAllOps
(
ServerPackets
.
serverInstance
,
errorMessage
);
return
false
;
}
}
...
...
src/main/java/com/owlmaddie/commands/CreatureChatCommands.java
View file @
1c6ddbae
...
...
@@ -62,9 +62,15 @@ public class CreatureChatCommands {
config
.
setModel
(
value
);
break
;
}
configHandler
.
saveConfig
(
config
,
useServerConfig
);
Text
feedbackMessage
=
Text
.
literal
(
settingDescription
+
" Set Successfully!"
).
formatted
(
Formatting
.
GREEN
);;
Text
feedbackMessage
;
if
(
configHandler
.
saveConfig
(
config
,
useServerConfig
))
{
// succeeded
feedbackMessage
=
Text
.
literal
(
settingDescription
+
" Set Successfully!"
).
formatted
(
Formatting
.
GREEN
);
}
else
{
// failed
feedbackMessage
=
Text
.
literal
(
settingDescription
+
" Set Failed!"
).
formatted
(
Formatting
.
RED
);
}
source
.
sendFeedback
(()
->
feedbackMessage
,
false
);
LOGGER
.
info
(
"Command executed: "
+
feedbackMessage
.
getString
());
return
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment