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