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.base.BlockDirection; 022import net.tridentsdk.base.Substance; 023import net.tridentsdk.entity.living.Player; 024import net.tridentsdk.event.Cancellable; 025 026/** 027 * Called whenever a block is placed 028 * 029 * @author The TridentSDK Team 030 * @since 0.3-alpha-DP 031 */ 032public class BlockPlaceEvent extends BlockEvent implements Cancellable { 033 private final Player player; 034 private final Block blockClicked; 035 private final BlockDirection faceClicked; 036 037 private boolean cancelled; 038 039 /** 040 * @param player Player who placed this block 041 * @param block Block that was placed 042 * @param blockClicked Block 043 * @param faceClicked BlockFace 044 */ 045 public BlockPlaceEvent(Player player, Block block, Block blockClicked, BlockDirection faceClicked) { 046 super(block); 047 this.player = player; 048 this.blockClicked = blockClicked; 049 this.faceClicked = faceClicked; 050 } 051 052 /** 053 * Gets the block face of the block that was clicked on to place this block 054 * 055 * @return BlockFace of the clicked block 056 */ 057 public BlockDirection faceClicked() { 058 return this.faceClicked; 059 } 060 061 /** 062 * Get the Material of the placed block 063 * 064 * @return Material of the placed block 065 */ 066 public Substance typePlaced() { 067 return this.block().substance(); 068 } 069 070 @Override 071 public boolean isIgnored() { 072 return cancelled; 073 } 074 075 @Override 076 public void cancel(boolean cancelled) { 077 this.cancelled = cancelled; 078 } 079 080 /** 081 * Gets the block clicked on to place this block 082 * 083 * @return Block that was clicked 084 */ 085 public Block blockClicked() { 086 return this.blockClicked; 087 } 088 089 /** 090 * Returns the player associated with this event 091 * 092 * @return Player who placed the block 093 */ 094 public Player player() { 095 return this.player; 096 } 097}