/* * This file is a part of the SteamWar software. * * Copyright (C) 2025 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 . */ package de.steamwar.bausystem.region; import de.steamwar.bausystem.BauSystem; import de.steamwar.core.Core; import lombok.NonNull; import org.bukkit.Location; import javax.annotation.CheckReturnValue; import java.lang.reflect.InvocationTargetException; import java.util.Optional; import java.util.UUID; import java.util.logging.Logger; import java.util.stream.Stream; public interface RegionSystem { Logger LOGGER = BauSystem.getInstance().getLogger(); UUID GLOBAL_REGION_ID = new UUID(0, 0); RegionSystem INSTANCE = init(); /** * Loads and initializes the Regions and anything that should be loaded on startup. */ void load(); /** * Returns the Location to teleport players to when they first join or Warp to "WorldSpawn" */ @NonNull Location getWorldSpawn(); /** * Returns the GlobalRegion. This Region should have their {@link Region#getID()} return the * '00000000-0000-0000-0000-000000000000' UUID for easier retrieval with {@link #getRegion(UUID)}. */ @NonNull Region getGlobalRegion(); /** * Should return a Region that is present at the specific Location or the {@link #getGlobalRegion()} * if none are present. */ @NonNull Region get(@NonNull Location location); /** * Should return the Region by their UUID. */ @CheckReturnValue Optional getRegion(@NonNull UUID id); /** * Does and should not contain the GlobalRegion returned by {@link #getGlobalRegion()}. */ @NonNull Stream getRegions(); /** * Only contains Regions of the same Type as the one you inputted. */ @NonNull Stream getConnectedRegions(Region region); private static RegionSystem init() { if (Core.getVersion() >= 21) { // TODO: Add some kind of detection if the DynamicRegionSystem should be used! try { return (RegionSystem) Class.forName("de.steamwar.bausystem.region.DynamicRegionSystem").getConstructor().newInstance(); } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { // Ignore } } try { return (RegionSystem) Class.forName("de.steamwar.bausystem.region.FixedRegionSystem").getConstructor().newInstance(); } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { // Ignore } return new RegionSystem() { @Override public void load() { throw new UnsupportedOperationException(); } @Override public @NonNull Location getWorldSpawn() { throw new UnsupportedOperationException(); } @Override public Region getGlobalRegion() { throw new UnsupportedOperationException(); } @Override public Region get(Location location) { throw new UnsupportedOperationException(); } @Override public Optional getRegion(UUID id) { throw new UnsupportedOperationException(); } @Override public Stream getRegions() { throw new UnsupportedOperationException(); } @Override public @NonNull Stream getConnectedRegions(Region region) { throw new UnsupportedOperationException(); } }; } }