Skip to content

Commit 3aa818c

Browse files
committed
Fixup container rollbacks
1 parent d6ad610 commit 3aa818c

4 files changed

Lines changed: 10 additions & 14 deletions

File tree

src/main/java/net/coreprotect/command/RollbackRestoreCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ else if (action == 0) {
424424
Chat.sendMessage(player2, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.ROLLBACK_STARTED, users, Selector.SECOND));
425425
}
426426

427-
if (finalArgAction.contains(5) || finalArgAction.contains(4)) {
427+
if (finalArgAction.contains(5)) {
428428
ContainerRollback.performContainerRollbackRestore(statement, player2, uuidList, rollbackusers2, rtime, blist, elist, euserlist, finalArgAction, location, radius, finalTimeStart, finalTimeEnd, restrictWorld, false, verbose, action);
429429
}
430430
else {

src/main/java/net/coreprotect/database/logger/ContainerLogger.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,7 @@ protected static void logTransaction(PreparedStatement preparedStmt, int batchCo
224224
return;
225225
}
226226

227-
// slot is only relevant when face data is set
228-
String itemData = null;
229-
if ((faceData != null && !faceData.isEmpty()) || ItemUtils.hasNonTrivialData(item)) {
230-
itemData = ItemUtils.serializeItem(item, slot, ItemUtils.parseBlockFaceOrNull(faceData));
231-
}
227+
String itemData = ItemUtils.serializeItem(item, slot, ItemUtils.parseBlockFaceOrNull(faceData));
232228

233229
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
234230
Location eventLocation = event.getLocation();

src/main/java/net/coreprotect/database/rollback/Rollback.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ public static LookupResult<?> performRollbackRestore(Statement statement, Comman
5050
rawLookupResult = Lookup.performLookup(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, null, startTime, endTime, -1, -1, restrictWorld, lookup, false);
5151
}
5252

53-
if (!(rawLookupResult instanceof final CommonLookupResult lookupResult)) {
54-
return null;
55-
}
56-
5753
boolean ROLLBACK_ITEMS = false;
5854
List<Object> itemRestrictList = new ArrayList<>(restrictList);
5955
Map<Object, Boolean> itemExcludeList = new HashMap<>(excludeList);
@@ -89,6 +85,10 @@ public static LookupResult<?> performRollbackRestore(Statement statement, Comman
8985
}
9086
}
9187

88+
if (!(rawLookupResult instanceof CommonLookupResult) && itemLookupResult == null) {
89+
return null;
90+
}
91+
9292
LinkedHashSet<Integer> worldList = new LinkedHashSet<>();
9393
TreeMap<Long, Integer> chunkList = new TreeMap<>();
9494
Map<Integer, Map<Long, List<CommonLookupData>>> dataList = new HashMap<>();
@@ -101,7 +101,7 @@ public static LookupResult<?> performRollbackRestore(Statement statement, Comman
101101

102102
int listC = 0;
103103
while (listC < 2) {
104-
List<CommonLookupData> scanList = lookupResult.data();
104+
List<CommonLookupData> scanList = rawLookupResult != null ? ((CommonLookupResult) rawLookupResult).data() : List.of(); // rawLookupResult can be null while upstream just handles it as an empty list
105105

106106
if (listC == 1 && itemLookupResult != null) {
107107
scanList = itemLookupResult.data();
@@ -211,7 +211,7 @@ public static LookupResult<?> performRollbackRestore(Statement statement, Comman
211211
Queue.queueRollbackUpdate(userString, blockList, Process.BLOCK_INVENTORY_ROLLBACK_UPDATE, rollbackType);
212212
}
213213
else {
214-
Queue.queueRollbackUpdate(userString, lookupResult.data(), Process.ROLLBACK_UPDATE, rollbackType);
214+
Queue.queueRollbackUpdate(userString, rawLookupResult instanceof CommonLookupResult lookupResult ? lookupResult.data() : null, Process.ROLLBACK_UPDATE, rollbackType);
215215
Queue.queueRollbackUpdate(userString, itemLookupResult != null ? itemLookupResult.data() : null, Process.CONTAINER_ROLLBACK_UPDATE, rollbackType);
216216
}
217217
}

src/main/java/net/coreprotect/utility/ItemUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ public static String serializeItem(@NonNull ItemStack itemStack, int slot, Block
517517
itemStack.setAmount(99);
518518
}
519519

520-
final JsonObject object = Bukkit.getUnsafe().serializeItemAsJson(itemStack);
520+
final JsonObject object = hasNonTrivialData(itemStack) ? Bukkit.getUnsafe().serializeItemAsJson(itemStack) : new JsonObject();
521521

522522
if (slot >= 0) {
523523
object.addProperty("co_slot", slot);
@@ -564,7 +564,7 @@ public static SerializedItem deserializeItem(@Nullable String itemString, @Nulla
564564
}
565565

566566
if (!object.has("DataVersion")) {
567-
// not an item
567+
// not an item, or just not saved fully due to not having any special data
568568
return type != null && amount > 0 && type.isItem() ? new SerializedItem(ItemStack.of(type, Math.min(amount, 99)), slot, faceData) : null;
569569
}
570570

0 commit comments

Comments
 (0)