added and implemented taskchain
This commit is contained in:
parent
4f4a6aef10
commit
ab71f09f8a
10
.idea/jarRepositories.xml
generated
10
.idea/jarRepositories.xml
generated
@ -26,5 +26,15 @@
|
|||||||
<option name="name" value="sonatype" />
|
<option name="name" value="sonatype" />
|
||||||
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
|
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven2" />
|
||||||
|
<option name="name" value="maven2" />
|
||||||
|
<option name="url" value="https://hub.spigotmc.org/nexus/content/groups/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven" />
|
||||||
|
<option name="name" value="maven" />
|
||||||
|
<option name="url" value="https://repo.aikar.co/content/groups/aikar/" />
|
||||||
|
</remote-repository>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
25
build.gradle
25
build.gradle
@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
|
id 'com.gradleup.shadow' version '8.3.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'eu.mhsl.minecraft'
|
group = 'eu.mhsl.minecraft'
|
||||||
@ -15,10 +16,14 @@ repositories {
|
|||||||
name = "sonatype"
|
name = "sonatype"
|
||||||
url = "https://oss.sonatype.org/content/groups/public/"
|
url = "https://oss.sonatype.org/content/groups/public/"
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
url = "https://repo.aikar.co/content/groups/aikar/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT"
|
compileOnly "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT"
|
||||||
|
implementation "co.aikar:taskchain-bukkit:3.7.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 21
|
def targetJavaVersion = 21
|
||||||
@ -31,14 +36,6 @@ java {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile).configureEach {
|
|
||||||
options.encoding = 'UTF-8'
|
|
||||||
|
|
||||||
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
|
||||||
options.release.set(targetJavaVersion)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
def props = [version: version]
|
def props = [version: version]
|
||||||
inputs.properties props
|
inputs.properties props
|
||||||
@ -49,8 +46,12 @@ processResources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks.register('copyJarToTestServer', Exec) {
|
tasks.register('copyJarToTestServer', Exec) {
|
||||||
dependsOn jar
|
commandLine 'cp', 'build/libs/PixelBlocks-1.0-SNAPSHOT-all.jar', '/home/elias/Dokumente/mcTestServer/plugins/pixelblocks.jar'
|
||||||
mustRunAfter jar
|
|
||||||
|
|
||||||
commandLine 'cp', 'build/libs/PixelBlocks-1.0-SNAPSHOT.jar', '/home/elias/Dokumente/mcTestServer/plugins/pixelblocks.jar'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
relocate 'co.aikar.taskchain', 'eu.mhsl.minecraft.pixelblocks.taskchain'
|
||||||
|
}
|
||||||
|
|
||||||
|
jar.dependsOn shadowJar
|
||||||
|
copyJarToTestServer.dependsOn jar
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package eu.mhsl.minecraft.pixelblocks;
|
package eu.mhsl.minecraft.pixelblocks;
|
||||||
|
|
||||||
|
import co.aikar.taskchain.BukkitTaskChainFactory;
|
||||||
|
import co.aikar.taskchain.TaskChain;
|
||||||
|
import co.aikar.taskchain.TaskChainFactory;
|
||||||
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.*;
|
||||||
@ -15,22 +18,31 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public final class PixelBlocksPlugin extends JavaPlugin {
|
public final class Main extends JavaPlugin {
|
||||||
public static PixelBlocksPlugin plugin;
|
public static Main plugin;
|
||||||
public static PixelBlockConfiguration configuration;
|
public static PixelBlockConfiguration configuration;
|
||||||
public static PixelBlockDatabase database;
|
public static PixelBlockDatabase database;
|
||||||
|
|
||||||
|
public static TaskChainFactory taskFactory;
|
||||||
|
|
||||||
public static List<PixelBlock> pixelBlocks = new ArrayList<>();
|
public static List<PixelBlock> pixelBlocks = new ArrayList<>();
|
||||||
|
|
||||||
|
public static <T> TaskChain<T> newChain() {
|
||||||
|
return taskFactory.newChain();
|
||||||
|
}
|
||||||
|
public static <T> TaskChain<T> newSharedChain(String name) {
|
||||||
|
return taskFactory.newSharedChain(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
PixelBlocksPlugin.plugin = this;
|
Main.plugin = this;
|
||||||
|
|
||||||
FileConfiguration config = this.getConfig();
|
FileConfiguration config = this.getConfig();
|
||||||
PixelBlockConfiguration.setDefaults(config);
|
PixelBlockConfiguration.setDefaults(config);
|
||||||
this.saveConfig();
|
this.saveConfig();
|
||||||
|
|
||||||
PixelBlocksPlugin.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()),
|
||||||
@ -38,11 +50,12 @@ public final class PixelBlocksPlugin extends JavaPlugin {
|
|||||||
);
|
);
|
||||||
|
|
||||||
File databaseFile = new File(plugin.getDataFolder(), "blocks.db");
|
File databaseFile = new File(plugin.getDataFolder(), "blocks.db");
|
||||||
PixelBlocksPlugin.database = new PixelBlockDatabase("jdbc:sqlite:" + databaseFile);
|
Main.database = new PixelBlockDatabase("jdbc:sqlite:" + databaseFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
Main.taskFactory = BukkitTaskChainFactory.create(this);
|
||||||
database.loadPixelBlocks();
|
database.loadPixelBlocks();
|
||||||
|
|
||||||
Listener[] listeners = {
|
Listener[] listeners = {
|
@ -68,11 +68,11 @@ public class PixelBlockDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deletePixelBlock(PixelBlock pixelBlock) {
|
public void deletePixelBlock(PixelBlock pixelBlock) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(PixelBlocksPlugin.plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(Main.plugin, () -> {
|
||||||
try {
|
try {
|
||||||
this.deletePixelBlock.setString(1, pixelBlock.blockUUID.toString());
|
this.deletePixelBlock.setString(1, pixelBlock.blockUUID.toString());
|
||||||
this.deletePixelBlock.executeUpdate();
|
this.deletePixelBlock.executeUpdate();
|
||||||
PixelBlocksPlugin.plugin.getLogger().info("DB: Deleted PixelBlock: " + pixelBlock.blockUUID);
|
Main.plugin.getLogger().info("DB: Deleted PixelBlock: " + pixelBlock.blockUUID);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException("Failed to delete PixelBlock", e);
|
throw new RuntimeException("Failed to delete PixelBlock", e);
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ public class PixelBlockDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void savePixelBlock(PixelBlock pixelBlock) {
|
public void savePixelBlock(PixelBlock pixelBlock) {
|
||||||
Bukkit.getScheduler().runTask(PixelBlocksPlugin.plugin, () -> {
|
Bukkit.getScheduler().runTask(Main.plugin, () -> {
|
||||||
List<UUID> storedPixelBlocks = new ArrayList<>();
|
List<UUID> storedPixelBlocks = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -118,7 +118,7 @@ public class PixelBlockDatabase {
|
|||||||
this.insertNewPixelBlock.setString(11, pixelBlock.facingDirection.toString());
|
this.insertNewPixelBlock.setString(11, pixelBlock.facingDirection.toString());
|
||||||
|
|
||||||
this.insertNewPixelBlock.executeUpdate();
|
this.insertNewPixelBlock.executeUpdate();
|
||||||
PixelBlocksPlugin.plugin.getLogger().info("DB: Created PixelBlock: " + pixelBlock.blockUUID);
|
Main.plugin.getLogger().info("DB: Created PixelBlock: " + pixelBlock.blockUUID);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException("Failed to save PixelBlock", e);
|
throw new RuntimeException("Failed to save PixelBlock", e);
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ public class PixelBlockDatabase {
|
|||||||
this.updateExistingPixelBlock.setString(11, pixelBlock.facingDirection.toString());
|
this.updateExistingPixelBlock.setString(11, pixelBlock.facingDirection.toString());
|
||||||
|
|
||||||
this.updateExistingPixelBlock.executeUpdate();
|
this.updateExistingPixelBlock.executeUpdate();
|
||||||
PixelBlocksPlugin.plugin.getLogger().info("DB: Updated PixelBlock: " + pixelBlock.blockUUID);
|
Main.plugin.getLogger().info("DB: Updated PixelBlock: " + pixelBlock.blockUUID);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException("Failed updating PixelBlock", e);
|
throw new RuntimeException("Failed updating PixelBlock", e);
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ public class PixelBlockDatabase {
|
|||||||
Direction.valueOf(allPixelBlocks.getString("direction"))
|
Direction.valueOf(allPixelBlocks.getString("direction"))
|
||||||
);
|
);
|
||||||
block.setLastEntryLocation(entryLocation);
|
block.setLastEntryLocation(entryLocation);
|
||||||
PixelBlocksPlugin.plugin.getLogger().info("DB: Loaded PixelBlock: " + block.blockUUID);
|
Main.plugin.getLogger().info("DB: Loaded PixelBlock: " + block.blockUUID);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException("Failed loading PixelBlocks", e);
|
throw new RuntimeException("Failed loading PixelBlocks", e);
|
||||||
|
@ -22,9 +22,9 @@ import java.util.Optional;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PixelBlockItem {
|
public class PixelBlockItem {
|
||||||
public static final NamespacedKey recipeKey = new NamespacedKey(PixelBlocksPlugin.plugin, "pixelblock");
|
public static final NamespacedKey recipeKey = new NamespacedKey(Main.plugin, "pixelblock");
|
||||||
public static NamespacedKey idProperty = new NamespacedKey(PixelBlocksPlugin.plugin, "id");
|
public static NamespacedKey idProperty = new NamespacedKey(Main.plugin, "id");
|
||||||
public static NamespacedKey ownerProperty = new NamespacedKey(PixelBlocksPlugin.plugin, "owner");
|
public static NamespacedKey ownerProperty = new NamespacedKey(Main.plugin, "owner");
|
||||||
|
|
||||||
public static final String itemTexture = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzE5NGU5ZTc3NTdkMDZkNmY1ZTViZTg0NTQ4YTdjYjUyMTczZDY4Y2NmODAyZDIxMTI3NWQzMWNkYmEwYTA2ZSJ9fX0=";
|
public static final String itemTexture = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzE5NGU5ZTc3NTdkMDZkNmY1ZTViZTg0NTQ4YTdjYjUyMTczZDY4Y2NmODAyZDIxMTI3NWQzMWNkYmEwYTA2ZSJ9fX0=";
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||||
|
|
||||||
import eu.mhsl.minecraft.pixelblocks.PixelBlocksPlugin;
|
import eu.mhsl.minecraft.pixelblocks.Main;
|
||||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||||
import io.papermc.paper.event.player.PrePlayerAttackEntityEvent;
|
import io.papermc.paper.event.player.PrePlayerAttackEntityEvent;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -13,7 +13,7 @@ public class BreakPixelBlockListener implements Listener {
|
|||||||
static void destroyPixelBlock(PrePlayerAttackEntityEvent event) {
|
static void destroyPixelBlock(PrePlayerAttackEntityEvent event) {
|
||||||
if(!(event.getAttacked() instanceof Interaction)) return;
|
if(!(event.getAttacked() instanceof Interaction)) return;
|
||||||
|
|
||||||
Location blockLocation = event.getAttacked().getLocation().add(0, PixelBlocksPlugin.configuration.hitboxOffset(), 0).toBlockLocation();
|
Location blockLocation = event.getAttacked().getLocation().add(0, Main.configuration.hitboxOffset(), 0).toBlockLocation();
|
||||||
PixelBlock pixelBlock = PixelBlock.getPixelBlockFromPlacedLocation(blockLocation);
|
PixelBlock pixelBlock = PixelBlock.getPixelBlockFromPlacedLocation(blockLocation);
|
||||||
if(pixelBlock == null) return;
|
if(pixelBlock == null) return;
|
||||||
pixelBlock.destroy(event.getPlayer());
|
pixelBlock.destroy(event.getPlayer());
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||||
|
|
||||||
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
|
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
|
||||||
import eu.mhsl.minecraft.pixelblocks.PixelBlocksPlugin;
|
import eu.mhsl.minecraft.pixelblocks.Main;
|
||||||
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;
|
||||||
@ -20,7 +20,7 @@ public class DiscoverRecipesListener implements Listener {
|
|||||||
if(!(event.getWhoClicked() instanceof Player player)) return;
|
if(!(event.getWhoClicked() instanceof Player player)) return;
|
||||||
if(!List.of(Material.HEART_OF_THE_SEA, Material.END_CRYSTAL).contains(clickedItem.getType())) return;
|
if(!List.of(Material.HEART_OF_THE_SEA, Material.END_CRYSTAL).contains(clickedItem.getType())) return;
|
||||||
if(player.hasDiscoveredRecipe(PixelBlockItem.recipeKey)) return;
|
if(player.hasDiscoveredRecipe(PixelBlockItem.recipeKey)) return;
|
||||||
PixelBlocksPlugin.plugin.getLogger().log(Level.INFO, String.format("%s unlocked tne PixelBlock recipe!", player.getName()));
|
Main.plugin.getLogger().log(Level.INFO, String.format("%s unlocked tne PixelBlock recipe!", player.getName()));
|
||||||
player.discoverRecipe(PixelBlockItem.recipeKey);
|
player.discoverRecipe(PixelBlockItem.recipeKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||||
|
|
||||||
import eu.mhsl.minecraft.pixelblocks.PixelBlocksPlugin;
|
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.*;
|
||||||
import org.bukkit.entity.Interaction;
|
import org.bukkit.entity.Interaction;
|
||||||
@ -16,7 +16,7 @@ public class EnterPixelBlockListener implements Listener {
|
|||||||
Location interactionLocation = event
|
Location interactionLocation = event
|
||||||
.getRightClicked()
|
.getRightClicked()
|
||||||
.getLocation()
|
.getLocation()
|
||||||
.add(0, PixelBlocksPlugin.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;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||||
|
|
||||||
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
|
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
|
||||||
import eu.mhsl.minecraft.pixelblocks.PixelBlocksPlugin;
|
import eu.mhsl.minecraft.pixelblocks.Main;
|
||||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
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;
|
||||||
@ -46,7 +46,7 @@ public class PlacePixelBlockListener implements Listener {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
UUID itemUUID = info.id();
|
UUID itemUUID = info.id();
|
||||||
pixelBlock = PixelBlocksPlugin.pixelBlocks.stream()
|
pixelBlock = Main.pixelBlocks.stream()
|
||||||
.filter(block -> block.blockUUID.equals(itemUUID))
|
.filter(block -> block.blockUUID.equals(itemUUID))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseGet(() -> new PixelBlock(
|
.orElseGet(() -> new PixelBlock(
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package eu.mhsl.minecraft.pixelblocks.pixelblock;
|
package eu.mhsl.minecraft.pixelblocks.pixelblock;
|
||||||
|
|
||||||
|
import co.aikar.taskchain.TaskChain;
|
||||||
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
|
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
|
||||||
import eu.mhsl.minecraft.pixelblocks.PixelBlocksPlugin;
|
import eu.mhsl.minecraft.pixelblocks.Main;
|
||||||
import eu.mhsl.minecraft.pixelblocks.utils.Direction;
|
import eu.mhsl.minecraft.pixelblocks.utils.Direction;
|
||||||
import eu.mhsl.minecraft.pixelblocks.utils.MinMaxUtil;
|
import eu.mhsl.minecraft.pixelblocks.utils.MinMaxUtil;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -20,8 +21,8 @@ import java.util.*;
|
|||||||
public class PixelBlock {
|
public class PixelBlock {
|
||||||
private final PixelBlockWorld pixelWorld;
|
private final PixelBlockWorld pixelWorld;
|
||||||
|
|
||||||
private final float hitboxOffset = (float) PixelBlocksPlugin.configuration.hitboxOffset();
|
private final float hitboxOffset = (float) Main.configuration.hitboxOffset();
|
||||||
private final int pixelsPerBlock = PixelBlocksPlugin.configuration.pixelsPerBlock();
|
private final int pixelsPerBlock = Main.configuration.pixelsPerBlock();
|
||||||
|
|
||||||
public Location pixelBlockLocation;
|
public Location pixelBlockLocation;
|
||||||
public Direction facingDirection;
|
public Direction facingDirection;
|
||||||
@ -38,11 +39,11 @@ public class PixelBlock {
|
|||||||
public static final int maxPixelsPerBlock = 2000;
|
public static final int maxPixelsPerBlock = 2000;
|
||||||
|
|
||||||
public static @NotNull String getWorldName(@NotNull PixelBlock pixelBlock) {
|
public static @NotNull String getWorldName(@NotNull PixelBlock pixelBlock) {
|
||||||
return PixelBlocksPlugin.plugin.getDataFolder().getPath() + File.separator + pixelBlock.blockUUID;
|
return Main.plugin.getDataFolder().getPath() + File.separator + pixelBlock.blockUUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @Nullable PixelBlock getPixelBlockFromBlockWorld(World world) {
|
public static @Nullable PixelBlock getPixelBlockFromBlockWorld(World world) {
|
||||||
return PixelBlocksPlugin.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);
|
||||||
@ -61,14 +62,14 @@ public class PixelBlock {
|
|||||||
searchLocation.setPitch(0);
|
searchLocation.setPitch(0);
|
||||||
searchLocation.setYaw(0);
|
searchLocation.setYaw(0);
|
||||||
|
|
||||||
return PixelBlocksPlugin.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 PixelBlock(Location originLocation, UUID ownerUUID, UUID blockUUID, Direction direction) {
|
public PixelBlock(Location originLocation, UUID ownerUUID, UUID blockUUID, Direction direction) {
|
||||||
PixelBlocksPlugin.pixelBlocks.add(this);
|
Main.pixelBlocks.add(this);
|
||||||
|
|
||||||
this.ownerUUID = ownerUUID;
|
this.ownerUUID = ownerUUID;
|
||||||
this.blockUUID = blockUUID;
|
this.blockUUID = blockUUID;
|
||||||
@ -82,17 +83,23 @@ public class PixelBlock {
|
|||||||
this.pixelWorld = new PixelBlockWorld(this);
|
this.pixelWorld = new PixelBlockWorld(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> TaskChain<T> getBlockTaskChain() {
|
||||||
|
return Main.newSharedChain(this.blockUUID.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public void enterBlock(@NotNull Player player) {
|
public void enterBlock(@NotNull Player player) {
|
||||||
if(PixelBlocksPlugin.configuration.onlyEditableByOwner() && !player.getUniqueId().equals(ownerUUID)) {
|
if(Main.configuration.onlyEditableByOwner() && !player.getUniqueId().equals(ownerUUID)) {
|
||||||
player.sendMessage(Component.text("Dieser Pixelblock gehört nicht dir!", NamedTextColor.RED));
|
player.sendMessage(Component.text("Dieser Pixelblock gehört nicht dir!", NamedTextColor.RED));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
getBlockTaskChain()
|
||||||
this.lastEntryLocation = player.getLocation();
|
.async(() -> {
|
||||||
this.lastEntryTime = System.currentTimeMillis();
|
this.lastEntryLocation = player.getLocation();
|
||||||
PixelBlocksPlugin.database.savePixelBlock(this);
|
this.lastEntryTime = System.currentTimeMillis();
|
||||||
|
Main.database.savePixelBlock(this);
|
||||||
player.teleport(this.pixelWorld.getSpawnLocation());
|
})
|
||||||
|
.sync(() -> player.teleport(this.pixelWorld.getSpawnLocation()))
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastEntryLocation(Location lastEntryLocation) {
|
public void setLastEntryLocation(Location lastEntryLocation) {
|
||||||
@ -156,56 +163,53 @@ public class PixelBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateEntities() {
|
public void updateEntities() {
|
||||||
Bukkit.getScheduler().runTask(PixelBlocksPlugin.plugin, () -> {
|
this.getBlockTaskChain()
|
||||||
this.clearEntities();
|
.sync(this::clearEntities)
|
||||||
|
.async(() -> {
|
||||||
|
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(pixelBlockLocation.getWorld(), x, y, z);
|
||||||
|
Location blockLocation = this.pixelWorld.getBuildOrigin();
|
||||||
|
switch (this.facingDirection) {
|
||||||
|
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();
|
||||||
|
|
||||||
for (int x = 0; x < pixelsPerBlock; x++) {
|
if(block.getMaterial() != Material.AIR) {
|
||||||
for (int y = 0; y < pixelsPerBlock; y++) {
|
pixels.add(new Pixel(relativeLocation, block, ((double) 1/pixelsPerBlock)));
|
||||||
for (int z = 0; z < pixelsPerBlock; z++) {
|
}
|
||||||
Location relativeLocation = new Location(pixelBlockLocation.getWorld(), x, y, z);
|
}
|
||||||
Location blockLocation = this.pixelWorld.getBuildOrigin();
|
|
||||||
switch (this.facingDirection) {
|
|
||||||
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();
|
|
||||||
|
|
||||||
if(block.getMaterial() != Material.AIR) {
|
|
||||||
pixels.add(new Pixel(relativeLocation, block, ((double) 1/pixelsPerBlock)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
.sync(() -> this.pixels.stream()
|
||||||
|
.limit(maxPixelsPerBlock)
|
||||||
|
.forEach(pixel -> pixel.place(this.pixelBlockLocation)))
|
||||||
|
.sync(() -> {
|
||||||
|
if(this.pixels.size() < 5) {
|
||||||
|
Location relativeLocation = new Location(pixelBlockLocation.getWorld(), 0, 0, 0);
|
||||||
|
BlockData block = Material.GRAY_STAINED_GLASS.createBlockData();
|
||||||
|
Pixel newPixel = new Pixel(relativeLocation, block, 1);
|
||||||
|
pixels.add(newPixel);
|
||||||
|
newPixel.place(this.pixelBlockLocation);
|
||||||
|
|
||||||
this.pixels.stream()
|
Location itemDisplayLocation = this.pixelBlockLocation.clone().add(0.5, 0.5, 0.5);
|
||||||
.limit(maxPixelsPerBlock)
|
this.barrier = (ItemDisplay) this.pixelBlockLocation.getWorld().spawnEntity(
|
||||||
.forEach(pixel -> pixel.place(this.pixelBlockLocation));
|
itemDisplayLocation,
|
||||||
|
EntityType.ITEM_DISPLAY
|
||||||
|
);
|
||||||
|
this.barrier.setItemStack(ItemStack.of(Material.BARRIER));
|
||||||
|
|
||||||
if(this.pixels.size() > maxPixelsPerBlock) {
|
spawnInteraction(true);
|
||||||
|
} else {
|
||||||
}
|
spawnInteraction(false);
|
||||||
|
}
|
||||||
if(this.pixels.size() < 5) {
|
})
|
||||||
Location relativeLocation = new Location(pixelBlockLocation.getWorld(), 0, 0, 0);
|
.execute();
|
||||||
BlockData block = Material.GRAY_STAINED_GLASS.createBlockData();
|
|
||||||
Pixel newPixel = new Pixel(relativeLocation, block, 1);
|
|
||||||
pixels.add(newPixel);
|
|
||||||
newPixel.place(this.pixelBlockLocation);
|
|
||||||
|
|
||||||
Location itemDisplayLocation = this.pixelBlockLocation.clone().add(0.5, 0.5, 0.5);
|
|
||||||
this.barrier = (ItemDisplay) this.pixelBlockLocation.getWorld().spawnEntity(
|
|
||||||
itemDisplayLocation,
|
|
||||||
EntityType.ITEM_DISPLAY
|
|
||||||
);
|
|
||||||
this.barrier.setItemStack(ItemStack.of(Material.BARRIER));
|
|
||||||
|
|
||||||
spawnInteraction(true);
|
|
||||||
} else {
|
|
||||||
spawnInteraction(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void place(Location placeLocation, Direction direction) {
|
public void place(Location placeLocation, Direction direction) {
|
||||||
@ -219,11 +223,11 @@ public class PixelBlock {
|
|||||||
this.pixelBlockLocation = newLocation;
|
this.pixelBlockLocation = newLocation;
|
||||||
this.facingDirection = direction;
|
this.facingDirection = direction;
|
||||||
updateEntities();
|
updateEntities();
|
||||||
PixelBlocksPlugin.database.savePixelBlock(this);
|
Main.database.savePixelBlock(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(Player destroyedBy) {
|
public void destroy(Player destroyedBy) {
|
||||||
if(PixelBlocksPlugin.configuration.onlyBreakableByOwner() && !destroyedBy.getUniqueId().equals(ownerUUID)) {
|
if(Main.configuration.onlyBreakableByOwner() && !destroyedBy.getUniqueId().equals(ownerUUID)) {
|
||||||
destroyedBy.sendMessage("Dieser Pixelblock gehört nicht dir!");
|
destroyedBy.sendMessage("Dieser Pixelblock gehört nicht dir!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -238,7 +242,7 @@ public class PixelBlock {
|
|||||||
.forEach(entity -> entity.teleport(this.lastEntryLocation));
|
.forEach(entity -> entity.teleport(this.lastEntryLocation));
|
||||||
|
|
||||||
this.clearEntities();
|
this.clearEntities();
|
||||||
PixelBlocksPlugin.database.deletePixelBlock(this);
|
Main.database.deletePixelBlock(this);
|
||||||
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.add(new Vector(0.5, 0.5, 0.5)), PixelBlockItem.getBlockAsItem(this));
|
this.pixelBlockLocation.getWorld().dropItem(this.pixelBlockLocation.add(new Vector(0.5, 0.5, 0.5)), PixelBlockItem.getBlockAsItem(this));
|
||||||
this.pixelBlockLocation = null;
|
this.pixelBlockLocation = null;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package eu.mhsl.minecraft.pixelblocks.pixelblock;
|
package eu.mhsl.minecraft.pixelblocks.pixelblock;
|
||||||
|
|
||||||
import eu.mhsl.minecraft.pixelblocks.PixelBlocksPlugin;
|
import eu.mhsl.minecraft.pixelblocks.Main;
|
||||||
import eu.mhsl.minecraft.pixelblocks.utils.LocationUtil;
|
import eu.mhsl.minecraft.pixelblocks.utils.LocationUtil;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -13,14 +13,14 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static eu.mhsl.minecraft.pixelblocks.PixelBlocksPlugin.plugin;
|
import static eu.mhsl.minecraft.pixelblocks.Main.plugin;
|
||||||
|
|
||||||
public class PixelBlockWorld {
|
public class PixelBlockWorld {
|
||||||
private final PixelBlock parentPixelBlock;
|
private final PixelBlock parentPixelBlock;
|
||||||
private final World world;
|
private final World world;
|
||||||
|
|
||||||
int worldGrassBorderWidth = 10;
|
int worldGrassBorderWidth = 10;
|
||||||
int pixelsPerBlock = PixelBlocksPlugin.configuration.pixelsPerBlock();
|
int pixelsPerBlock = Main.configuration.pixelsPerBlock();
|
||||||
|
|
||||||
public static boolean isPixelWorld(@NotNull World world) {
|
public static boolean isPixelWorld(@NotNull World world) {
|
||||||
return world.getName().startsWith(plugin.getDataFolder().getPath());
|
return world.getName().startsWith(plugin.getDataFolder().getPath());
|
||||||
@ -49,7 +49,7 @@ public class PixelBlockWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull String getWorldPathName() {
|
public @NotNull String getWorldPathName() {
|
||||||
return PixelBlocksPlugin.plugin.getDataFolder().getPath() + File.separator + "worlds" + File.separator + this.parentPixelBlock.blockUUID;
|
return Main.plugin.getDataFolder().getPath() + File.separator + "worlds" + File.separator + this.parentPixelBlock.blockUUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Location getSpawnLocation() {
|
public @NotNull Location getSpawnLocation() {
|
||||||
@ -114,7 +114,7 @@ public class PixelBlockWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setBuildingPlatform() {
|
private void setBuildingPlatform() {
|
||||||
Bukkit.getScheduler().runTask(PixelBlocksPlugin.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);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: PixelBlocks
|
name: PixelBlocks
|
||||||
version: '${version}'
|
version: '${version}'
|
||||||
main: eu.mhsl.minecraft.pixelblocks.PixelBlocksPlugin
|
main: eu.mhsl.minecraft.pixelblocks.Main
|
||||||
api-version: '1.21'
|
api-version: '1.21'
|
||||||
commands:
|
commands:
|
||||||
createpixelblock:
|
createpixelblock:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user