3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-16 13:00:06 +01:00

Add ability to modify ThrownPotion properties. Adds BUKKIT-3197

Dieser Commit ist enthalten in:
Olof Larsson 2012-12-17 09:45:30 +01:00 committet von GJ
Ursprung 2c5b2a8f6f
Commit abee107830
2 geänderte Dateien mit 24 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -12,7 +12,7 @@ import org.bukkit.entity.LivingEntity;
public class EntityPotion extends EntityProjectile { public class EntityPotion extends EntityProjectile {
private ItemStack c; public ItemStack c; // CraftBukkit private --> public
public EntityPotion(World world) { public EntityPotion(World world) {
super(world); super(world);

Datei anzeigen

@ -4,26 +4,42 @@ import java.util.Collection;
import net.minecraft.server.EntityPotion; import net.minecraft.server.EntityPotion;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.ThrownPotion; import org.bukkit.entity.ThrownPotion;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.Potion; import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
public class CraftThrownPotion extends CraftProjectile implements ThrownPotion { public class CraftThrownPotion extends CraftProjectile implements ThrownPotion {
private Collection<PotionEffect> effects = null;
public CraftThrownPotion(CraftServer server, EntityPotion entity) { public CraftThrownPotion(CraftServer server, EntityPotion entity) {
super(server, entity); super(server, entity);
} }
// TODO: This one does not handle custom NBT potion effects does it?
// In that case this method could be said to be misleading or incorrect
public Collection<PotionEffect> getEffects() { public Collection<PotionEffect> getEffects() {
if (effects == null) { return Potion.getBrewer().getEffectsFromDamage(getHandle().getPotionValue());
effects = Potion.getBrewer().getEffectsFromDamage(getHandle().getPotionValue());
} }
return effects; public ItemStack getItem() {
// We run this method once since it will set the item stack if there is none.
getHandle().getPotionValue();
return CraftItemStack.asBukkitCopy(getHandle().c);
}
public void setItem(ItemStack item) {
// The ItemStack must not be null.
Validate.notNull(item, "ItemStack cannot be null.");
// The ItemStack must be a potion.
Validate.isTrue(item.getType() == Material.POTION, "ItemStack must be a potion. This item stack was " + item.getType() + ".");
getHandle().c = CraftItemStack.asNMSCopy(item);
} }
@Override @Override