forked from BRNSystems/RegexingHoppers
Add cooldowns
This commit is contained in:
@@ -26,17 +26,40 @@ public class RegexingHoppers implements ModInitializer {
|
||||
}
|
||||
|
||||
public static boolean shouldNotMove(Inventory hopper, String itemName) {
|
||||
NamedScreenHandlerFactory factory = (NamedScreenHandlerFactory) hopper;
|
||||
String customName = factory.getDisplayName().getLiteralString();
|
||||
if (customName != null) {
|
||||
try {
|
||||
Pattern pattern = Pattern.compile(customName);
|
||||
// Check if the text matches the regex
|
||||
Matcher matcher = pattern.matcher(itemName);
|
||||
return !matcher.matches();
|
||||
} catch (PatternSyntaxException ignored) {
|
||||
// Log entering the method with given parameters
|
||||
LOGGER.debug("Entering shouldNotMove with itemName: {}", itemName);
|
||||
|
||||
if (hopper instanceof NamedScreenHandlerFactory) {
|
||||
NamedScreenHandlerFactory factory = (NamedScreenHandlerFactory) hopper;
|
||||
String customName = factory.getDisplayName().getLiteralString();
|
||||
|
||||
// Log the custom name used for matching
|
||||
LOGGER.info("Custom regex pattern from hopper: {}", customName);
|
||||
|
||||
if (customName != null && !customName.isEmpty()) {
|
||||
try {
|
||||
Pattern pattern = Pattern.compile(customName);
|
||||
Matcher matcher = pattern.matcher(itemName);
|
||||
|
||||
// Log the result of the regex matching
|
||||
boolean matches = matcher.matches();
|
||||
LOGGER.info("Regex matching result: {}", matches);
|
||||
|
||||
return !matches;
|
||||
} catch (PatternSyntaxException e) {
|
||||
// Log exception if regex pattern is invalid
|
||||
LOGGER.info("Invalid regex pattern: {}", customName, e);
|
||||
}
|
||||
} else {
|
||||
// Log case when custom name is null or empty
|
||||
LOGGER.info("Custom name is null or empty, not performing regex matching.");
|
||||
}
|
||||
} else {
|
||||
// Log if hopper is not an instance of NamedScreenHandlerFactory
|
||||
LOGGER.info("Hopper is not an instance of NamedScreenHandlerFactory.");
|
||||
}
|
||||
|
||||
// Default return value in case no conditions are met
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user