Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
24ef0c1d
Commit
24ef0c1d
authored
Aug 11, 2019
by
liujiahua123123
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Config
parent
7c1cba29
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
259 additions
and
2 deletions
+259
-2
mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java
mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java
+5
-2
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfig.java
...c/main/java/net/mamoe/mirai/utils/config/MiraiConfig.java
+88
-0
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java
...java/net/mamoe/mirai/utils/config/MiraiConfigSection.java
+12
-0
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiListSection.java
...n/java/net/mamoe/mirai/utils/config/MiraiListSection.java
+52
-0
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiMapSection.java
...in/java/net/mamoe/mirai/utils/config/MiraiMapSection.java
+88
-0
pom.xml
pom.xml
+14
-0
No files found.
mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java
View file @
24ef0c1d
...
@@ -46,7 +46,9 @@ public class MiraiServer {
...
@@ -46,7 +46,9 @@ public class MiraiServer {
protected
void
shutdown
(){
protected
void
shutdown
(){
if
(
this
.
enabled
)
{
if
(
this
.
enabled
)
{
this
.
getLogger
().
log
(
LoggerTextFormat
.
SKY_BLUE
+
"About to shutdown Mirai"
);
this
.
getEventManager
().
boardcastEvent
(
new
ServerDisableEvent
());
this
.
getEventManager
().
boardcastEvent
(
new
ServerDisableEvent
());
this
.
getLogger
().
log
(
LoggerTextFormat
.
SKY_BLUE
+
"Data have been saved"
);
}
}
}
}
...
@@ -61,9 +63,10 @@ public class MiraiServer {
...
@@ -61,9 +63,10 @@ public class MiraiServer {
this
.
eventManager
=
MiraiEventManager
.
getInstance
();
this
.
eventManager
=
MiraiEventManager
.
getInstance
();
this
.
taskManager
=
MiraiTaskManager
.
getInstance
();
this
.
taskManager
=
MiraiTaskManager
.
getInstance
();
this
.
getLogger
().
log
(
LoggerTextFormat
.
SKY_BLUE
+
"About to run Mirai
"
+
MiraiServer
.
getMiraiVersion
()
+
"
under "
+
(
isUnix
()?
"unix"
:
"windows"
)
);
this
.
getLogger
().
log
(
LoggerTextFormat
.
SKY_BLUE
+
"About to run Mirai
("
+
MiraiServer
.
getMiraiVersion
()
+
")
under "
+
(
isUnix
()?
"unix"
:
"windows"
)
);
this
.
getLogger
().
log
(
"Loading data under "
+
this
.
parentFolder
);
this
.
getLogger
().
log
(
"Loading data under "
+
LoggerTextFormat
.
GREEN
+
this
.
parentFolder
);
/*
/*
try {
try {
Network.start(Network.getAvailablePort());
Network.start(Network.getAvailablePort());
...
...
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfig.java
0 → 100644
View file @
24ef0c1d
package
net.mamoe.mirai.utils.config
;
import
org.ini4j.Config
;
import
org.ini4j.Ini
;
import
org.ini4j.Profile
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Vector
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* Mirai Config
* Only support {INI} format
* Support MAP and LIST
* Thread safe
*/
public
class
MiraiConfig
{
private
File
file
;
private
Ini
ini
;
private
volatile
Map
<
String
,
MiraiConfigSection
>
cacheSection
=
new
ConcurrentHashMap
<>();
private
volatile
List
<
String
>
needSaving
=
new
Vector
<>();
public
MiraiConfig
(
File
file
){
if
(!
file
.
getName
().
contains
(
"."
)){
file
=
new
File
(
file
.
getParent
()
+
file
.
getName
()
+
".ini"
);
}
this
.
file
=
file
;
try
{
Config
config
=
new
Config
();
config
.
setMultiSection
(
true
);
ini
=
new
Ini
();
ini
.
setConfig
(
config
);
ini
.
load
(
this
.
file
.
toURI
().
toURL
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
void
setSection
(
String
key
,
MiraiConfigSection
section
){
cacheSection
.
put
(
key
,
section
);
needSaving
.
add
(
key
);
}
public
MiraiMapSection
getMapSection
(
String
key
){
if
(!
cacheSection
.
containsKey
(
key
))
{
MiraiMapSection
section
=
new
MiraiMapSection
();
section
.
putAll
(
ini
.
get
(
key
));
cacheSection
.
put
(
key
,
section
);
}
return
(
MiraiMapSection
)
cacheSection
.
get
(
key
);
}
public
MiraiListSection
getListSection
(
String
key
){
if
(!
cacheSection
.
containsKey
(
key
))
{
MiraiListSection
section
=
new
MiraiListSection
();
section
.
addAll
(
ini
.
get
(
key
).
values
());
cacheSection
.
put
(
key
,
section
);
}
return
(
MiraiListSection
)
cacheSection
.
get
(
key
);
}
public
synchronized
void
save
(){
needSaving
.
forEach
(
a
->
{
cacheSection
.
get
(
a
).
saveAsSection
(
ini
.
get
(
a
));
});
try
{
ini
.
store
(
file
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
needSaving
.
clear
();
}
public
void
clearCache
(){
needSaving
.
clear
();
cacheSection
.
clear
();
}
}
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java
0 → 100644
View file @
24ef0c1d
package
net.mamoe.mirai.utils.config
;
import
org.ini4j.Profile
;
import
java.io.Closeable
;
import
java.util.Map
;
public
interface
MiraiConfigSection
extends
Closeable
{
void
saveAsSection
(
Profile
.
Section
section
);
}
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiListSection.java
0 → 100644
View file @
24ef0c1d
package
net.mamoe.mirai.utils.config
;
import
org.ini4j.Profile
;
import
java.io.IOException
;
import
java.util.Map
;
import
java.util.Vector
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.locks.Lock
;
import
java.util.concurrent.locks.ReentrantLock
;
public
class
MiraiListSection
extends
Vector
<
Object
>
implements
MiraiConfigSection
{
private
Lock
lock
=
new
ReentrantLock
();
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
getAs
(
int
index
){
return
(
T
)
super
.
get
(
index
);
}
public
int
getInt
(
int
index
){
return
this
.
getAs
(
index
);
}
public
int
getDouble
(
int
index
){
return
this
.
getAs
(
index
);
}
public
int
getString
(
int
index
){
return
this
.
getAs
(
index
);
}
public
int
getFloat
(
int
index
)
{
return
this
.
getAs
(
index
);
}
@Override
public
synchronized
void
saveAsSection
(
Profile
.
Section
section
)
{
section
.
clear
();
AtomicInteger
integer
=
new
AtomicInteger
(
0
);
this
.
forEach
(
a
->
{
section
.
put
(
String
.
valueOf
(
integer
.
getAndAdd
(
1
)),
a
);
});
}
@Override
public
void
close
()
throws
IOException
{
}
}
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiMapSection.java
0 → 100644
View file @
24ef0c1d
package
net.mamoe.mirai.utils.config
;
import
org.ini4j.Profile
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.stream.Collectors
;
public
class
MiraiMapSection
extends
ConcurrentHashMap
<
String
,
Object
>
implements
MiraiConfigSection
{
public
Object
get
(
String
key
){
return
this
.
get
(
key
,
null
);
}
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
get
(
String
key
,
T
defaultValue
)
{
if
(
key
==
null
||
key
.
isEmpty
()){
return
defaultValue
;
}
if
(
super
.
containsKey
(
key
)){
return
(
T
)
super
.
get
(
key
);
}
return
defaultValue
;
}
public
void
set
(
String
key
,
Object
value
){
this
.
put
(
key
,
value
);
}
public
void
remove
(
String
key
){
super
.
remove
(
key
);
}
public
int
getInt
(
String
key
)
{
return
this
.
getInt
(
key
,
0
);
}
public
int
getInt
(
String
key
,
int
defaultValue
)
{
return
this
.
get
(
key
,
defaultValue
);
}
public
double
getDouble
(
String
key
)
{
return
this
.
getDouble
(
key
,
0
D
);
}
public
double
getDouble
(
String
key
,
double
defaultValue
)
{
return
this
.
get
(
key
,
defaultValue
);
}
public
float
getFloat
(
String
key
)
{
return
this
.
getFloat
(
key
,
0
F
);
}
public
float
getFloat
(
String
key
,
float
defaultValue
)
{
return
this
.
get
(
key
,
defaultValue
);
}
public
String
getString
(
String
key
)
{
return
this
.
getString
(
key
,
""
);
}
public
String
getString
(
String
key
,
String
defaultValue
)
{
return
String
.
valueOf
(
this
.
get
(
key
,
defaultValue
));
}
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
List
<
T
>
asList
(){
return
this
.
values
().
stream
().
map
(
a
->
(
T
)(
a
)).
collect
(
Collectors
.
toList
());
}
@Override
public
synchronized
void
saveAsSection
(
Profile
.
Section
section
)
{
section
.
clear
();
this
.
forEach
(
section:
:
put
);
}
@Override
public
void
close
()
throws
IOException
{
}
}
pom.xml
View file @
24ef0c1d
...
@@ -83,6 +83,13 @@
...
@@ -83,6 +83,13 @@
<version>
1.18.8
</version>
<version>
1.18.8
</version>
<scope>
compile
</scope>
<scope>
compile
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.ini4j
</groupId>
<artifactId>
ini4j
</artifactId>
<version>
0.5.2
</version>
</dependency>
</dependencies>
</dependencies>
<dependencyManagement>
<dependencyManagement>
...
@@ -100,6 +107,13 @@
...
@@ -100,6 +107,13 @@
<artifactId>
netty-all
</artifactId>
<artifactId>
netty-all
</artifactId>
<version>
4.1.38.Final
</version>
<version>
4.1.38.Final
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.ini4j
</groupId>
<artifactId>
ini4j
</artifactId>
<version>
0.5.2
</version>
</dependency>
</dependencies>
</dependencies>
</dependencyManagement>
</dependencyManagement>
...
...
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