-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fixed a bug related to the INIT_POST Screen event. The event wasn't always firing properly.
- Loading branch information
Showing
6 changed files
with
98 additions
and
2 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
42 changes: 42 additions & 0 deletions
42
...1.20.5/src/main/java/io/github/thecsdev/tcdcommons/api/util/integrity/IntegrityUtils.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,42 @@ | ||
package io.github.thecsdev.tcdcommons.api.util.integrity; | ||
|
||
import java.io.File; | ||
import java.util.Locale; | ||
import java.util.Objects; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Utility methods for mods looking to test their own codebase's integrity. | ||
*/ | ||
public final class IntegrityUtils | ||
{ | ||
// ================================================== | ||
private IntegrityUtils() {} | ||
// ================================================== | ||
/** | ||
* Retrieves the name of the JAR {@link File} that contains a given {@link Class}. | ||
* Will return {@code null} if a JAR file is not present or applicable in a given | ||
* context, like for example if a {@link Class} is dynamically loaded from a | ||
* directory or a non-JAR source. | ||
* @param containingClass The {@link Class} whose JAR file name is to be retrieved. | ||
*/ | ||
public static final @Nullable String getJarFileName(Class<?> containingClass) | ||
throws NullPointerException, SecurityException | ||
{ | ||
//validate arguments | ||
Objects.requireNonNull(containingClass); | ||
|
||
//obtain the jar file path and ensure | ||
//it contains forward slashes and ends with ".jar" | ||
final var path = containingClass.getProtectionDomain() | ||
.getCodeSource().getLocation() | ||
.getPath().replace('\\', '/'); | ||
if(!path.contains("/") || !path.toLowerCase(Locale.ENGLISH).endsWith(".jar")) | ||
return null; | ||
|
||
//get the last part after the last '/' instance, and return it | ||
return path.substring(path.lastIndexOf('/')); | ||
} | ||
// ================================================== | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...c-1.21/src/main/java/io/github/thecsdev/tcdcommons/api/util/integrity/IntegrityUtils.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,42 @@ | ||
package io.github.thecsdev.tcdcommons.api.util.integrity; | ||
|
||
import java.io.File; | ||
import java.util.Locale; | ||
import java.util.Objects; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Utility methods for mods looking to test their own codebase's integrity. | ||
*/ | ||
public final class IntegrityUtils | ||
{ | ||
// ================================================== | ||
private IntegrityUtils() {} | ||
// ================================================== | ||
/** | ||
* Retrieves the name of the JAR {@link File} that contains a given {@link Class}. | ||
* Will return {@code null} if a JAR file is not present or applicable in a given | ||
* context, like for example if a {@link Class} is dynamically loaded from a | ||
* directory or a non-JAR source. | ||
* @param containingClass The {@link Class} whose JAR file name is to be retrieved. | ||
*/ | ||
public static final @Nullable String getJarFileName(Class<?> containingClass) | ||
throws NullPointerException, SecurityException | ||
{ | ||
//validate arguments | ||
Objects.requireNonNull(containingClass); | ||
|
||
//obtain the jar file path and ensure | ||
//it contains forward slashes and ends with ".jar" | ||
final var path = containingClass.getProtectionDomain() | ||
.getCodeSource().getLocation() | ||
.getPath().replace('\\', '/'); | ||
if(!path.contains("/") || !path.toLowerCase(Locale.ENGLISH).endsWith(".jar")) | ||
return null; | ||
|
||
//get the last part after the last '/' instance, and return it | ||
return path.substring(path.lastIndexOf('/')); | ||
} | ||
// ================================================== | ||
} |
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