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
88bdaf15
Commit
88bdaf15
authored
Apr 26, 2022
by
KingRainbow44
Browse files
Use a custom consumer instead of the built-in one
parent
99325523
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/plugin/PluginManager.java
View file @
88bdaf15
...
@@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter;
...
@@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter;
import
emu.grasscutter.server.event.Event
;
import
emu.grasscutter.server.event.Event
;
import
emu.grasscutter.server.event.EventHandler
;
import
emu.grasscutter.server.event.EventHandler
;
import
emu.grasscutter.server.event.HandlerPriority
;
import
emu.grasscutter.server.event.HandlerPriority
;
import
emu.grasscutter.utils.EventConsumer
;
import
emu.grasscutter.utils.Utils
;
import
emu.grasscutter.utils.Utils
;
import
java.io.File
;
import
java.io.File
;
...
@@ -14,7 +15,6 @@ import java.net.URLClassLoader;
...
@@ -14,7 +15,6 @@ import java.net.URLClassLoader;
import
java.util.*
;
import
java.util.*
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarFile
;
import
java.util.jar.JarFile
;
import
java.util.stream.Stream
;
/**
/**
* Manages the server's plugins and the event system.
* Manages the server's plugins and the event system.
...
@@ -164,6 +164,6 @@ public final class PluginManager {
...
@@ -164,6 +164,6 @@ public final class PluginManager {
private
void
invokeHandler
(
Event
event
,
EventHandler
handler
)
{
private
void
invokeHandler
(
Event
event
,
EventHandler
handler
)
{
if
(!
event
.
isCanceled
()
||
if
(!
event
.
isCanceled
()
||
(
event
.
isCanceled
()
&&
handler
.
ignoresCanceled
())
(
event
.
isCanceled
()
&&
handler
.
ignoresCanceled
())
)
handler
.
getCallback
().
accept
(
event
);
)
handler
.
getCallback
().
consume
(
event
);
}
}
}
}
\ No newline at end of file
src/main/java/emu/grasscutter/server/event/EventHandler.java
View file @
88bdaf15
package
emu.grasscutter.server.event
;
package
emu.grasscutter.server.event
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.utils.EventConsumer
;
import
java.util.function.Consumer
;
public
final
class
EventHandler
{
public
final
class
EventHandler
{
private
final
Class
<?
extends
Event
>
event
;
private
final
Class
<?
extends
Event
>
event
;
...
@@ -16,15 +15,11 @@ public final class EventHandler {
...
@@ -16,15 +15,11 @@ public final class EventHandler {
return
new
EventHandler
(
event
);
return
new
EventHandler
(
event
);
}
}
/**
private
EventHandler
(
Class
<?
extends
Event
>
event
)
{
* @deprecated Will be replaced with a private constructor instead. Use {@link #forEvent(Class)} instead.
*/
@Deprecated
(
forRemoval
=
true
,
since
=
"1.0.1"
)
public
EventHandler
(
Class
<?
extends
Event
>
event
)
{
this
.
event
=
event
;
this
.
event
=
event
;
}
}
private
Consumer
<
Event
>
listener
;
private
Event
Consumer
listener
;
private
HandlerPriority
priority
;
private
HandlerPriority
priority
;
private
boolean
handleCanceled
;
private
boolean
handleCanceled
;
...
@@ -40,7 +35,7 @@ public final class EventHandler {
...
@@ -40,7 +35,7 @@ public final class EventHandler {
* Returns the callback for the handler.
* Returns the callback for the handler.
* @return A consumer callback.
* @return A consumer callback.
*/
*/
public
Consumer
<
Event
>
getCallback
()
{
public
Event
Consumer
getCallback
()
{
return
this
.
listener
;
return
this
.
listener
;
}
}
...
@@ -65,7 +60,7 @@ public final class EventHandler {
...
@@ -65,7 +60,7 @@ public final class EventHandler {
* @param listener An event handler method.
* @param listener An event handler method.
* @return Method chaining.
* @return Method chaining.
*/
*/
public
EventHandler
listener
(
Consumer
<
Event
>
listener
)
{
public
EventHandler
listener
(
Event
Consumer
listener
)
{
this
.
listener
=
listener
;
return
this
;
this
.
listener
=
listener
;
return
this
;
}
}
...
...
src/main/java/emu/grasscutter/utils/EventConsumer.java
0 → 100644
View file @
88bdaf15
package
emu.grasscutter.utils
;
import
emu.grasscutter.server.event.Event
;
public
interface
EventConsumer
{
<
T
extends
Event
>
void
consume
(
T
event
);
}
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