001/* 002 * Trident - A Multithreaded Server Alternative 003 * Copyright 2014 The TridentSDK Team 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package net.tridentsdk.event.block; 019 020import net.tridentsdk.base.Block; 021import net.tridentsdk.event.Cancellable; 022 023/** 024 * Called when a block's redstone state is updated, called on each individual section of wire when they change, etc. 025 * 026 * @author The TridentSDK Team 027 * @since 0.3-alpha-DP 028 */ 029public class BlockRedstoneEvent extends BlockEvent implements Cancellable { 030 private final int strength; 031 private final Block causer; 032 private final Cause cause; 033 private boolean cancelled; 034 035 /** 036 * @param block Block which redstone state was updated 037 * @param strength Integer representing the strength (power level) of the redstone 038 * @param causer Block which caused the redstone update 039 * @param cause Cause for the redstone update 040 */ 041 public BlockRedstoneEvent(Block block, int strength, Block causer, Cause cause) { 042 super(block); 043 this.strength = strength; 044 this.causer = causer; 045 this.cause = cause; 046 } 047 048 /** 049 * Returns the block which caused the redstone update 050 * 051 * @return Block which caused the redstone updaye 052 */ 053 public Block causer() { 054 return this.causer; 055 } 056 057 /** 058 * Returns the cause of the redstone update 059 * 060 * @return Cause of the redstone update 061 */ 062 public Cause cause() { 063 return this.cause; 064 } 065 066 /** 067 * Returns the strength (power level) of the redstone 068 * 069 * @return Integer representing the power level of the redstone 070 */ 071 public int strength() { 072 return this.strength; 073 } 074 075 @Override 076 public boolean isIgnored() { 077 return cancelled; 078 } 079 080 @Override 081 public void cancel(boolean cancelled) { 082 this.cancelled = cancelled; 083 } 084 085 /** 086 * Representing the cause of a redstone update 087 */ 088 public enum Cause { 089 LEVER, 090 BUTTON, 091 WIRE, 092 TORCH, 093 PRESSURE_PLATE, 094 HOOK, 095 TRAP_CHEST, 096 SENSOR, 097 REPEATER, 098 COMPARATOR 099 } 100}