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.setup;
020
021
022import com.plotsquared.core.PlotSquared;
023import com.plotsquared.core.plot.PlotArea;
024import com.plotsquared.core.plot.PlotAreaTerrainType;
025import com.plotsquared.core.plot.PlotAreaType;
026import com.plotsquared.core.plot.PlotId;
027import com.plotsquared.core.util.SetupUtils;
028
029public class PlotAreaBuilder {
030
031    private String generatorName;
032    private String plotManager;
033    private PlotAreaType plotAreaType;
034    private PlotAreaTerrainType terrainType;
035    private String worldName;
036    private String areaName;
037    private PlotId minimumId;
038    private PlotId maximumId;
039    private SettingsNodesWrapper settingsNodesWrapper;
040    private SetupUtils setupManager;
041
042    private PlotAreaBuilder() {
043    }
044
045    public static PlotAreaBuilder newBuilder() {
046        return new PlotAreaBuilder();
047    }
048
049    public static PlotAreaBuilder ofPlotArea(PlotArea area) {
050        return new PlotAreaBuilder()
051                .worldName(area.getWorldName())
052                .areaName(area.getId())
053                .plotAreaType(area.getType())
054                .terrainType(area.getTerrain())
055                .generatorName(area.getGenerator().getName())
056                .plotManager(PlotSquared.platform().pluginName())
057                .minimumId(area.getMin())
058                .maximumId(area.getMax())
059                .settingsNodesWrapper(new SettingsNodesWrapper(area.getSettingNodes(), null));
060    }
061
062    public PlotAreaBuilder minimumId(PlotId minimumId) {
063        if (this.maximumId != null
064                && (minimumId.getX() > this.maximumId.getX() || minimumId.getY() > this.maximumId.getY())) {
065            throw new IllegalStateException("minId >= maxId");
066        }
067        this.minimumId = minimumId;
068        return this;
069    }
070
071    public PlotAreaBuilder maximumId(PlotId maximumId) {
072        if (this.minimumId != null
073                && (maximumId.getX() < this.minimumId.getX() || maximumId.getY() < this.minimumId.getY())) {
074            throw new IllegalStateException("maxId <= minId");
075        }
076        this.maximumId = maximumId;
077        return this;
078    }
079
080    public String generatorName() {
081        return this.generatorName;
082    }
083
084    public String plotManager() {
085        return this.plotManager;
086    }
087
088    public PlotAreaType plotAreaType() {
089        return this.plotAreaType;
090    }
091
092    public PlotAreaTerrainType terrainType() {
093        return this.terrainType;
094    }
095
096    public String worldName() {
097        return this.worldName;
098    }
099
100    public String areaName() {
101        return this.areaName;
102    }
103
104    public PlotId minimumId() {
105        return this.minimumId;
106    }
107
108    public PlotId maximumId() {
109        return this.maximumId;
110    }
111
112    public SettingsNodesWrapper settingsNodesWrapper() {
113        return this.settingsNodesWrapper;
114    }
115
116    public SetupUtils setupManager() {
117        return this.setupManager;
118    }
119
120    public PlotAreaBuilder generatorName(String generatorName) {
121        this.generatorName = generatorName;
122        return this;
123    }
124
125    public PlotAreaBuilder plotManager(String plotManager) {
126        this.plotManager = plotManager;
127        return this;
128    }
129
130    public PlotAreaBuilder plotAreaType(PlotAreaType plotAreaType) {
131        this.plotAreaType = plotAreaType;
132        return this;
133    }
134
135    public PlotAreaBuilder terrainType(PlotAreaTerrainType terrainType) {
136        this.terrainType = terrainType;
137        return this;
138    }
139
140    public PlotAreaBuilder worldName(String worldName) {
141        this.worldName = worldName;
142        return this;
143    }
144
145    public PlotAreaBuilder areaName(String areaName) {
146        this.areaName = areaName;
147        return this;
148    }
149
150    public PlotAreaBuilder settingsNodesWrapper(SettingsNodesWrapper settingsNodesWrapper) {
151        this.settingsNodesWrapper = settingsNodesWrapper;
152        return this;
153    }
154
155    public PlotAreaBuilder setupManager(SetupUtils setupManager) {
156        this.setupManager = setupManager;
157        return this;
158    }
159
160}