Skip to content

Commit 51bcd96

Browse files
committed
[sync] Update embedded LibEnchantment from standalone
1 parent 3544e08 commit 51bcd96

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

src/imperazim/enchantment/EnchantmentFactory.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public static function register(int $id, CustomEnchantment $enchant): void {
2626
self::$enchants[$id] = $enchant;
2727

2828
$parser = StringToEnchantmentParser::getInstance();
29-
$parser->register($enchant->name, fn() => $enchant);
29+
$parser->override($enchant->name, fn() => $enchant);
3030
$displayName = $enchant->getDisplayName();
3131
if ($displayName !== '' && $displayName !== $enchant->name) {
32-
$parser->register($displayName, fn() => $enchant);
32+
$parser->override($displayName, fn() => $enchant);
3333
}
3434
}
3535

@@ -120,15 +120,24 @@ private static function unregisterId(int $id): void {
120120
self::setPrivateProperty($idMap, 'idToEnum', $idToEnum);
121121
}
122122

123+
private static function findProperty(object $object, string $property): ReflectionProperty {
124+
$class = new ReflectionClass($object);
125+
while ($class !== false) {
126+
if ($class->hasProperty($property)) {
127+
$prop = $class->getProperty($property);
128+
$prop->setAccessible(true);
129+
return $prop;
130+
}
131+
$class = $class->getParentClass();
132+
}
133+
throw new \RuntimeException("Property $property not found in " . get_class($object) . " hierarchy");
134+
}
135+
123136
private static function getPrivateProperty(object $object, string $property): mixed {
124-
$reflection = new ReflectionProperty($object, $property);
125-
$reflection->setAccessible(true);
126-
return $reflection->getValue($object);
137+
return self::findProperty($object, $property)->getValue($object);
127138
}
128139

129140
private static function setPrivateProperty(object $object, string $property, mixed $value): void {
130-
$reflection = new ReflectionProperty($object, $property);
131-
$reflection->setAccessible(true);
132-
$reflection->setValue($object, $value);
141+
self::findProperty($object, $property)->setValue($object, $value);
133142
}
134143
}

0 commit comments

Comments
 (0)