// Returns true if a door wasn't changed. private static boolean fixDoor(Player player) { Block block = player.getTargetBlock(null, 10); int type = block.getTypeId(); boolean doCheck = false; // Check if the block being looked at is a door block. if (Lockette.protectTrapDoors) { if (type == Material.TRAP_DOOR.getId()) doCheck = true; } if (Lockette.protectDoors) { if ((type == Material.WOODEN_DOOR.getId()) || (type == Material.IRON_DOOR_BLOCK.getId()) || (type == materialFenceGate)) doCheck = true; } if (!doCheck) return (true); Block signBlock = Lockette.findBlockOwner(block); if (signBlock == null) return (true); Sign sign = (Sign) signBlock.getState(); int length = player.getName().length(); if (length > 15) length = 15; // Check owner only. if (sign.getLine(1) .replaceAll("(?i)\u00A7[0-F]", "") .equals(player.getName().substring(0, length))) { Lockette.toggleSingleDoor(block); return (false); } return (true); }
// Returns true if it should be allowed, false if it should be canceled. private static boolean interactDoor(Block block, Player player) { Block signBlock = Lockette.findBlockOwner(block); if (signBlock == null) return (true); boolean wooden = (block.getTypeId() == Material.WOODEN_DOOR.getId()); boolean trap = false; if (block.getTypeId() == materialFenceGate) wooden = true; if (Lockette.protectTrapDoors) if (block.getTypeId() == Material.TRAP_DOOR.getId()) { wooden = true; trap = true; } // Someone touched an owned door, lets see if they are allowed. boolean allow = false; if (canInteract(block, signBlock, player, true)) allow = true; /* // Fee stuff... if(!allow){ // Check if we can pay a fee to activate. int fee = getSignOption(signBlock, "fee", Lockette.altFee, 0); if(signBlock.equals(plugin.playerList.get(player.getName()))){ if(fee == 0){ player.sendMessage("unable to pay fee"); } else{ player.sendMessage("Fee of " +plugin.economyFormat(fee)+" paid (fake)"); plugin.playerList.put(player.getName(), block); allow = true; } / if(fee != 0){ Sign sign = (Sign) signBlock.getState(); String text = sign.getLine(1).replaceAll("(?i)\u00A7[0-F]", ""); if(plugin.economyTransfer(player.getName(), text, fee)){ allow = true; plugin.playerList.put(player.getName(), block); } else{} }/ } else if(fee != 0){ player.sendMessage("first touch sign to pay fee."); } } */ if (allow) { List<Block> list = Lockette.toggleDoors(block, Lockette.getSignAttachedBlock(signBlock), wooden, trap); int delta = Lockette.getSignOption(signBlock, "timer", Lockette.altTimer, Lockette.defaultDoorTimer); plugin.doorCloser.add(list, delta != 0, delta); return (true); } // Don't have permission. // event.setCancelled(true); // if(Lockette.oldListener){ // if(wooden) Lockette.toggleSingleDoor(block); // } // Report only once, unless a different block is clicked. if (block.equals(plugin.playerList.get(player.getName()))) return (false); plugin.playerList.put(player.getName(), block); plugin.localizedMessage(player, null, "msg-user-denied-door"); return (false); }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerInteract(PlayerInteractEvent event) { if (!event.hasBlock()) return; Action action = event.getAction(); Player player = event.getPlayer(); Block block = event.getClickedBlock(); int type = block.getTypeId(); BlockFace face = event.getBlockFace(); if (action == Action.RIGHT_CLICK_BLOCK) { if (Lockette.protectTrapDoors) if (type == Material.TRAP_DOOR.getId()) { if (interactDoor(block, player)) return; event.setUseInteractedBlock(Result.DENY); event.setUseItemInHand(Result.DENY); return; } if (Lockette.protectDoors) if ((type == Material.WOODEN_DOOR.getId()) || (type == Material.IRON_DOOR_BLOCK.getId()) || (type == materialFenceGate)) { if (interactDoor(block, player)) return; event.setUseInteractedBlock(Result.DENY); event.setUseItemInHand(Result.DENY); return; } if (type == Material.WALL_SIGN.getId()) { interactSign(block, player); return; } if (type == Material.CHEST.getId()) { // Try at making a 1.7->1.8 chest fixer. Lockette.rotateChestOrientation(block, face); } if ((type == Material.CHEST.getId()) || (type == Material.DISPENSER.getId()) || (type == Material.FURNACE.getId()) || (type == Material.BURNING_FURNACE.getId()) || (type == Material.BREWING_STAND.getId()) || Lockette.isInList(type, Lockette.customBlockList)) { // Trying something out.... if (Lockette.directPlacement) if (event.hasItem()) if ((face != BlockFace.UP) && (face != BlockFace.DOWN)) { ItemStack item = event.getItem(); if (item.getTypeId() == Material.SIGN.getId()) { Block checkBlock = block.getRelative(face); type = checkBlock.getTypeId(); if (type == Material.AIR.getId()) { boolean place = false; if (Lockette.isProtected(block)) { // Add a users sign only if owner. if (Lockette.isOwner(block, player.getName())) place = true; } else place = true; // if(Lockette.altPrivate == null){}//if(Lockette.altMoreUsers == null){} if (place) { // player.sendMessage(ChatColor.RED + "Lockette: Using a sign on a container"); event.setUseItemInHand(Result.ALLOW); // ? seems to work in 568 event.setUseInteractedBlock(Result.DENY); return; } } } } if (interactContainer(block, player)) return; event.setUseInteractedBlock(Result.DENY); event.setUseItemInHand(Result.DENY); return; } if (type == Material.DIRT.getId()) if (event.hasItem()) { ItemStack item = event.getItem(); type = item.getTypeId(); if ((type == Material.DIAMOND_HOE.getId()) || (type == Material.GOLD_HOE.getId()) || (type == Material.IRON_HOE.getId()) || (type == Material.STONE_HOE.getId()) || (type == Material.WOOD_HOE.getId())) { Block checkBlock = block.getRelative(BlockFace.UP); type = checkBlock.getTypeId(); if ((type == Material.WOODEN_DOOR.getId()) || (type == Material.IRON_DOOR_BLOCK.getId()) || (type == materialFenceGate)) { event.setUseInteractedBlock(Result.DENY); return; } } } } else if (action == Action.LEFT_CLICK_BLOCK) { if (Lockette.protectTrapDoors) if (type == Material.TRAP_DOOR.getId()) { if (interactDoor(block, player)) return; event.setUseInteractedBlock(Result.DENY); event.setUseItemInHand(Result.DENY); return; } if (Lockette.protectDoors) if ((type == Material.WOODEN_DOOR.getId()) || (type == Material.IRON_DOOR_BLOCK.getId()) || (type == materialFenceGate)) { if (interactDoor(block, player)) return; event.setUseInteractedBlock(Result.DENY); event.setUseItemInHand(Result.DENY); return; } } }