Remove Brew when its Item combusts

This commit is contained in:
Sn0wStorm 2013-08-19 17:41:16 +02:00
parent a166d6cfe6
commit 4496e94e55
2 changed files with 25 additions and 6 deletions

View File

@ -102,7 +102,7 @@ public class Brew {
return 0; return 0;
} }
// remove potion from file (drinking, despawning, should be more!) // remove potion from file (drinking, despawning, combusting, should be more!)
public static void remove(ItemStack item) { public static void remove(ItemStack item) {
potions.remove(getUID(item)); potions.remove(getUID(item));
} }

View File

@ -4,7 +4,9 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemDespawnEvent; import org.bukkit.event.entity.ItemDespawnEvent;
//import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.dre.brewery.Brew; import com.dre.brewery.Brew;
@ -12,12 +14,29 @@ import com.dre.brewery.Brew;
public class EntityListener implements Listener { public class EntityListener implements Listener {
// Remove the Potion from Brew when it despawns // Remove the Potion from Brew when it despawns
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.MONITOR)
public void onItemDespawn(ItemDespawnEvent event) { public void onItemDespawn(ItemDespawnEvent event) {
if (!event.isCancelled()) {
ItemStack item = event.getEntity().getItemStack(); ItemStack item = event.getEntity().getItemStack();
if (item.getTypeId() == 373) { if (item.getTypeId() == 373) {
Brew.remove(item); Brew.remove(item);
} }
} }
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityCombust(EntityCombustEvent event) {
if (!event.isCancelled()) {
Entity entity = event.getEntity();
if (entity.getType().getTypeId() == 1) {
if (entity instanceof Item) {
ItemStack item = ((Item) entity).getItemStack();
if (item.getTypeId() == 373) {
Brew.remove(item);
}
}
}
}
}
} }