Permalink
Browse files

Switch to using fake blocks, no more world pollution

  • Loading branch information...
me4502 committed Aug 18, 2018
1 parent cf10f8f commit 7f419618ccf37b113ad16d08812cf44287c53cfe
@@ -22,6 +22,7 @@
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.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 boolean isPersistent() {
}
@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());
}
}
}
}
}
@@ -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 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 @@
* @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);
}
@@ -48,7 +48,6 @@
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 void updateServerCUI(Actor actor) {
// 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 void updateServerCUI(Actor actor) {
((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);
}
}
@@ -29,8 +29,11 @@
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 @@
*/
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);
}
@@ -497,4 +497,8 @@ public boolean remove() {
return false;
}
@Override
public void sendFakeBlock(Vector pos, BlockStateHolder block) {
}
}
@@ -31,6 +31,7 @@
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 @@ public GameMode getGameMode() {
public void setGameMode(GameMode gameMode) {
basePlayer.setGameMode(gameMode);
}
@Override
public void sendFakeBlock(Vector pos, BlockStateHolder block) {
basePlayer.sendFakeBlock(pos, block);
}
}
@@ -127,7 +127,12 @@ public static BaseBlock createStructureBlock(Player player) {
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));

0 comments on commit 7f41961

Please sign in to comment.