diff --git a/build.gradle b/build.gradle index 7bc57c2dc..0f4236c7a 100644 --- a/build.gradle +++ b/build.gradle @@ -77,7 +77,6 @@ subprojects { maven {url "https://mvnrepository.com/artifact/"} maven {url "http://repo.dmulloy2.net/content/groups/public/"} maven {url "https://repo.destroystokyo.com/repository/maven-public//"} - maven {url "http://ci.emc.gs/nexus/content/groups/aikar/" } maven {url "http://ci.athion.net/job/PlotSquared/ws/mvn/"} maven {url "http://empcraft.com/maven2"} maven {url "https://hub.spigotmc.org/nexus/content/groups/public/"} @@ -86,6 +85,7 @@ subprojects { maven {url "http://repo.spongepowered.org/maven"} maven {url "https://repo.inventivetalent.org/content/groups/public/"} maven {url "http://dl.bintray.com/tastybento/maven-repo"} + maven {url "http://ci.emc.gs/nexus/content/groups/aikar/" } } task javadocJar(type: Jar, dependsOn: javadoc) { diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle index 060c1039e..f67401fda 100644 --- a/worldedit-bukkit/build.gradle +++ b/worldedit-bukkit/build.gradle @@ -10,7 +10,7 @@ dependencies { compile project(':worldedit-core') compile 'com.sk89q:dummypermscompat:1.8' compile 'com.destroystokyo.paper:paper-api:1.13-R0.1-SNAPSHOT' - compile "org.bukkit:craftbukkit:1.13-R0.1-SNAPSHOT" + compile "org.spigotmc:spigot:1.13-R0.1-SNAPSHOT" testCompile 'org.mockito:mockito-core:1.9.0-rc1' compile 'net.milkbowl.vault:VaultAPI:1.5.6' compile 'com.massivecraft:factions:2.8.0' diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/CachedBukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/CachedBukkitAdapter.java index d1e7244f3..7257c0ca0 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/CachedBukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/CachedBukkitAdapter.java @@ -1,5 +1,6 @@ package com.sk89q.worldedit.bukkit; +import com.bekvon.bukkit.residence.commands.material; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -25,11 +26,14 @@ public class CachedBukkitAdapter { blockTypes = new BlockTypes[materials.length]; for (int i = 0; i < materials.length; i++) { Material material = materials[i]; - if (material.isBlock() && !material.isLegacy()) { - NamespacedKey key = material.getKey(); - blockTypes[i] = BlockTypes.get(key.getNamespace() + ":" + key.getKey()); - } else if (material.isItem() && !material.isLegacy()) { - itemTypes[i] = ItemTypes.get(material.getKey().toString()); + if (material.isLegacy()) continue; + NamespacedKey key = material.getKey(); + String id = key.getNamespace() + ":" + key.getKey(); + if (material.isBlock()) { + blockTypes[i] = BlockTypes.get(id); + } + if (material.isItem()) { + itemTypes[i] = ItemTypes.get(id); } } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java index 7e1948d20..fd701868f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.world.block.*; import com.sk89q.worldedit.world.entity.EntityTypes; +import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; import net.jpountz.lz4.LZ4BlockInputStream; import net.jpountz.lz4.LZ4BlockOutputStream; @@ -148,48 +149,18 @@ public class SchematicStreamer extends NBTStreamer { if (fc == null) { setupClipboard(0); } - String id = convertEntityId(compound.getString("id")); + String id = compound.getString("id"); if (id.isEmpty()) { return; } ListTag positionTag = compound.getListTag("Pos"); ListTag directionTag = compound.getListTag("Rotation"); - BaseEntity state = new BaseEntity(EntityTypes.get(id), compound); + BaseEntity state = new BaseEntity(EntityTypes.parse(id), compound); fc.createEntity(clipboard, positionTag.asDouble(0), positionTag.asDouble(1), positionTag.asDouble(2), (float) directionTag.asDouble(0), (float) directionTag.asDouble(1), state); } }); } - private String convertEntityId(String id) { - switch(id) { - case "xp_orb": - return "experience_orb"; - case "xp_bottle": - return "experience_bottle"; - case "eye_of_ender_signal": - return "eye_of_ender"; - case "ender_crystal": - return "end_crystal"; - case "fireworks_rocket": - return "firework_rocket"; - case "commandblock_minecart": - return "command_block_minecart"; - case "snowman": - return "snow_golem"; - case "villager_golem": - return "iron_golem"; - case "evocation_fangs": - return "evoker_fangs"; - case "evocation_illager": - return "evoker"; - case "vindication_illager": - return "vindicator"; - case "illusion_illager": - return "illusioner"; - } - return id; - } - @Override public void readFully() throws IOException { super.readFully(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEditException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEditException.java index 67b926224..4f96d53be 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEditException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEditException.java @@ -22,7 +22,7 @@ package com.sk89q.worldedit; /** * Parent for all WorldEdit exceptions. */ -public abstract class WorldEditException extends Exception { +public abstract class WorldEditException extends RuntimeException { /** * Create a new exception. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultItemParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultItemParser.java index d2319a609..523ea1898 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultItemParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultItemParser.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.extension.factory; +import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.extension.input.InputParseException; @@ -26,6 +27,7 @@ import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.world.item.ItemType; +import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; public class DefaultItemParser extends InputParser { @@ -44,8 +46,17 @@ public class DefaultItemParser extends InputParser { ItemType type; if (split.length == 1) { type = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(split[0])); - } else { + } else if (MathMan.isInteger(split[0])) { type = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(split[0]), Integer.parseInt(split[1])); + } else { + type = ItemTypes.parse(input); + if (type != null) { + Integer legacy = LegacyMapper.getInstance().getLegacyCombined(type); + if (legacy != null) { + ItemTypes newType = LegacyMapper.getInstance().getItemFromLegacy(legacy >> 4, Integer.parseInt(split[1])); + if (newType != null) type = newType; + } + } } item = new BaseItem(type); } catch (NumberFormatException e) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index 811de21b3..7fec8deb8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -150,8 +150,15 @@ public interface BlockType extends FawePattern, Comparable { */ BlockMaterial getMaterial(); + /** + * Gets the legacy ID. Needed for legacy reasons. + * + * DO NOT USE THIS. + * + * @return legacy id or 0, if unknown + */ default int getLegacyCombinedId() { - Integer combinedId = LegacyMapper.getInstance().getLegacyFromBlock(this); + Integer combinedId = LegacyMapper.getInstance().getLegacyCombined(this); return combinedId == null ? 0 : combinedId; } @@ -169,4 +176,14 @@ public interface BlockType extends FawePattern, Comparable { @Override int hashCode(); + + @Deprecated + default int getLegacyId() { + Integer id = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState()); + if (id != null) { + return id >> 4; + } else { + return 0; + } + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityTypes.java index 9c8d44210..d8ac07270 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityTypes.java @@ -122,12 +122,81 @@ public class EntityTypes { private EntityTypes() { } + public static EntityType parse(String id) { + if (id.startsWith("minecraft:")) id = id.substring(10); + switch (id) { + case "FallingSand": return EntityTypes.FALLING_BLOCK; + case "FireworksRocketEntity": return EntityTypes.FIREWORK_ROCKET; + case "LavaSlime": return EntityTypes.MAGMA_CUBE; + case "MinecartChest": return EntityTypes.CHEST_MINECART; + case "MinecartCommandBlock": return EntityTypes.COMMAND_BLOCK_MINECART; + case "MinecartFurnace": return EntityTypes.FURNACE_MINECART; + case "MinecartHopper": return EntityTypes.HOPPER_MINECART; + case "MinecartRideable": return EntityTypes.MINECART; + case "MinecartSpawner": return EntityTypes.SPAWNER_MINECART; + case "MinecartTNT": return EntityTypes.TNT_MINECART; + case "MushroomCow": return EntityTypes.MOOSHROOM; + case "PigZombie": return EntityTypes.ZOMBIE_PIGMAN; + case "PrimedTnt": return EntityTypes.TNT; + case "SnowMan": return EntityTypes.SNOW_GOLEM; + case "ThrownEgg": return EntityTypes.EGG; + case "ThrownEnderpearl": return EntityTypes.ENDER_PEARL; + case "ThrownExpBottle": return EntityTypes.EXPERIENCE_BOTTLE; + case "ThrownPotion": return EntityTypes.POTION; + case "WitherBoss": return EntityTypes.WITHER; + case "XPOrb": return EntityTypes.EXPERIENCE_ORB; + default: + if (Character.isUpperCase(id.charAt(0))) { + StringBuilder result = new StringBuilder(); + for (int i = 0; i < result.length(); i++) { + char c = id.charAt(i); + if (Character.isUpperCase(c)) { + c = Character.toLowerCase(c); + if (i != 0) result.append('_'); + } + result.append(c); + } + return parse(result.toString()); + } + switch (id.toLowerCase()) { + case "xp_orb": + return EntityTypes.EXPERIENCE_ORB; + case "xp_bottle": + return EntityTypes.EXPERIENCE_BOTTLE; + case "eye_of_ender_signal": + return EntityTypes.EYE_OF_ENDER; + case "ender_crystal": + return EntityTypes.END_CRYSTAL; + case "fireworks_rocket": + return EntityTypes.FIREWORK_ROCKET; + case "commandblock_minecart": + return EntityTypes.COMMAND_BLOCK_MINECART; + case "snowman": + return EntityTypes.SNOW_GOLEM; + case "villager_golem": + return EntityTypes.IRON_GOLEM; + case "evocation_fangs": + return EntityTypes.EVOKER_FANGS; + case "evocation_illager": + return EntityTypes.EVOKER; + case "vindication_illager": + return EntityTypes.VINDICATOR; + case "illusion_illager": + return EntityTypes.ILLUSIONER; + default: + return get(id); + } + } + } + private static EntityType register(final String id) { return register(new EntityType(id)); } public static EntityType register(final EntityType entityType) { - return EntityType.REGISTRY.register(entityType.getId(), entityType); + String id = entityType.getId(); + if (id.startsWith("minecraft:")) EntityType.REGISTRY.register(id.substring(10), entityType); + return EntityType.REGISTRY.register(id, entityType); } public static @Nullable EntityType get(final String id) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java index a3bb1ef64..6d507b807 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java @@ -957,7 +957,8 @@ public enum ItemTypes implements ItemType { private static ItemTypes register(final String id) { // Get the enum name (remove namespace if minecraft:) - String typeName = id.substring(0, Math.max(id.indexOf('['), id.length())); + int propStart = id.indexOf('['); + String typeName = id.substring(0, propStart == -1 ? id.length() : propStart); String enumName = (typeName.startsWith("minecraft:") ? typeName.substring(10) : typeName).toUpperCase(); // Check existing ItemTypes existing = valueOf(enumName.toUpperCase()); @@ -967,6 +968,7 @@ public enum ItemTypes implements ItemType { // Create it existing = ReflectionUtils.addEnum(ItemTypes.class, enumName, new Class[]{String.class}, new Object[]{id}); } + if (typeName.startsWith("minecraft:")) $REGISTRY.put(typeName.substring(10), existing); $REGISTRY.put(typeName, existing); return existing; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java index 819678824..fa9f23934 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java @@ -26,6 +26,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -150,10 +151,16 @@ public class LegacyMapper { } @Nullable - public Integer getLegacyFromItem(ItemType itemType) { + public Integer getLegacyCombined(ItemType itemType) { return itemMap.inverse().get(itemType); } + @Nullable + public int[] getLegacyFromItem(ItemType itemType) { + Integer combinedId = getLegacyCombined(itemType); + return combinedId == null ? null : new int[] { combinedId >> 4, combinedId & 0xF }; + } + @Nullable public BlockState getBlockFromLegacy(int legacyId) { return getBlock(legacyId << 4); @@ -190,17 +197,23 @@ public class LegacyMapper { } @Nullable - public Integer getLegacyFromBlock(BlockState blockState) { + public Integer getLegacyCombined(BlockState blockState) { Integer result = blockStateToLegacyId4Data.get(blockState.getInternalId()); if (result == null) result = blockStateToLegacyId4Data.get(blockState.getInternalBlockTypeId()); return result; } @Nullable - public Integer getLegacyFromBlock(BlockType type) { + public Integer getLegacyCombined(BlockType type) { return blockStateToLegacyId4Data.get(type.getDefaultState()); } + @Deprecated + public int[] getLegacyFromBlock(BlockState blockState) { + Integer combinedId = getLegacyCombined(blockState); + return combinedId == null ? null : new int[] { combinedId >> 4, combinedId & 0xF }; + } + public static LegacyMapper getInstance() { if (INSTANCE == null) { INSTANCE = new LegacyMapper();