added more options for config

This commit is contained in:
Lars Neuhaus 2024-07-20 17:01:53 +02:00
parent e48413d111
commit 966f870d96
3 changed files with 21 additions and 9 deletions

View File

@ -35,6 +35,9 @@ public final class PixelBlocks extends JavaPlugin {
config.addDefault("liveUpdate", true);
config.addDefault("worldGrassBorderWidth", 5);
config.addDefault("hitboxOffset", 0.005);
config.addDefault("deleteOnBreak", false);
config.addDefault("onlyBreakableByOwners", false);
config.addDefault("onlyEditableByOwners", true);
config.options().copyDefaults(true);
saveConfig();
@ -42,6 +45,9 @@ public final class PixelBlocks extends JavaPlugin {
PixelBlock.liveUpdate = config.getBoolean("liveUpdate");
PixelBlock.worldGrassBorderWidth = config.getInt("worldGrassBorderWidth");
PixelBlock.hitboxOffset = (float) config.getDouble("hitboxOffset");
PixelBlock.deleteOnBreak = config.getBoolean("deleteOnBreak");
PixelBlock.onlyBreakableByOwners = config.getBoolean("onlyBreakableByOwners");
PixelBlock.onlyEditableByOwners = config.getBoolean("onlyEditableByOwners");
dataBase = new DataBase("jdbc:sqlite:pixelblocks.db");
dataBase.loadPixelBlocks();

View File

@ -35,7 +35,6 @@ public class BlockPlaceListener implements Listener {
PixelBlock pixelBlock = new PixelBlock(newBlockLocation, event.getPlayer().getUniqueId(), UUID.fromString(event.getItemInHand().getItemMeta().getItemName()));
if(pixelBlock.place(newBlockLocation, PixelBlock.vectorToDirection(event.getPlayer().getLocation().getDirection()))) {
event.getPlayer().getInventory().remove(event.getItemInHand());
System.out.println(event.getPlayer().getLocation().getDirection());
} else {
event.getPlayer().sendMessage("Hier wurde bereits ein Pixelblock plaziert.");
}

View File

@ -25,6 +25,9 @@ public class PixelBlock {
public static int worldGrassBorderWidth = 5;
public static int pixelsPerBlock = 16;
public static boolean liveUpdate = true;
public static boolean deleteOnBreak = false;
public static boolean onlyBreakableByOwners = false;
public static boolean onlyEditableByOwners = true;
public Location pixelBlockLocation;
public Direction direction;
@ -169,7 +172,7 @@ public class PixelBlock {
}
public void handleInteraction(Player player) {
if(!player.getUniqueId().equals(ownerUID)) {
if(onlyEditableByOwners && !player.getUniqueId().equals(ownerUID)) {
player.sendMessage("Dieser Pixelblock gehört nicht dir!");
return;
}
@ -182,10 +185,10 @@ public class PixelBlock {
}
public void handleAttack(Player player) {
// if(!player.getUniqueId().equals(ownerUID)) {
// player.sendMessage("Dieser Pixelblock gehört nicht dir!");
// return;
// }
if(onlyBreakableByOwners && !player.getUniqueId().equals(ownerUID)) {
player.sendMessage("Dieser Pixelblock gehört nicht dir!");
return;
}
World world = Objects.requireNonNull(this.getPixelWorld());
@ -198,9 +201,13 @@ public class PixelBlock {
world.getEntities().forEach(entity -> entity.teleport(this.lastEntryLocation));
this.remove();
this.pixelBlockLocation.getWorld().playSound(this.pixelBlockLocation, Sound.BLOCK_COPPER_BULB_BREAK, 1.0F, 30);
this.pixelBlockLocation.getWorld().dropItem(this.pixelBlockLocation, this.getAsItem());
if(deleteOnBreak) {
this.delete();
} else {
this.remove();
this.pixelBlockLocation.getWorld().playSound(this.pixelBlockLocation, Sound.BLOCK_COPPER_BULB_BREAK, 1.0F, 30);
this.pixelBlockLocation.getWorld().dropItem(this.pixelBlockLocation, this.getAsItem());
}
}
public void handleBlockBreak(BlockBreakEvent event) {