13
0
geforkt von Mirrors/Paper

SPIGOT-2039: Correctly check Potion Tags both with or without the "minecraft:" prefix, and default to UNCRAFTABLE if there is a completely garbage value.

Dieser Commit ist enthalten in:
t00thpick1 2016-03-23 23:42:15 -05:00 committet von md_5
Ursprung 712213dacc
Commit 0ff499cf03

Datei anzeigen

@ -14,47 +14,47 @@ import org.bukkit.potion.PotionData;
public class CraftPotionUtil { public class CraftPotionUtil {
private static final BiMap<PotionType, String> regular = ImmutableBiMap.<PotionType, String>builder() private static final BiMap<PotionType, String> regular = ImmutableBiMap.<PotionType, String>builder()
.put(PotionType.UNCRAFTABLE, "minecraft:empty") .put(PotionType.UNCRAFTABLE, "empty")
.put(PotionType.WATER, "minecraft:water") .put(PotionType.WATER, "water")
.put(PotionType.MUNDANE, "minecraft:mundane") .put(PotionType.MUNDANE, "mundane")
.put(PotionType.THICK, "minecraft:thick") .put(PotionType.THICK, "thick")
.put(PotionType.AWKWARD, "minecraft:awkward") .put(PotionType.AWKWARD, "awkward")
.put(PotionType.NIGHT_VISION, "minecraft:night_vision") .put(PotionType.NIGHT_VISION, "night_vision")
.put(PotionType.INVISIBILITY, "minecraft:invisibility") .put(PotionType.INVISIBILITY, "invisibility")
.put(PotionType.JUMP, "minecraft:leaping") .put(PotionType.JUMP, "leaping")
.put(PotionType.FIRE_RESISTANCE, "minecraft:fire_resistance") .put(PotionType.FIRE_RESISTANCE, "fire_resistance")
.put(PotionType.SPEED, "minecraft:swiftness") .put(PotionType.SPEED, "swiftness")
.put(PotionType.SLOWNESS, "minecraft:slowness") .put(PotionType.SLOWNESS, "slowness")
.put(PotionType.WATER_BREATHING, "minecraft:water_breathing") .put(PotionType.WATER_BREATHING, "water_breathing")
.put(PotionType.INSTANT_HEAL, "minecraft:healing") .put(PotionType.INSTANT_HEAL, "healing")
.put(PotionType.INSTANT_DAMAGE, "minecraft:harming") .put(PotionType.INSTANT_DAMAGE, "harming")
.put(PotionType.POISON, "minecraft:poison") .put(PotionType.POISON, "poison")
.put(PotionType.REGEN, "minecraft:regeneration") .put(PotionType.REGEN, "regeneration")
.put(PotionType.STRENGTH, "minecraft:strength") .put(PotionType.STRENGTH, "strength")
.put(PotionType.WEAKNESS, "minecraft:weakness") .put(PotionType.WEAKNESS, "weakness")
.put(PotionType.LUCK, "minecraft:luck") .put(PotionType.LUCK, "luck")
.build(); .build();
private static final BiMap<PotionType, String> upgradeable = ImmutableBiMap.<PotionType, String>builder() private static final BiMap<PotionType, String> upgradeable = ImmutableBiMap.<PotionType, String>builder()
.put(PotionType.JUMP, "minecraft:strong_leaping") .put(PotionType.JUMP, "strong_leaping")
.put(PotionType.SPEED, "minecraft:strong_swiftness") .put(PotionType.SPEED, "strong_swiftness")
.put(PotionType.INSTANT_HEAL, "minecraft:strong_healing") .put(PotionType.INSTANT_HEAL, "strong_healing")
.put(PotionType.INSTANT_DAMAGE, "minecraft:strong_harming") .put(PotionType.INSTANT_DAMAGE, "strong_harming")
.put(PotionType.POISON, "minecraft:strong_poison") .put(PotionType.POISON, "strong_poison")
.put(PotionType.REGEN, "minecraft:strong_regeneration") .put(PotionType.REGEN, "strong_regeneration")
.put(PotionType.STRENGTH, "minecraft:strong_strength") .put(PotionType.STRENGTH, "strong_strength")
.build(); .build();
private static final BiMap<PotionType, String> extendable = ImmutableBiMap.<PotionType, String>builder() private static final BiMap<PotionType, String> extendable = ImmutableBiMap.<PotionType, String>builder()
.put(PotionType.NIGHT_VISION, "minecraft:long_night_vision") .put(PotionType.NIGHT_VISION, "long_night_vision")
.put(PotionType.INVISIBILITY, "minecraft:long_invisibility") .put(PotionType.INVISIBILITY, "long_invisibility")
.put(PotionType.JUMP, "minecraft:long_leaping") .put(PotionType.JUMP, "long_leaping")
.put(PotionType.FIRE_RESISTANCE, "minecraft:long_fire_resistance") .put(PotionType.FIRE_RESISTANCE, "long_fire_resistance")
.put(PotionType.SPEED, "minecraft:long_swiftness") .put(PotionType.SPEED, "long_swiftness")
.put(PotionType.SLOWNESS, "minecraft:long_slowness") .put(PotionType.SLOWNESS, "long_slowness")
.put(PotionType.WATER_BREATHING, "minecraft:long_water_breathing") .put(PotionType.WATER_BREATHING, "long_water_breathing")
.put(PotionType.POISON, "minecraft:long_poison") .put(PotionType.POISON, "long_poison")
.put(PotionType.REGEN, "minecraft:long_regeneration") .put(PotionType.REGEN, "long_regeneration")
.put(PotionType.STRENGTH, "minecraft:long_strength") .put(PotionType.STRENGTH, "long_strength")
.put(PotionType.WEAKNESS, "minecraft:long_weakness") .put(PotionType.WEAKNESS, "long_weakness")
.build(); .build();
public static String fromBukkit(PotionData data) { public static String fromBukkit(PotionData data) {
@ -68,6 +68,9 @@ public class CraftPotionUtil {
} }
public static PotionData toBukkit(String type) { public static PotionData toBukkit(String type) {
if (type.startsWith("minecraft:")) {
type = type.substring(10);
}
PotionType potionType = null; PotionType potionType = null;
potionType = extendable.inverse().get(type); potionType = extendable.inverse().get(type);
if (potionType != null) { if (potionType != null) {
@ -77,7 +80,11 @@ public class CraftPotionUtil {
if (potionType != null) { if (potionType != null) {
return new PotionData(potionType, false, true); return new PotionData(potionType, false, true);
} }
return new PotionData(regular.inverse().get(type), false, false); potionType = regular.inverse().get(type);
if (potionType != null) {
return new PotionData(potionType, false, true);
}
return new PotionData(PotionType.UNCRAFTABLE, false, false);
} }
public static MobEffect fromBukkit(PotionEffect effect) { public static MobEffect fromBukkit(PotionEffect effect) {