mirror of
https://github.com/BentoBoxWorld/Boxed.git
synced 2025-01-05 18:37:48 +01:00
Minor refactors. Using final, etc.
This commit is contained in:
parent
beea5e82e8
commit
3f94ceab56
@ -237,7 +237,7 @@ public class AdvancementsManager {
|
||||
/**
|
||||
* Get the score for this advancement
|
||||
* @param a - advancement
|
||||
* @return score of advancement, or 0 if cannot be worked out
|
||||
* @return score of advancement, or 0 if it cannot be worked out
|
||||
*/
|
||||
public int getScore(Advancement a) {
|
||||
String adv = "advancements." + a.getKey().getKey();
|
||||
|
@ -66,11 +66,8 @@ public class Boxed extends GameModeAddon {
|
||||
private final Config<Settings> configObject = new Config<>(this, Settings.class);
|
||||
private AdvancementsManager advManager;
|
||||
private AbstractBoxedChunkGenerator netherChunkGenerator;
|
||||
private World baseWorld;
|
||||
private World baseWorldNether;
|
||||
private World seedWorld;
|
||||
private World seedWorldNether;
|
||||
private Map<World, ChunkGenerator> generatorMap = new HashMap<>();
|
||||
private final Map<World, ChunkGenerator> generatorMap = new HashMap<>();
|
||||
//private World seedWorldEnd;
|
||||
private BiomeProvider boxedBiomeProvider;
|
||||
|
||||
@ -185,8 +182,8 @@ public class Boxed extends GameModeAddon {
|
||||
log("Creating Boxed Seed Nether world ...");
|
||||
// This creates a vanilla base world with biomes
|
||||
AbstractBoxedChunkGenerator seedBaseGen = new BoxedSeedChunkGenerator(this, Environment.NETHER);
|
||||
baseWorldNether = WorldCreator
|
||||
.name(worldName + "/" + SEED+NETHER+BASE)
|
||||
World baseWorldNether = WorldCreator
|
||||
.name(worldName + "/" + SEED + NETHER + BASE)
|
||||
.generator(seedBaseGen)
|
||||
.environment(Environment.NETHER)
|
||||
.seed(getSettings().getSeed())
|
||||
@ -200,8 +197,8 @@ public class Boxed extends GameModeAddon {
|
||||
// This copies a base world with custom biomes
|
||||
log("Creating Boxed Biomed Nether world ...");
|
||||
BoxedSeedChunkGenerator seedWorldNetherGenerator = new BoxedSeedChunkGenerator(this, Environment.NETHER, new NetherSeedBiomeGenerator(this, seedBaseGen));
|
||||
seedWorldNether = WorldCreator
|
||||
.name(worldName + "/" + SEED+NETHER)
|
||||
World seedWorldNether = WorldCreator
|
||||
.name(worldName + "/" + SEED + NETHER)
|
||||
.generator(seedWorldNetherGenerator)
|
||||
.environment(Environment.NETHER)
|
||||
.seed(getSettings().getSeed())
|
||||
@ -224,8 +221,8 @@ public class Boxed extends GameModeAddon {
|
||||
log("Creating Boxed Seed world ...");
|
||||
// This creates a vanilla base world with biomes
|
||||
AbstractBoxedChunkGenerator seedBaseGen = new BoxedSeedChunkGenerator(this, Environment.NORMAL);
|
||||
baseWorld = WorldCreator
|
||||
.name(worldName + "/" + SEED+BASE)
|
||||
World baseWorld = WorldCreator
|
||||
.name(worldName + "/" + SEED + BASE)
|
||||
.generator(seedBaseGen)
|
||||
.environment(Environment.NORMAL)
|
||||
.seed(getSettings().getSeed())
|
||||
@ -268,7 +265,6 @@ public class Boxed extends GameModeAddon {
|
||||
* Registers a world with world management plugins
|
||||
*
|
||||
* @param world the World to register
|
||||
* @param islandWorld true if this is an island world
|
||||
*/
|
||||
private void registerToWorldManagementPlugins(@NonNull World world) {
|
||||
if (getPlugin().getHooks() != null) {
|
||||
@ -285,7 +281,7 @@ public class Boxed extends GameModeAddon {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies chunks from the seed world so they can be pasted in the game world
|
||||
* Copies chunks from the seed world, so they can be pasted in the game world
|
||||
* @param world - source world
|
||||
* @param gen - generator to store the chunks
|
||||
*/
|
||||
|
@ -91,7 +91,7 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
|
||||
return false;
|
||||
}
|
||||
// First arg must always be the structure name
|
||||
List<String> options = Bukkit.getStructureManager().getStructures().keySet().stream().map(k -> k.getKey()).toList();
|
||||
List<String> options = Bukkit.getStructureManager().getStructures().keySet().stream().map(NamespacedKey::getKey).toList();
|
||||
if (!options.contains(args.get(0).toLowerCase(Locale.ENGLISH))) {
|
||||
user.sendMessage("boxed.commands.boxadmin.place.unknown-structure");
|
||||
return false;
|
||||
@ -144,9 +144,9 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
NamespacedKey tag = NamespacedKey.fromString(args.get(0).toLowerCase(Locale.ENGLISH));
|
||||
Structure s = Bukkit.getStructureManager().loadStructure(tag);
|
||||
int x = args.size() == 1 || args.get(1).equals("~") ? user.getLocation().getBlockX() : Integer.valueOf(args.get(1).trim());
|
||||
int y = args.size() == 1 || args.get(2).equals("~") ? user.getLocation().getBlockY() : Integer.valueOf(args.get(2).trim());
|
||||
int z = args.size() == 1 || args.get(3).equals("~") ? user.getLocation().getBlockZ() : Integer.valueOf(args.get(3).trim());
|
||||
int x = args.size() == 1 || args.get(1).equals("~") ? user.getLocation().getBlockX() : Integer.parseInt(args.get(1).trim());
|
||||
int y = args.size() == 1 || args.get(2).equals("~") ? user.getLocation().getBlockY() : Integer.parseInt(args.get(2).trim());
|
||||
int z = args.size() == 1 || args.get(3).equals("~") ? user.getLocation().getBlockZ() : Integer.parseInt(args.get(3).trim());
|
||||
Location spot = new Location(user.getWorld(), x, y, z);
|
||||
s.place(spot, true, sr, mirror, PALETTE, INTEGRITY, new Random());
|
||||
NewAreaListener.removeJigsaw(new StructureRecord(tag.getKey(), s, spot, sr, mirror, noMobs));
|
||||
@ -168,7 +168,7 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
|
||||
try {
|
||||
config.load(structures);
|
||||
StringBuilder v = new StringBuilder();
|
||||
v.append(tag.getKey() + "," + sr2.name() + "," + mirror2.name());
|
||||
v.append(tag.getKey()).append(",").append(sr2.name()).append(",").append(mirror2.name());
|
||||
if (noMobs) {
|
||||
v.append(" NO_MOBS");
|
||||
}
|
||||
@ -189,7 +189,7 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
|
||||
{
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size() - 1) : "";
|
||||
if (args.size() == 2) {
|
||||
return Optional.of(Util.tabLimit(Bukkit.getStructureManager().getStructures().keySet().stream().map(k -> k.getKey()).toList(), lastArg));
|
||||
return Optional.of(Util.tabLimit(Bukkit.getStructureManager().getStructures().keySet().stream().map(NamespacedKey::getKey).toList(), lastArg));
|
||||
} else if (args.size() == 3) {
|
||||
return Optional.of(List.of(String.valueOf(user.getLocation().getBlockX()), "~"));
|
||||
} else if (args.size() == 4) {
|
||||
|
@ -46,8 +46,7 @@ public abstract class AbstractCopyBiomeProvider extends BiomeProvider {
|
||||
if (c != null) {
|
||||
int xx = Math.floorMod(x, 16);
|
||||
int zz = Math.floorMod(z, 16);
|
||||
Biome biome = c.chunkBiomes().getOrDefault(new Vector(xx, y, zz), defaultBiome);
|
||||
return biome;
|
||||
return c.chunkBiomes().getOrDefault(new Vector(xx, y, zz), defaultBiome);
|
||||
} else {
|
||||
BentoBox.getInstance().logWarning("Snapshot at " + chunkX + " " + chunkZ + " is not stored");
|
||||
return defaultBiome;
|
||||
|
@ -199,7 +199,7 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider {
|
||||
* Loads the custom biomes from the config file
|
||||
* @param config - Yaml configuration object
|
||||
* @param sector - the direction section to load
|
||||
* @return
|
||||
* @return sorted map of the biomes and their probabilities as keys
|
||||
*/
|
||||
private SortedMap<Double, Biome> loadQuad(YamlConfiguration config, String sector) {
|
||||
SortedMap<Double, Biome> result = new TreeMap<>();
|
||||
|
@ -26,10 +26,12 @@ public abstract class AbstractBoxedChunkGenerator extends ChunkGenerator {
|
||||
|
||||
protected final Boxed addon;
|
||||
protected static int size;
|
||||
protected Map<Pair<Integer, Integer>, ChunkStore> chunks = new HashMap<>();
|
||||
public record ChunkStore(ChunkSnapshot snapshot, List<EntityData> bpEnts, List<ChestData> chests, Map<Vector, Biome> chunkBiomes) {};
|
||||
public record EntityData(Vector relativeLoc, BlueprintEntity entity) {};
|
||||
public record ChestData(Vector relativeLoc, BlueprintBlock chest) {};
|
||||
protected final Map<Pair<Integer, Integer>, ChunkStore> chunks = new HashMap<>();
|
||||
public record ChunkStore(ChunkSnapshot snapshot, List<EntityData> bpEnts, List<ChestData> chests, Map<Vector, Biome> chunkBiomes) {}
|
||||
|
||||
public record EntityData(Vector relativeLoc, BlueprintEntity entity) {}
|
||||
|
||||
public record ChestData(Vector relativeLoc, BlueprintBlock chest) {}
|
||||
|
||||
//private final WorldRef wordRefNether;
|
||||
|
||||
|
@ -31,10 +31,10 @@ import world.bentobox.boxed.generators.chunks.AbstractBoxedChunkGenerator.ChunkS
|
||||
*/
|
||||
public class BoxedBlockPopulator extends BlockPopulator {
|
||||
|
||||
private Boxed addon;
|
||||
private final Boxed addon;
|
||||
|
||||
/**
|
||||
* @param addon
|
||||
* @param addon Boxed
|
||||
*/
|
||||
public BoxedBlockPopulator(Boxed addon) {
|
||||
this.addon = addon;
|
||||
@ -82,7 +82,7 @@ public class BoxedBlockPopulator extends BlockPopulator {
|
||||
/**
|
||||
* Handles signs, chests and mob spawner blocks
|
||||
*
|
||||
* @param block - block
|
||||
* @param bs - block state
|
||||
* @param bpBlock - config
|
||||
*/
|
||||
public void setBlockState(BlockState bs, BlueprintBlock bpBlock) {
|
||||
|
@ -169,8 +169,8 @@ public class AdvancementListener implements Listener {
|
||||
|
||||
/**
|
||||
* Special case Advancement awarding
|
||||
* Awards the nether and end advancements when they portal for the first time.
|
||||
* @param e
|
||||
* Awards the nether and end advancements when they use a portal for the first time.
|
||||
* @param e PlayerPortalEvent
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPortal(PlayerPortalEvent e) {
|
||||
|
@ -47,13 +47,12 @@ public class EnderPearlListener implements Listener {
|
||||
}
|
||||
|
||||
User u = User.getInstance(e.getPlayer());
|
||||
// If the to is outside the box, cancel it
|
||||
// If the to-location is outside the box, cancel it
|
||||
if (e.getTo() != null) {
|
||||
Island i = addon.getIslands().getIsland(e.getFrom().getWorld(), u);
|
||||
if (i == null || !i.onIsland(e.getTo())) {
|
||||
u.sendMessage("boxed.general.errors.no-teleport-outside");
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,19 +91,16 @@ public class EnderPearlListener implements Listener {
|
||||
// Moving is allowed
|
||||
moveBox(u, fromIsland, l);
|
||||
Util.teleportAsync(player, l);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Different box. This is never allowed. Cancel the throw
|
||||
e.setCancelled(true);
|
||||
u.sendMessage("boxed.general.errors.no-teleport-outside");
|
||||
return;
|
||||
}
|
||||
}, () -> {
|
||||
// No box. This is never allowed. Cancel the throw
|
||||
e.setCancelled(true);
|
||||
u.sendMessage("boxed.general.errors.no-teleport-outside");
|
||||
return;
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -3,13 +3,7 @@ package world.bentobox.boxed.listeners;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -75,7 +69,7 @@ public class NewAreaListener implements Listener {
|
||||
* @param mirror - mirror setting
|
||||
* @param noMobs - if false, mobs not pasted
|
||||
*/
|
||||
public record StructureRecord(String name, Structure structure, Location location, StructureRotation rot, Mirror mirror, Boolean noMobs) {};
|
||||
public record StructureRecord(String name, Structure structure, Location location, StructureRotation rot, Mirror mirror, Boolean noMobs) {}
|
||||
|
||||
private static final Map<Integer, EntityType> BUTCHER_ANIMALS = Map.of(0, EntityType.COW, 1, EntityType.SHEEP, 2, EntityType.PIG);
|
||||
private static final List<BlockFace> CARDINALS = List.of(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST);
|
||||
@ -89,16 +83,16 @@ public class NewAreaListener implements Listener {
|
||||
"shipwreck", "stronghold", "swamp_hut", "village_desert", "village_plains",
|
||||
"village_savanna", "village_snowy", "village_taiga");
|
||||
private final Boxed addon;
|
||||
private File structureFile;
|
||||
private Queue<StructureRecord> itemsToBuild = new LinkedList<>();
|
||||
private static Random rand = new Random();
|
||||
private final File structureFile;
|
||||
private final Queue<StructureRecord> itemsToBuild = new LinkedList<>();
|
||||
private static final Random rand = new Random();
|
||||
private boolean pasting;
|
||||
private static Gson gson = new Gson();
|
||||
Pair<Integer, Integer> min = new Pair<Integer, Integer>(0,0);
|
||||
Pair<Integer, Integer> max = new Pair<Integer, Integer>(0,0);
|
||||
private static final Gson gson = new Gson();
|
||||
Pair<Integer, Integer> min = new Pair<>(0, 0);
|
||||
Pair<Integer, Integer> max = new Pair<>(0, 0);
|
||||
// Database handler for structure data
|
||||
private final Database<IslandStructures> handler;
|
||||
private Map<String, IslandStructures> islandStructureCache = new HashMap<>();
|
||||
private final Map<String, IslandStructures> islandStructureCache = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
@ -118,7 +112,7 @@ public class NewAreaListener implements Listener {
|
||||
}
|
||||
|
||||
private void runStructurePrinter(Boxed addon2) {
|
||||
Bukkit.getScheduler().runTaskTimer(addon.getPlugin(), () -> buildStructure(), 20, 20);
|
||||
Bukkit.getScheduler().runTaskTimer(addon.getPlugin(), this::buildStructure, 20, 20);
|
||||
for (String js : JAR_STRUCTURES) {
|
||||
addon.saveResource("structures/" + js + ".nbt", false);
|
||||
File structureFile = new File(addon.getDataFolder(), "structures/" + js + ".nbt");
|
||||
@ -259,13 +253,13 @@ public class NewAreaListener implements Listener {
|
||||
if (e == null) {
|
||||
addon.logError("Error in structures.yml - unknown environment " + env);
|
||||
} else {
|
||||
place("structure",config.getConfigurationSection(env), center, e);
|
||||
place(config.getConfigurationSection(env), center, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void place(String string, ConfigurationSection section, Location center, Environment env) {
|
||||
private void place(ConfigurationSection section, Location center, Environment env) {
|
||||
World world = env.equals(Environment.NORMAL) ? addon.getOverWorld() : addon.getNetherWorld();
|
||||
// Loop through the structures in the file - there could be more than one
|
||||
for (String vector : section.getKeys(false)) {
|
||||
@ -296,13 +290,13 @@ public class NewAreaListener implements Listener {
|
||||
// Extract coords
|
||||
String[] value = vector.split(",");
|
||||
if (value.length > 2) {
|
||||
int x = Integer.valueOf(value[0].strip()) + center.getBlockX();
|
||||
int y = Integer.valueOf(value[1].strip());
|
||||
int z = Integer.valueOf(value[2].strip()) + center.getBlockZ();
|
||||
int x = Integer.parseInt(value[0].strip()) + center.getBlockX();
|
||||
int y = Integer.parseInt(value[1].strip());
|
||||
int z = Integer.parseInt(value[2].strip()) + center.getBlockZ();
|
||||
Location l = new Location(world, x, y, z);
|
||||
itemsToBuild.add(new StructureRecord(name, s, l, rot, mirror, noMobs));
|
||||
} else {
|
||||
addon.logError("Structure file syntax error: " + vector + ": " + value);
|
||||
addon.logError("Structure file syntax error: " + vector + ": " + Arrays.toString(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -376,13 +370,13 @@ public class NewAreaListener implements Listener {
|
||||
|
||||
/**
|
||||
* Process a structure block. Sets it to a structure void at a minimum.
|
||||
* If the structure block has meta data indicating it is a chest, then it will fill
|
||||
* If the structure block has metadata indicating it is a chest, then it will fill
|
||||
* the chest with a buried treasure loot. If it is waterlogged, then it will change
|
||||
* the void to water.
|
||||
* @param b structure block block
|
||||
* @param b structure block
|
||||
*/
|
||||
private static void processStructureBlock(Block b) {
|
||||
// I would like to read the data from the block an do something with it!
|
||||
// I would like to read the data from the block and do something with it!
|
||||
String data = nmsData(b);
|
||||
BoxedStructureBlock bsb = gson.fromJson(data, BoxedStructureBlock.class);
|
||||
b.setType(Material.STRUCTURE_VOID);
|
||||
@ -428,9 +422,8 @@ public class NewAreaListener implements Listener {
|
||||
case "minecraft:village/common/pigs" -> EntityType.PIG;
|
||||
case "minecraft:village/common/cows" -> EntityType.COW;
|
||||
case "minecraft:village/common/iron_golem" -> EntityType.IRON_GOLEM;
|
||||
case "minecraft:village/common/butcher_animals" -> BUTCHER_ANIMALS.get(rand.nextInt(3));
|
||||
case "minecraft:village/common/animals" -> BUTCHER_ANIMALS.get(rand.nextInt(3));
|
||||
default -> null;
|
||||
case "minecraft:village/common/butcher_animals", "minecraft:village/common/animals" -> BUTCHER_ANIMALS.get(rand.nextInt(3));
|
||||
default -> null;
|
||||
};
|
||||
// Boxed
|
||||
if (type == null && bjb.getPool().startsWith("minecraft:boxed/")) {
|
||||
|
@ -9,11 +9,11 @@ boxed:
|
||||
admin: boxadmin
|
||||
# The default action for new player command call.
|
||||
# Sub-command of main player command that will be run on first player command call.
|
||||
# By default it is sub-command 'create'.
|
||||
# By default, it is sub-command 'create'.
|
||||
new-player-action: create
|
||||
# The default action for player command.
|
||||
# Sub-command of main player command that will be run on each player command call.
|
||||
# By default it is sub-command 'go'.
|
||||
# By default, it is sub-command 'go'.
|
||||
default-action: go
|
||||
# Announce advancements. We recommend you set the game rule `/gamerule announceAdvancements false`
|
||||
# but that blocks all new advancement announcements. This setting tells Boxed to broadcast new advancements.
|
||||
|
Loading…
Reference in New Issue
Block a user