Switch to using fake blocks, no more world pollution

This commit is contained in:
Matthew Miller 2018-08-18 15:22:49 +10:00
parent cf10f8ff8a
commit 7f419618cc
8 changed files with 62 additions and 14 deletions

View File

@ -22,6 +22,7 @@ package com.sk89q.worldedit.bukkit;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity;
@ -31,6 +32,7 @@ import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import org.bukkit.Bukkit;
@ -239,4 +241,20 @@ public class BukkitPlayer extends AbstractPlayerActor {
}
@Override
public void sendFakeBlock(Vector pos, BlockStateHolder block) {
System.out.println("Setting " + (block == null ? "reset" : block.getAsString()) + " as " + pos.toString());
Location loc = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ());
if (block == null) {
player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData());
} else {
player.sendBlockChange(loc, BukkitAdapter.adapt(block));
if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
adapter.sendFakeNBT(player, pos, ((BaseBlock) block).getNbtData());
}
}
}
}
}

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.bukkit.adapter;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.registry.state.Property;
@ -27,6 +29,7 @@ import com.sk89q.worldedit.world.block.BlockType;
import org.bukkit.Location;
import org.bukkit.block.Biome;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.Map;
@ -101,4 +104,13 @@ public interface BukkitImplAdapter {
* @return The properties map
*/
Map<String, ? extends Property> getProperties(BlockType blockType);
/**
* Send the given NBT data to the player.
*
* @param player The player
* @param pos The position
* @param nbtData The NBT Data
*/
void sendFakeNBT(Player player, Vector pos, CompoundTag nbtData);
}

View File

@ -48,7 +48,6 @@ import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.snapshot.Snapshot;
@ -637,12 +636,7 @@ public class LocalSession {
// Remove the old block.
if (cuiTemporaryBlock != null) {
// TODO Tell server to reset fake block.
try {
createEditSession(player).setBlock(cuiTemporaryBlock, BlockTypes.AIR.getDefaultState());
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
}
player.sendFakeBlock(cuiTemporaryBlock, null);
cuiTemporaryBlock = null;
}
@ -656,12 +650,7 @@ public class LocalSession {
((IntTag) tags.get("z")).getValue()
);
// TODO Send temporary block at that pos to the player.
try {
createEditSession(player).setBlock(cuiTemporaryBlock, block);
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
}
player.sendFakeBlock(cuiTemporaryBlock, block);
}
}

View File

@ -29,8 +29,11 @@ import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.gamemode.GameMode;
import javax.annotation.Nullable;
/**
* Represents a player
*/
@ -262,4 +265,15 @@ public interface Player extends Entity, Actor {
*/
void setPosition(Vector pos);
/**
* Sends a fake block to the client.
*
* <p>
* This block isn't real.
* </p>
*
* @param pos The position of the block
* @param block The block to send, null to reset
*/
void sendFakeBlock(Vector pos, @Nullable BlockStateHolder block);
}

View File

@ -497,4 +497,8 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
return false;
}
@Override
public void sendFakeBlock(Vector pos, BlockStateHolder block) {
}
}

View File

@ -31,6 +31,7 @@ import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.gamemode.GameMode;
import java.util.UUID;
@ -155,4 +156,9 @@ class PlayerProxy extends AbstractPlayerActor {
public void setGameMode(GameMode gameMode) {
basePlayer.setGameMode(gameMode);
}
@Override
public void sendFakeBlock(Vector pos, BlockStateHolder block) {
basePlayer.sendFakeBlock(pos, block);
}
}

View File

@ -127,7 +127,12 @@ public class ServerCUIHandler {
posY -= y;
posZ -= z;
structureTag.put("name", new StringTag(player.getUniqueId().toString()));
// if (Math.abs(posX) > 32 || Math.abs(posY) > 32 || Math.abs(posZ) > 32) {
// // Structure blocks have a limit
// return null;
// }
structureTag.put("name", new StringTag("worldedit:" + player.getName()));
structureTag.put("author", new StringTag(player.getName()));
structureTag.put("metadata", new StringTag(""));
structureTag.put("x", new IntTag(x));