mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-27 14:30:23 +00:00
only failthrough on FailThroughEvent
This commit is contained in:
1 parent
b630ab6531
commit
2175ea849f
8 files changed
+20
-7
No files matched your search
@@ -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 {
|
||||||
|
}
|
||||||
+2
-1
@@ -3,6 +3,7 @@ package com.dfsek.terra.api.event.events.config;
|
|||||||
import com.dfsek.tectonic.config.Configuration;
|
import com.dfsek.tectonic.config.Configuration;
|
||||||
import com.dfsek.terra.api.config.ConfigPack;
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
import com.dfsek.terra.api.config.Loader;
|
import com.dfsek.terra.api.config.Loader;
|
||||||
|
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||||
import com.dfsek.terra.api.event.events.PackEvent;
|
import com.dfsek.terra.api.event.events.PackEvent;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
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
|
* Addons should listen to this event if they wish to add
|
||||||
* another configuration format.
|
* another configuration format.
|
||||||
*/
|
*/
|
||||||
public class ConfigurationDiscoveryEvent implements PackEvent {
|
public class ConfigurationDiscoveryEvent implements PackEvent, FailThroughEvent {
|
||||||
private final ConfigPack pack;
|
private final ConfigPack pack;
|
||||||
private final Loader loader;
|
private final Loader loader;
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -4,6 +4,7 @@ import com.dfsek.tectonic.abstraction.AbstractConfiguration;
|
|||||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||||
import com.dfsek.terra.api.config.ConfigPack;
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
import com.dfsek.terra.api.config.ConfigType;
|
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.event.events.PackEvent;
|
||||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
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
|
* Addons should listen to this event if they wish to add
|
||||||
* config values to existing {@link ConfigType}s.
|
* config values to existing {@link ConfigType}s.
|
||||||
*/
|
*/
|
||||||
public class ConfigurationLoadEvent implements PackEvent {
|
public class ConfigurationLoadEvent implements PackEvent, FailThroughEvent {
|
||||||
private final ConfigPack pack;
|
private final ConfigPack pack;
|
||||||
private final AbstractConfiguration configuration;
|
private final AbstractConfiguration configuration;
|
||||||
private final Consumer<ConfigTemplate> loader;
|
private final Consumer<ConfigTemplate> loader;
|
||||||
|
|||||||
+2
-1
@@ -3,12 +3,13 @@ package com.dfsek.terra.api.event.events.config.pack;
|
|||||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||||
import com.dfsek.tectonic.exception.ConfigException;
|
import com.dfsek.tectonic.exception.ConfigException;
|
||||||
import com.dfsek.terra.api.config.ConfigPack;
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
|
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||||
import com.dfsek.terra.api.event.events.PackEvent;
|
import com.dfsek.terra.api.event.events.PackEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An event related to the loading process of config packs.
|
* 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 ConfigPack pack;
|
||||||
private final ExceptionalConsumer<ConfigTemplate> configLoader;
|
private final ExceptionalConsumer<ConfigTemplate> configLoader;
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -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.ConfigPack;
|
||||||
import com.dfsek.terra.api.config.ConfigType;
|
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.event.events.PackEvent;
|
||||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
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 ConfigType<?, ?> type;
|
||||||
private final CheckedRegistry<?> registry;
|
private final CheckedRegistry<?> registry;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ import com.dfsek.terra.api.config.ConfigPack;
|
|||||||
import com.dfsek.terra.api.config.ConfigType;
|
import com.dfsek.terra.api.config.ConfigType;
|
||||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
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) {
|
public ConfigTypePostLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry, ConfigPack pack) {
|
||||||
super(type, registry, pack);
|
super(type, registry, pack);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ import com.dfsek.terra.api.config.ConfigPack;
|
|||||||
import com.dfsek.terra.api.config.ConfigType;
|
import com.dfsek.terra.api.config.ConfigType;
|
||||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
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) {
|
public ConfigTypePreLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry, ConfigPack pack) {
|
||||||
super(type, registry, pack);
|
super(type, registry, pack);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -3,6 +3,7 @@ package com.dfsek.terra.event;
|
|||||||
import com.dfsek.terra.api.TerraPlugin;
|
import com.dfsek.terra.api.TerraPlugin;
|
||||||
import com.dfsek.terra.api.addon.TerraAddon;
|
import com.dfsek.terra.api.addon.TerraAddon;
|
||||||
import com.dfsek.terra.api.event.events.Event;
|
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.events.PackEvent;
|
||||||
import com.dfsek.terra.api.event.functional.EventContext;
|
import com.dfsek.terra.api.event.functional.EventContext;
|
||||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||||
@@ -39,7 +40,7 @@ public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
|
|||||||
((EventContextImpl<Event>) context).handle(event);
|
((EventContextImpl<Event>) context).handle(event);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} 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();
|
StringWriter writer = new StringWriter();
|
||||||
e.printStackTrace(new PrintWriter(writer));
|
e.printStackTrace(new PrintWriter(writer));
|
||||||
main.logger().warning("Exception occurred during event handling:");
|
main.logger().warning("Exception occurred during event handling:");
|
||||||
|
|||||||
Reference in new issue
Block a user