package de.steamwar.bausystem.region; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.region.loader.RegionLoader; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.core.VersionedCallable; import java.util.function.Function; import lombok.experimental.UtilityClass; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import java.io.File; import org.bukkit.entity.Player; @UtilityClass public class RegionUtils { public void actionBar(Region region, String s) { Bukkit.getOnlinePlayers() .stream() .filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) .filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal()) .forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); } public static void message(Region region, String s) { Bukkit.getOnlinePlayers() .stream() .filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) .filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal()) .forEach(player -> player.sendMessage(s)); } public static void message(Region region, Function function) { Bukkit.getOnlinePlayers() .stream() .filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) .filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal()) .forEach(player -> { String message = function.apply(player); if (message == null) { return; } player.sendMessage(message); }); } static EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) { return VersionedCallable.call(new VersionedCallable<>(() -> Region_15.paste(file, pastePoint, pasteOptions), 15)); } static EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) { return VersionedCallable.call(new VersionedCallable<>(() -> Region_15.paste(clipboard, pastePoint, pasteOptions), 15)); } static void save(Region region) { if (region.getPrototype() != null) { region.regionData.add("prototype", region.getPrototype().getName()); } region.regionData.add("flagStorage", FlagStorage.toYAPION(region.getFlagStorage())); RegionLoader.save(); } }