forked from MrNavaStar/InvSync
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Ruf
committed
Feb 2, 2023
1 parent
3c438c5
commit 0a6268a
Showing
2 changed files
with
16 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
Update fork | ||
Add config flag SYNCHRONIZATION_DELAY_METHOD | ||
Potential change of the event order to synchronize achievements before the inventory (this has never been a problem before, but still) | ||
Add logging to the inv sync events that occur on loading or saving the inventory |
18 changes: 15 additions & 3 deletions
18
src/main/java/de/michiruf/invsync/event/InvSyncEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
package de.michiruf.invsync.event; | ||
|
||
import de.michiruf.invsync.Logger; | ||
import de.michiruf.invsync.data.entity.PlayerData; | ||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import org.apache.logging.log4j.Level; | ||
|
||
public class InvSyncEvents { | ||
|
||
public static final Event<PlayerDataHandler> FETCH_PLAYER_DATA = EventFactory.createArrayBacked(PlayerDataHandler.class, callbacks -> (player, playerData) -> { | ||
for (var callback : callbacks) | ||
if (playerData != null) | ||
callback.handle(player, playerData); | ||
try { | ||
callback.handle(player, playerData); | ||
} catch (Exception e) { | ||
Logger.logException(Level.ERROR, e); | ||
} | ||
else | ||
Logger.log(Level.WARN, "PlayerData is null"); | ||
}); | ||
|
||
public static final Event<PlayerDataHandler> SAVE_PLAYER_DATA = EventFactory.createArrayBacked(PlayerDataHandler.class, callbacks -> (player, playerData) -> { | ||
for (var callback : callbacks) | ||
callback.handle(player, playerData); | ||
try { | ||
callback.handle(player, playerData); | ||
} catch (Exception e) { | ||
Logger.logException(Level.ERROR, e); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface PlayerDataHandler { | ||
|
||
void handle(ServerPlayerEntity player, PlayerData playerData); | ||
void handle(ServerPlayerEntity player, PlayerData playerData) throws Exception; | ||
} | ||
} |