mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-12-28 12:07:33 +01:00
parent
d112e9b1dc
commit
9df0dd48e4
@ -63,21 +63,16 @@ class CachedPackage {
|
||||
* @return Class object.
|
||||
* @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!");
|
||||
|
||||
Optional<Class<?>> result = cache.get(className);
|
||||
if (result == null) {
|
||||
return cache.computeIfAbsent(className, x -> {
|
||||
try {
|
||||
Class<?> clazz = source.loadClass(combine(packageName, className));
|
||||
result = Optional.ofNullable(clazz);
|
||||
cache.put(className, result);
|
||||
return Optional.ofNullable(source.loadClass(combine(packageName, className)));
|
||||
} catch (ClassNotFoundException ex) {
|
||||
cache.put(className, Optional.empty());
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,7 @@
|
||||
package com.comphenix.protocol.utility;
|
||||
|
||||
import static com.comphenix.protocol.utility.TestUtils.assertItemsEqual;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@ -75,6 +74,11 @@ public class MinecraftReflectionTest {
|
||||
MinecraftReflection.getBukkitEntity("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullable() {
|
||||
assertNull(MinecraftReflection.getNullableNMS("ProtocolLib"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributeSnapshot() {
|
||||
assertEquals(AttributeSnapshot.class, MinecraftReflection.getAttributeSnapshotClass());
|
||||
|
Loading…
Reference in New Issue
Block a user