added config file
This commit is contained in:
parent
ef4d9cf524
commit
315750475a
@ -3,9 +3,11 @@ package eu.mhsl.minecraft.pixelblocks;
|
|||||||
import eu.mhsl.minecraft.pixelblocks.commands.CreatePixelBlockCommand;
|
import eu.mhsl.minecraft.pixelblocks.commands.CreatePixelBlockCommand;
|
||||||
import eu.mhsl.minecraft.pixelblocks.commands.ExitWorldCommand;
|
import eu.mhsl.minecraft.pixelblocks.commands.ExitWorldCommand;
|
||||||
import eu.mhsl.minecraft.pixelblocks.listeners.*;
|
import eu.mhsl.minecraft.pixelblocks.listeners.*;
|
||||||
|
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.ShapedRecipe;
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
@ -18,13 +20,29 @@ import java.util.Objects;
|
|||||||
public final class PixelBlocks extends JavaPlugin {
|
public final class PixelBlocks extends JavaPlugin {
|
||||||
public static PixelBlocks plugin;
|
public static PixelBlocks plugin;
|
||||||
public static DataBase dataBase;
|
public static DataBase dataBase;
|
||||||
public static String pathSeparator = File.separator;
|
public static String pathSeparator;
|
||||||
|
public FileConfiguration config;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
PixelBlocks.plugin = this;
|
PixelBlocks.plugin = this;
|
||||||
this.getLogger().info("PixelBlocks Plugin was enabled.");
|
this.getLogger().info("PixelBlocks Plugin was enabled.");
|
||||||
|
|
||||||
|
pathSeparator = File.separator;
|
||||||
|
|
||||||
|
config = this.getConfig();
|
||||||
|
config.addDefault("pixelsPerBlock", 16);
|
||||||
|
config.addDefault("liveUpdate", true);
|
||||||
|
config.addDefault("worldGrassBorderWidth", 5);
|
||||||
|
config.addDefault("hitboxOffset", 0.005);
|
||||||
|
config.options().copyDefaults(true);
|
||||||
|
saveConfig();
|
||||||
|
|
||||||
|
PixelBlock.pixelsPerBlock = config.getInt("pixelsPerBlock");
|
||||||
|
PixelBlock.liveUpdate = config.getBoolean("liveUpdate");
|
||||||
|
PixelBlock.worldGrassBorderWidth = config.getInt("worldGrassBorderWidth");
|
||||||
|
PixelBlock.hitboxOffset = (float) config.getDouble("hitboxOffset");
|
||||||
|
|
||||||
dataBase = new DataBase("jdbc:sqlite:pixelblocks.db");
|
dataBase = new DataBase("jdbc:sqlite:pixelblocks.db");
|
||||||
dataBase.loadPixelBlocks();
|
dataBase.loadPixelBlocks();
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ public class BlockBreakListener implements Listener {
|
|||||||
PixelBlock pixelBlock = PixelBlock.getPixelBlockFromWorld(event.getBlock().getLocation().getWorld());
|
PixelBlock pixelBlock = PixelBlock.getPixelBlockFromWorld(event.getBlock().getLocation().getWorld());
|
||||||
|
|
||||||
assert pixelBlock != null;
|
assert pixelBlock != null;
|
||||||
pixelBlock.handleBlockBreak(event, true);
|
pixelBlock.handleBlockBreak(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public class BlockPlaceListener implements Listener {
|
|||||||
PixelBlock pixelBlock = PixelBlock.getPixelBlockFromWorld(event.getBlock().getLocation().getWorld());
|
PixelBlock pixelBlock = PixelBlock.getPixelBlockFromWorld(event.getBlock().getLocation().getWorld());
|
||||||
|
|
||||||
assert pixelBlock != null;
|
assert pixelBlock != null;
|
||||||
pixelBlock.handleBlockPlace(event, true);
|
pixelBlock.handleBlockPlace(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ public class PixelBlock {
|
|||||||
public static float hitboxOffset = 0.005F;
|
public static float hitboxOffset = 0.005F;
|
||||||
public static int worldGrassBorderWidth = 5;
|
public static int worldGrassBorderWidth = 5;
|
||||||
public static int pixelsPerBlock = 16;
|
public static int pixelsPerBlock = 16;
|
||||||
|
public static boolean liveUpdate = true;
|
||||||
|
|
||||||
public Location pixelBlockLocation;
|
public Location pixelBlockLocation;
|
||||||
public ArrayList<Pixel> pixels = new ArrayList<>();
|
public ArrayList<Pixel> pixels = new ArrayList<>();
|
||||||
@ -78,9 +79,9 @@ public class PixelBlock {
|
|||||||
|
|
||||||
void createPixelWorld() {
|
void createPixelWorld() {
|
||||||
File file = new File(getWorldPathFromPixelblock(this));
|
File file = new File(getWorldPathFromPixelblock(this));
|
||||||
|
final WorldCreator worldCreator = new WorldCreator(getWorldPathFromPixelblock(this));
|
||||||
|
|
||||||
if(!file.exists() || !file.isDirectory()) {
|
if(!file.exists() || !file.isDirectory()) {
|
||||||
final WorldCreator worldCreator = new WorldCreator(getWorldPathFromPixelblock(this));
|
|
||||||
worldCreator.type(WorldType.FLAT);
|
worldCreator.type(WorldType.FLAT);
|
||||||
worldCreator.generator(new EmptyChunkGenerator());
|
worldCreator.generator(new EmptyChunkGenerator());
|
||||||
World newWorld = Bukkit.createWorld(worldCreator);
|
World newWorld = Bukkit.createWorld(worldCreator);
|
||||||
@ -97,22 +98,23 @@ public class PixelBlock {
|
|||||||
Location grassStartLocation = borderStartLocation.clone().subtract(worldGrassBorderWidth, 0, worldGrassBorderWidth);
|
Location grassStartLocation = borderStartLocation.clone().subtract(worldGrassBorderWidth, 0, worldGrassBorderWidth);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
for (int x = 0; x < 18 + 2 * worldGrassBorderWidth; x++) {
|
for (int x = 0; x < (pixelsPerBlock+2) + 2 * worldGrassBorderWidth; x++) {
|
||||||
for (int z = 0; z < 18 + 2 * worldGrassBorderWidth; z++) {
|
for (int z = 0; z < (pixelsPerBlock+2) + 2 * worldGrassBorderWidth; z++) {
|
||||||
grassStartLocation.clone().add(x, 0, z).getBlock().setType(Material.GRASS_BLOCK);
|
grassStartLocation.clone().add(x, 0, z).getBlock().setType(Material.GRASS_BLOCK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int x = 0; x < 18 + 2 * worldGrassBorderWidth; x++) {
|
for (int x = 0; x < (pixelsPerBlock+2) + 2 * worldGrassBorderWidth; x++) {
|
||||||
for (int z = 0; z < 18 + 2 * worldGrassBorderWidth; z++) {
|
for (int z = 0; z < (pixelsPerBlock+2) + 2 * worldGrassBorderWidth; z++) {
|
||||||
grassStartLocation.clone().add(x, -1, z).getBlock().setType(Material.DIRT);
|
grassStartLocation.clone().add(x, -1, z).getBlock().setType(Material.DIRT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int x = 0; x < 18; x++) {
|
for (int x = 0; x < (pixelsPerBlock+2); x++) {
|
||||||
for (int z = 0; z < 18; z++) {
|
for (int z = 0; z < (pixelsPerBlock+2); z++) {
|
||||||
Location currentLocation = borderStartLocation.clone().add(x, 0, z);
|
Location currentLocation = borderStartLocation.clone().add(x, 0, z);
|
||||||
|
|
||||||
if (currentLocation.x() == borderStartLocation.x() || currentLocation.z() == borderStartLocation.z()) {
|
if (currentLocation.x() == borderStartLocation.x() || currentLocation.z() == borderStartLocation.z()) {
|
||||||
currentLocation.getBlock().setType(Material.RED_CONCRETE);
|
currentLocation.getBlock().setType(Material.RED_CONCRETE);
|
||||||
} else if (currentLocation.x() == borderStartLocation.x() + 17 || currentLocation.z() == borderStartLocation.z() + 17) {
|
} else if (currentLocation.x() == borderStartLocation.x() + (pixelsPerBlock+1) || currentLocation.z() == borderStartLocation.z() + (pixelsPerBlock+1)) {
|
||||||
currentLocation.getBlock().setType(Material.RED_CONCRETE);
|
currentLocation.getBlock().setType(Material.RED_CONCRETE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,7 +132,7 @@ public class PixelBlock {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
new WorldCreator(getWorldPathFromPixelblock(this)).createWorld();
|
worldCreator.createWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,21 +183,21 @@ public class PixelBlock {
|
|||||||
this.pixelBlockLocation.getWorld().dropItem(this.pixelBlockLocation, this.getAsItem());
|
this.pixelBlockLocation.getWorld().dropItem(this.pixelBlockLocation, this.getAsItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleBlockBreak(BlockBreakEvent event, boolean liveUpdate) {
|
public void handleBlockBreak(BlockBreakEvent event) {
|
||||||
Location blockLocation = event.getBlock().getLocation();
|
Location blockLocation = event.getBlock().getLocation();
|
||||||
Location spawnLocation = blockLocation.getWorld().getSpawnLocation();
|
Location spawnLocation = blockLocation.getWorld().getSpawnLocation();
|
||||||
|
|
||||||
if(blockLocation.x() < spawnLocation.x() || blockLocation.z() < spawnLocation.z() || blockLocation.y() < spawnLocation.y()) {
|
if(blockLocation.x() < spawnLocation.x() || blockLocation.z() < spawnLocation.z() || blockLocation.y() < spawnLocation.y()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
} else if(blockLocation.x() > spawnLocation.x()+15 || blockLocation.z() > spawnLocation.z()+15 || blockLocation.y() > spawnLocation.y()+15) {
|
} else if(blockLocation.x() > spawnLocation.x()+(pixelsPerBlock-1) || blockLocation.z() > spawnLocation.z()+(pixelsPerBlock-1) || blockLocation.y() > spawnLocation.y()+(pixelsPerBlock-1)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
if(liveUpdate) {
|
if(liveUpdate) {
|
||||||
Location relativeLocation = blockLocation.subtract(spawnLocation.x(), spawnLocation.y(), spawnLocation.z());
|
Location relativeLocation = blockLocation.subtract(spawnLocation.getX(), spawnLocation.getY(), spawnLocation.getZ());
|
||||||
relativeLocation.setWorld(this.pixelBlockLocation.getWorld());
|
relativeLocation.setWorld(this.pixelBlockLocation.getWorld());
|
||||||
List<Pixel> pixels = this.pixels.stream().filter(pixel -> pixel.relativeLocation.equals(relativeLocation)).toList();
|
List<Pixel> pixels = this.pixels.stream().filter(pixel -> pixel.relativeLocation.equals(relativeLocation)).toList();
|
||||||
if(!pixels.isEmpty()) {
|
if(!pixels.isEmpty()) {
|
||||||
@ -207,21 +209,21 @@ public class PixelBlock {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleBlockPlace(BlockPlaceEvent event, boolean liveUpdate) {
|
public void handleBlockPlace(BlockPlaceEvent event) {
|
||||||
Location blockLocation = event.getBlock().getLocation();
|
Location blockLocation = event.getBlock().getLocation();
|
||||||
Location spawnLocation = blockLocation.getWorld().getSpawnLocation();
|
Location spawnLocation = blockLocation.getWorld().getSpawnLocation();
|
||||||
|
|
||||||
if(blockLocation.x() < spawnLocation.x() || blockLocation.z() < spawnLocation.z() || blockLocation.y() < spawnLocation.y()) {
|
if(blockLocation.x() < spawnLocation.x() || blockLocation.z() < spawnLocation.z() || blockLocation.y() < spawnLocation.y()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
} else if(blockLocation.x() > spawnLocation.x()+15 || blockLocation.z() > spawnLocation.z()+15 || blockLocation.y() > spawnLocation.y()+15) {
|
} else if(blockLocation.x() > spawnLocation.x()+(pixelsPerBlock-1) || blockLocation.z() > spawnLocation.z()+(pixelsPerBlock-1) || blockLocation.y() > spawnLocation.y()+(pixelsPerBlock-1)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(PixelBlocks.plugin, () -> {
|
Bukkit.getScheduler().runTask(PixelBlocks.plugin, () -> {
|
||||||
if(liveUpdate) {
|
if(liveUpdate) {
|
||||||
Location relativeLocation = blockLocation.subtract(spawnLocation.x(), spawnLocation.y(), spawnLocation.z());
|
Location relativeLocation = blockLocation.subtract(spawnLocation.getX(), spawnLocation.getY(), spawnLocation.getZ());
|
||||||
relativeLocation.setWorld(this.pixelBlockLocation.getWorld());
|
relativeLocation.setWorld(this.pixelBlockLocation.getWorld());
|
||||||
|
|
||||||
Pixel newPixel = new Pixel(relativeLocation, event.getBlock().getBlockData(), ((double) 1 /pixelsPerBlock), 0);
|
Pixel newPixel = new Pixel(relativeLocation, event.getBlock().getBlockData(), ((double) 1 /pixelsPerBlock), 0);
|
||||||
@ -276,18 +278,18 @@ public class PixelBlock {
|
|||||||
.orElseThrow().relativeLocation.getZ();
|
.orElseThrow().relativeLocation.getZ();
|
||||||
|
|
||||||
Location spawnLocation = pixelBlockLocation.clone().add(
|
Location spawnLocation = pixelBlockLocation.clone().add(
|
||||||
((startingX+endingX+1)/2)/16,
|
((startingX+endingX+1)/2)/pixelsPerBlock,
|
||||||
(startingY/16)-hitboxOffset,
|
(startingY/pixelsPerBlock)-hitboxOffset,
|
||||||
((startingZ+endingZ+1)/2)/16
|
((startingZ+endingZ+1)/2)/pixelsPerBlock
|
||||||
);
|
);
|
||||||
|
|
||||||
float height = (float) (endingY-startingY+1)/16 + 2*hitboxOffset;
|
float height = (float) (endingY-startingY+1)/pixelsPerBlock + 2*hitboxOffset;
|
||||||
|
|
||||||
float width;
|
float width;
|
||||||
if((endingX-startingX) > (endingZ-startingZ)) {
|
if((endingX-startingX) > (endingZ-startingZ)) {
|
||||||
width = (float) (endingX-startingX+1)/16 + 2*hitboxOffset;
|
width = (float) (endingX-startingX+1)/pixelsPerBlock + 2*hitboxOffset;
|
||||||
} else {
|
} else {
|
||||||
width = (float) (endingZ-startingZ+1)/16 + 2*hitboxOffset;
|
width = (float) (endingZ-startingZ+1)/pixelsPerBlock + 2*hitboxOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(spawnLocation.getX()+width/2 > this.pixelBlockLocation.getX()+1) {
|
if(spawnLocation.getX()+width/2 > this.pixelBlockLocation.getX()+1) {
|
||||||
@ -318,9 +320,9 @@ public class PixelBlock {
|
|||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
this.clearEntities(true);
|
this.clearEntities(true);
|
||||||
|
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < pixelsPerBlock; x++) {
|
||||||
for (int y = 0; y < 16; y++) {
|
for (int y = 0; y < pixelsPerBlock; y++) {
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < pixelsPerBlock; z++) {
|
||||||
Location relativeLocation = new Location(pixelBlockLocation.getWorld(), x, y, z);
|
Location relativeLocation = new Location(pixelBlockLocation.getWorld(), x, y, z);
|
||||||
Location blockLocation = Objects.requireNonNull(Bukkit
|
Location blockLocation = Objects.requireNonNull(Bukkit
|
||||||
.getWorld(getWorldPathFromPixelblock(this)))
|
.getWorld(getWorldPathFromPixelblock(this)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user