code reformat
This commit is contained in:
parent
796bee9696
commit
03c26bc2f9
@ -31,6 +31,7 @@ public final class Main extends JavaPlugin {
|
||||
public static <T> TaskChain<T> chain() {
|
||||
return taskFactory.newChain();
|
||||
}
|
||||
|
||||
public static <T> TaskChain<T> sharedChain(String name) {
|
||||
return taskFactory.newSharedChain(name);
|
||||
}
|
||||
@ -44,10 +45,10 @@ public final class Main extends JavaPlugin {
|
||||
this.saveConfig();
|
||||
|
||||
Main.configuration = new PixelBlockConfiguration(
|
||||
config.getInt(PixelBlockConfiguration.Keys.PixelsPerBlock.getKey()),
|
||||
config.getDouble(PixelBlockConfiguration.Keys.HitboxOffset.getKey()),
|
||||
config.getBoolean(PixelBlockConfiguration.Keys.OnlyBreakableByOwners.getKey()),
|
||||
config.getBoolean(PixelBlockConfiguration.Keys.OnlyEditableByOwners.getKey())
|
||||
config.getInt(PixelBlockConfiguration.Keys.PixelsPerBlock.getKey()),
|
||||
config.getDouble(PixelBlockConfiguration.Keys.HitboxOffset.getKey()),
|
||||
config.getBoolean(PixelBlockConfiguration.Keys.OnlyBreakableByOwners.getKey()),
|
||||
config.getBoolean(PixelBlockConfiguration.Keys.OnlyEditableByOwners.getKey())
|
||||
);
|
||||
|
||||
File databaseFile = new File(plugin.getDataFolder(), "blocks.db");
|
||||
@ -80,7 +81,7 @@ public final class Main extends JavaPlugin {
|
||||
new PreventGrowthListener()
|
||||
};
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
for(Listener listener : listeners) {
|
||||
getServer().getPluginManager().registerEvents(listener, plugin);
|
||||
}
|
||||
|
||||
@ -95,7 +96,7 @@ public final class Main extends JavaPlugin {
|
||||
Bukkit.getOnlinePlayers().forEach(QuitWhileInPixelBlockListener::kickPlayerOutOfWorld);
|
||||
try {
|
||||
database.close();
|
||||
} catch (SQLException e) {
|
||||
} catch(SQLException e) {
|
||||
throw new RuntimeException("Failed disabling", e);
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record PixelBlockConfiguration(
|
||||
int pixelsPerBlock,
|
||||
double hitboxOffset,
|
||||
boolean onlyBreakableByOwner,
|
||||
boolean onlyEditableByOwner
|
||||
int pixelsPerBlock,
|
||||
double hitboxOffset,
|
||||
boolean onlyBreakableByOwner,
|
||||
boolean onlyEditableByOwner
|
||||
) {
|
||||
public static void setDefaults(FileConfiguration config) {
|
||||
config.addDefault(Keys.PixelsPerBlock.key, 16);
|
||||
@ -24,6 +24,7 @@ public record PixelBlockConfiguration(
|
||||
OnlyEditableByOwners("onlyEditableByOwners");
|
||||
|
||||
private final String key;
|
||||
|
||||
Keys(@NotNull String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package eu.mhsl.minecraft.pixelblocks;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.utils.Direction;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import eu.mhsl.minecraft.pixelblocks.utils.Direction;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@ -21,7 +21,7 @@ public class PixelBlockDatabase {
|
||||
this.db = DriverManager.getConnection(url);
|
||||
|
||||
this.db.createStatement().execute(
|
||||
"CREATE TABLE IF NOT EXISTS pixelblocks (" +
|
||||
"CREATE TABLE IF NOT EXISTS pixelblocks (" +
|
||||
"uuid CHAR(36) PRIMARY KEY, " +
|
||||
"owner CHAR(36), " +
|
||||
"locationWorldName CHAR(36), " +
|
||||
@ -33,7 +33,7 @@ public class PixelBlockDatabase {
|
||||
"entryLocationY DOUBLE, " +
|
||||
"entryLocationZ DOUBLE, " +
|
||||
"direction CHAR(36)" +
|
||||
")"
|
||||
")"
|
||||
);
|
||||
|
||||
this.deletePixelBlock = this.db.prepareStatement("DELETE FROM pixelblocks WHERE uuid = ?");
|
||||
@ -45,7 +45,7 @@ public class PixelBlockDatabase {
|
||||
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"
|
||||
);
|
||||
|
||||
} catch (SQLException | RuntimeException | ClassNotFoundException e) {
|
||||
} catch(SQLException | RuntimeException | ClassNotFoundException e) {
|
||||
throw new RuntimeException("Error while initializing database", e);
|
||||
}
|
||||
}
|
||||
@ -62,7 +62,7 @@ public class PixelBlockDatabase {
|
||||
try {
|
||||
this.deletePixelBlock.setString(1, pixelBlock.getBlockUUID().toString());
|
||||
this.deletePixelBlock.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
} catch(SQLException e) {
|
||||
throw new RuntimeException("Failed to delete PixelBlock from the database", e);
|
||||
}
|
||||
});
|
||||
@ -79,7 +79,7 @@ public class PixelBlockDatabase {
|
||||
this.insertOrReplacePixelBlock.setDouble(5, pixelBlock.getPixelBlockLocation().getY());
|
||||
this.insertOrReplacePixelBlock.setDouble(6, pixelBlock.getPixelBlockLocation().getZ());
|
||||
|
||||
if (pixelBlock.hasLastEntryLocation()) {
|
||||
if(pixelBlock.hasLastEntryLocation()) {
|
||||
this.insertOrReplacePixelBlock.setString(7, pixelBlock.getLastEntryLocation().getWorld().getName());
|
||||
this.insertOrReplacePixelBlock.setDouble(8, pixelBlock.getLastEntryLocation().getX());
|
||||
this.insertOrReplacePixelBlock.setDouble(9, pixelBlock.getLastEntryLocation().getY());
|
||||
@ -94,7 +94,7 @@ public class PixelBlockDatabase {
|
||||
this.insertOrReplacePixelBlock.setString(11, pixelBlock.getFacingDirection().toString());
|
||||
|
||||
this.insertOrReplacePixelBlock.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
} catch(SQLException e) {
|
||||
throw new RuntimeException("Failed to create or update PixelBlock in the database", e);
|
||||
}
|
||||
});
|
||||
@ -104,7 +104,7 @@ public class PixelBlockDatabase {
|
||||
try {
|
||||
ResultSet allPixelBlocks = this.getAllPixelBlocks.executeQuery();
|
||||
|
||||
while (allPixelBlocks.next()) {
|
||||
while(allPixelBlocks.next()) {
|
||||
Location blockLocation = new Location(
|
||||
Bukkit.getWorld(allPixelBlocks.getString("locationWorldName")),
|
||||
allPixelBlocks.getDouble("locationX"),
|
||||
@ -127,7 +127,7 @@ public class PixelBlockDatabase {
|
||||
entryLocation
|
||||
));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
} catch(SQLException e) {
|
||||
throw new RuntimeException("Failed loading PixelBlocks from the database", e);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ public class PixelBlockItem {
|
||||
return owner != null;
|
||||
}
|
||||
}
|
||||
|
||||
public static @Nullable BlockInfo getBlockInfo(ItemStack item) {
|
||||
PersistentDataContainer container = item.getItemMeta().getPersistentDataContainer();
|
||||
if(!container.has(idProperty)) return null;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.commands;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlockWorld;
|
||||
import eu.mhsl.minecraft.pixelblocks.utils.Direction;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
|
@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ExitWorldCommand implements CommandExecutor {
|
||||
@Override
|
||||
|
@ -1,12 +1,12 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
|
||||
import eu.mhsl.minecraft.pixelblocks.Main;
|
||||
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -2,7 +2,7 @@ package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.Main;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Interaction;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -14,10 +14,10 @@ public class EnterPixelBlockListener implements Listener {
|
||||
if(!(event.getRightClicked() instanceof Interaction)) return;
|
||||
|
||||
Location interactionLocation = event
|
||||
.getRightClicked()
|
||||
.getLocation()
|
||||
.add(0, Main.configuration().hitboxOffset(), 0)
|
||||
.toBlockLocation();
|
||||
.getRightClicked()
|
||||
.getLocation()
|
||||
.add(0, Main.configuration().hitboxOffset(), 0)
|
||||
.toBlockLocation();
|
||||
PixelBlock pixelBlock = PixelBlock.getPixelBlockFromPlacedLocation(interactionLocation);
|
||||
if(pixelBlock == null) return;
|
||||
pixelBlock.enterBlock(event.getPlayer());
|
||||
|
@ -19,9 +19,9 @@ public class PlacePixelListener implements Listener {
|
||||
@EventHandler
|
||||
public void onBuketEmpty(PlayerBucketEmptyEvent event) {
|
||||
EventCanceling.shouldCancelInPixelBlock(
|
||||
event,
|
||||
event.getBlock().getWorld(),
|
||||
pixelBlock -> !pixelBlock.getPixelWorld().allowPlacements(event.getBlock().getLocation())
|
||||
event,
|
||||
event.getBlock().getWorld(),
|
||||
pixelBlock -> !pixelBlock.getPixelWorld().allowPlacements(event.getBlock().getLocation())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,9 @@ package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
import eu.mhsl.minecraft.pixelblocks.utils.EventCanceling;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.event.inventory.InventoryInteractEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.CraftingInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
@ -29,7 +31,7 @@ public class PreventInventorysListener implements Listener {
|
||||
|
||||
private static boolean isDisallowedInventory(Inventory inventory) {
|
||||
return !(inventory instanceof PlayerInventory
|
||||
|| inventory instanceof CraftingInventory
|
||||
|| inventory.getType() == InventoryType.ENDER_CHEST);
|
||||
|| inventory instanceof CraftingInventory
|
||||
|| inventory.getType() == InventoryType.ENDER_CHEST);
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ public class PreventLiquidsFlowListener implements Listener {
|
||||
@EventHandler
|
||||
public void onLiquidFlow(BlockFromToEvent event) {
|
||||
EventCanceling.shouldCancelInPixelBlock(
|
||||
event,
|
||||
event.getToBlock().getWorld(),
|
||||
pixelBlock -> !pixelBlock.getPixelWorld().allowPlacements(event.getToBlock().getLocation())
|
||||
event,
|
||||
event.getToBlock().getWorld(),
|
||||
pixelBlock -> !pixelBlock.getPixelWorld().allowPlacements(event.getToBlock().getLocation())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class PreventPistonsListener implements Listener {
|
||||
event.getBlock().getWorld(),
|
||||
(pixelBlock) -> event.getBlocks().stream()
|
||||
.anyMatch(block -> !pixelBlock.getPixelWorld()
|
||||
.allowPlacements(block.getLocation().add(event.getDirection().getDirection())))
|
||||
.allowPlacements(block.getLocation().add(event.getDirection().getDirection())))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,24 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.pixelblock;
|
||||
|
||||
import co.aikar.taskchain.TaskChain;
|
||||
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
|
||||
import eu.mhsl.minecraft.pixelblocks.Main;
|
||||
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
|
||||
import eu.mhsl.minecraft.pixelblocks.utils.Direction;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PixelBlock {
|
||||
private boolean exists = true;
|
||||
@ -32,15 +38,15 @@ public class PixelBlock {
|
||||
|
||||
public static @Nullable PixelBlock getPixelBlockFromBlockWorld(World world) {
|
||||
return Main.pixelBlocks.stream()
|
||||
.filter(block -> block.blockUUID.equals(getUUIDFromWorld(world)))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
.filter(block -> block.blockUUID.equals(getUUIDFromWorld(world)))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static @Nullable UUID getUUIDFromWorld(@NotNull World world) {
|
||||
try {
|
||||
return UUID.fromString(List.of(world.getName().split("/")).getLast());
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch(IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -51,14 +57,15 @@ public class PixelBlock {
|
||||
searchLocation.setYaw(0);
|
||||
|
||||
return Main.pixelBlocks.stream()
|
||||
.filter(block -> Objects.equals(block.pixelBlockLocation, searchLocation))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
.filter(block -> Objects.equals(block.pixelBlockLocation, searchLocation))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static PixelBlock fromExisting(UUID blockUUID, UUID ownerUUID, Location pixelBlockLocation, Direction direction, Location lastEntryLocation) {
|
||||
return new PixelBlock(blockUUID, ownerUUID, pixelBlockLocation, direction, lastEntryLocation);
|
||||
}
|
||||
|
||||
private PixelBlock(UUID blockUUID, UUID ownerUUID, Location pixelBlockLocation, Direction direction, Location lastEntryLocation) {
|
||||
this.blockUUID = blockUUID;
|
||||
this.ownerUUID = ownerUUID;
|
||||
@ -84,6 +91,7 @@ public class PixelBlock {
|
||||
public static PixelBlock createPixelBlock(UUID blockUUID, UUID ownerUUID, Location pixelBlockLocation, Direction direction) {
|
||||
return new PixelBlock(blockUUID, ownerUUID, pixelBlockLocation, direction);
|
||||
}
|
||||
|
||||
private PixelBlock(UUID blockUUID, UUID ownerUUID, Location pixelBlockLocation, Direction direction) {
|
||||
if(Main.pixelBlocks.stream().anyMatch(pixelBlock -> pixelBlock.getBlockUUID().equals(blockUUID)))
|
||||
throw new IllegalStateException(String.format("PixelBlock '%s' ist bereits in der Welt vorhanden!", blockUUID));
|
||||
|
@ -34,8 +34,8 @@ public class PixelBlockHitbox {
|
||||
pixelBlockLocation.clone().add(0.5, -offset, 0.5),
|
||||
EntityType.INTERACTION
|
||||
);
|
||||
interaction.setInteractionHeight(1 + 2*offset);
|
||||
interaction.setInteractionWidth(1 + 2*offset);
|
||||
interaction.setInteractionHeight(1 + 2 * offset);
|
||||
interaction.setInteractionWidth(1 + 2 * offset);
|
||||
} else {
|
||||
// double startingX = this.parentBlock.getPixelBlockLocation().x() + MinMaxUtil.getMinProperty(pixels, pixel -> pixel.relativeLocation().getX()) * scale;
|
||||
// double startingY = this.parentBlock.getPixelBlockLocation().y() + MinMaxUtil.getMinProperty(pixels, pixel -> pixel.relativeLocation().getY()) * scale;
|
||||
|
@ -13,7 +13,10 @@ import org.bukkit.persistence.PersistentDataHolder;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.util.Transformation;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PixelBlockPlaceholder {
|
||||
private static final NamespacedKey placeholderOfTag = new NamespacedKey(Main.plugin(), "placeholder_of");
|
||||
|
@ -46,8 +46,8 @@ public class PixelBlockWorld {
|
||||
Location origin = getBuildOrigin();
|
||||
int offset = pixelsPerBlock - 1;
|
||||
return blockLocation.x() >= origin.x() && blockLocation.x() <= origin.x() + offset
|
||||
&& blockLocation.z() >= origin.z() && blockLocation.z() <= origin.z() + offset
|
||||
&& blockLocation.y() >= origin.y() && blockLocation.y() <= origin.y() + offset;
|
||||
&& blockLocation.z() >= origin.z() && blockLocation.z() <= origin.z() + offset
|
||||
&& blockLocation.y() >= origin.y() && blockLocation.y() <= origin.y() + offset;
|
||||
}
|
||||
|
||||
public @NotNull String getWorldPathName() {
|
||||
@ -59,7 +59,7 @@ public class PixelBlockWorld {
|
||||
}
|
||||
|
||||
public @NotNull Location getPortalLocation() {
|
||||
return this.getBuildOrigin().add((double) pixelsPerBlock/2 -2, 0, -worldGrassBorderWidth+3);
|
||||
return this.getBuildOrigin().add((double) pixelsPerBlock / 2 - 2, 0, -worldGrassBorderWidth + 3);
|
||||
}
|
||||
|
||||
public @NotNull List<Player> getPlayersInWorld() {
|
||||
@ -90,21 +90,27 @@ public class PixelBlockWorld {
|
||||
return getBorderOrigin().add(worldGrassBorderWidth + pixelsPerBlock, 0, worldGrassBorderWidth + pixelsPerBlock);
|
||||
}
|
||||
|
||||
public record PixelData(Vector relativeLocation, BlockData block, double scale) {}
|
||||
public record PixelData(Vector relativeLocation, BlockData block, double scale) {
|
||||
}
|
||||
|
||||
public List<PixelData> getPixels(Direction direction) {
|
||||
List<PixelData> pixelData = new ArrayList<>();
|
||||
|
||||
for (int x = 0; x < pixelsPerBlock; x++) {
|
||||
for (int y = 0; y < pixelsPerBlock; y++) {
|
||||
for (int z = 0; z < pixelsPerBlock; z++) {
|
||||
for(int x = 0; x < pixelsPerBlock; x++) {
|
||||
for(int y = 0; y < pixelsPerBlock; y++) {
|
||||
for(int z = 0; z < pixelsPerBlock; z++) {
|
||||
Location relativeLocation = new Location(world, x, y, z);
|
||||
|
||||
Location blockLocation = this.getBuildOrigin();
|
||||
switch (direction) {
|
||||
case south -> blockLocation.add(relativeLocation.x(), relativeLocation.y(), relativeLocation.z());
|
||||
case north -> blockLocation.add((pixelsPerBlock-1)-relativeLocation.x(), relativeLocation.y(), (pixelsPerBlock-1)-relativeLocation.z());
|
||||
case east -> blockLocation.add((pixelsPerBlock-1)-relativeLocation.z(), relativeLocation.y(), relativeLocation.x());
|
||||
case west -> blockLocation.add(relativeLocation.z(), relativeLocation.y(), (pixelsPerBlock-1)-relativeLocation.x());
|
||||
switch(direction) {
|
||||
case south ->
|
||||
blockLocation.add(relativeLocation.x(), relativeLocation.y(), relativeLocation.z());
|
||||
case north ->
|
||||
blockLocation.add((pixelsPerBlock - 1) - relativeLocation.x(), relativeLocation.y(), (pixelsPerBlock - 1) - relativeLocation.z());
|
||||
case east ->
|
||||
blockLocation.add((pixelsPerBlock - 1) - relativeLocation.z(), relativeLocation.y(), relativeLocation.x());
|
||||
case west ->
|
||||
blockLocation.add(relativeLocation.z(), relativeLocation.y(), (pixelsPerBlock - 1) - relativeLocation.x());
|
||||
}
|
||||
BlockData block = blockLocation.getBlock().getBlockData();
|
||||
|
||||
@ -122,7 +128,8 @@ public class PixelBlockWorld {
|
||||
final WorldCreator worldCreator = new WorldCreator(getWorldPathName());
|
||||
|
||||
worldCreator.type(WorldType.FLAT);
|
||||
worldCreator.generator(new ChunkGenerator() {});
|
||||
worldCreator.generator(new ChunkGenerator() {
|
||||
});
|
||||
|
||||
World world = Bukkit.createWorld(worldCreator);
|
||||
Objects.requireNonNull(world);
|
||||
@ -137,7 +144,7 @@ public class PixelBlockWorld {
|
||||
|
||||
WorldBorder worldBorder = world.getWorldBorder();
|
||||
worldBorder.setCenter(getBuildOrigin().add((double) pixelsPerBlock / 2, 0, (double) pixelsPerBlock / 2));
|
||||
worldBorder.setSize(pixelsPerBlock + (2*worldGrassBorderWidth));
|
||||
worldBorder.setSize(pixelsPerBlock + (2 * worldGrassBorderWidth));
|
||||
worldBorder.setWarningDistance(0);
|
||||
worldBorder.setDamageAmount(0);
|
||||
return world;
|
||||
@ -145,24 +152,24 @@ public class PixelBlockWorld {
|
||||
|
||||
private void setBuildingPlatform() {
|
||||
Bukkit.getScheduler().runTask(Main.plugin(), () -> {
|
||||
for (int x = 0; x < (pixelsPerBlock+2) + 2 * worldGrassBorderWidth; x++) {
|
||||
for (int z = 0; z < (pixelsPerBlock+2) + 2 * worldGrassBorderWidth; z++) {
|
||||
for(int x = 0; x < (pixelsPerBlock + 2) + 2 * worldGrassBorderWidth; x++) {
|
||||
for(int z = 0; z < (pixelsPerBlock + 2) + 2 * worldGrassBorderWidth; z++) {
|
||||
getPlatformOrigin().add(x, 0, z).getBlock().setType(Material.GRASS_BLOCK);
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < (pixelsPerBlock+2) + 2 * worldGrassBorderWidth; x++) {
|
||||
for (int z = 0; z < (pixelsPerBlock+2) + 2 * worldGrassBorderWidth; z++) {
|
||||
for(int x = 0; x < (pixelsPerBlock + 2) + 2 * worldGrassBorderWidth; x++) {
|
||||
for(int z = 0; z < (pixelsPerBlock + 2) + 2 * worldGrassBorderWidth; z++) {
|
||||
getPlatformOrigin().add(x, -1, z).getBlock().setType(Material.DIRT);
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < (pixelsPerBlock+2); x++) {
|
||||
for (int z = 0; z < (pixelsPerBlock+2); z++) {
|
||||
for(int x = 0; x < (pixelsPerBlock + 2); x++) {
|
||||
for(int z = 0; z < (pixelsPerBlock + 2); z++) {
|
||||
Location currentLocation = getBorderOrigin().add(x, 0, z);
|
||||
|
||||
if (currentLocation.x() == getBorderOrigin().x() || currentLocation.z() == getBorderOrigin().z()) {
|
||||
if(currentLocation.x() == getBorderOrigin().x() || currentLocation.z() == getBorderOrigin().z()) {
|
||||
currentLocation.getBlock().setType(Material.RED_CONCRETE);
|
||||
} else if (currentLocation.x() == getBorderOrigin().x() + (pixelsPerBlock+1) || currentLocation.z() == getBorderOrigin().z() + (pixelsPerBlock+1)) {
|
||||
} else if(currentLocation.x() == getBorderOrigin().x() + (pixelsPerBlock + 1) || currentLocation.z() == getBorderOrigin().z() + (pixelsPerBlock + 1)) {
|
||||
currentLocation.getBlock().setType(Material.RED_CONCRETE);
|
||||
}
|
||||
}
|
||||
@ -170,22 +177,22 @@ public class PixelBlockWorld {
|
||||
|
||||
Random random = new Random();
|
||||
LocationUtil.iterateBlocks(getPlatformOrigin().add(1, 1, 1), getPlatformOriginEnd().add(0, 1, 0), location -> {
|
||||
if (allowPlacements(location)) return;
|
||||
if (!location.clone().subtract(0, 1, 0).getBlock().getType().equals(Material.GRASS_BLOCK)) return;
|
||||
if (!location.getBlock().getType().equals(Material.AIR)) return;
|
||||
if(allowPlacements(location)) return;
|
||||
if(!location.clone().subtract(0, 1, 0).getBlock().getType().equals(Material.GRASS_BLOCK)) return;
|
||||
if(!location.getBlock().getType().equals(Material.AIR)) return;
|
||||
|
||||
if (random.nextInt(10) == 0) {
|
||||
if(random.nextInt(10) == 0) {
|
||||
Material[] flowers = {
|
||||
Material.DANDELION,
|
||||
Material.POPPY,
|
||||
Material.BLUE_ORCHID,
|
||||
Material.ALLIUM,
|
||||
Material.AZURE_BLUET,
|
||||
Material.RED_TULIP,
|
||||
Material.ORANGE_TULIP,
|
||||
Material.WHITE_TULIP,
|
||||
Material.CORNFLOWER,
|
||||
Material.LILY_OF_THE_VALLEY,
|
||||
Material.DANDELION,
|
||||
Material.POPPY,
|
||||
Material.BLUE_ORCHID,
|
||||
Material.ALLIUM,
|
||||
Material.AZURE_BLUET,
|
||||
Material.RED_TULIP,
|
||||
Material.ORANGE_TULIP,
|
||||
Material.WHITE_TULIP,
|
||||
Material.CORNFLOWER,
|
||||
Material.LILY_OF_THE_VALLEY,
|
||||
};
|
||||
|
||||
Material randomFlower = flowers[random.nextInt(flowers.length)];
|
||||
@ -193,13 +200,13 @@ public class PixelBlockWorld {
|
||||
}
|
||||
});
|
||||
|
||||
for (int x = 0; x < 4; x++) {
|
||||
for (int y = 0; y < 5; y++) {
|
||||
for(int x = 0; x < 4; x++) {
|
||||
for(int y = 0; y < 5; y++) {
|
||||
getPortalLocation().add(x, y, 0).getBlock().setType(Material.OBSIDIAN);
|
||||
}
|
||||
}
|
||||
for (int x = 1; x < 3; x++) {
|
||||
for (int y = 1; y < 4; y++) {
|
||||
for(int x = 1; x < 3; x++) {
|
||||
for(int y = 1; y < 4; y++) {
|
||||
getPortalLocation().add(x, y, 0).getBlock().setType(Material.NETHER_PORTAL);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import java.util.function.Consumer;
|
||||
|
||||
public class LocationUtil {
|
||||
public static void iterateBlocks(Location loc1, Location loc2, Consumer<Location> action) {
|
||||
if (loc1.getWorld() != loc2.getWorld()) {
|
||||
if(loc1.getWorld() != loc2.getWorld()) {
|
||||
throw new IllegalArgumentException("Locations must be in the same world");
|
||||
}
|
||||
|
||||
@ -19,9 +19,9 @@ public class LocationUtil {
|
||||
int minZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
|
||||
int maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
|
||||
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
for(int x = minX; x <= maxX; x++) {
|
||||
for(int y = minY; y <= maxY; y++) {
|
||||
for(int z = minZ; z <= maxZ; z++) {
|
||||
action.accept(new Location(world, x, y, z));
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ public class MinMaxUtil {
|
||||
public static <I, O extends Comparable<O>> O getMinProperty(List<I> list, Function<I, O> supplier) {
|
||||
return supplier.apply(list.stream().min(Comparator.comparing(supplier)).orElseThrow());
|
||||
}
|
||||
|
||||
public static <I, O extends Comparable<O>> O getMaxProperty(List<I> list, Function<I, O> supplier) {
|
||||
return supplier.apply(list.stream().max(Comparator.comparing(supplier)).orElseThrow());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user