Fix some api compatibility issues

This commit is contained in:
Jesse Boyd 2018-08-14 17:18:49 +10:00
parent 22511b2e19
commit 55d34343dd
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
10 changed files with 134 additions and 47 deletions

View File

@ -77,7 +77,6 @@ subprojects {
maven {url "https://mvnrepository.com/artifact/"} maven {url "https://mvnrepository.com/artifact/"}
maven {url "http://repo.dmulloy2.net/content/groups/public/"} maven {url "http://repo.dmulloy2.net/content/groups/public/"}
maven {url "https://repo.destroystokyo.com/repository/maven-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://ci.athion.net/job/PlotSquared/ws/mvn/"}
maven {url "http://empcraft.com/maven2"} maven {url "http://empcraft.com/maven2"}
maven {url "https://hub.spigotmc.org/nexus/content/groups/public/"} maven {url "https://hub.spigotmc.org/nexus/content/groups/public/"}
@ -86,6 +85,7 @@ subprojects {
maven {url "http://repo.spongepowered.org/maven"} maven {url "http://repo.spongepowered.org/maven"}
maven {url "https://repo.inventivetalent.org/content/groups/public/"} maven {url "https://repo.inventivetalent.org/content/groups/public/"}
maven {url "http://dl.bintray.com/tastybento/maven-repo"} 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) { task javadocJar(type: Jar, dependsOn: javadoc) {

View File

@ -10,7 +10,7 @@ dependencies {
compile project(':worldedit-core') compile project(':worldedit-core')
compile 'com.sk89q:dummypermscompat:1.8' compile 'com.sk89q:dummypermscompat:1.8'
compile 'com.destroystokyo.paper:paper-api:1.13-R0.1-SNAPSHOT' 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' testCompile 'org.mockito:mockito-core:1.9.0-rc1'
compile 'net.milkbowl.vault:VaultAPI:1.5.6' compile 'net.milkbowl.vault:VaultAPI:1.5.6'
compile 'com.massivecraft:factions:2.8.0' compile 'com.massivecraft:factions:2.8.0'

View File

@ -1,5 +1,6 @@
package com.sk89q.worldedit.bukkit; package com.sk89q.worldedit.bukkit;
import com.bekvon.bukkit.residence.commands.material;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -25,11 +26,14 @@ public class CachedBukkitAdapter {
blockTypes = new BlockTypes[materials.length]; blockTypes = new BlockTypes[materials.length];
for (int i = 0; i < materials.length; i++) { for (int i = 0; i < materials.length; i++) {
Material material = materials[i]; Material material = materials[i];
if (material.isBlock() && !material.isLegacy()) { if (material.isLegacy()) continue;
NamespacedKey key = material.getKey(); NamespacedKey key = material.getKey();
blockTypes[i] = BlockTypes.get(key.getNamespace() + ":" + key.getKey()); String id = key.getNamespace() + ":" + key.getKey();
} else if (material.isItem() && !material.isLegacy()) { if (material.isBlock()) {
itemTypes[i] = ItemTypes.get(material.getKey().toString()); blockTypes[i] = BlockTypes.get(id);
}
if (material.isItem()) {
itemTypes[i] = ItemTypes.get(id);
} }
} }
} }

View File

@ -23,6 +23,7 @@ import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.block.*; import com.sk89q.worldedit.world.block.*;
import com.sk89q.worldedit.world.entity.EntityTypes; import com.sk89q.worldedit.world.entity.EntityTypes;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
import net.jpountz.lz4.LZ4BlockInputStream; import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream; import net.jpountz.lz4.LZ4BlockOutputStream;
@ -148,48 +149,18 @@ public class SchematicStreamer extends NBTStreamer {
if (fc == null) { if (fc == null) {
setupClipboard(0); setupClipboard(0);
} }
String id = convertEntityId(compound.getString("id")); String id = compound.getString("id");
if (id.isEmpty()) { if (id.isEmpty()) {
return; return;
} }
ListTag positionTag = compound.getListTag("Pos"); ListTag positionTag = compound.getListTag("Pos");
ListTag directionTag = compound.getListTag("Rotation"); 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); 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 @Override
public void readFully() throws IOException { public void readFully() throws IOException {
super.readFully(); super.readFully();

View File

@ -22,7 +22,7 @@ package com.sk89q.worldedit;
/** /**
* Parent for all WorldEdit exceptions. * Parent for all WorldEdit exceptions.
*/ */
public abstract class WorldEditException extends Exception { public abstract class WorldEditException extends RuntimeException {
/** /**
* Create a new exception. * Create a new exception.

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.extension.factory; package com.sk89q.worldedit.extension.factory;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.extension.input.InputParseException; 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.extension.platform.Capability;
import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
public class DefaultItemParser extends InputParser<BaseItem> { public class DefaultItemParser extends InputParser<BaseItem> {
@ -44,8 +46,17 @@ public class DefaultItemParser extends InputParser<BaseItem> {
ItemType type; ItemType type;
if (split.length == 1) { if (split.length == 1) {
type = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(split[0])); 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])); 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); item = new BaseItem(type);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {

View File

@ -150,8 +150,15 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
*/ */
BlockMaterial getMaterial(); BlockMaterial getMaterial();
/**
* Gets the legacy ID. Needed for legacy reasons.
*
* DO NOT USE THIS.
*
* @return legacy id or 0, if unknown
*/
default int getLegacyCombinedId() { default int getLegacyCombinedId() {
Integer combinedId = LegacyMapper.getInstance().getLegacyFromBlock(this); Integer combinedId = LegacyMapper.getInstance().getLegacyCombined(this);
return combinedId == null ? 0 : combinedId; return combinedId == null ? 0 : combinedId;
} }
@ -169,4 +176,14 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
@Override @Override
int hashCode(); int hashCode();
@Deprecated
default int getLegacyId() {
Integer id = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState());
if (id != null) {
return id >> 4;
} else {
return 0;
}
}
} }

View File

@ -122,12 +122,81 @@ public class EntityTypes {
private 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) { private static EntityType register(final String id) {
return register(new EntityType(id)); return register(new EntityType(id));
} }
public static EntityType register(final EntityType entityType) { 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) { public static @Nullable EntityType get(final String id) {

View File

@ -957,7 +957,8 @@ public enum ItemTypes implements ItemType {
private static ItemTypes register(final String id) { private static ItemTypes register(final String id) {
// Get the enum name (remove namespace if minecraft:) // 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(); String enumName = (typeName.startsWith("minecraft:") ? typeName.substring(10) : typeName).toUpperCase();
// Check existing // Check existing
ItemTypes existing = valueOf(enumName.toUpperCase()); ItemTypes existing = valueOf(enumName.toUpperCase());
@ -967,6 +968,7 @@ public enum ItemTypes implements ItemType {
// Create it // Create it
existing = ReflectionUtils.addEnum(ItemTypes.class, enumName, new Class[]{String.class}, new Object[]{id}); 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); $REGISTRY.put(typeName, existing);
return existing; return existing;
} }

View File

@ -26,6 +26,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -150,10 +151,16 @@ public class LegacyMapper {
} }
@Nullable @Nullable
public Integer getLegacyFromItem(ItemType itemType) { public Integer getLegacyCombined(ItemType itemType) {
return itemMap.inverse().get(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 @Nullable
public BlockState getBlockFromLegacy(int legacyId) { public BlockState getBlockFromLegacy(int legacyId) {
return getBlock(legacyId << 4); return getBlock(legacyId << 4);
@ -190,17 +197,23 @@ public class LegacyMapper {
} }
@Nullable @Nullable
public Integer getLegacyFromBlock(BlockState blockState) { public Integer getLegacyCombined(BlockState blockState) {
Integer result = blockStateToLegacyId4Data.get(blockState.getInternalId()); Integer result = blockStateToLegacyId4Data.get(blockState.getInternalId());
if (result == null) result = blockStateToLegacyId4Data.get(blockState.getInternalBlockTypeId()); if (result == null) result = blockStateToLegacyId4Data.get(blockState.getInternalBlockTypeId());
return result; return result;
} }
@Nullable @Nullable
public Integer getLegacyFromBlock(BlockType type) { public Integer getLegacyCombined(BlockType type) {
return blockStateToLegacyId4Data.get(type.getDefaultState()); 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() { public static LegacyMapper getInstance() {
if (INSTANCE == null) { if (INSTANCE == null) {
INSTANCE = new LegacyMapper(); INSTANCE = new LegacyMapper();