Files
FalsePatternLib/src/main/java/com/falsepattern/lib/mixin/ITargetedMod.java
T

60 lines
2.0 KiB
Java
Raw Normal View History

2022-07-31 20:41:56 +02:00
/*
2022-07-30 15:21:11 +02:00
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
* The above copyright notice, this permission notice and the word "SNEED"
* shall be included in all copies or substantial portions of the Software.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.mixin;
2022-06-12 11:58:13 +02:00
import com.falsepattern.lib.StableAPI;
import com.google.common.io.Files;
2022-07-31 20:41:56 +02:00
import java.nio.file.Path;
import java.util.function.Predicate;
2022-06-12 11:58:13 +02:00
@StableAPI(since = "0.8.0")
public interface ITargetedMod {
String getModName();
2022-06-08 16:01:06 +02:00
2022-04-17 18:01:02 +02:00
boolean isLoadInDevelopment();
2022-06-08 16:06:35 +02:00
@SuppressWarnings("UnstableApiUsage")
default boolean isMatchingJar(Path path) {
String pathString = path.toString();
String nameLowerCase = Files.getNameWithoutExtension(pathString).toLowerCase();
String fileExtension = Files.getFileExtension(pathString);
return "jar".equals(fileExtension) && getCondition().test(nameLowerCase);
}
2022-06-08 16:01:06 +02:00
Predicate<String> getCondition();
final class PredicateHelpers {
public static Predicate<String> startsWith(String subString) {
2022-07-25 22:12:43 +01:00
return (name) -> name.startsWith(subString.toLowerCase());
}
public static Predicate<String> contains(String subString) {
2022-07-25 22:12:43 +01:00
return (name) -> name.contains(subString.toLowerCase());
}
public static Predicate<String> matches(String regex) {
return (name) -> name.matches(regex);
}
}
}