001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.core.location;
020
021import org.checkerframework.checker.nullness.qual.NonNull;
022
023/**
024 * PlotSquared representation of a platform world
025 *
026 * @param <T> Platform world type
027 */
028public interface World<T> {
029
030    /**
031     * Get a {@link NullWorld} implementation
032     *
033     * @param <T> implementation-specific world object type e.g. a bukkit World
034     * @return NullWorld instance
035     */
036    static <T> NullWorld<T> nullWorld() {
037        return new NullWorld<>();
038    }
039
040    /**
041     * Get the platform world represented by this world
042     *
043     * @return Platform world
044     */
045    @NonNull T getPlatformWorld();
046
047    /**
048     * Get the name of the world
049     *
050     * @return World name
051     */
052    @NonNull String getName();
053
054    /**
055     * Get the min world height. Inclusive.
056     *
057     * @since 6.6.0
058     */
059    int getMinHeight();
060
061
062    /**
063     * Get the max world height. Inclusive.
064     *
065     * @since 6.6.0
066     */
067    int getMaxHeight();
068
069    class NullWorld<T> implements World<T> {
070
071        private NullWorld() {
072        }
073
074        @NonNull
075        @Override
076        public T getPlatformWorld() {
077            throw new UnsupportedOperationException("Cannot get platform world from NullWorld");
078        }
079
080        @Override
081        public @NonNull String getName() {
082            return "";
083        }
084
085        @Override
086        public int getMinHeight() {
087            return 0;
088        }
089
090        @Override
091        public int getMaxHeight() {
092            return 0;
093        }
094
095        @Override
096        public boolean equals(final Object obj) {
097            return obj instanceof NullWorld;
098        }
099
100        @Override
101        public int hashCode() {
102            return "null".hashCode();
103        }
104
105    }
106
107}