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
2374c53e
Commit
2374c53e
authored
Apr 27, 2022
by
Yazawazi
Committed by
GitHub
Apr 27, 2022
Browse files
onEnable & onDisable
parent
7789df6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/task/TaskHandler.java
View file @
2374c53e
...
@@ -9,6 +9,14 @@ public class TaskHandler implements Job {
...
@@ -9,6 +9,14 @@ public class TaskHandler implements Job {
execute
(
null
);
execute
(
null
);
}
}
public
void
onEnable
()
{
}
public
void
onDisable
()
{
}
@Override
@Override
public
void
execute
(
JobExecutionContext
context
)
throws
JobExecutionException
{
public
void
execute
(
JobExecutionContext
context
)
throws
JobExecutionException
{
// TODO Auto-generated method stub
// TODO Auto-generated method stub
...
...
src/main/java/emu/grasscutter/task/TaskMap.java
View file @
2374c53e
...
@@ -30,7 +30,7 @@ public final class TaskMap {
...
@@ -30,7 +30,7 @@ public final class TaskMap {
public
void
resetNow
()
{
public
void
resetNow
()
{
// Unregister all tasks
// Unregister all tasks
for
(
TaskHandler
task
:
this
.
tasks
.
values
())
{
for
(
TaskHandler
task
:
this
.
tasks
.
values
())
{
unregisterTask
(
task
.
getClass
().
getAnnotation
(
Task
.
class
).
taskName
()
);
unregisterTask
(
task
);
}
}
// Run all afterReset tasks
// Run all afterReset tasks
...
@@ -51,17 +51,19 @@ public final class TaskMap {
...
@@ -51,17 +51,19 @@ public final class TaskMap {
}
}
}
}
public
TaskMap
unregisterTask
(
String
task
Name
)
{
public
TaskMap
unregisterTask
(
TaskHandler
task
)
{
this
.
tasks
.
remove
(
taskName
);
this
.
tasks
.
remove
(
task
.
getClass
().
getAnnotation
(
Task
.
class
).
taskName
()
);
this
.
annotations
.
remove
(
taskName
);
this
.
annotations
.
remove
(
task
.
getClass
().
getAnnotation
(
Task
.
class
).
taskName
()
);
try
{
try
{
Scheduler
scheduler
=
schedulerFactory
.
getScheduler
();
Scheduler
scheduler
=
schedulerFactory
.
getScheduler
();
scheduler
.
deleteJob
(
new
JobKey
(
taskName
));
scheduler
.
deleteJob
(
new
JobKey
(
task
.
getClass
().
getAnnotation
(
Task
.
class
).
taskName
()
));
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
task
.
onDisable
();
return
this
;
return
this
;
}
}
...
@@ -88,6 +90,7 @@ public final class TaskMap {
...
@@ -88,6 +90,7 @@ public final class TaskMap {
if
(
annotation
.
executeImmediately
())
{
if
(
annotation
.
executeImmediately
())
{
task
.
execute
(
null
);
task
.
execute
(
null
);
}
}
task
.
onEnable
();
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
src/main/java/emu/grasscutter/task/tasks/MoonCard.java
View file @
2374c53e
...
@@ -11,6 +11,17 @@ import org.quartz.JobExecutionException;
...
@@ -11,6 +11,17 @@ import org.quartz.JobExecutionException;
@Task
(
taskName
=
"MoonCard"
,
taskCronExpression
=
"0 0 0 * * ?"
,
triggerName
=
"MoonCardTrigger"
)
@Task
(
taskName
=
"MoonCard"
,
taskCronExpression
=
"0 0 0 * * ?"
,
triggerName
=
"MoonCardTrigger"
)
// taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system)
// taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system)
public
class
MoonCard
extends
TaskHandler
{
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
@Override
public
synchronized
void
execute
(
JobExecutionContext
context
)
throws
JobExecutionException
{
public
synchronized
void
execute
(
JobExecutionContext
context
)
throws
JobExecutionException
{
Grasscutter
.
getGameServer
().
getPlayers
().
forEach
((
uid
,
player
)
->
{
Grasscutter
.
getGameServer
().
getPlayers
().
forEach
((
uid
,
player
)
->
{
...
...
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