Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
d32f706c
Commit
d32f706c
authored
Apr 27, 2022
by
KingRainbow44
Browse files
Merge branch 'development' into api
# Conflicts: # src/main/java/emu/grasscutter/plugin/api/ServerHook.java
parents
47d8fd3c
f0d728b4
Changes
308
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/task/TaskHandler.java
0 → 100644
View file @
d32f706c
package
emu.grasscutter.task
;
import
org.quartz.*
;
@PersistJobDataAfterExecution
public
class
TaskHandler
implements
Job
{
public
void
restartExecute
()
throws
JobExecutionException
{
execute
(
null
);
}
public
void
onEnable
()
{
}
public
void
onDisable
()
{
}
@Override
public
void
execute
(
JobExecutionContext
context
)
throws
JobExecutionException
{
// TODO Auto-generated method stub
}
}
src/main/java/emu/grasscutter/task/TaskMap.java
0 → 100644
View file @
d32f706c
package
emu.grasscutter.task
;
import
emu.grasscutter.Grasscutter
;
import
org.quartz.*
;
import
org.quartz.impl.StdSchedulerFactory
;
import
org.reflections.Reflections
;
import
java.util.*
;
@SuppressWarnings
({
"UnusedReturnValue"
,
"unused"
})
public
final
class
TaskMap
{
private
final
Map
<
String
,
TaskHandler
>
tasks
=
new
HashMap
<>();
private
final
Map
<
String
,
Task
>
annotations
=
new
HashMap
<>();
private
final
Map
<
String
,
TaskHandler
>
afterReset
=
new
HashMap
<>();
private
final
SchedulerFactory
schedulerFactory
=
new
StdSchedulerFactory
();
public
TaskMap
()
{
this
(
false
);
}
public
TaskMap
(
boolean
scan
)
{
if
(
scan
)
this
.
scan
();
}
public
static
TaskMap
getInstance
()
{
return
Grasscutter
.
getGameServer
().
getTaskMap
();
}
public
void
resetNow
()
{
// Unregister all tasks
for
(
TaskHandler
task
:
this
.
tasks
.
values
())
{
unregisterTask
(
task
);
}
// Run all afterReset tasks
for
(
TaskHandler
task
:
this
.
afterReset
.
values
())
{
try
{
task
.
restartExecute
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
// Remove all afterReset tasks
this
.
afterReset
.
clear
();
// Register all tasks
for
(
TaskHandler
task
:
this
.
tasks
.
values
())
{
registerTask
(
task
.
getClass
().
getAnnotation
(
Task
.
class
).
taskName
(),
task
);
}
}
public
TaskMap
unregisterTask
(
TaskHandler
task
)
{
this
.
tasks
.
remove
(
task
.
getClass
().
getAnnotation
(
Task
.
class
).
taskName
());
this
.
annotations
.
remove
(
task
.
getClass
().
getAnnotation
(
Task
.
class
).
taskName
());
try
{
Scheduler
scheduler
=
schedulerFactory
.
getScheduler
();
scheduler
.
deleteJob
(
new
JobKey
(
task
.
getClass
().
getAnnotation
(
Task
.
class
).
taskName
()));
}
catch
(
SchedulerException
e
)
{
e
.
printStackTrace
();
}
task
.
onDisable
();
return
this
;
}
public
TaskMap
registerTask
(
String
taskName
,
TaskHandler
task
)
{
Task
annotation
=
task
.
getClass
().
getAnnotation
(
Task
.
class
);
this
.
annotations
.
put
(
taskName
,
annotation
);
this
.
tasks
.
put
(
taskName
,
task
);
// register task
try
{
Scheduler
scheduler
=
schedulerFactory
.
getScheduler
();
JobDetail
job
=
JobBuilder
.
newJob
(
task
.
getClass
())
.
withIdentity
(
taskName
)
.
build
();
Trigger
convTrigger
=
TriggerBuilder
.
newTrigger
()
.
withIdentity
(
annotation
.
triggerName
())
.
withSchedule
(
CronScheduleBuilder
.
cronSchedule
(
annotation
.
taskCronExpression
()))
.
build
();
scheduler
.
scheduleJob
(
job
,
convTrigger
);
if
(
annotation
.
executeImmediately
())
{
task
.
execute
(
null
);
}
task
.
onEnable
();
}
catch
(
SchedulerException
e
)
{
e
.
printStackTrace
();
}
return
this
;
}
public
List
<
TaskHandler
>
getHandlersAsList
()
{
return
new
LinkedList
<>(
this
.
tasks
.
values
());
}
public
HashMap
<
String
,
TaskHandler
>
getHandlers
()
{
return
new
LinkedHashMap
<>(
this
.
tasks
);
}
public
TaskHandler
getHandler
(
String
taskName
)
{
return
this
.
tasks
.
get
(
taskName
);
}
private
void
scan
()
{
Reflections
reflector
=
Grasscutter
.
reflector
;
Set
<
Class
<?>>
classes
=
reflector
.
getTypesAnnotatedWith
(
Task
.
class
);
classes
.
forEach
(
annotated
->
{
try
{
Task
taskData
=
annotated
.
getAnnotation
(
Task
.
class
);
Object
object
=
annotated
.
newInstance
();
if
(
object
instanceof
TaskHandler
)
{
this
.
registerTask
(
taskData
.
taskName
(),
(
TaskHandler
)
object
);
if
(
taskData
.
executeImmediatelyAfterReset
())
{
this
.
afterReset
.
put
(
taskData
.
taskName
(),
(
TaskHandler
)
object
);
}
}
else
{
Grasscutter
.
getLogger
().
error
(
"Class "
+
annotated
.
getName
()
+
" is not a TaskHandler!"
);
}
}
catch
(
Exception
exception
)
{
Grasscutter
.
getLogger
().
error
(
"Failed to register task handler for "
+
annotated
.
getSimpleName
(),
exception
);
}
});
try
{
Scheduler
scheduler
=
schedulerFactory
.
getScheduler
();
scheduler
.
start
();
}
catch
(
SchedulerException
e
)
{
e
.
printStackTrace
();
}
}
}
src/main/java/emu/grasscutter/task/tasks/MoonCard.java
0 → 100644
View file @
d32f706c
package
emu.grasscutter.task.tasks
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.task.Task
;
import
emu.grasscutter.task.TaskHandler
;
import
org.quartz.JobExecutionContext
;
import
org.quartz.JobExecutionException
;
@Task
(
taskName
=
"MoonCard"
,
taskCronExpression
=
"0 0 0 * * ?"
,
triggerName
=
"MoonCardTrigger"
)
// taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system)
public
class
MoonCard
extends
TaskHandler
{
@Override
public
void
onEnable
()
{
Grasscutter
.
getLogger
().
info
(
"[Task] MoonCard task enabled."
);
}
@Override
public
void
onDisable
()
{
Grasscutter
.
getLogger
().
info
(
"[Task] MoonCard task disabled."
);
}
@Override
public
synchronized
void
execute
(
JobExecutionContext
context
)
throws
JobExecutionException
{
Grasscutter
.
getGameServer
().
getPlayers
().
forEach
((
uid
,
player
)
->
{
if
(
player
.
isOnline
())
{
if
(
player
.
inMoonCard
())
{
player
.
getTodayMoonCard
();
}
}
});
}
}
src/main/java/emu/grasscutter/tools/Tools.java
View file @
d32f706c
...
@@ -18,9 +18,9 @@ import java.util.stream.Collectors;
...
@@ -18,9 +18,9 @@ import java.util.stream.Collectors;
import
com.google.gson.reflect.TypeToken
;
import
com.google.gson.reflect.TypeToken
;
import
emu.grasscutter.G
enshin
Constants
;
import
emu.grasscutter.G
ame
Constants
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.G
enshin
Data
;
import
emu.grasscutter.data.G
ame
Data
;
import
emu.grasscutter.data.ResourceLoader
;
import
emu.grasscutter.data.ResourceLoader
;
import
emu.grasscutter.data.def.AvatarData
;
import
emu.grasscutter.data.def.AvatarData
;
import
emu.grasscutter.data.def.ItemData
;
import
emu.grasscutter.data.def.ItemData
;
...
@@ -45,48 +45,48 @@ public final class Tools {
...
@@ -45,48 +45,48 @@ public final class Tools {
DateTimeFormatter
dtf
=
DateTimeFormatter
.
ofPattern
(
"yyyy/MM/dd HH:mm:ss"
);
DateTimeFormatter
dtf
=
DateTimeFormatter
.
ofPattern
(
"yyyy/MM/dd HH:mm:ss"
);
LocalDateTime
now
=
LocalDateTime
.
now
();
LocalDateTime
now
=
LocalDateTime
.
now
();
writer
.
println
(
"// G
enshin Impact "
+
Genshin
Constants
.
VERSION
+
" GM Handbook"
);
writer
.
println
(
"// G
rasscutter "
+
Game
Constants
.
VERSION
+
" GM Handbook"
);
writer
.
println
(
"// Created "
+
dtf
.
format
(
now
)
+
System
.
lineSeparator
()
+
System
.
lineSeparator
());
writer
.
println
(
"// Created "
+
dtf
.
format
(
now
)
+
System
.
lineSeparator
()
+
System
.
lineSeparator
());
list
=
new
ArrayList
<>(
G
enshin
Data
.
getAvatarDataMap
().
keySet
());
list
=
new
ArrayList
<>(
G
ame
Data
.
getAvatarDataMap
().
keySet
());
Collections
.
sort
(
list
);
Collections
.
sort
(
list
);
writer
.
println
(
"// Avatars"
);
writer
.
println
(
"// Avatars"
);
for
(
Integer
id
:
list
)
{
for
(
Integer
id
:
list
)
{
AvatarData
data
=
G
enshin
Data
.
getAvatarDataMap
().
get
(
id
);
AvatarData
data
=
G
ame
Data
.
getAvatarDataMap
().
get
(
id
);
writer
.
println
(
data
.
getId
()
+
" : "
+
map
.
get
(
data
.
getNameTextMapHash
()));
writer
.
println
(
data
.
getId
()
+
" : "
+
map
.
get
(
data
.
getNameTextMapHash
()));
}
}
writer
.
println
();
writer
.
println
();
list
=
new
ArrayList
<>(
G
enshin
Data
.
getItemDataMap
().
keySet
());
list
=
new
ArrayList
<>(
G
ame
Data
.
getItemDataMap
().
keySet
());
Collections
.
sort
(
list
);
Collections
.
sort
(
list
);
writer
.
println
(
"// Items"
);
writer
.
println
(
"// Items"
);
for
(
Integer
id
:
list
)
{
for
(
Integer
id
:
list
)
{
ItemData
data
=
G
enshin
Data
.
getItemDataMap
().
get
(
id
);
ItemData
data
=
G
ame
Data
.
getItemDataMap
().
get
(
id
);
writer
.
println
(
data
.
getId
()
+
" : "
+
map
.
get
(
data
.
getNameTextMapHash
()));
writer
.
println
(
data
.
getId
()
+
" : "
+
map
.
get
(
data
.
getNameTextMapHash
()));
}
}
writer
.
println
();
writer
.
println
();
writer
.
println
(
"// Scenes"
);
writer
.
println
(
"// Scenes"
);
list
=
new
ArrayList
<>(
G
enshin
Data
.
getSceneDataMap
().
keySet
());
list
=
new
ArrayList
<>(
G
ame
Data
.
getSceneDataMap
().
keySet
());
Collections
.
sort
(
list
);
Collections
.
sort
(
list
);
for
(
Integer
id
:
list
)
{
for
(
Integer
id
:
list
)
{
SceneData
data
=
G
enshin
Data
.
getSceneDataMap
().
get
(
id
);
SceneData
data
=
G
ame
Data
.
getSceneDataMap
().
get
(
id
);
writer
.
println
(
data
.
getId
()
+
" : "
+
data
.
getScriptData
());
writer
.
println
(
data
.
getId
()
+
" : "
+
data
.
getScriptData
());
}
}
writer
.
println
();
writer
.
println
();
writer
.
println
(
"// Monsters"
);
writer
.
println
(
"// Monsters"
);
list
=
new
ArrayList
<>(
G
enshin
Data
.
getMonsterDataMap
().
keySet
());
list
=
new
ArrayList
<>(
G
ame
Data
.
getMonsterDataMap
().
keySet
());
Collections
.
sort
(
list
);
Collections
.
sort
(
list
);
for
(
Integer
id
:
list
)
{
for
(
Integer
id
:
list
)
{
MonsterData
data
=
G
enshin
Data
.
getMonsterDataMap
().
get
(
id
);
MonsterData
data
=
G
ame
Data
.
getMonsterDataMap
().
get
(
id
);
writer
.
println
(
data
.
getId
()
+
" : "
+
map
.
get
(
data
.
getNameTextMapHash
()));
writer
.
println
(
data
.
getId
()
+
" : "
+
map
.
get
(
data
.
getNameTextMapHash
()));
}
}
}
}
...
...
src/main/java/emu/grasscutter/utils/Crypto.java
View file @
d32f706c
...
@@ -34,7 +34,7 @@ public final class Crypto {
...
@@ -34,7 +34,7 @@ public final class Crypto {
public
static
void
extractSecretKeyBuffer
(
byte
[]
data
)
{
public
static
void
extractSecretKeyBuffer
(
byte
[]
data
)
{
try
{
try
{
GetPlayerTokenRsp
p
=
GetPlayerTokenRsp
.
parseFrom
(
data
);
GetPlayerTokenRsp
p
=
GetPlayerTokenRsp
.
parseFrom
(
data
);
FileUtils
.
write
(
Grasscutter
.
getConfig
().
KEY_FOLDER
+
"secretKeyBuffer.bin"
,
p
.
getSecretKeyB
uffer
().
toByteArray
());
FileUtils
.
write
(
Grasscutter
.
getConfig
().
KEY_FOLDER
+
"secretKeyBuffer.bin"
,
p
.
getSecretKeyB
ytes
().
toByteArray
());
Grasscutter
.
getLogger
().
info
(
"Secret Key: "
+
p
.
getSecretKey
());
Grasscutter
.
getLogger
().
info
(
"Secret Key: "
+
p
.
getSecretKey
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
"Crypto error."
,
e
);
Grasscutter
.
getLogger
().
error
(
"Crypto error."
,
e
);
...
...
src/main/java/emu/grasscutter/utils/DateHelper.java
0 → 100644
View file @
d32f706c
package
emu.grasscutter.utils
;
import
java.util.Date
;
import
java.util.Calendar
;
public
final
class
DateHelper
{
public
static
Date
onlyYearMonthDay
(
Date
now
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
now
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTime
();
}
}
src/main/java/emu/grasscutter/utils/Utils.java
View file @
d32f706c
...
@@ -174,11 +174,11 @@ public final class Utils {
...
@@ -174,11 +174,11 @@ public final class Utils {
// Check for resources folder.
// Check for resources folder.
if
(!
fileExists
(
resourcesFolder
))
{
if
(!
fileExists
(
resourcesFolder
))
{
logger
.
info
(
"Creating resources folder..."
);
logger
.
info
(
"Creating resources folder..."
);
logger
.
info
(
"Place a copy of '
GenshinData
' in the resources folder."
);
logger
.
info
(
"Place a copy of '
BinOutput' and 'ExcelBinOutput
' in the resources folder."
);
createFolder
(
resourcesFolder
);
exit
=
true
;
createFolder
(
resourcesFolder
);
exit
=
true
;
}
}
// Check for
GenshinData
.
// Check for
BinOutput + ExcelBinOuput
.
if
(!
fileExists
(
resourcesFolder
+
"BinOutput"
)
||
if
(!
fileExists
(
resourcesFolder
+
"BinOutput"
)
||
!
fileExists
(
resourcesFolder
+
"ExcelBinOutput"
))
{
!
fileExists
(
resourcesFolder
+
"ExcelBinOutput"
))
{
logger
.
info
(
"Place a copy of 'BinOutput' and 'ExcelBinOutput' in the resources folder."
);
logger
.
info
(
"Place a copy of 'BinOutput' and 'ExcelBinOutput' in the resources folder."
);
...
...
start.cmd
View file @
d32f706c
...
@@ -33,7 +33,7 @@ if not "%JAVA_PATH%" == "DO_NOT_CHECK_PATH" (
...
@@ -33,7 +33,7 @@ if not "%JAVA_PATH%" == "DO_NOT_CHECK_PATH" (
goto
:EXIT
goto
:EXIT
)
)
)
else
set
JAVA_PATH
=
)
else
set
JAVA_PATH
=
if
not
exist
"
%SERVER_PATH%
grasscutter.jar
"
(
if
not
exist
"
%SERVER_PATH%
%
SERVER_JAR_NAME
%
"
(
call
:LOG
[
ERROR
]
Server
jar
not
found
.
call
:LOG
[
ERROR
]
Server
jar
not
found
.
goto
:EXIT
goto
:EXIT
)
)
...
@@ -129,7 +129,7 @@ del /f /q "%temp%\db.vbs" >nul 2>nul
...
@@ -129,7 +129,7 @@ del /f /q "%temp%\db.vbs" >nul 2>nul
:GAME
:GAME
call
:LOG
[
INFO
]
Starting
server
...
call
:LOG
[
INFO
]
Starting
server
...
"
%JAVA_PATH%
java.exe"
-jar
"
%SERVER_PATH%
grasscutter.jar
"
"
%JAVA_PATH%
java.exe"
-jar
"
%SERVER_PATH%
%
SERVER_JAR_NAME
%
"
call
:LOG
[
INFO
]
Server
stopped
call
:LOG
[
INFO
]
Server
stopped
:EXIT
:EXIT
...
...
Prev
1
…
12
13
14
15
16
Next
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