Get it to a point where it works minimally on 1.13 Spigot.

This commit is contained in:
Matthew Miller 2018-07-16 00:21:32 +10:00
parent 59ca29577c
commit 3e1d438565
16 changed files with 2751 additions and 70 deletions

View File

@ -10,7 +10,7 @@ repositories {
dependencies {
compile project(':worldedit-core')
compile 'com.sk89q:dummypermscompat:1.8'
compile 'org.bukkit:bukkit:1.13-pre5-R0.1-SNAPSHOT' // zzz
compile 'org.bukkit:bukkit:1.13-pre7-R0.1-SNAPSHOT' // zzz
// compile 'org.bukkit:bukkit:1.9.4-R0.1-SNAPSHOT' // zzz
testCompile 'org.mockito:mockito-core:1.9.0-rc1'
}
@ -36,7 +36,7 @@ jar {
shadowJar {
dependencies {
include(dependency(':worldedit-core'))
include(dependency('com.google.code.gson:gson:2.2.4'))
include(dependency('com.google.code.gson:gson'))
}
relocate('com.google.gson', 'com.sk89q.worldedit.internal.gson')

View File

@ -0,0 +1,68 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.blocks.BlockMaterial;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
import com.sk89q.worldedit.world.registry.PassthroughBlockMaterial;
import org.bukkit.Material;
import java.util.EnumMap;
import java.util.Map;
import javax.annotation.Nullable;
public class BukkitBlockRegistry extends BundledBlockRegistry {
private Map<Material, BukkitBlockMaterial> materialMap = new EnumMap<>(Material.class);
@Nullable
@Override
public BlockMaterial getMaterial(String id) {
return materialMap.computeIfAbsent(BukkitUtil.toMaterial(BlockTypes.get(id)),
material -> new BukkitBlockMaterial(BukkitBlockRegistry.super.getMaterial(id), material));
}
public static class BukkitBlockMaterial extends PassthroughBlockMaterial {
private final Material material;
public BukkitBlockMaterial(@Nullable BlockMaterial material, Material bukkitMaterial) {
super(material);
this.material = bukkitMaterial;
}
@Override
public boolean isSolid() {
return material.isSolid();
}
@Override
public boolean isBurnable() {
return material.isBurnable();
}
@Override
public boolean isTranslucent() {
return material.isTransparent();
}
}
}

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import com.sk89q.worldedit.world.registry.BlockRegistry;
import com.sk89q.worldedit.world.registry.BundledRegistries;
/**
@ -28,6 +29,7 @@ import com.sk89q.worldedit.world.registry.BundledRegistries;
class BukkitRegistries extends BundledRegistries {
private static final BukkitRegistries INSTANCE = new BukkitRegistries();
private final BlockRegistry blockRegistry = new BukkitBlockRegistry();
private final BiomeRegistry biomeRegistry = new BukkitBiomeRegistry();
/**
@ -36,6 +38,11 @@ class BukkitRegistries extends BundledRegistries {
BukkitRegistries() {
}
@Override
public BlockRegistry getBlockRegistry() {
return blockRegistry;
}
@Override
public BiomeRegistry getBiomeRegistry() {
return biomeRegistry;

View File

@ -21,14 +21,18 @@ package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -48,6 +52,12 @@ public final class BukkitUtil {
private BukkitUtil() {
}
private static final ParserContext TO_BLOCK_CONTEXT = new ParserContext();
static {
TO_BLOCK_CONTEXT.setRestricted(false);
}
public static com.sk89q.worldedit.world.World getWorld(World w) {
return new BukkitWorld(w);
}
@ -130,12 +140,31 @@ public final class BukkitUtil {
return ((BukkitWorld) world).getWorld();
}
public static Material toMaterial(ItemType itemType) {
if (!itemType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Bukkit only supports Minecraft items");
}
return Material.getMaterial(itemType.getId().replace("minecraft:", "").toUpperCase());
}
public static Material toMaterial(BlockType blockType) {
if (!blockType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Bukkit only supports Minecraft blocks");
}
return Material.getMaterial(blockType.getId().replace("minecraft:", "").toUpperCase());
}
public static BlockState toBlock(BlockData blockData) {
return null; // TODO BLOCKING
try {
return WorldEdit.getInstance().getBlockFactory().parseFromInput(blockData.getAsString(), TO_BLOCK_CONTEXT).toImmutableState();
} catch (InputParseException e) {
e.printStackTrace();
}
return null;
}
public static BlockData toBlock(BlockStateHolder block) {
return Bukkit.createBlockData(block.toString()); // TODO BLOCKING
return Bukkit.createBlockData(block.getAsString());
}
public static BlockState toBlock(ItemStack itemStack) throws WorldEditException {
@ -151,7 +180,6 @@ public final class BukkitUtil {
}
public static ItemStack toItemStack(BaseItemStack item) {
BlockData blockData = Bukkit.createBlockData(item.getType().getId());
return new ItemStack(blockData.getMaterial(), item.getAmount());
return new ItemStack(toMaterial(item.getType()), item.getAmount());
}
}

View File

@ -284,10 +284,8 @@ public class BukkitWorld extends AbstractWorld {
public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt) {
World world = getWorld();
TreeType bukkitType = toBukkitTreeType(type);
return type != null && world.generateTree(BukkitUtil.toLocation(world, pt), bukkitType);
// return type != null && world.generateTree(BukkitUtil.toLocation(world, pt), bukkitType,
// new EditSessionBlockChangeDelegate(editSession));
// TODO
return type != null && world.generateTree(BukkitUtil.toLocation(world, pt), bukkitType,
new EditSessionBlockChangeDelegate(editSession));
}
@Override
@ -368,7 +366,7 @@ public class BukkitWorld extends AbstractWorld {
return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight);
} else {
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
bukkitBlock.setData(BukkitUtil.toBlock(block), notifyAndLight);
bukkitBlock.setBlockData(BukkitUtil.toBlock(block), notifyAndLight);
return true;
}
}

View File

@ -20,11 +20,16 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.BlockChangeDelegate;
import org.bukkit.block.data.BlockData;
/**
* Proxy class to catch calls to set blocks.
*/
public class EditSessionBlockChangeDelegate {//implements BlockChangeDelegate {
public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
private EditSession editSession;
@ -32,50 +37,29 @@ public class EditSessionBlockChangeDelegate {//implements BlockChangeDelegate {
this.editSession = editSession;
}
// TODO This needs a fix in Spigot itself
@Override
public boolean setBlockData(int x, int y, int z, BlockData blockData) {
try {
editSession.setBlock(new Vector(x, y, z), BukkitUtil.toBlock(blockData));
} catch (MaxChangedBlocksException e) {
return false;
}
return true;
}
// @Override
// public boolean setRawTypeId(int x, int y, int z, int typeId) {
// try {
// return editSession.setBlock(new Vector(x, y, z), LegacyMapper.getInstance().getBlockFromLegacy(typeId));
// } catch (MaxChangedBlocksException ex) {
// return false;
// }
// }
//
// @Override
// public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) {
// try {
// return editSession.setBlock(new Vector(x, y, z), LegacyMapper.getInstance().getBlockFromLegacy(typeId, data));
// } catch (MaxChangedBlocksException ex) {
// return false;
// }
// }
//
// @Override
// public boolean setTypeId(int x, int y, int z, int typeId) {
// return setRawTypeId(x, y, z, typeId);
// }
//
// @Override
// public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
// return setRawTypeIdAndData(x, y, z, typeId, data);
// }
//
// @Override
// public int getTypeId(int x, int y, int z) {
// int[] datas = LegacyMapper.getInstance().getLegacyFromBlock(editSession.getBlock(new Vector(x, y, z)));
// return datas[0];
// }
//
// @Override
// public int getHeight() {
// return editSession.getWorld().getMaxY() + 1;
// }
//
// @Override
// public boolean isEmpty(int x, int y, int z) {
// return editSession.getBlock(new Vector(x, y, z)).getBlockType() == BlockTypes.AIR;
// }
@Override
public BlockData getBlockData(int x, int y, int z) {
return BukkitUtil.toBlock(editSession.getBlock(new Vector(x, y, z)));
}
@Override
public int getHeight() {
return editSession.getWorld().getMaxY() + 1;
}
@Override
public boolean isEmpty(int x, int y, int z) {
return editSession.getBlock(new Vector(x, y, z)).getBlockType() == BlockTypes.AIR;
}
}

View File

@ -2,6 +2,7 @@ name: WorldEdit
main: com.sk89q.worldedit.bukkit.WorldEditPlugin
version: "${internalVersion}"
softdepend: [Spout] #hack to fix trove errors
api-version: 1.13
# Permissions aren't here. Read http://wiki.sk89q.com/wiki/WEPIF/DinnerPerms
# for how WorldEdit permissions actually work.

View File

@ -22,6 +22,7 @@ package com.sk89q.worldedit;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.util.logging.LogFormat;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.snapshot.SnapshotRepository;
import java.io.File;
@ -148,4 +149,23 @@ public abstract class LocalConfiguration {
return new File(".");
}
public String convertLegacyItem(String legacy) {
String item = legacy;
try {
String[] splitter = item.split(":", 2);
int id = 0;
byte data = 0;
if (splitter.length == 1) {
id = Integer.parseInt(item);
} else {
id = Integer.parseInt(splitter[0]);
data = Byte.parseByte(splitter[1]);
}
item = LegacyMapper.getInstance().getItemFromLegacy(id, data).getId();
} catch (Throwable e) {
}
return item;
}
}

View File

@ -56,11 +56,7 @@ public class YAMLConfiguration extends LocalConfiguration {
}
profile = config.getBoolean("debug", profile);
wandItem = config.getString("wand-item", wandItem);
try {
wandItem = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(wandItem)).getId();
} catch (Throwable e) {
}
wandItem = convertLegacyItem(config.getString("wand-item", wandItem));
defaultChangeLimit = Math.max(-1, config.getInt(
"limits.max-blocks-changed.default", defaultChangeLimit));
@ -104,11 +100,7 @@ public class YAMLConfiguration extends LocalConfiguration {
useInventoryCreativeOverride = config.getBoolean("use-inventory.creative-mode-overrides",
useInventoryCreativeOverride);
navigationWand = config.getString("navigation-wand.item", navigationWand);
try {
navigationWand = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(navigationWand)).getId();
} catch (Throwable e) {
}
navigationWand = convertLegacyItem(config.getString("navigation-wand.item", navigationWand));
navigationWandMaxDistance = config.getInt("navigation-wand.max-distance", navigationWandMaxDistance);
navigationUseGlass = config.getBoolean("navigation.use-glass", navigationUseGlass);

View File

@ -22,6 +22,7 @@ package com.sk89q.worldedit.world.block;
import com.sk89q.worldedit.registry.state.Property;
import java.util.Map;
import java.util.stream.Collectors;
public interface BlockStateHolder<T extends BlockStateHolder> {
@ -70,4 +71,13 @@ public interface BlockStateHolder<T extends BlockStateHolder> {
* @return A BlockState
*/
BlockState toImmutableState();
default String getAsString() {
if (getStates().isEmpty()) {
return this.getBlockType().getId();
} else {
String properties = getStates().entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.joining(","));
return this.getBlockType().getId() + "[" + properties + "]";
}
}
}

View File

@ -63,7 +63,7 @@ public class BundledBlockData {
private BundledBlockData() {
try {
loadFromResource();
} catch (IOException e) {
} catch (Throwable e) {
log.log(Level.WARNING, "Failed to load the built-in block registry", e);
}
}

View File

@ -44,7 +44,7 @@ public class BundledBlockRegistry implements BlockRegistry {
@Nullable
@Override
public BlockMaterial getMaterial(String id) {
return BundledBlockData.getInstance().getMaterialById(id);
return new PassthroughBlockMaterial(BundledBlockData.getInstance().getMaterialById(id));
}
@Nullable

View File

@ -61,7 +61,7 @@ public class BundledItemData {
private BundledItemData() {
try {
loadFromResource();
} catch (IOException e) {
} catch (Throwable e) {
log.log(Level.WARNING, "Failed to load the built-in item registry", e);
}
}

View File

@ -57,7 +57,7 @@ public class LegacyMapper {
private LegacyMapper() {
try {
loadFromResource();
} catch (IOException e) {
} catch (Throwable e) {
log.log(Level.WARNING, "Failed to load the built-in legacy id registry", e);
}
}

View File

@ -0,0 +1,249 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BlockMaterial;
import javax.annotation.Nullable;
public class PassthroughBlockMaterial implements BlockMaterial {
@Nullable private final BlockMaterial blockMaterial;
public PassthroughBlockMaterial(@Nullable BlockMaterial material) {
this.blockMaterial = material;
}
@Override
public boolean isRenderedAsNormalBlock() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isRenderedAsNormalBlock();
}
}
@Override
public boolean isFullCube() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isFullCube();
}
}
@Override
public boolean isOpaque() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isOpaque();
}
}
@Override
public boolean isPowerSource() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isPowerSource();
}
}
@Override
public boolean isLiquid() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isLiquid();
}
}
@Override
public boolean isSolid() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isSolid();
}
}
@Override
public float getHardness() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getHardness();
}
}
@Override
public float getResistance() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getResistance();
}
}
@Override
public float getSlipperiness() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getSlipperiness();
}
}
@Override
public boolean isGrassBlocking() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isGrassBlocking();
}
}
@Override
public float getAmbientOcclusionLightValue() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getAmbientOcclusionLightValue();
}
}
@Override
public int getLightOpacity() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getLightOpacity();
}
}
@Override
public int getLightValue() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getLightValue();
}
}
@Override
public boolean isFragileWhenPushed() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isFragileWhenPushed();
}
}
@Override
public boolean isUnpushable() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isUnpushable();
}
}
@Override
public boolean isAdventureModeExempt() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isAdventureModeExempt();
}
}
@Override
public boolean isTicksRandomly() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isTicksRandomly();
}
}
@Override
public boolean isUsingNeighborLight() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isUsingNeighborLight();
}
}
@Override
public boolean isMovementBlocker() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isMovementBlocker();
}
}
@Override
public boolean isBurnable() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isOpaque();
}
}
@Override
public boolean isToolRequired() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isToolRequired();
}
}
@Override
public boolean isReplacedDuringPlacement() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isReplacedDuringPlacement();
}
}
@Override
public boolean isTranslucent() {
if (blockMaterial == null) {
return !isOpaque();
} else {
return blockMaterial.isTranslucent();
}
}
@Override
public boolean hasContainer() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.hasContainer();
}
}
}

File diff suppressed because it is too large Load Diff