Skip to content

Commit 3038e96

Browse files
committed
Fixed broken entity rollbacks
1 parent afb13e6 commit 3038e96

File tree

4 files changed

+8
-36
lines changed

4 files changed

+8
-36
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class RollbackEntityHandler {
4646
* The username associated with this entity change
4747
* @return The number of entities affected (1 if successful, 0 otherwise)
4848
*/
49-
public static int processEntity(Object[] row, int rollbackType, String finalUserString, int rowTypeRaw, int rowData, int rowAction, int rowRolledBack, int rowX, int rowY, int rowZ, int rowWorldId, int rowUserId, String rowUser) {
49+
public static int processEntity(Object[] row, int rollbackType, String finalUserString, int oldTypeRaw, int rowTypeRaw, int rowData, int rowAction, int rowRolledBack, int rowX, int rowY, int rowZ, int rowWorldId, int rowUserId, String rowUser) {
5050
try {
5151
// Entity kill
5252
if (rowAction == 3) {
@@ -76,12 +76,11 @@ public static int processEntity(Object[] row, int rollbackType, String finalUser
7676
}
7777
}
7878
else if (rowTypeRaw <= 0) {
79-
int oldTypeRaw = rowTypeRaw;
8079
// Attempt to remove entity
8180
if (rowRolledBack == 1) {
8281
boolean removed = false;
8382
int entityId = -1;
84-
String entityName = EntityUtils.getEntityType(Math.abs(oldTypeRaw)).name();
83+
String entityName = EntityUtils.getEntityType(oldTypeRaw).name();
8584
String token = "" + rowX + "." + rowY + "." + rowZ + "." + rowWorldId + "." + entityName + "";
8685
Object[] cachedEntity = CacheHandler.entityCache.get(token);
8786

@@ -107,7 +106,7 @@ else if (rowTypeRaw <= 0) {
107106
}
108107
}
109108
else {
110-
if (entity.getType().equals(EntityUtils.getEntityType(Math.abs(oldTypeRaw)))) {
109+
if (entity.getType().equals(EntityUtils.getEntityType(oldTypeRaw))) {
111110
Location entityLocation = entity.getLocation();
112111
int entityx = entityLocation.getBlockX();
113112
int entityY = entityLocation.getBlockY();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ else if (rowAction == 3 && rollbackType == 1) { // entity removal
169169
}
170170
}
171171
else if (rowAction == 3) { // entity kill
172-
entityCount += RollbackEntityHandler.processEntity(row, rollbackType, finalUserString, rowTypeRaw, rowData, rowAction, MaterialUtils.rolledBack((Integer) row[9], false), rowX, rowY, rowZ, rowWorldId, (Integer) row[2], rowUser);
172+
entityCount += RollbackEntityHandler.processEntity(row, rollbackType, finalUserString, oldTypeRaw, rowTypeRaw, rowData, rowAction, MaterialUtils.rolledBack((Integer) row[9], false), rowX, rowY, rowZ, rowWorldId, (Integer) row[2], rowUser);
173173
}
174174
else {
175175
String world = WorldUtils.getWorldName(rowWorldId);

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

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -533,16 +533,7 @@ public static List<Object> deserializeMetadata(byte[] metadata) {
533533
* Additional data for the entity
534534
*/
535535
public static void queueEntitySpawn(String user, BlockState block, EntityType type, int data) {
536-
if (Queue.class.getDeclaredMethods() != null) {
537-
try {
538-
java.lang.reflect.Method method = Queue.class.getDeclaredMethod("queueEntitySpawn", String.class, BlockState.class, EntityType.class, int.class);
539-
method.setAccessible(true);
540-
method.invoke(null, user, block, type, data);
541-
}
542-
catch (Exception e) {
543-
e.printStackTrace();
544-
}
545-
}
536+
Queue.queueEntitySpawn(user, block, type, data);
546537
}
547538

548539
/**
@@ -556,16 +547,7 @@ public static void queueEntitySpawn(String user, BlockState block, EntityType ty
556547
* The row ID for the skull data
557548
*/
558549
public static void queueSkullUpdate(String user, BlockState block, int rowId) {
559-
if (Queue.class.getDeclaredMethods() != null) {
560-
try {
561-
java.lang.reflect.Method method = Queue.class.getDeclaredMethod("queueSkullUpdate", String.class, BlockState.class, int.class);
562-
method.setAccessible(true);
563-
method.invoke(null, user, block, rowId);
564-
}
565-
catch (Exception e) {
566-
e.printStackTrace();
567-
}
568-
}
550+
Queue.queueSkullUpdate(user, block, rowId);
569551
}
570552

571553
/**
@@ -581,15 +563,6 @@ public static void queueSkullUpdate(String user, BlockState block, int rowId) {
581563
* The time of the update
582564
*/
583565
public static void queueSignUpdate(String user, BlockState block, int action, int time) {
584-
if (Queue.class.getDeclaredMethods() != null) {
585-
try {
586-
java.lang.reflect.Method method = Queue.class.getDeclaredMethod("queueSignUpdate", String.class, BlockState.class, int.class, int.class);
587-
method.setAccessible(true);
588-
method.invoke(null, user, block, action, time);
589-
}
590-
catch (Exception e) {
591-
e.printStackTrace();
592-
}
593-
}
566+
Queue.queueSignUpdate(user, block, action, time);
594567
}
595568
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ public static EntityType getSpawnerType(int type) {
131131

132132
return result;
133133
}
134-
}
134+
}

0 commit comments

Comments
 (0)