Silence messages about touching Redstone ore.

This commit is contained in:
sk89q 2014-08-24 17:56:15 -07:00
parent 7cd4a1d411
commit f6406b668c
3 changed files with 36 additions and 1 deletions

View File

@ -36,4 +36,17 @@ public static <T extends DelegateEvent> T setSilent(T event) {
return event;
}
/**
* Set an event to be silent.
*
* @param event the event
* @param silent true to set silent
* @param <T> the type of event
* @return the same event
*/
public static <T extends DelegateEvent> T setSilent(T event, boolean silent) {
event.setSilent(silent);
return event;
}
}

View File

@ -23,6 +23,7 @@
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.cause.Cause;
import com.sk89q.worldguard.bukkit.event.DelegateEvents;
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent;
@ -206,6 +207,11 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
Entity entity = event.getEntity();
Material to = event.getTo();
// Forget about Redstone ore, especially since we handle it in INTERACT
if (Materials.isRedstoneOre(block.getType()) && Materials.isRedstoneOre(to)) {
return;
}
// Fire two events: one as BREAK and one as PLACE
if (event.getTo() != Material.AIR && event.getBlock().getType() != Material.AIR) {
Events.fireToCancel(event, new BreakBlockEvent(event, create(entity), block));
@ -291,11 +297,17 @@ public void onPlayerInteract(PlayerInteractEvent event) {
@Nullable ItemStack item = player.getItemInHand();
Block clicked = event.getClickedBlock();
Block placed;
boolean silent = false;
Cause cause = create(player);
switch (event.getAction()) {
case PHYSICAL:
interactDebounce.debounce(clicked, event.getPlayer(), event, new UseBlockEvent(event, cause, clicked));
// Forget about Redstone ore
if (Materials.isRedstoneOre(clicked.getType())) {
silent = true;
}
interactDebounce.debounce(clicked, event.getPlayer(), event, DelegateEvents.setSilent(new UseBlockEvent(event, cause, clicked), silent));
break;
case RIGHT_CLICK_BLOCK:

View File

@ -576,6 +576,16 @@ public static boolean isInventoryBlock(Material material) {
|| material == Material.DROPPER;
}
/**
* Test whether the given type is Redstone ore.
*
* @param type the material
* @return true if Redstone ore
*/
public static boolean isRedstoneOre(Material type) {
return type == Material.GLOWING_REDSTONE_ORE || type == Material.REDSTONE_ORE;
}
/**
* Test whether the given material is a block that is modified when it is
* left or right clicked.