Ursprung
d112e9b1dc
Commit
9df0dd48e4
@ -63,21 +63,16 @@ class CachedPackage {
|
|||||||
* @return Class object.
|
* @return Class object.
|
||||||
* @throws RuntimeException If we are unable to find the given class.
|
* @throws RuntimeException If we are unable to find the given class.
|
||||||
*/
|
*/
|
||||||
public Optional<Class<?>> getPackageClass(String className) {
|
public Optional<Class<?>> getPackageClass(final String className) {
|
||||||
Preconditions.checkNotNull(className, "className cannot be null!");
|
Preconditions.checkNotNull(className, "className cannot be null!");
|
||||||
|
|
||||||
Optional<Class<?>> result = cache.get(className);
|
return cache.computeIfAbsent(className, x -> {
|
||||||
if (result == null) {
|
|
||||||
try {
|
try {
|
||||||
Class<?> clazz = source.loadClass(combine(packageName, className));
|
return Optional.ofNullable(source.loadClass(combine(packageName, className)));
|
||||||
result = Optional.ofNullable(clazz);
|
|
||||||
cache.put(className, result);
|
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
cache.put(className, Optional.empty());
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2021,7 +2021,7 @@ public class MinecraftReflection {
|
|||||||
.orElseThrow(() -> new RuntimeException("Failed to find NMS class: " + className));
|
.orElseThrow(() -> new RuntimeException("Failed to find NMS class: " + className));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> getNullableNMS(String className) {
|
static Class<?> getNullableNMS(String className) {
|
||||||
if (minecraftPackage == null)
|
if (minecraftPackage == null)
|
||||||
minecraftPackage = new CachedPackage(getMinecraftPackage(), getClassSource());
|
minecraftPackage = new CachedPackage(getMinecraftPackage(), getClassSource());
|
||||||
return minecraftPackage.getPackageClass(className).orElse(null);
|
return minecraftPackage.getPackageClass(className).orElse(null);
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package com.comphenix.protocol.utility;
|
package com.comphenix.protocol.utility;
|
||||||
|
|
||||||
import static com.comphenix.protocol.utility.TestUtils.assertItemsEqual;
|
import static com.comphenix.protocol.utility.TestUtils.assertItemsEqual;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@ -75,6 +74,11 @@ public class MinecraftReflectionTest {
|
|||||||
MinecraftReflection.getBukkitEntity("Hello");
|
MinecraftReflection.getBukkitEntity("Hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullable() {
|
||||||
|
assertNull(MinecraftReflection.getNullableNMS("ProtocolLib"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttributeSnapshot() {
|
public void testAttributeSnapshot() {
|
||||||
assertEquals(AttributeSnapshot.class, MinecraftReflection.getAttributeSnapshotClass());
|
assertEquals(AttributeSnapshot.class, MinecraftReflection.getAttributeSnapshotClass());
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren