1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
package org.bukkit.craftbukkit.potion;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import net.minecraft.server.MobEffect;
import net.minecraft.server.MobEffectList;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.bukkit.potion.PotionData;
public class CraftPotionUtil {
private static final BiMap<PotionType, String> regular = ImmutableBiMap.<PotionType, String>builder()
.put(PotionType.UNCRAFTABLE, "empty")
.put(PotionType.WATER, "water")
.put(PotionType.MUNDANE, "mundane")
.put(PotionType.THICK, "thick")
.put(PotionType.AWKWARD, "awkward")
.put(PotionType.NIGHT_VISION, "night_vision")
.put(PotionType.INVISIBILITY, "invisibility")
.put(PotionType.JUMP, "leaping")
.put(PotionType.FIRE_RESISTANCE, "fire_resistance")
.put(PotionType.SPEED, "swiftness")
.put(PotionType.SLOWNESS, "slowness")
.put(PotionType.WATER_BREATHING, "water_breathing")
.put(PotionType.INSTANT_HEAL, "healing")
.put(PotionType.INSTANT_DAMAGE, "harming")
.put(PotionType.POISON, "poison")
.put(PotionType.REGEN, "regeneration")
.put(PotionType.STRENGTH, "strength")
.put(PotionType.WEAKNESS, "weakness")
.put(PotionType.LUCK, "luck")
.build();
private static final BiMap<PotionType, String> upgradeable = ImmutableBiMap.<PotionType, String>builder()
.put(PotionType.JUMP, "strong_leaping")
.put(PotionType.SPEED, "strong_swiftness")
.put(PotionType.INSTANT_HEAL, "strong_healing")
.put(PotionType.INSTANT_DAMAGE, "strong_harming")
.put(PotionType.POISON, "strong_poison")
.put(PotionType.REGEN, "strong_regeneration")
.put(PotionType.STRENGTH, "strong_strength")
.build();
private static final BiMap<PotionType, String> extendable = ImmutableBiMap.<PotionType, String>builder()
.put(PotionType.NIGHT_VISION, "long_night_vision")
.put(PotionType.INVISIBILITY, "long_invisibility")
.put(PotionType.JUMP, "long_leaping")
.put(PotionType.FIRE_RESISTANCE, "long_fire_resistance")
.put(PotionType.SPEED, "long_swiftness")
.put(PotionType.SLOWNESS, "long_slowness")
.put(PotionType.WATER_BREATHING, "long_water_breathing")
.put(PotionType.POISON, "long_poison")
.put(PotionType.REGEN, "long_regeneration")
.put(PotionType.STRENGTH, "long_strength")
.put(PotionType.WEAKNESS, "long_weakness")
.build();
public static String fromBukkit(PotionData data) {
if (data.isUpgraded()) {
return upgradeable.get(data.getType());
}
if (data.isExtended()) {
return extendable.get(data.getType());
}
return regular.get(data.getType());
}
public static PotionData toBukkit(String type) {
if (type.startsWith("minecraft:")) {
type = type.substring(10);
}
PotionType potionType = null;
potionType = extendable.inverse().get(type);
if (potionType != null) {
return new PotionData(potionType, true, false);
}
potionType = upgradeable.inverse().get(type);
if (potionType != null) {
return new PotionData(potionType, false, true);
}
potionType = regular.inverse().get(type);
if (potionType != null) {
return new PotionData(potionType, false, false);
}
return new PotionData(PotionType.UNCRAFTABLE, false, false);
}
public static MobEffect fromBukkit(PotionEffect effect) {
MobEffectList type = MobEffectList.fromId(effect.getType().getId());
return new MobEffect(type, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
}
public static PotionEffect toBukkit(MobEffect effect) {
PotionEffectType type = PotionEffectType.getById(MobEffectList.getId(effect.getMobEffect()));
int amp = effect.getAmplifier();
int duration = effect.getDuration();
boolean ambient = effect.isAmbient();
boolean particles = effect.isShowParticles();
return new PotionEffect(type, duration, amp, ambient, particles);
}
public static boolean equals(MobEffectList mobEffect, PotionEffectType type) {
PotionEffectType typeV = PotionEffectType.getById(MobEffectList.getId(mobEffect));
return typeV.equals(type);
}
}
|