2022-07-31 20:41:56 +02:00
|
|
|
/*
|
2023-07-16 12:36:11 +02:00
|
|
|
* Copyright (C) 2022-2023 FalsePattern
|
2022-07-30 15:21:11 +02:00
|
|
|
* All Rights Reserved
|
|
|
|
|
*
|
2023-07-16 12:36:11 +02:00
|
|
|
* The above copyright notice and this permission notice
|
2022-07-30 15:21:11 +02:00
|
|
|
* 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/>.
|
|
|
|
|
*/
|
2022-04-17 17:26:30 +02:00
|
|
|
package com.falsepattern.lib.mixin;
|
|
|
|
|
|
2022-06-12 11:58:13 +02:00
|
|
|
import com.falsepattern.lib.StableAPI;
|
2022-04-17 17:26:30 +02:00
|
|
|
import com.google.common.io.Files;
|
2022-07-31 20:41:56 +02:00
|
|
|
|
2022-04-17 17:26:30 +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")
|
2022-04-17 17:26:30 +02:00
|
|
|
public interface ITargetedMod {
|
|
|
|
|
|
2022-08-06 13:12:55 +02:00
|
|
|
@StableAPI.Expose
|
2022-04-17 17:26:30 +02:00
|
|
|
String getModName();
|
2022-06-08 16:01:06 +02:00
|
|
|
|
2022-08-06 13:12:55 +02:00
|
|
|
@StableAPI.Expose
|
2022-04-17 18:01:02 +02:00
|
|
|
boolean isLoadInDevelopment();
|
2022-04-17 17:26:30 +02:00
|
|
|
|
2022-06-08 16:06:35 +02:00
|
|
|
@SuppressWarnings("UnstableApiUsage")
|
2022-08-06 13:12:55 +02:00
|
|
|
@StableAPI.Expose
|
2022-04-17 17:26:30 +02:00
|
|
|
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-08-17 20:10:51 +02:00
|
|
|
|
2022-08-06 13:12:55 +02:00
|
|
|
@StableAPI.Expose
|
2022-06-08 16:01:06 +02:00
|
|
|
Predicate<String> getCondition();
|
|
|
|
|
|
2022-08-06 13:12:55 +02:00
|
|
|
@StableAPI(since = "0.5.0")
|
2022-04-17 20:30:32 +02:00
|
|
|
final class PredicateHelpers {
|
2022-08-06 13:12:55 +02:00
|
|
|
@StableAPI.Expose
|
2022-04-17 20:30:32 +02:00
|
|
|
public static Predicate<String> startsWith(String subString) {
|
2022-07-25 22:12:43 +01:00
|
|
|
return (name) -> name.startsWith(subString.toLowerCase());
|
2022-04-17 20:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-06 13:12:55 +02:00
|
|
|
@StableAPI.Expose
|
2022-04-17 20:30:32 +02:00
|
|
|
public static Predicate<String> contains(String subString) {
|
2022-07-25 22:12:43 +01:00
|
|
|
return (name) -> name.contains(subString.toLowerCase());
|
2022-04-17 20:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-06 13:12:55 +02:00
|
|
|
@StableAPI.Expose
|
2022-04-17 20:30:32 +02:00
|
|
|
public static Predicate<String> matches(String regex) {
|
|
|
|
|
return (name) -> name.matches(regex);
|
|
|
|
|
}
|
2022-04-17 17:26:30 +02:00
|
|
|
}
|
|
|
|
|
}
|