forked from github-mirror/CoreProtect
Further improved attribute handling
This commit is contained in:
1 parent
127170d7b6
commit
fc91bc558c
1 file changed
+40
-1
@@ -6,12 +6,16 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.util.io.BukkitObjectInputStream;
|
import org.bukkit.util.io.BukkitObjectInputStream;
|
||||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||||
|
|
||||||
|
import net.coreprotect.bukkit.BukkitAdapter;
|
||||||
import net.coreprotect.config.ConfigHandler;
|
import net.coreprotect.config.ConfigHandler;
|
||||||
import net.coreprotect.database.Database;
|
import net.coreprotect.database.Database;
|
||||||
|
|
||||||
@@ -25,7 +29,7 @@ public class EntityStatement {
|
|||||||
try {
|
try {
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
BukkitObjectOutputStream oos = new BukkitObjectOutputStream(bos);
|
BukkitObjectOutputStream oos = new BukkitObjectOutputStream(bos);
|
||||||
oos.writeObject(data);
|
oos.writeObject(sanitizeData(data));
|
||||||
oos.flush();
|
oos.flush();
|
||||||
oos.close();
|
oos.close();
|
||||||
bos.close();
|
bos.close();
|
||||||
@@ -47,6 +51,41 @@ public class EntityStatement {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<Object> sanitizeData(List<Object> data) {
|
||||||
|
List<Object> result = new ArrayList<>(data.size());
|
||||||
|
for (Object value : data) {
|
||||||
|
result.add(sanitizeValue(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object sanitizeValue(Object value) {
|
||||||
|
if (value instanceof Attribute) {
|
||||||
|
return BukkitAdapter.ADAPTER.getRegistryKey(value);
|
||||||
|
}
|
||||||
|
else if (value instanceof List<?>) {
|
||||||
|
List<?> list = (List<?>) value;
|
||||||
|
List<Object> result = new ArrayList<>(list.size());
|
||||||
|
for (Object item : list) {
|
||||||
|
result.add(sanitizeValue(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (value instanceof Map<?, ?>) {
|
||||||
|
Map<?, ?> map = (Map<?, ?>) value;
|
||||||
|
Map<Object, Object> result = new LinkedHashMap<>(map.size());
|
||||||
|
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||||
|
result.put(sanitizeValue(entry.getKey()), sanitizeValue(entry.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<Object> getData(Statement statement, BlockState block, String query) {
|
public static List<Object> getData(Statement statement, BlockState block, String query) {
|
||||||
List<Object> result = new ArrayList<>();
|
List<Object> result = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user