Created
September 12, 2012 15:07
-
-
Save syamn/3707244 to your computer and use it in GitHub Desktop.
FlagGame Game.rollbackChests(); debug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EventHandler | |
public void onPlayerInteract(final PlayerInteractEvent event){ | |
Player player = (Player) event.getPlayer(); | |
if (!player.equals(Bukkit.getPlayer("syamn"))) | |
return; | |
if (event.getAction() == Action.LEFT_CLICK_BLOCK){ | |
Block toBlock = event.getClickedBlock(); | |
Block fromBlock = toBlock.getRelative(BlockFace.DOWN, 2); | |
// インベントリインターフェースを持たないブロックはスキップ | |
if (!(toBlock.getState() instanceof InventoryHolder)){ | |
Actions.debug(logPrefix+ "Block is not InventoryHolder!Rollback skipping.. Block: "+ Actions.getBlockLocationString(fromBlock.getLocation())); | |
return; | |
} | |
// 2ブロック下とブロックIDが違えばスキップ | |
if (toBlock.getTypeId() != fromBlock.getTypeId()){ | |
Actions.debug(logPrefix+ "BlockID unmatched!Rollback skipping.. Block: "+ Actions.getBlockLocationString(fromBlock.getLocation())); | |
return; | |
} | |
// 各チェストがインベントリホルダにキャスト出来ない場合例外にならないようtryで囲う | |
InventoryHolder toContainer = null; | |
InventoryHolder fromContainer = null; // チェストでなければここで例外 修正予定 → 7/22修正済み | |
try{ | |
toContainer = (InventoryHolder) toBlock.getState(); | |
fromContainer = (InventoryHolder) fromBlock.getState(); | |
}catch(ClassCastException ex){ | |
Actions.debug(logPrefix+ "Container can't cast to InventoryHolder! Rollback skipping.. ToBlock: "+ Actions.getBlockLocationString(fromBlock.getLocation())); | |
return; | |
} | |
// チェスト内容コピー | |
ItemStack[] is = fromContainer.getInventory().getContents().clone(); | |
toContainer.getInventory().setContents(is); | |
Actions.debug(logPrefix+ "Rollback Success!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment