mirror of https://github.com/Minestom/Minestom.git
Merge pull request #229 from Project-Cepi/better-catching
Better catching for events/commands
This commit is contained in:
commit
d31fe2d88e
|
@ -1,5 +1,6 @@
|
|||
package net.minestom.server.command.builder;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.condition.CommandCondition;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
|
@ -54,11 +55,19 @@ public class ParsedCommand {
|
|||
final CommandCondition commandCondition = syntax.getCommandCondition();
|
||||
if (commandCondition == null || commandCondition.canUse(source, commandString)) {
|
||||
context.retrieveDefaultValues(syntax.getDefaultValuesMap());
|
||||
executor.apply(source, context);
|
||||
try {
|
||||
executor.apply(source, context);
|
||||
} catch (Exception exception) {
|
||||
MinecraftServer.getExceptionManager().handleException(exception);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// The executor is probably the default one
|
||||
executor.apply(source, context);
|
||||
try {
|
||||
executor.apply(source, context);
|
||||
} catch (Exception exception) {
|
||||
MinecraftServer.getExceptionManager().handleException(exception);
|
||||
}
|
||||
}
|
||||
} else if (callback != null && argumentSyntaxException != null) {
|
||||
// No syntax has been validated but the faulty argument with a callback has been found
|
||||
|
|
|
@ -108,22 +108,27 @@ public interface EventHandler extends IExtensionObserver {
|
|||
*/
|
||||
default <E extends Event> void callEvent(@NotNull Class<E> eventClass, @NotNull E event) {
|
||||
|
||||
// Global listeners
|
||||
if (!(this instanceof GlobalEventHandler)) {
|
||||
final GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
|
||||
runEvent(globalEventHandler.getEventCallbacks(eventClass), event);
|
||||
}
|
||||
try {
|
||||
|
||||
// Local listeners
|
||||
final Collection<EventCallback> eventCallbacks = getEventCallbacks(eventClass);
|
||||
runEvent(eventCallbacks, event);
|
||||
|
||||
// Call the same event for the current entity instance
|
||||
if (this instanceof Entity) {
|
||||
final Instance instance = ((Entity) this).getInstance();
|
||||
if (instance != null) {
|
||||
runEvent(instance.getEventCallbacks(eventClass), event);
|
||||
// Global listeners
|
||||
if (!(this instanceof GlobalEventHandler)) {
|
||||
final GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
|
||||
runEvent(globalEventHandler.getEventCallbacks(eventClass), event);
|
||||
}
|
||||
|
||||
// Local listeners
|
||||
final Collection<EventCallback> eventCallbacks = getEventCallbacks(eventClass);
|
||||
runEvent(eventCallbacks, event);
|
||||
|
||||
// Call the same event for the current entity instance
|
||||
if (this instanceof Entity) {
|
||||
final Instance instance = ((Entity) this).getInstance();
|
||||
if (instance != null) {
|
||||
runEvent(instance.getEventCallbacks(eventClass), event);
|
||||
}
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
MinecraftServer.getExceptionManager().handleException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue