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("liveUpdate", true);
config.addDefault("worldGrassBorderWidth", 5); config.addDefault("worldGrassBorderWidth", 5);
config.addDefault("hitboxOffset", 0.005); config.addDefault("hitboxOffset", 0.005);
config.addDefault("deleteOnBreak", false);
config.addDefault("onlyBreakableByOwners", false);
config.addDefault("onlyEditableByOwners", true);
config.options().copyDefaults(true); config.options().copyDefaults(true);
saveConfig(); saveConfig();
@ -42,6 +45,9 @@ public final class PixelBlocks extends JavaPlugin {
PixelBlock.liveUpdate = config.getBoolean("liveUpdate"); PixelBlock.liveUpdate = config.getBoolean("liveUpdate");
PixelBlock.worldGrassBorderWidth = config.getInt("worldGrassBorderWidth"); PixelBlock.worldGrassBorderWidth = config.getInt("worldGrassBorderWidth");
PixelBlock.hitboxOffset = (float) config.getDouble("hitboxOffset"); 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 = new DataBase("jdbc:sqlite:pixelblocks.db");
dataBase.loadPixelBlocks(); 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())); PixelBlock pixelBlock = new PixelBlock(newBlockLocation, event.getPlayer().getUniqueId(), UUID.fromString(event.getItemInHand().getItemMeta().getItemName()));
if(pixelBlock.place(newBlockLocation, PixelBlock.vectorToDirection(event.getPlayer().getLocation().getDirection()))) { if(pixelBlock.place(newBlockLocation, PixelBlock.vectorToDirection(event.getPlayer().getLocation().getDirection()))) {
event.getPlayer().getInventory().remove(event.getItemInHand()); event.getPlayer().getInventory().remove(event.getItemInHand());
System.out.println(event.getPlayer().getLocation().getDirection());
} else { } else {
event.getPlayer().sendMessage("Hier wurde bereits ein Pixelblock plaziert."); 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 worldGrassBorderWidth = 5;
public static int pixelsPerBlock = 16; public static int pixelsPerBlock = 16;
public static boolean liveUpdate = true; public static boolean liveUpdate = true;
public static boolean deleteOnBreak = false;
public static boolean onlyBreakableByOwners = false;
public static boolean onlyEditableByOwners = true;
public Location pixelBlockLocation; public Location pixelBlockLocation;
public Direction direction; public Direction direction;
@ -169,7 +172,7 @@ public class PixelBlock {
} }
public void handleInteraction(Player player) { public void handleInteraction(Player player) {
if(!player.getUniqueId().equals(ownerUID)) { if(onlyEditableByOwners && !player.getUniqueId().equals(ownerUID)) {
player.sendMessage("Dieser Pixelblock gehört nicht dir!"); player.sendMessage("Dieser Pixelblock gehört nicht dir!");
return; return;
} }
@ -182,10 +185,10 @@ public class PixelBlock {
} }
public void handleAttack(Player player) { public void handleAttack(Player player) {
// if(!player.getUniqueId().equals(ownerUID)) { if(onlyBreakableByOwners && !player.getUniqueId().equals(ownerUID)) {
// player.sendMessage("Dieser Pixelblock gehört nicht dir!"); player.sendMessage("Dieser Pixelblock gehört nicht dir!");
// return; return;
// } }
World world = Objects.requireNonNull(this.getPixelWorld()); World world = Objects.requireNonNull(this.getPixelWorld());
@ -198,10 +201,14 @@ public class PixelBlock {
world.getEntities().forEach(entity -> entity.teleport(this.lastEntryLocation)); world.getEntities().forEach(entity -> entity.teleport(this.lastEntryLocation));
if(deleteOnBreak) {
this.delete();
} else {
this.remove(); this.remove();
this.pixelBlockLocation.getWorld().playSound(this.pixelBlockLocation, Sound.BLOCK_COPPER_BULB_BREAK, 1.0F, 30); this.pixelBlockLocation.getWorld().playSound(this.pixelBlockLocation, Sound.BLOCK_COPPER_BULB_BREAK, 1.0F, 30);
this.pixelBlockLocation.getWorld().dropItem(this.pixelBlockLocation, this.getAsItem()); this.pixelBlockLocation.getWorld().dropItem(this.pixelBlockLocation, this.getAsItem());
} }
}
public void handleBlockBreak(BlockBreakEvent event) { public void handleBlockBreak(BlockBreakEvent event) {
Location blockLocation = event.getBlock().getLocation(); Location blockLocation = event.getBlock().getLocation();