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
0
Merge Requests
0
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
6c2c12c6
Commit
6c2c12c6
authored
Apr 07, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding auto-saving to the mod, every 15 minutes
parent
cfc59775
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
1 deletion
+55
-1
ModInit.java
src/main/java/com/owlmaddie/ModInit.java
+11
-1
ChatDataAutoSaver.java
src/main/java/com/owlmaddie/chat/ChatDataAutoSaver.java
+21
-0
ChatDataSaverScheduler.java
src/main/java/com/owlmaddie/chat/ChatDataSaverScheduler.java
+23
-0
No files found.
src/main/java/com/owlmaddie/ModInit.java
View file @
6c2c12c6
...
...
@@ -21,6 +21,8 @@ import net.minecraft.text.Text;
import
net.minecraft.util.Identifier
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.owlmaddie.chat.ChatDataSaverScheduler
;
import
java.util.concurrent.TimeUnit
;
import
java.util.Arrays
;
import
java.util.Locale
;
...
...
@@ -34,6 +36,7 @@ import java.util.UUID;
public
class
ModInit
implements
ModInitializer
{
public
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
"mobgpt"
);
public
static
MinecraftServer
serverInstance
;
private
static
ChatDataSaverScheduler
scheduler
=
null
;
public
static
final
Identifier
PACKET_C2S_GREETING
=
new
Identifier
(
"mobgpt"
,
"packet_c2s_greeting"
);
public
static
final
Identifier
PACKET_C2S_READ_NEXT
=
new
Identifier
(
"mobgpt"
,
"packet_c2s_read_next"
);
public
static
final
Identifier
PACKET_C2S_START_CHAT
=
new
Identifier
(
"mobgpt"
,
"packet_c2s_start_chat"
);
...
...
@@ -180,9 +183,13 @@ public class ModInit implements ModInitializer {
ServerWorldEvents
.
LOAD
.
register
((
server
,
world
)
->
{
String
world_name
=
world
.
getRegistryKey
().
getValue
().
getPath
();
if
(
world_name
==
"overworld"
)
{
if
(
world_name
.
equals
(
"overworld"
)
)
{
serverInstance
=
server
;
ChatDataManager
.
getServerInstance
().
loadChatData
(
server
);
// Start the auto-save task to save every X minutes
scheduler
=
new
ChatDataSaverScheduler
();
scheduler
.
startAutoSaveTask
(
server
,
15
,
TimeUnit
.
MINUTES
);
}
});
ServerWorldEvents
.
UNLOAD
.
register
((
server
,
world
)
->
{
...
...
@@ -190,6 +197,9 @@ public class ModInit implements ModInitializer {
if
(
world_name
==
"overworld"
)
{
ChatDataManager
.
getServerInstance
().
saveChatData
(
server
);
serverInstance
=
null
;
// Shutdown auto scheduler
scheduler
.
stopAutoSaveTask
();
}
});
...
...
src/main/java/com/owlmaddie/chat/ChatDataAutoSaver.java
0 → 100644
View file @
6c2c12c6
package
com
.
owlmaddie
.
chat
;
import
net.minecraft.server.MinecraftServer
;
/**
* The {@code ChatDataAutoSaver} class is a Runnable task, which autosaves the server chat data to JSON.
* It can be scheduled with the {@code ChatDataSaverScheduler} class.
*/
public
class
ChatDataAutoSaver
implements
Runnable
{
private
final
MinecraftServer
server
;
public
ChatDataAutoSaver
(
MinecraftServer
server
)
{
this
.
server
=
server
;
}
@Override
public
void
run
()
{
// Your method to save chat data
ChatDataManager
.
getServerInstance
().
saveChatData
(
server
);
}
}
src/main/java/com/owlmaddie/chat/ChatDataSaverScheduler.java
0 → 100644
View file @
6c2c12c6
package
com
.
owlmaddie
.
chat
;
import
net.minecraft.server.MinecraftServer
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
/**
* The {@code ChatDataSaverScheduler} class is used to start the auto save Runnable task and schedule it.
*/
public
class
ChatDataSaverScheduler
{
private
final
ScheduledExecutorService
scheduler
=
Executors
.
newScheduledThreadPool
(
1
);
public
void
startAutoSaveTask
(
MinecraftServer
server
,
long
interval
,
TimeUnit
timeUnit
)
{
ChatDataAutoSaver
saverTask
=
new
ChatDataAutoSaver
(
server
);
scheduler
.
scheduleAtFixedRate
(
saverTask
,
interval
,
interval
,
timeUnit
);
}
public
void
stopAutoSaveTask
()
{
scheduler
.
shutdown
();
}
}
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