@SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) return;

    final Player player = event.getPlayer();
    final Block block = event.getClickedBlock();
    final ItemStack item = event.getItem();

    if (player.getWorld() != plugin.getIslandWorld()) return;
    if (player.isOp()) return;
    if (player.hasPermission("islandworld.bypass.island")) return;

    if (block != null) {
      final Material t = block.getType();

      plugin.debug("Interact with block: " + t.getId() + " : " + block);

      if (!(plugin.getConfig().getBoolean("flags.use-switches", false) && isSwitch(t))) {
        if (!(isOnAllowedList(t) || plugin.canBuildOnLocation(player, block.getLocation())))
          event.setCancelled(true);
      }
    } else {
      if (item != null) {
        plugin.debug("Using item: " + item.getTypeId());

        if (!(isOnAllowedList(item.getType())
            || plugin.canBuildOnLocation(player, player.getLocation()))) event.setCancelled(true);
      }
    }
    plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled());
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onRightHandPlayerInteact(PlayerInteractEvent event) {
    if (event.isCancelled()) return;

    final Player player = event.getPlayer();

    if (player != null
        && (event.getAction() == Action.RIGHT_CLICK_BLOCK
            || event.getAction() == Action.RIGHT_CLICK_AIR)) {
      Location loc = player.getLocation();
      // If block is not null use block location, if null use player loc
      final Block block = event.getClickedBlock();
      if (block != null) loc = block.getLocation();

      if (player.getWorld() != plugin.getIslandWorld()) return;
      if (player.isOp()) return;
      if (player.hasPermission("islandworld.bypass.island")) return;

      if (player.getItemInHand().getType() == Material.MONSTER_EGG) {
        if (!(plugin.canBuildOnLocation(player, loc))) event.setCancelled(true);
      } else if (player.getItemInHand().getType() == Material.FIREBALL) {
        if (!plugin.canBuildOnLocation(player, loc)) event.setCancelled(true);
      }
    }
    plugin.debug("Evento :" + event.getEventName() + ", cancelled:" + event.isCancelled());
  }
    // Hits a netherrack block
    public void onPlayerInteract(PlayerInteractEvent event) {
      // Do not run if cancelled
      if (event.isCancelled()) {
        return;
      }

      // Only run if netherrack ignition is enabled
      if (igniteNetherrack) {
        // Check to see if player clicked a netherrack block
        if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
          if (event.getClickedBlock().getType() == Material.NETHERRACK) {
            // Ignite this block if Firetouch enabled
            Player player = event.getPlayer();
            PotionEntry buff = getPlugin().BuffList.get(player);

            if (buff != null) {
              if (buff.HasBuff.get(Name) != null && buff.HasBuff.get(Name)) {
                // Ignite block
                BlockIgniteEvent ignite =
                    new BlockIgniteEvent(
                        event.getClickedBlock(), IgniteCause.FLINT_AND_STEEL, player);
                getPlugin().getServer().getPluginManager().callEvent(ignite);
                if (!ignite.isCancelled()) {
                  Block above = event.getClickedBlock().getRelative(0, 1, 0);
                  if (above.isEmpty()) {
                    above.setType(Material.FIRE);
                  }
                }
              }
            }
          }
        }
      }
    }
Esempio n. 4
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) return;

    if (event.getAction() == org.bukkit.event.block.Action.LEFT_CLICK_BLOCK
        || event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK) {
      PlayerEvent playerEvent;
      if (SignUtil.isSign(event.getClickedBlock())) {
        playerEvent =
            new PlayerEvent(
                SignUtil.getSign(event.getClickedBlock()),
                event.getAction() == Action.LEFT_CLICK_BLOCK
                    ? PlayerEvent.Action.LEFT_CLICK
                    : PlayerEvent.Action.RIGHT_CLICK,
                event.getPlayer(),
                event);
      } else {
        playerEvent =
            new PlayerEvent(
                event.getClickedBlock(),
                event.getAction() == Action.LEFT_CLICK_BLOCK
                    ? PlayerEvent.Action.LEFT_CLICK
                    : PlayerEvent.Action.RIGHT_CLICK,
                event.getPlayer(),
                event);
      }
      mechanicsHandler.callPlayerEvent(playerEvent);
    }
  }
 @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
 public void onPlayerInteract(PlayerInteractEvent event) {
   Player player = event.getPlayer();
   Block block = event.getClickedBlock();
   if (player.getItemInHand().getType() == Material.STICK) {
     select(player, event);
   }
   /*if(player.getItemInHand().getType() == Material.STICK && player.getItemInHand().hasItemMeta()){
   	if(player.getItemInHand().getItemMeta().getDisplayName().contains(Tools.SelectionTool)){
   		select(player, event);
   	}else if(player.getItemInHand().getItemMeta().getDisplayName().contains(Tools.InfoTool)){
   		info(player, block, event);
   	}
   }*/
   if (block == null) {
     return;
   }
   if (event.getAction() != Action.LEFT_CLICK_BLOCK
       && event.getAction() != Action.RIGHT_CLICK_BLOCK) {
     pressure(player, block, event);
     return;
   }
   if (event.isCancelled()) {
     return;
   }
   if (player.getItemInHand().getType() == Material.ARMOR_STAND) {
     armorStand(player, block, event);
   }
   interact(player, block, event);
 }
Esempio n. 6
0
  @EventHandler
  public void onPlayerInteract(PlayerInteractEvent event) {
    int BLWand = getConfig().getInt("blocklog.wand");
    boolean WandEnabled = plugin.users.contains(event.getPlayer().getName());
    if (!event.isCancelled()) {
      if (event.getPlayer().getItemInHand().getTypeId() == BLWand && WandEnabled) {
        if ((event.getAction() == Action.RIGHT_CLICK_BLOCK
                && (!event.getPlayer().getItemInHand().getType().isBlock())
            || event.getAction() == Action.LEFT_CLICK_BLOCK)) {
          Material type = event.getClickedBlock().getType();
          if (type == Material.WOODEN_DOOR
              || type == Material.TRAP_DOOR
              || type == Material.CHEST
              || type == Material.DISPENSER
              || type == Material.STONE_BUTTON
              || type == Material.LEVER)
            getBlockInteractions(
                event.getPlayer(), event.getClickedBlock(), Interaction.getByMaterial(type));
          else getBlockEdits(event.getPlayer(), event.getClickedBlock());

          event.setCancelled(true);
        }
      }
    }
  }
  @Override
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Block block = event.getClickedBlock();
    Player player = event.getPlayer();

    if (block == null) {
      return; // clicked in air, apparently
    }

    if (!canPlayerUseBlock(player, block)) {
      event.setCancelled(true);
      return;
    }

    if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
      return; // only interested on right-clicks for below
    }

    if (!this.playerCanUseItemHere(player, block, event.getMaterial())) {
      event.setCancelled(true);
      return;
    }
  }
Esempio n. 8
0
  /**
   * Event - onBlockRightClick - If a player right clicks a block check their permissions and set a
   * Coordinate.
   */
  @Override
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Player player = event.getPlayer();

    if (player.getItemInHand().getTypeId() == this.plugin.configMV.getInt("setwand", 270)
        && MultiVerse.Permissions.has(player, "multiverse.portal.create")) {
      String[] whitelist = this.plugin.configMV.getString("portalblocks", "").split(",");
      if (whitelist.length > 0 && whitelist[0] != "") {
        for (String element : whitelist) {
          int w = Integer.valueOf(element);
          if (w != event.getClickedBlock().getTypeId()) {
            return;
          }
        }
      }
      Location l = event.getClickedBlock().getLocation();
      if (this.plugin.playerSessions.get(player.getName()).compareLocation2(l)) {
        return;
      }
      this.plugin.playerSessions.get(player.getName()).setLocation2(l);
      player.sendMessage("Position 2 - Set");
    }
  }
	@EventHandler(priority = EventPriority.NORMAL)
	public void onPlayerInteract(final PlayerInteractEvent event)
	{
		final IUser user = userMap.getUser(event.getPlayer());
		user.updateActivity(true);
		switch (event.getAction())
		{
		case RIGHT_CLICK_BLOCK:
			if (event.isCancelled())
			{
				return;
			}

			final ISettings settings = ess.getSettings();
			if (settings.getData().getCommands().getHome().isUpdateBedAtDaytime() && event.getClickedBlock().getType() == Material.BED_BLOCK)
			{
				event.getPlayer().setBedSpawnLocation(event.getClickedBlock().getLocation());
			}
			break;
		case LEFT_CLICK_AIR:
		case LEFT_CLICK_BLOCK:
			if (user.getData().hasPowerTools() && user.getData().isPowerToolsEnabled())
			{
				if (usePowertools(user))
				{
					event.setCancelled(true);
				}
			}
			break;
		default:
			break;
		}
	}
 /**
  * Called when a player clicks on anything.
  *
  * @param event The Interact event.
  */
 @EventHandler
 public void playerInteract(PlayerInteractEvent event) {
   if (event.isCancelled()) {
     return;
   }
   if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
     if (event.getClickedBlock().getState() instanceof Sign) {
       this.plugin.log(Level.FINER, "Found a Sign!");
       Sign s = (Sign) event.getClickedBlock().getState();
       SignStatus status = this.pd.getSignStatus(s);
       if (status == SignStatus.SignPortal) {
         String destString = this.pd.processSign(s);
         this.takePlayerToDestination(event.getPlayer(), destString);
         event.setCancelled(true);
       } else if (status == SignStatus.Disabled) {
         this.pd.activateSignPortal(event.getPlayer(), ChatColor.RED + "Disabled", s);
         event.setCancelled(true);
       } else if (status == SignStatus.Legacy) {
         this.pd.activateSignPortal(event.getPlayer(), ChatColor.AQUA + "Legacy", s);
         event.setCancelled(true);
       } else if (status == SignStatus.NetherPortalSign) {
         event.setCancelled(true);
       }
     }
   }
 }
Esempio n. 11
0
 @EventHandler(order = Order.EARLIEST)
 public void onPlayerInteract(PlayerInteractEvent event) {
   BridgePlayer player = EntityFactory.createPlayer(event.getPlayer());
   Human human = event.getPlayer().get(Human.class);
   if (human == null) {
     return;
   }
   org.bukkit.event.block.Action bukkitAction;
   if (event.getAction() == Action.LEFT_CLICK) {
     if (event.isAir()) {
       bukkitAction = org.bukkit.event.block.Action.LEFT_CLICK_AIR;
     } else {
       bukkitAction = org.bukkit.event.block.Action.LEFT_CLICK_BLOCK;
     }
   } else if (event.getAction() == Action.RIGHT_CLICK) {
     if (event.isAir()) {
       bukkitAction = org.bukkit.event.block.Action.RIGHT_CLICK_AIR;
     } else {
       bukkitAction = org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK;
     }
   } else {
     bukkitAction = org.bukkit.event.block.Action.PHYSICAL;
   }
   ItemStack item =
       BukkitUtil.fromItemStack(
           event.getPlayer().get(PlayerInventory.class).getQuickbar().getCurrentItem());
   Block clickedBlock = null;
   if (event.getInteractedPoint() != null) {
     clickedBlock =
         player
             .getWorld()
             .getBlockAt(
                 event.getInteractedPoint().getBlockX(),
                 event.getInteractedPoint().getBlockY(),
                 event.getInteractedPoint().getBlockZ());
   }
   BlockFace face = BukkitUtil.toBukkitBlockFace(event.getClickedFace());
   org.bukkit.event.player.PlayerInteractEvent interactEvent =
       new org.bukkit.event.player.PlayerInteractEvent(
           player, bukkitAction, item, clickedBlock, face);
   Bukkit.getPluginManager().callEvent(interactEvent);
   if (interactEvent.isCancelled()) {
     event.setCancelled(true);
   }
   if (interactEvent.useItemInHand() != org.bukkit.event.Event.Result.DEFAULT) {
     if (interactEvent.useItemInHand() == org.bukkit.event.Event.Result.ALLOW) {
       event.setUseItemInHand(org.spout.api.event.Result.ALLOW);
     } else {
       event.setUseItemInHand(org.spout.api.event.Result.DENY);
     }
   }
   if (interactEvent.useInteractedBlock() != org.bukkit.event.Event.Result.DEFAULT) {
     if (interactEvent.useInteractedBlock() == org.bukkit.event.Event.Result.ALLOW) {
       event.setInteractWithBlock(org.spout.api.event.Result.ALLOW);
     } else {
       event.setInteractWithBlock(org.spout.api.event.Result.DENY);
     }
   }
 }
Esempio n. 12
0
 @EventHandler
 public void onInteract(PlayerInteractEvent event) {
   if (event.isCancelled()) return;
   Block b = event.getClickedBlock();
   if (event.getAction() == Action.PHYSICAL
       && b != null
       && b.hasMetadata("Placer")
       && b.getType() == Material.STONE_PLATE
       && b.getRelative(BlockFace.DOWN).getType() == Material.GRAVEL) {
     b.removeMetadata("Placer", HungergamesApi.getHungergames());
     b.setType(Material.AIR);
     b.getWorld().createExplosion(b.getLocation().clone().add(0.5, 0.5, 0.5), 4F);
   }
 }
Esempio n. 13
0
  @EventHandler
  public void onPlayerAction(PlayerInteractEvent e) {
    Player player = e.getPlayer();
    if ((e.getAction() == Action.RIGHT_CLICK_AIR
        || (e.getAction() == Action.RIGHT_CLICK_BLOCK) && !e.isCancelled())) {
      ItemStack item = player.getItemInHand();
      if (item.getType() == Material.BOW
          || item.getType() == Material.SNOW_BALL
          || item.getType() == Material.EGG
          || item.getType() == Material.POTION) return;

      RPGItem rItem = ItemManager.toRPGItem(item);
      if (rItem == null) return;
      if (!WorldGuard.canPvP(player.getLocation()) && !rItem.ignoreWorldGuard) return;
      if (rItem.getHasPermission() == true
          && player.hasPermission(rItem.getPermission()) == false) {
        e.setCancelled(true);
        player.sendMessage(
            ChatColor.RED
                + String.format(
                    Locale.get("message.error.permission", Locale.getPlayerLocale(player))));
      }
      rItem.rightClick(player);
      if (player.getItemInHand().getTypeId() != 0) {
        RPGItem.updateItem(item, Locale.getPlayerLocale(player));
      } else player.setItemInHand(null);
      player.updateInventory();
    } else if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
      ItemStack item = player.getItemInHand();
      if (item.getType() == Material.BOW
          || item.getType() == Material.SNOW_BALL
          || item.getType() == Material.EGG
          || item.getType() == Material.POTION) return;

      RPGItem rItem = ItemManager.toRPGItem(item);
      if (rItem == null) return;
      if (!WorldGuard.canPvP(player.getLocation()) && !rItem.ignoreWorldGuard) return;
      if (rItem.getHasPermission() == true
          && player.hasPermission(rItem.getPermission()) == false) {
        e.setCancelled(true);
        player.sendMessage(
            ChatColor.RED
                + String.format(
                    Locale.get("message.error.permission", Locale.getPlayerLocale(player))));
      }
      rItem.leftClick(player);
      RPGItem.updateItem(item, Locale.getPlayerLocale(player));
    }
  }
  @Override
  public void onPlayerInteract(final PlayerInteractEvent event) {
    if (event.isCancelled()) {
      return;
    }
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
      return;
    }

    if (ess.getSettings().getBedSetsHome()
        && event.getClickedBlock().getType() == Material.BED_BLOCK) {
      try {
        final User user = ess.getUser(event.getPlayer());
        user.setHome();
        user.sendMessage(Util.i18n("homeSetToBed"));
      } catch (Throwable ex) {
      }
    }
  }
  @Override
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.useInteractedBlock() == Result.DENY || event.isCancelled()) return;

    boolean silentchest = false;
    boolean anychest = false;
    int x = event.getClickedBlock().getX();
    int y = event.getClickedBlock().getY();
    int z = event.getClickedBlock().getZ();

    if (event.getAction() == Action.RIGHT_CLICK_BLOCK
        && event.getClickedBlock().getState() instanceof Chest
        && PermissionRelay.hasPermission(event.getPlayer(), "OpenInv.silent")
        && OpenInv.GetPlayerSilentChestStatus(event.getPlayer().getName())) {
      silentchest = true;
    }

    if (event.getAction() == Action.RIGHT_CLICK_BLOCK
        && event.getClickedBlock().getState() instanceof Chest
        && PermissionRelay.hasPermission(event.getPlayer(), "OpenInv.anychest")) {
      try {
        EntityPlayer player = ((CraftPlayer) event.getPlayer()).getHandle();
        World world = player.world;
        // If block on top
        if (world.e(x, y + 1, z)) anychest = true;

        // If block next to chest is chest and has a block on top
        if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.e(x - 1, y + 1, z)))
          anychest = true;
        if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.e(x + 1, y + 1, z)))
          anychest = true;
        if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.e(x, y + 1, z - 1)))
          anychest = true;
        if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.e(x, y + 1, z + 1)))
          anychest = true;
      } catch (Exception e) // Incompatible CraftBukkit?
      {
        e.printStackTrace();
        event
            .getPlayer()
            .sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
      }
    }

    // If the chest is blocked
    if (anychest || silentchest) {
      EntityPlayer player = ((CraftPlayer) event.getPlayer()).getHandle();
      World world = player.world;
      Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
      if (chest == null) return;

      if (!anychest) {
        if (world.e(x, y + 1, z)) return;
        if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.e(x - 1, y + 1, z))) return;
        if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.e(x + 1, y + 1, z))) return;
        if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.e(x, y + 1, z - 1))) return;
        if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.e(x, y + 1, z + 1))) return;
      }

      if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
        chest =
            new InventoryLargeChest(
                "Large chest",
                (TileEntityChest) world.getTileEntity(x - 1, y, z),
                (IInventory) chest);
      if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
        chest =
            new InventoryLargeChest(
                "Large chest",
                (IInventory) chest,
                (TileEntityChest) world.getTileEntity(x + 1, y, z));
      if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
        chest =
            new InventoryLargeChest(
                "Large chest",
                (TileEntityChest) world.getTileEntity(x, y, z - 1),
                (IInventory) chest);
      if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
        chest =
            new InventoryLargeChest(
                "Large chest",
                (IInventory) chest,
                (TileEntityChest) world.getTileEntity(x, y, z + 1));

      if (!silentchest) {
        player.a((IInventory) chest);
      } else {
        try {
          Field ciField = player.getClass().getDeclaredField("ci");
          ciField.setAccessible(true);
          int ci = ciField.getInt(player);
          ci = ci % 100 + 1;
          ciField.setInt(player, ci);
          player.netServerHandler.sendPacket(
              new Packet100OpenWindow(
                  ci, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
          player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
          System.out.println(player.activeContainer.toString());
          player.activeContainer.windowId = ci;
          player.activeContainer.a((ICrafting) player);
          event.getPlayer().sendMessage("You are opening a silent chest.");
        } catch (Exception e) {
          e.printStackTrace();
          event.getPlayer().sendMessage(ChatColor.RED + "Error while sending silent chest.");
        }
      }

      if (anychest) event.getPlayer().sendMessage("You are opening a blocked chest.");
    }

    if (event.getAction() == Action.RIGHT_CLICK_BLOCK
        && (event.getClickedBlock() == Block.CHEST
            || event.getClickedBlock() == Block.FURNACE
            || event.getClickedBlock() == Block.DISPENSER)) {
      return;
    }

    if (event.getAction() == Action.RIGHT_CLICK_AIR
        || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
      Player player = event.getPlayer();

      if (!(player.getItemInHand().getType() == Material.STICK)
          || (!OpenInv.GetPlayerItemOpenInvStatus(player.getName()))
          || !PermissionRelay.hasPermission(player, "openinv")) {
        return;
      }

      player.performCommand("openinv");
    }

    if (event.getAction() == Action.LEFT_CLICK_BLOCK
        && event.getClickedBlock().getState() instanceof Sign) {
      Player player = event.getPlayer();
      try {
        if (PermissionRelay.hasPermission(player, "openinv")
            && ((Sign) event.getClickedBlock().getState())
                .getLine(0)
                .equalsIgnoreCase("[openinv]")) {
          if (plugin.getServer().getPlayer(((Sign) event.getClickedBlock().getState()).getLine(1))
              != null) {
            Sign sign = ((Sign) event.getClickedBlock().getState());
            String text = sign.getLine(1).trim() + sign.getLine(2).trim() + sign.getLine(2).trim();
            player.performCommand("openinv " + text);
          } else {
            player.sendMessage("Player not found.");
          }
        }
      } catch (Exception ex) {
        player.sendMessage("Internal Error.");
        ex.printStackTrace();
      }
    }
  }
  @EventHandler(priority = EventPriority.LOW)
  public void onPlayerInteract(final PlayerInteractEvent ev) {
    final Block block = ev.getClickedBlock();
    final Player player = ev.getPlayer();

    if (block == null) return;
    else if (block.getType().toString().toLowerCase().contains("lever")) {
      Block signblock1 = block.getRelative(BlockFace.SOUTH, 1);
      Block signblock2 = block.getRelative(BlockFace.NORTH, 1);
      Block signblock3 = block.getRelative(BlockFace.WEST, 1);
      Block signblock4 = block.getRelative(BlockFace.EAST, 1);
      Sign sign = null;
      // Lever lever = (Lever) block.getState().getData();

      if (signblock1.getState() instanceof Sign) sign = (Sign) signblock1.getState();
      else if (signblock2.getState() instanceof Sign) sign = (Sign) signblock2.getState();
      else if (signblock3.getState() instanceof Sign) sign = (Sign) signblock3.getState();
      else if (signblock4.getState() instanceof Sign) sign = (Sign) signblock4.getState();
      else return;

      String[] lines = sign.getLines();
      if (lines[1].startsWith("/")) {
        ev.setCancelled(true);
        return;
      } else return;
    } else if (block.getType().toString().toLowerCase().contains("button")) {
      if (ev.isCancelled()) return;

      if (!(ev.getAction().equals(Action.RIGHT_CLICK_BLOCK) && rightClick)) return;

      if (!(enableNormal || enableConsole || enableAlias)) return;

      if (((Button) block.getState().getData()).isPowered()) return;

      final BlockFace bf = ((Button) block.getState().getData()).getFacing();

      if (bf == BlockFace.NORTH) {
        BlockFace[] testBlocks = {
          BlockFace.UP, BlockFace.DOWN, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST
        };
        BlockFace[] testFaces = {BlockFace.NORTH, BlockFace.SOUTH};
        Block lever = block.getRelative(BlockFace.SOUTH, 3);
        ev.setCancelled(signFinder(player, block, testBlocks, testFaces, lever));
      } else if (bf == BlockFace.SOUTH) {
        BlockFace[] testBlocks = {
          BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST
        };
        BlockFace[] testFaces = {BlockFace.SOUTH, BlockFace.NORTH};
        Block lever = block.getRelative(BlockFace.NORTH, 3);
        ev.setCancelled(signFinder(player, block, testBlocks, testFaces, lever));
      } else if (bf == BlockFace.EAST) {
        BlockFace[] testBlocks = {
          BlockFace.UP, BlockFace.DOWN, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH
        };
        BlockFace[] testFaces = {BlockFace.EAST, BlockFace.WEST};
        Block lever = block.getRelative(BlockFace.WEST, 3);
        ev.setCancelled(signFinder(player, block, testBlocks, testFaces, lever));
      } else if (bf == BlockFace.WEST) {
        BlockFace[] testBlocks = {
          BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.SOUTH, BlockFace.NORTH
        };
        BlockFace[] testFaces = {BlockFace.WEST, BlockFace.EAST};
        Block lever = block.getRelative(BlockFace.EAST, 3);
        ev.setCancelled(signFinder(player, block, testBlocks, testFaces, lever));
      }
    } else {
      return;
    }
  }
  @SuppressWarnings("deprecation")
  @Override
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Player player = event.getPlayer();
    String playerName = player.getName();
    if (!plugin.getPlayerData().containsKey(playerName)) {
      plugin.getPlayerData().put(playerName, new PlayerData(plugin, playerName));
    }
    Location eventBlockLoc = event.getClickedBlock().getLocation();
    LocalShop shop = plugin.getShopManager().getLocalShop(eventBlockLoc);
    // If user Right clicks a sign try to buy/sell from it.
    if (((event.getClickedBlock().getType().equals(Material.WALL_SIGN)
                || event.getClickedBlock().getType().equals(Material.SIGN_POST))
            && event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
        && shop != null) {
      // Ignore consumables & send message to a player
      if (consumables.contains(player.getItemInHand().getType())) {
        event.setCancelled(true);
        player.sendMessage(ChatColor.DARK_AQUA + "Oops!  You can't eat while working with shops!");
        return;
      }

      for (ShopSign sign : shop.getSigns()) {
        if (sign == null) {
          continue;
        }
        if (sign.getLoc().equals(eventBlockLoc)) {
          // Check for null sign-type? We should NEVER have this issue
          if (sign.getType() == null) {
            log.log(
                Level.WARNING,
                "[LocalShops] - Null Shop Sign detected, report error. Sign info: {0}",
                sign.toString());
            continue;
          }
          if (sign.getType().equals(ShopSign.SignType.BUY)) {
            ShopCommandExecutor.commandTypeMap
                .get("buy")
                .getCommandInstance(
                    plugin,
                    "buy",
                    event.getPlayer(),
                    "buy " + sign.getItemName() + " " + sign.getAmount(),
                    false)
                .process();
            // TODO: Remove when bukkit fixes inventory updating
            player.updateInventory();
            return;
          } else if (sign.getType().equals(ShopSign.SignType.SELL)) {
            ShopCommandExecutor.commandTypeMap
                .get("sell")
                .getCommandInstance(
                    plugin,
                    "sell",
                    event.getPlayer(),
                    "sell " + sign.getItemName() + " " + sign.getAmount(),
                    false)
                .process();
            player.updateInventory();
            return;
          } else {
            // Stop the loop if it's not a Buy/Sell Sign - only 1 possible sign location match
            break;
          }
        }
      }
    }
    // If our user is select & is not holding an item, selection time
    if (plugin.getPlayerData().get(playerName).isSelecting()
        && (player.getItemInHand().getType() == Material.AIR
            || player.getItemInHand().getType() == Material.STICK)) {
      PlayerData pData = plugin.getPlayerData().get(playerName);
      Location loc = event.getClickedBlock().getLocation();
      int x = loc.getBlockX();
      int y = loc.getBlockY();
      int z = loc.getBlockZ();

      if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
        String size = null;
        pData.setPositionA(loc);
        if (pData.getPositionB() != null) {
          size =
              GenericFunctions.calculateCuboidSize(
                  pData.getPositionA(),
                  pData.getPositionB(),
                  Config.getShopSizeMaxWidth(),
                  Config.getShopSizeMaxHeight());
        }
        if (size != null) {
          player.sendMessage(
              ChatColor.DARK_AQUA
                  + "First Position "
                  + ChatColor.LIGHT_PURPLE
                  + x
                  + " "
                  + y
                  + " "
                  + z
                  + ChatColor.DARK_AQUA
                  + " size "
                  + ChatColor.LIGHT_PURPLE
                  + size);
        } else {
          player.sendMessage(
              ChatColor.DARK_AQUA
                  + "First Position "
                  + ChatColor.LIGHT_PURPLE
                  + x
                  + " "
                  + y
                  + " "
                  + z);
        }

        if (pData.getPositionA() != null && pData.getPositionB() == null) {
          player.sendMessage(
              ChatColor.DARK_AQUA
                  + "Now, right click to select the far upper corner for the shop.");
        } else if (pData.getPositionA() != null && pData.getPositionB() != null) {
          player.sendMessage(
              ChatColor.DARK_AQUA
                  + "Type "
                  + ChatColor.WHITE
                  + "/shop create [Shop Name]"
                  + ChatColor.DARK_AQUA
                  + ", if you're happy with your selection, otherwise keep selecting!");
        }
      } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        pData.setPositionB(loc);
        String size =
            GenericFunctions.calculateCuboidSize(
                pData.getPositionA(),
                pData.getPositionB(),
                Config.getShopSizeMaxWidth(),
                Config.getShopSizeMaxHeight());
        if (size != null) {
          player.sendMessage(
              ChatColor.DARK_AQUA
                  + "Second Position "
                  + ChatColor.LIGHT_PURPLE
                  + x
                  + " "
                  + y
                  + " "
                  + z
                  + ChatColor.DARK_AQUA
                  + " size "
                  + ChatColor.LIGHT_PURPLE
                  + size);
        } else {
          player.sendMessage(
              ChatColor.DARK_AQUA
                  + "Second Position "
                  + ChatColor.LIGHT_PURPLE
                  + x
                  + " "
                  + y
                  + " "
                  + z);
        }

        if (pData.getPositionB() != null && pData.getPositionA() == null) {
          player.sendMessage(
              ChatColor.DARK_AQUA + "Now, left click to select the bottom corner for a shop.");
        } else if (pData.getPositionA() != null && pData.getPositionB() != null) {
          player.sendMessage(
              ChatColor.DARK_AQUA
                  + "Type "
                  + ChatColor.WHITE
                  + "/shop create [Shop Name]"
                  + ChatColor.DARK_AQUA
                  + ", if you're happy with your selection, otherwise keep selecting!");
        }
      }
    }
  }
Esempio n. 18
0
  @Override
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) return;

    final Player player = event.getPlayer();
    String playerName = player.getName();
    if (!plugin.getPlayerData().containsKey(playerName)) {
      plugin.getPlayerData().put(playerName, new PlayerData(plugin, playerName));
    }

    // If our user is select & is not holding an item, selection time
    if (plugin.getPlayerData().get(playerName).isSelecting()
        && player.getItemInHand().getType() == Material.AIR
        && event.getClickedBlock().getType() == Material.WOODEN_DOOR) {
      int x, y, z;
      Location loc = event.getClickedBlock().getLocation();
      x = loc.getBlockX();
      y = loc.getBlockY();
      z = loc.getBlockZ();
      PlayerData pData = plugin.getPlayerData().get(playerName);
      Door door = (Door) event.getClickedBlock().getState().getData();
      if (door.isTopHalf()) y = y - 1;
      if (event.getAction() == Action.LEFT_CLICK_BLOCK) {

        if (Inn.doorAlreadyExists(x, y, z)) {
          player.sendMessage(ChatColor.RED + "This door is already registered!");
          return;
        }
        int[] xyz = {x, y, z};
        pData.setPositionA(xyz);
        player.sendMessage(ChatColor.DARK_AQUA + "Door selected");
        event.setCancelled(true);
        if (pData.getPositionA() != null) {
          player.sendMessage(
              ChatColor.DARK_AQUA
                  + "Type "
                  + ChatColor.WHITE
                  + "/inn create [Price]"
                  + ChatColor.DARK_AQUA
                  + ", if you're happy with your selection, otherwise keep selecting!");
        }
      }
      // Are we trying to delete a door?
    } else if (plugin.getPlayerData().get(playerName).isRemoving()
        && player.getItemInHand().getType() == Material.AIR
        && event.getClickedBlock().getType() == Material.WOODEN_DOOR) {
      int x, y, z;
      Location loc = event.getClickedBlock().getLocation();
      x = loc.getBlockX();
      y = loc.getBlockY();
      z = loc.getBlockZ();
      Door door = (Door) event.getClickedBlock().getState().getData();
      if (door.isTopHalf()) y = y - 1;
      if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
        event.setCancelled(true);
        if (Inn.doorAlreadyExists(x, y, z)) {
          if (!IPermissions.permission(player, "inn.admin.delete", player.isOp())) {
            if (!Inn.getOwner(x, y, z).equalsIgnoreCase(playerName)) {
              player.sendMessage(ChatColor.RED + "You do not own this door!");
              return;
            }
          }
          String query = "DELETE FROM doors WHERE x=" + x + " AND y=" + y + " AND z=" + z;
          Inn.manageSQLite.deleteQuery(query);
          player.sendMessage(ChatColor.RED + "This Inn door has been deleted!");
          return;
        } else {
          player.sendMessage(ChatColor.RED + "This door is not a Inn door!");
        }
      }
      // Are we trying to open a door?
    } else if (event.getClickedBlock().getType() == Material.WOODEN_DOOR) {
      if (IPermissions.permission(player, "inn.bypass", player.isOp())) return;
      int x, y, z;
      Location loc = event.getClickedBlock().getLocation();
      x = loc.getBlockX();
      y = loc.getBlockY();
      z = loc.getBlockZ();
      Door door = (Door) event.getClickedBlock().getState().getData();
      if (door.isTopHalf()) y = y - 1;
      if (Inn.doorAlreadyExists(x, y, z)) {
        String owner = Inn.getOwner(x, y, z);
        if (owner.equalsIgnoreCase(playerName)) {
          player.sendMessage(ChatColor.GREEN + "This is your inn door!");
          return;
        }
        int price = Inn.getDoorPrice(x, y, z);
        if (Inn.isTimeoutExpired(x, y, z, playerName)) {
          MethodAccount playerAccount = plugin.Method.getAccount(playerName);
          if (playerAccount.hasEnough(price)) {
            playerAccount.subtract(price);
            MethodAccount playerAccount2 = plugin.Method.getAccount(owner);
            playerAccount2.add(price);
            Inn.addTimeout(x, y, z, playerName);
            player.sendMessage(ChatColor.DARK_AQUA + "You are entering " + owner + " inn room");

          } else event.setCancelled(true);
        } else return;
      }
    }
  }
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Action action = event.getAction();
    if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {
      Block block = event.getClickedBlock();
      Material type = block.getType();
      Player player = event.getPlayer();

      GlobalConfiguration cfg = plugin.getGlobalConfiguration();
      WorldConfiguration wcfg = cfg.getWorldConfig(event.getClickedBlock().getWorld().getName());

      if (wcfg.useRegions && player.getItemInHand().getTypeId() == wcfg.regionWand) {
        Vector pt = toVector(block);

        RegionManager mgr =
            plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
        ApplicableRegionSet app = mgr.getApplicableRegions(pt);
        List<String> regions = mgr.getApplicableRegionsIDs(pt);

        if (regions.size() > 0) {
          player.sendMessage(
              ChatColor.YELLOW
                  + "Can you build? "
                  + (app.canBuild(BukkitPlayer.wrapPlayer(plugin, player)) ? "Yes" : "No"));

          StringBuilder str = new StringBuilder();
          for (Iterator<String> it = regions.iterator(); it.hasNext(); ) {
            str.append(it.next());
            if (it.hasNext()) {
              str.append(", ");
            }
          }

          player.sendMessage(ChatColor.YELLOW + "Applicable regions: " + str.toString());
        } else {
          player.sendMessage(ChatColor.YELLOW + "WorldGuard: No defined regions here!");
        }
      }

      if (block.getType() == Material.CHEST
          || block.getType() == Material.DISPENSER
          || block.getType() == Material.FURNACE
          || block.getType() == Material.BURNING_FURNACE
          || block.getType() == Material.NOTE_BLOCK) {
        if (wcfg.useRegions) {
          Vector pt = toVector(block);
          LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player);
          RegionManager mgr =
              plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());

          if (!plugin.hasPermission(player, "region.bypass")) {
            ApplicableRegionSet set = mgr.getApplicableRegions(pt);
            if (!set.isStateFlagAllowed(Flags.CHEST_ACCESS) && !set.canBuild(localPlayer)) {
              player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
              event.setCancelled(true);
              return;
            }
          }
        }
      }

      if (wcfg.useRegions && (type == Material.LEVER || type == Material.STONE_BUTTON)) {
        Vector pt = toVector(block);
        RegionManager mgr =
            cfg.getWorldGuardPlugin()
                .getGlobalRegionManager()
                .getRegionManager(player.getWorld().getName());
        ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt);
        LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player);

        if (!applicableRegions.isStateFlagAllowed(Flags.LEVER_AND_BUTTON, localPlayer)) {
          player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
          event.setCancelled(true);
          return;
        }
      }

      if (wcfg.useRegions && type == Material.CAKE_BLOCK) {

        Vector pt = toVector(block);

        if (!cfg.canBuild(player, pt)) {
          player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");

          byte newData = (byte) (block.getData() - 1);
          newData = newData < 0 ? 0 : newData;

          block.setData(newData);
          player.setHealth(player.getHealth() - 3);

          return;
        }
      }

      if (wcfg.useRegions
          && wcfg.useiConomy
          && cfg.getiConomy() != null
          && (type == Material.SIGN_POST || type == Material.SIGN || type == Material.WALL_SIGN)) {
        BlockState blockstate = block.getState();

        if (((Sign) blockstate).getLine(0).equalsIgnoreCase("[WorldGuard]")
            && ((Sign) blockstate).getLine(1).equalsIgnoreCase("For sale")) {
          String regionId = ((Sign) blockstate).getLine(2);
          // String regionComment = ((Sign)block).getLine(3);

          if (regionId != null && regionId != "") {
            RegionManager mgr =
                cfg.getWorldGuardPlugin()
                    .getGlobalRegionManager()
                    .getRegionManager(player.getWorld().getName());
            ProtectedRegion region = mgr.getRegion(regionId);

            if (region != null) {
              RegionFlagContainer flags = region.getFlags();

              if (flags.getBooleanFlag(Flags.BUYABLE).getValue(false)) {
                if (iConomy.getBank().hasAccount(player.getName())) {
                  Account account = iConomy.getBank().getAccount(player.getName());
                  double balance = account.getBalance();
                  double regionPrice = flags.getDoubleFlag(Flags.PRICE).getValue();

                  if (balance >= regionPrice) {
                    account.subtract(regionPrice);
                    player.sendMessage(
                        ChatColor.YELLOW
                            + "You have bought the region "
                            + regionId
                            + " for "
                            + iConomy.getBank().format(regionPrice));
                    DefaultDomain owners = region.getOwners();
                    owners.addPlayer(player.getName());
                    region.setOwners(owners);
                    flags.getBooleanFlag(Flags.BUYABLE).setValue(false);
                    account.save();
                  } else {
                    player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
                  }
                } else {
                  player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
                }
              } else {
                player.sendMessage(ChatColor.RED + "Region: " + regionId + " is not buyable");
              }
            } else {
              player.sendMessage(
                  ChatColor.DARK_RED + "The region " + regionId + " does not exist.");
            }
          } else {
            player.sendMessage(ChatColor.DARK_RED + "No region specified.");
          }
        }
      }

      if (wcfg.getBlacklist() != null) {

        if (!wcfg.getBlacklist()
            .check(
                new BlockInteractBlacklistEvent(
                    BukkitPlayer.wrapPlayer(plugin, player), toVector(block), block.getTypeId()),
                false,
                false)) {
          event.setCancelled(true);
          return;
        }
      }
    }
  }
 @EventHandler
 public void playerInteract(PlayerInteractEvent event) {
   if (event.isCancelled()) {
     return;
   }
   Player player = event.getPlayer();
   if (player.hasPermission(BannerEditorCommand.PERMISSION)
       && player.getItemInHand().getType().equals(Material.STICK)) {
     BlockState state = event.getClickedBlock().getState();
     if (state instanceof Banner) {
       Banner banner = (Banner) state;
       BannerEditorConfig config = BannerEditorCommand.getPlayerConfig(event.getPlayer());
       BannerEditorMode mode = config.getEditorMode();
       int patternId = config.getPatternId();
       switch (mode) {
         case LIST:
           sendBannerInfoMessage(player, banner);
           break;
         case TEXTURE:
           if (patternId > 0 && patternId <= banner.numberOfPatterns()) {
             banner.setPattern(
                 patternId - 1,
                 new Pattern(
                     banner.getPattern(patternId - 1).getColor(),
                     (PatternType)
                         cycle(banner.getPattern(patternId - 1).getPattern(), event.getAction())));
             banner.update(true, false);
           } else if (patternId == 0) {
             sendNoPattern(player);
           } else {
             sendInvalidPatternId(player, patternId);
           }
           break;
         case COLOR:
           if (patternId > 0 && patternId <= banner.numberOfPatterns()) {
             banner.setPattern(
                 patternId - 1,
                 new Pattern(
                     (DyeColor)
                         cycle(banner.getPattern(patternId - 1).getColor(), event.getAction()),
                     banner.getPattern(patternId - 1).getPattern()));
             banner.update(true, false);
           } else if (patternId == 0) {
             banner.setBaseColor((DyeColor) cycle(banner.getBaseColor(), event.getAction()));
             banner.update(true, false);
           } else {
             sendInvalidPatternId(player, patternId);
           }
           break;
         case ADD:
           banner.addPattern(new Pattern(DyeColor.WHITE, PatternType.CIRCLE_MIDDLE));
           banner.update(true, false);
           break;
         case REMOVE:
           if (patternId > 0 && patternId <= banner.numberOfPatterns()) {
             Pattern pat = banner.removePattern(patternId - 1);
             banner.update(true, false);
           } else if (patternId == 0) {
             sendBaseNoPattern(player);
           } else {
             sendInvalidPatternId(player, patternId);
           }
           break;
         case GET:
           ItemStack item = new ItemStack(Material.BANNER);
           BannerMeta meta = (BannerMeta) item.getItemMeta();
           meta.setBaseColor(banner.getBaseColor());
           for (Pattern pattern : banner.getPatterns()) {
             meta.addPattern(pattern);
           }
           item.setItemMeta(meta);
           int amount = item.getMaxStackSize();
           item.setAmount(amount);
           player.getInventory().addItem(item);
           sendGotBanner(player, amount);
       }
       event.setCancelled(true);
     }
   }
 }