2021-06-14 15:27:40 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of the SteamWar software.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-04-19 17:22:15 +02:00
|
|
|
package de.steamwar.bausystem.region;
|
|
|
|
|
2021-04-20 13:46:51 +02:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
2021-05-13 16:33:43 +02:00
|
|
|
import de.steamwar.bausystem.BauSystem;
|
2021-04-20 13:46:51 +02:00
|
|
|
import de.steamwar.bausystem.region.loader.RegionLoader;
|
2021-04-19 17:22:15 +02:00
|
|
|
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
|
|
|
import de.steamwar.bausystem.region.utils.RegionType;
|
2021-04-20 13:46:51 +02:00
|
|
|
import de.steamwar.core.VersionedCallable;
|
2021-04-19 17:22:15 +02:00
|
|
|
import lombok.experimental.UtilityClass;
|
|
|
|
import net.md_5.bungee.api.ChatMessageType;
|
|
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
|
|
|
import org.bukkit.Bukkit;
|
2021-06-14 15:27:40 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2021-04-19 17:22:15 +02:00
|
|
|
|
2021-04-20 13:46:51 +02:00
|
|
|
import java.io.File;
|
2021-06-14 15:27:40 +02:00
|
|
|
import java.util.function.Function;
|
2021-05-01 16:24:31 +02:00
|
|
|
|
2021-04-20 13:46:51 +02:00
|
|
|
|
2021-04-19 17:22:15 +02:00
|
|
|
@UtilityClass
|
|
|
|
public class RegionUtils {
|
|
|
|
|
|
|
|
public void actionBar(Region region, String s) {
|
2021-05-07 17:38:55 +02:00
|
|
|
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)));
|
2021-04-19 17:22:15 +02:00
|
|
|
}
|
|
|
|
|
2021-06-14 15:27:40 +02:00
|
|
|
public void actionBarNew(Region region, String s, Object... objects) {
|
|
|
|
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(BauSystem.MESSAGE.parse(s, player, objects))));
|
|
|
|
}
|
|
|
|
|
2021-05-13 16:33:43 +02:00
|
|
|
public static void messageOLD(Region region, String s) {
|
2021-05-07 17:38:55 +02:00
|
|
|
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));
|
2021-05-01 10:53:01 +02:00
|
|
|
}
|
|
|
|
|
2021-05-13 16:33:43 +02:00
|
|
|
public static void message(Region region, String message, Object... objects) {
|
|
|
|
Bukkit.getOnlinePlayers()
|
|
|
|
.stream()
|
|
|
|
.filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
|
|
|
|
.filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal())
|
|
|
|
.forEach(player -> {
|
|
|
|
BauSystem.MESSAGE.send(message, player, objects);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-01 16:24:31 +02:00
|
|
|
public static void message(Region region, Function<Player, String> function) {
|
2021-05-07 17:38:55 +02:00
|
|
|
Bukkit.getOnlinePlayers()
|
|
|
|
.stream()
|
|
|
|
.filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
|
|
|
|
.filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal())
|
|
|
|
.forEach(player -> {
|
2021-05-01 16:24:31 +02:00
|
|
|
String message = function.apply(player);
|
|
|
|
if (message == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.sendMessage(message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-20 13:46:51 +02:00
|
|
|
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) {
|
2021-04-22 19:44:32 +02:00
|
|
|
if (region.getPrototype() != null) {
|
|
|
|
region.regionData.add("prototype", region.getPrototype().getName());
|
|
|
|
}
|
2021-04-20 13:46:51 +02:00
|
|
|
region.regionData.add("flagStorage", FlagStorage.toYAPION(region.getFlagStorage()));
|
|
|
|
RegionLoader.save();
|
|
|
|
}
|
|
|
|
|
2021-04-19 17:22:15 +02:00
|
|
|
}
|