Fix a bug where events would not post

This commit is contained in:
Aria 2023-03-13 03:33:03 -07:00
parent 5db113cbd3
commit a70425d418
3 changed files with 42 additions and 21 deletions

View file

@ -72,20 +72,17 @@ public class EventBus
}
List<EventContainer> containers = entry.getValue();
if(eventClazz.isInstance(Event.class))
if(eventClazz.equals(event.getClass()))
{
for (EventContainer eventContainer : containers) {
try {
eventContainer.function.invoke(event);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
//Event t = (Event)eventClazz.getConstructor().newInstance();
eventContainer.function.invoke(eventContainer.containingClass, event);
} catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException | SecurityException e) {
e.printStackTrace();
}
if(event.isCancelled()) cancelled=true;
cancelled=event.isCancelled();
}
}
}

View file

@ -0,0 +1,17 @@
package dev.zontreck.ariaslib.events;
public class NBTLoadFailedEvent extends Event
{
public String fileName;
@Override
public boolean isCancellable() {
return false;
}
public NBTLoadFailedEvent(String fileName)
{
this.fileName=fileName;
}
}

View file

@ -9,26 +9,33 @@ import java.io.FileOutputStream;
import java.io.IOException;
import dev.zontreck.ariaslib.events.EventBus;
import dev.zontreck.ariaslib.events.NBTLoadFailedEvent;
import dev.zontreck.ariaslib.events.NBTLoadedEvent;
import dev.zontreck.ariaslib.events.NBTSavingEvent;
public class NBTIO {
public static CompoundTag read(File file) throws FileNotFoundException, IOException
{
FileInputStream fis = new FileInputStream(file);
CompoundTag tag;
try{
DataInputStream dis = new DataInputStream(fis);
// Start loading
// We can only be a compound tag
dis.skipBytes(1); // Skip the compound tag type bit
tag = (CompoundTag) TagTypes.Compound.type.load(dis);
EventBus.BUS.post(new NBTLoadedEvent(tag, file.getName()));
// Complete
return tag;
FileInputStream fis = new FileInputStream(file);
CompoundTag tag;
DataInputStream dis = new DataInputStream(fis);
// Start loading
// We can only be a compound tag
dis.skipBytes(1); // Skip the compound tag type bit
tag = (CompoundTag) TagTypes.Compound.type.load(dis);
EventBus.BUS.post(new NBTLoadedEvent(tag, file.getName()));
// Complete
return tag;
}catch(Exception e) {
EventBus.BUS.post(new NBTLoadFailedEvent(file.getName()));
return new CompoundTag();
}
}