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.generator; 020 021import com.plotsquared.core.configuration.ConfigurationNode; 022import com.plotsquared.core.configuration.ConfigurationSection; 023import com.plotsquared.core.configuration.ConfigurationUtil; 024import com.plotsquared.core.configuration.Settings; 025import com.plotsquared.core.configuration.caption.TranslatableCaption; 026import com.plotsquared.core.configuration.file.YamlConfiguration; 027import com.plotsquared.core.inject.annotations.WorldConfig; 028import com.plotsquared.core.plot.BlockBucket; 029import com.plotsquared.core.plot.PlotId; 030import com.plotsquared.core.queue.GlobalBlockQueue; 031import com.sk89q.worldedit.function.pattern.Pattern; 032import com.sk89q.worldedit.world.block.BlockTypes; 033import org.apache.logging.log4j.LogManager; 034import org.apache.logging.log4j.Logger; 035import org.checkerframework.checker.nullness.qual.NonNull; 036 037import javax.annotation.Nullable; 038 039@SuppressWarnings("WeakerAccess") 040public abstract class ClassicPlotWorld extends SquarePlotWorld { 041 private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + ClassicPlotWorld.class.getSimpleName()); 042 043 public int ROAD_HEIGHT = 62; 044 public int PLOT_HEIGHT = 62; 045 public int WALL_HEIGHT = 62; 046 public BlockBucket MAIN_BLOCK = new BlockBucket(BlockTypes.STONE); 047 public BlockBucket TOP_BLOCK = new BlockBucket(BlockTypes.GRASS_BLOCK); 048 public BlockBucket WALL_BLOCK = new BlockBucket(BlockTypes.STONE_SLAB); 049 public BlockBucket CLAIMED_WALL_BLOCK = new BlockBucket(BlockTypes.SANDSTONE_SLAB); 050 public BlockBucket WALL_FILLING = new BlockBucket(BlockTypes.STONE); 051 public BlockBucket ROAD_BLOCK = new BlockBucket(BlockTypes.QUARTZ_BLOCK); 052 public boolean PLOT_BEDROCK = true; 053 public boolean PLACE_TOP_BLOCK = true; 054 055 public ClassicPlotWorld( 056 final @NonNull String worldName, 057 final @Nullable String id, 058 final @NonNull IndependentPlotGenerator generator, 059 final @Nullable PlotId min, 060 final @Nullable PlotId max, 061 @WorldConfig final @NonNull YamlConfiguration worldConfiguration, 062 final @NonNull GlobalBlockQueue blockQueue 063 ) { 064 super(worldName, id, generator, min, max, worldConfiguration, blockQueue); 065 } 066 067 /** 068 * CONFIG NODE | DEFAULT VALUE | DESCRIPTION | CONFIGURATION TYPE | REQUIRED FOR INITIAL SETUP. 069 * 070 * <p>Set the last boolean to false if you do not check a specific config node to be set while using the setup 071 * command - this may be useful if a config value can be changed at a later date, and has no impact on the actual 072 * world generation</p> 073 */ 074 @NonNull 075 @Override 076 public ConfigurationNode[] getSettingNodes() { 077 return new ConfigurationNode[]{ 078 new ConfigurationNode("plot.height", this.PLOT_HEIGHT, TranslatableCaption.of("setup.plot_height"), 079 ConfigurationUtil.INTEGER 080 ), 081 new ConfigurationNode("plot.size", this.PLOT_WIDTH, TranslatableCaption.of("setup.plot_width"), 082 ConfigurationUtil.INTEGER 083 ), 084 new ConfigurationNode("plot.filling", this.MAIN_BLOCK, TranslatableCaption.of("setup.plot_block"), 085 ConfigurationUtil.BLOCK_BUCKET 086 ), 087 new ConfigurationNode("wall.place_top_block", this.PLACE_TOP_BLOCK, 088 TranslatableCaption.of("setup.top_block_boolean"), ConfigurationUtil.BOOLEAN 089 ), 090 new ConfigurationNode("plot.floor", this.TOP_BLOCK, TranslatableCaption.of("setup.plot_block_floor"), 091 ConfigurationUtil.BLOCK_BUCKET 092 ), 093 new ConfigurationNode("wall.block", this.WALL_BLOCK, TranslatableCaption.of("setup.top_wall_block"), 094 ConfigurationUtil.BLOCK_BUCKET 095 ), 096 new ConfigurationNode("wall.block_claimed", this.CLAIMED_WALL_BLOCK, 097 TranslatableCaption.of("setup.wall_block_claimed"), ConfigurationUtil.BLOCK_BUCKET 098 ), 099 new ConfigurationNode("road.width", this.ROAD_WIDTH, TranslatableCaption.of("setup.road_width"), 100 ConfigurationUtil.INTEGER 101 ), 102 new ConfigurationNode("road.height", this.ROAD_HEIGHT, TranslatableCaption.of("setup.road_height"), 103 ConfigurationUtil.INTEGER 104 ), 105 new ConfigurationNode("road.block", this.ROAD_BLOCK, TranslatableCaption.of("setup.road_block"), 106 ConfigurationUtil.BLOCK_BUCKET 107 ), 108 new ConfigurationNode("wall.filling", this.WALL_FILLING, TranslatableCaption.of("setup.wall_filling_block"), 109 ConfigurationUtil.BLOCK_BUCKET 110 ), 111 new ConfigurationNode("wall.height", this.WALL_HEIGHT, TranslatableCaption.of("setup.wall_height"), 112 ConfigurationUtil.INTEGER 113 ), 114 new ConfigurationNode("plot.bedrock", this.PLOT_BEDROCK, TranslatableCaption.of("setup.bedrock_boolean"), 115 ConfigurationUtil.BOOLEAN 116 )}; 117 } 118 119 /** 120 * This method is called when a world loads. Make sure you set all your constants here. You are provided with the 121 * configuration section for that specific world. 122 */ 123 @Override 124 public void loadConfiguration(ConfigurationSection config) { 125 super.loadConfiguration(config); 126 this.PLOT_BEDROCK = config.getBoolean("plot.bedrock"); 127 this.PLOT_HEIGHT = Math.min(getMaxGenHeight(), config.getInt("plot.height")); 128 this.MAIN_BLOCK = createCheckedBlockBucket(config.getString("plot.filling"), MAIN_BLOCK); 129 this.TOP_BLOCK = createCheckedBlockBucket(config.getString("plot.floor"), TOP_BLOCK); 130 this.WALL_BLOCK = createCheckedBlockBucket(config.getString("wall.block"), WALL_BLOCK); 131 this.ROAD_HEIGHT = Math.min(getMaxGenHeight(), config.getInt("road.height")); 132 this.ROAD_BLOCK = createCheckedBlockBucket(config.getString("road.block"), ROAD_BLOCK); 133 this.WALL_FILLING = createCheckedBlockBucket(config.getString("wall.filling"), WALL_FILLING); 134 this.PLACE_TOP_BLOCK = config.getBoolean("wall.place_top_block"); 135 this.WALL_HEIGHT = Math.min(getMaxGenHeight() - (PLACE_TOP_BLOCK ? 1 : 0), config.getInt("wall.height")); 136 this.CLAIMED_WALL_BLOCK = createCheckedBlockBucket(config.getString("wall.block_claimed"), CLAIMED_WALL_BLOCK); 137 } 138 139 int schematicStartHeight() { 140 int plotRoadMin = Math.min(PLOT_HEIGHT, ROAD_HEIGHT); 141 if (!Settings.Schematics.USE_WALL_IN_ROAD_SCHEM_HEIGHT) { 142 return plotRoadMin; 143 } 144 return Math.min(WALL_HEIGHT, plotRoadMin); 145 } 146 147 private static BlockBucket createCheckedBlockBucket(String input, BlockBucket def) { 148 final BlockBucket bucket = new BlockBucket(input); 149 Pattern pattern = null; 150 try { 151 pattern = bucket.toPattern(); 152 } catch (Exception ignore) { 153 } 154 if (pattern == null) { 155 LOGGER.error("Failed to parse pattern '{}', check your worlds.yml", input); 156 LOGGER.error("Falling back to {}", def); 157 return def; 158 } 159 return bucket; 160 } 161 162}