Change version, fix sending world properties, fix deadlock

Dieser Commit ist enthalten in:
Moulberry 2023-09-23 19:05:26 +08:00
Ursprung 1cead96565
Commit 48e10626f8
4 geänderte Dateien mit 81 neuen und 90 gelöschten Zeilen

Datei anzeigen

@ -8,7 +8,7 @@ plugins {
} }
group = "com.moulberry.axiom" group = "com.moulberry.axiom"
version = "1.2.1" version = "1.4.0"
description = "Serverside component for Axiom on Paper" description = "Serverside component for Axiom on Paper"
java { java {

Datei anzeigen

@ -149,22 +149,6 @@ public class AxiomPaper extends JavaPlugin implements Listener {
} }
} }
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
World world = player.getWorld();
ServerWorldPropertiesRegistry properties = getWorldProperties(world);
if (properties == null) {
player.sendPluginMessage(this, "axiom:register_world_properties", new byte[]{0});
} else {
properties.registerFor(this, player);
}
}, 20); // Why does this need to be delayed?
}
@EventHandler @EventHandler
public void onGameRuleChanged(WorldGameRuleChangeEvent event) { public void onGameRuleChanged(WorldGameRuleChangeEvent event) {
if (event.getGameRule() == GameRule.DO_WEATHER_CYCLE) { if (event.getGameRule() == GameRule.DO_WEATHER_CYCLE) {

Datei anzeigen

@ -6,11 +6,13 @@ import com.moulberry.axiom.View;
import com.moulberry.axiom.event.AxiomHandshakeEvent; import com.moulberry.axiom.event.AxiomHandshakeEvent;
import com.moulberry.axiom.persistence.ItemStackDataType; import com.moulberry.axiom.persistence.ItemStackDataType;
import com.moulberry.axiom.persistence.UUIDDataType; import com.moulberry.axiom.persistence.UUIDDataType;
import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -101,6 +103,16 @@ public class HelloPacketListener implements PluginMessageListener {
player.sendPluginMessage(this.plugin, "axiom:set_editor_views", buf.accessByteBufWithCorrectSize()); player.sendPluginMessage(this.plugin, "axiom:set_editor_views", buf.accessByteBufWithCorrectSize());
} }
// Register world properties
World world = player.getWorld();
ServerWorldPropertiesRegistry properties = plugin.getWorldProperties(world);
if (properties == null) {
player.sendPluginMessage(plugin, "axiom:register_world_properties", new byte[]{0});
} else {
properties.registerFor(plugin, player);
}
} }
} }

Datei anzeigen

@ -169,99 +169,94 @@ public class SetBlockBufferPacketListener {
Short2ObjectMap<CompressedBlockEntity> blockEntityChunkMap = buffer.getBlockEntityChunkMap(entry.getLongKey()); Short2ObjectMap<CompressedBlockEntity> blockEntityChunkMap = buffer.getBlockEntityChunkMap(entry.getLongKey());
sectionStates.acquire(); for (int x = 0; x < 16; x++) {
try { for (int y = 0; y < 16; y++) {
for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) {
for (int y = 0; y < 16; y++) { BlockState blockState = container.get(x, y, z);
for (int z = 0; z < 16; z++) { if (blockState == emptyState) continue;
BlockState blockState = container.get(x, y, z);
if (blockState == emptyState) continue;
switch (sectionProtection.getSectionState()) { switch (sectionProtection.getSectionState()) {
case ALLOW -> {} case ALLOW -> {}
case DENY -> blockState = Blocks.REDSTONE_BLOCK.defaultBlockState(); case DENY -> blockState = Blocks.REDSTONE_BLOCK.defaultBlockState();
case CHECK -> blockState = Blocks.DIAMOND_BLOCK.defaultBlockState(); case CHECK -> blockState = Blocks.DIAMOND_BLOCK.defaultBlockState();
} }
int bx = cx*16 + x; int bx = cx*16 + x;
int by = cy*16 + y; int by = cy*16 + y;
int bz = cz*16 + z; int bz = cz*16 + z;
// if (!regionProtection.canBuild(bx, by, bz)) { // if (!regionProtection.canBuild(bx, by, bz)) {
// continue; // continue;
// } // }
blockPos.set(bx, by, bz); blockPos.set(bx, by, bz);
if (hasOnlyAir && blockState.isAir()) { if (hasOnlyAir && blockState.isAir()) {
continue; continue;
} }
BlockState old = section.setBlockState(x, y, z, blockState, false); BlockState old = section.setBlockState(x, y, z, blockState, true);
if (blockState != old) { if (blockState != old) {
Block block = blockState.getBlock(); Block block = blockState.getBlock();
motionBlocking.update(x, by, z, blockState); motionBlocking.update(x, by, z, blockState);
motionBlockingNoLeaves.update(x, by, z, blockState); motionBlockingNoLeaves.update(x, by, z, blockState);
oceanFloor.update(x, by, z, blockState); oceanFloor.update(x, by, z, blockState);
worldSurface.update(x, by, z, blockState); worldSurface.update(x, by, z, blockState);
if (false) { // Full update if (false) { // Full update
old.onRemove(world, blockPos, blockState, false); old.onRemove(world, blockPos, blockState, false);
if (sectionStates.get(x, y, z).is(block)) { if (sectionStates.get(x, y, z).is(block)) {
blockState.onPlace(world, blockPos, old, false); blockState.onPlace(world, blockPos, old, false);
}
} }
}
if (blockState.hasBlockEntity()) { if (blockState.hasBlockEntity()) {
BlockEntity blockEntity = chunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK); BlockEntity blockEntity = chunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);
if (blockEntity == null) { if (blockEntity == null) {
// There isn't a block entity here, create it! // There isn't a block entity here, create it!
blockEntity = ((EntityBlock)block).newBlockEntity(blockPos, blockState); blockEntity = ((EntityBlock)block).newBlockEntity(blockPos, blockState);
if (blockEntity != null) { if (blockEntity != null) {
chunk.addAndRegisterBlockEntity(blockEntity); chunk.addAndRegisterBlockEntity(blockEntity);
}
} else if (blockEntity.getType().isValid(blockState)) {
// Block entity is here and the type is correct
blockEntity.setBlockState(blockState);
try {
this.updateBlockEntityTicker.invoke(chunk, blockEntity);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
} else {
// Block entity type isn't correct, we need to recreate it
chunk.removeBlockEntity(blockPos);
blockEntity = ((EntityBlock)block).newBlockEntity(blockPos, blockState);
if (blockEntity != null) {
chunk.addAndRegisterBlockEntity(blockEntity);
}
} }
if (blockEntity != null && blockEntityChunkMap != null) { } else if (blockEntity.getType().isValid(blockState)) {
int key = x | (y << 4) | (z << 8); // Block entity is here and the type is correct
CompressedBlockEntity savedBlockEntity = blockEntityChunkMap.get((short) key); blockEntity.setBlockState(blockState);
if (savedBlockEntity != null) {
blockEntity.load(savedBlockEntity.decompress()); try {
} this.updateBlockEntityTicker.invoke(chunk, blockEntity);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
} }
} else if (old.hasBlockEntity()) { } else {
// Block entity type isn't correct, we need to recreate it
chunk.removeBlockEntity(blockPos); chunk.removeBlockEntity(blockPos);
}
world.getChunkSource().blockChanged(blockPos); // todo: maybe simply resend chunk instead of this? blockEntity = ((EntityBlock)block).newBlockEntity(blockPos, blockState);
if (blockEntity != null) {
if (LightEngine.hasDifferentLightProperties(chunk, blockPos, old, blockState)) { chunk.addAndRegisterBlockEntity(blockEntity);
lightEngine.checkBlock(blockPos); }
} }
if (blockEntity != null && blockEntityChunkMap != null) {
int key = x | (y << 4) | (z << 8);
CompressedBlockEntity savedBlockEntity = blockEntityChunkMap.get((short) key);
if (savedBlockEntity != null) {
blockEntity.load(savedBlockEntity.decompress());
}
}
} else if (old.hasBlockEntity()) {
chunk.removeBlockEntity(blockPos);
}
world.getChunkSource().blockChanged(blockPos); // todo: maybe simply resend chunk instead of this?
if (LightEngine.hasDifferentLightProperties(chunk, blockPos, old, blockState)) {
lightEngine.checkBlock(blockPos);
} }
} }
} }
} }
} finally {
sectionStates.release();
} }
boolean nowHasOnlyAir = section.hasOnlyAir(); boolean nowHasOnlyAir = section.hasOnlyAir();