-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add the clisten command * Move classes to features package * Implement most requested changes * Make calls to MappingsHelper blocking * Gracefully handle empty results * Wrap mappings trees in CompletableFuture * Optional -> @nullable + gracefully handle errors * Fail CompletableFuture on exception * Extract exception handling to function * Make sure mappings dir is created first * Do not nest flatMap calls * Minor rewrite * Fix bug * Use Util#toMap * Implement requested changes
- Loading branch information
Showing
13 changed files
with
1,534 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/net/earthcomputer/clientcommands/ReflectionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.earthcomputer.clientcommands; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.stream.Stream; | ||
|
||
public final class ReflectionUtils { | ||
|
||
private ReflectionUtils() { | ||
} | ||
|
||
public static Stream<Field> getAllFields(Class<?> clazz) { | ||
Stream.Builder<Field> builder = Stream.builder(); | ||
Class<?> targetClass = clazz; | ||
while (targetClass.getSuperclass() != null) { | ||
Field[] fields = targetClass.getDeclaredFields(); | ||
for (Field field : fields) { | ||
builder.add(field); | ||
} | ||
targetClass = targetClass.getSuperclass(); | ||
} | ||
return builder.build(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/net/earthcomputer/clientcommands/UnsafeUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.earthcomputer.clientcommands; | ||
|
||
import com.mojang.logging.LogUtils; | ||
import net.minecraft.Util; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import sun.misc.Unsafe; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.lang.reflect.Field; | ||
|
||
/** | ||
* @author Gaming32 | ||
*/ | ||
public final class UnsafeUtils { | ||
|
||
private UnsafeUtils() { | ||
} | ||
|
||
private static final Logger LOGGER = LogUtils.getLogger(); | ||
|
||
private static final @Nullable Unsafe UNSAFE = Util.make(() -> { | ||
try { | ||
final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); | ||
unsafeField.setAccessible(true); | ||
return (Unsafe) unsafeField.get(null); | ||
} catch (Exception e) { | ||
LOGGER.error("Could not access theUnsafe", e); | ||
return null; | ||
} | ||
}); | ||
|
||
private static final @Nullable MethodHandles.Lookup IMPL_LOOKUP = Util.make(() -> { | ||
try { | ||
//noinspection ConstantValue | ||
if (UNSAFE == null) { | ||
return null; | ||
} | ||
final Field implLookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP"); | ||
return (MethodHandles.Lookup) UNSAFE.getObject(UNSAFE.staticFieldBase(implLookupField), UNSAFE.staticFieldOffset(implLookupField)); | ||
} catch (Exception e) { | ||
LOGGER.error("Could not access IMPL_LOOKUP", e); | ||
return null; | ||
} | ||
}); | ||
|
||
public static @Nullable Unsafe getUnsafe() { | ||
return UNSAFE; | ||
} | ||
|
||
public static @Nullable MethodHandles.Lookup getImplLookup() { | ||
return IMPL_LOOKUP; | ||
} | ||
} |
Oops, something went wrong.