Skip to content

Commit

Permalink
Detect more changes to Cauldrons
Browse files Browse the repository at this point in the history
  • Loading branch information
Sn0wStorm committed Jun 28, 2016
1 parent 49efcea commit e69deab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/com/dre/brewery/P.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public void onEnable() {
p.getServer().getPluginManager().registerEvents(entityListener, p);
p.getServer().getPluginManager().registerEvents(inventoryListener, p);
p.getServer().getPluginManager().registerEvents(worldListener, p);
if (use1_9) {
p.getServer().getPluginManager().registerEvents(new CauldronListener(), p);
}

// Heartbeat
p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 650, 1200);
Expand Down
22 changes: 22 additions & 0 deletions src/com/dre/brewery/listeners/CauldronListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.dre.brewery.listeners;

import com.dre.brewery.BCauldron;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.CauldronLevelChangeEvent;

public class CauldronListener implements Listener {

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCauldronChange(CauldronLevelChangeEvent event) {
if (event.getNewLevel() == 0 && event.getOldLevel() != 0) {
if (event.getReason() == CauldronLevelChangeEvent.ChangeReason.BOTTLE_FILL) {
return;
}
BCauldron.remove(event.getBlock());
} else if (event.getNewLevel() == 3 && event.getOldLevel() != 3) {
BCauldron.remove(event.getBlock());
}
}
}
20 changes: 7 additions & 13 deletions src/com/dre/brewery/listeners/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
Material materialInHand = event.getMaterial();
ItemStack item = event.getItem();

if (materialInHand == null) {
if (materialInHand == null || materialInHand == Material.BUCKET) {
return;

} else if (materialInHand == Material.WATCH) {
Expand All @@ -64,22 +64,16 @@ public void onPlayerInteract(PlayerInteractEvent event) {
}
return;

// reset cauldron when refilling to prevent
// unlimited source of potions
// reset cauldron when refilling to prevent unlimited source of potions
} else if (materialInHand == Material.WATER_BUCKET) {
if (BCauldron.getFillLevel(clickedBlock) != 0 && BCauldron.getFillLevel(clickedBlock) < 2) {
// will only remove when existing
BCauldron.remove(clickedBlock);
if (!P.use1_9) {
if (BCauldron.getFillLevel(clickedBlock) != 0 && BCauldron.getFillLevel(clickedBlock) < 2) {
// will only remove when existing
BCauldron.remove(clickedBlock);
}
}
return;

// Its possible to empty a Cauldron with a Bucket in 1.9
} else if (P.use1_9 && materialInHand == Material.BUCKET) {
if (BCauldron.getFillLevel(clickedBlock) == 2) {
// will only remove when existing
BCauldron.remove(clickedBlock);
}
return;
}

// Check if fire alive below cauldron when adding ingredients
Expand Down

0 comments on commit e69deab

Please sign in to comment.