mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
only failthrough on FailThroughEvent
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.dfsek.terra.api.event.events;
|
||||
|
||||
/**
|
||||
* An event which (optionally) passes exceptions thrown by listeners to
|
||||
* the event caller.
|
||||
*/
|
||||
public interface FailThroughEvent extends Event {
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.api.event.events.config;
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.Loader;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -14,7 +15,7 @@ import java.util.function.Consumer;
|
||||
* Addons should listen to this event if they wish to add
|
||||
* another configuration format.
|
||||
*/
|
||||
public class ConfigurationDiscoveryEvent implements PackEvent {
|
||||
public class ConfigurationDiscoveryEvent implements PackEvent, FailThroughEvent {
|
||||
private final ConfigPack pack;
|
||||
private final Loader loader;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.dfsek.tectonic.abstraction.AbstractConfiguration;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
||||
|
||||
@@ -15,7 +16,7 @@ import java.util.function.Consumer;
|
||||
* Addons should listen to this event if they wish to add
|
||||
* config values to existing {@link ConfigType}s.
|
||||
*/
|
||||
public class ConfigurationLoadEvent implements PackEvent {
|
||||
public class ConfigurationLoadEvent implements PackEvent, FailThroughEvent {
|
||||
private final ConfigPack pack;
|
||||
private final AbstractConfiguration configuration;
|
||||
private final Consumer<ConfigTemplate> loader;
|
||||
|
||||
@@ -3,12 +3,13 @@ package com.dfsek.terra.api.event.events.config.pack;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
|
||||
/**
|
||||
* An event related to the loading process of config packs.
|
||||
*/
|
||||
public abstract class ConfigPackLoadEvent implements PackEvent {
|
||||
public abstract class ConfigPackLoadEvent implements PackEvent, FailThroughEvent {
|
||||
private final ConfigPack pack;
|
||||
private final ExceptionalConsumer<ConfigTemplate> configLoader;
|
||||
|
||||
|
||||
@@ -2,11 +2,12 @@ package com.dfsek.terra.api.event.events.config.type;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
||||
|
||||
public abstract class ConfigTypeLoadEvent implements PackEvent {
|
||||
public abstract class ConfigTypeLoadEvent implements PackEvent, FailThroughEvent {
|
||||
private final ConfigType<?, ?> type;
|
||||
private final CheckedRegistry<?> registry;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
|
||||
public class ConfigTypePostLoadEvent extends ConfigTypeLoadEvent{
|
||||
public class ConfigTypePostLoadEvent extends ConfigTypeLoadEvent {
|
||||
public ConfigTypePostLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry, ConfigPack pack) {
|
||||
super(type, registry, pack);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
|
||||
public class ConfigTypePreLoadEvent extends ConfigTypeLoadEvent{
|
||||
public class ConfigTypePreLoadEvent extends ConfigTypeLoadEvent {
|
||||
public ConfigTypePreLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry, ConfigPack pack) {
|
||||
super(type, registry, pack);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.event;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
import com.dfsek.terra.api.event.functional.EventContext;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
@@ -39,7 +40,7 @@ public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
|
||||
((EventContextImpl<Event>) context).handle(event);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
if(context.isFailThrough()) throw e; // Rethrow if it's fail-through.
|
||||
if(context.isFailThrough() && event instanceof FailThroughEvent) throw e; // Rethrow if it's fail-through.
|
||||
StringWriter writer = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(writer));
|
||||
main.logger().warning("Exception occurred during event handling:");
|
||||
|
||||
Reference in New Issue
Block a user