Fix a bug where events would not post
This commit is contained in:
parent
5db113cbd3
commit
a70425d418
3 changed files with 42 additions and 21 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue