Skip to content

Commit

Permalink
Add regex
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Jul 8, 2024
1 parent 3c40b80 commit 35270f2
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class PerWorldUtils {
Expand All @@ -34,6 +35,18 @@ public static List<String> getDisabledWorlds(Plugin plugin) {
withGroupWorlds.remove(var);
withGroupWorlds.addAll(GroupsYML.get().getStringList(group));
}

if (var.endsWith("*")) {
String worldExpression = var.replace("*", "");

withGroupWorlds.addAll(getAllWorldWithCondition(name -> name.startsWith(worldExpression)));
}

if (var.startsWith("*")) {
String worldExpression = var.replace("*", "");

withGroupWorlds.addAll(getAllWorldWithCondition(name -> name.endsWith(worldExpression)));
}
}

if (PerWorldPlugins.getInstance().getConfig().getBoolean("blacklist")) {
Expand All @@ -52,6 +65,10 @@ public static List<String> getDisabledWorlds(Plugin plugin) {
}
}

public static List<String> getAllWorldWithCondition(Predicate<String> function) {
return Bukkit.getWorlds().stream().map(World::getName).filter(function).collect(Collectors.toList());
}

public static boolean checkEvent(Event event, List<String> disabledWorlds) {
if (event instanceof PlayerEvent) {
return disabledWorlds.contains(((PlayerEvent) event).getPlayer().getWorld().getName());
Expand Down

0 comments on commit 35270f2

Please sign in to comment.