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.plot;
020
021import com.plotsquared.core.location.Location;
022import com.sk89q.worldedit.regions.CuboidRegion;
023import org.checkerframework.checker.nullness.qual.NonNull;
024import org.checkerframework.checker.nullness.qual.Nullable;
025
026import java.util.Collection;
027
028/**
029 * A world that contains plots
030 */
031public abstract class PlotWorld {
032
033    private final String world;
034
035    /**
036     * Create a new plot world with a given world name
037     *
038     * @param world World name
039     */
040    protected PlotWorld(final @NonNull String world) {
041        this.world = world;
042    }
043
044    /**
045     * Get the plot area that contains the given location, or null
046     * if the location is not a part of a plot area.
047     *
048     * @param location Location
049     * @return Containing plot area, or null
050     */
051    public @Nullable
052    abstract PlotArea getArea(final @NonNull Location location);
053
054    /**
055     * Get all plot areas in the world
056     *
057     * @return All plot areas in the world
058     */
059    public @NonNull
060    abstract Collection<PlotArea> getAreas();
061
062    /**
063     * Get all plot areas in a specified region
064     *
065     * @param region Region
066     * @return All areas in the region
067     */
068    public @NonNull
069    abstract Collection<PlotArea> getAreasInRegion(
070            final @NonNull CuboidRegion region
071    );
072
073    /**
074     * Register a new area in the world
075     *
076     * @param area Plot area
077     */
078    public void addArea(final @NonNull PlotArea area) {
079        throw new UnsupportedOperationException("This world type does not allow adding new areas");
080    }
081
082    /**
083     * Remove an area from the world
084     *
085     * @param area Plot area
086     */
087    public void removeArea(final @NonNull PlotArea area) {
088        throw new UnsupportedOperationException("This world type does not allow removing areas");
089    }
090
091    /**
092     * Get the world name
093     *
094     * @return World name
095     */
096    public String getWorld() {
097        return this.world;
098    }
099
100    @Override
101    public boolean equals(final Object o) {
102        if (this == o) {
103            return true;
104        }
105        if (o == null || getClass() != o.getClass()) {
106            return false;
107        }
108        final PlotWorld plotWorld = (PlotWorld) o;
109        return world.equals(plotWorld.world);
110    }
111
112    @Override
113    public int hashCode() {
114        return world.hashCode();
115    }
116
117    /**
118     * @deprecated This method is not meant to be invoked or overridden, with no replacement.
119     */
120    @Deprecated(forRemoval = true, since = "6.6.0")
121    protected boolean canEqual(final Object other) {
122        return other instanceof PlotWorld;
123    }
124
125}