Restricting teleportation to one area

Discussion in 'Spigot Plugin Help' started by sylvain, Jan 7, 2020.

  1. Hi !

    I didn't really know where to ask that question, so there you go.
    I was wondering if it was possible to restrict a teleport if the player has a certain item in the inventory / If one of these items has a certain enchantment example sharpness 6.

    If there is a plugin that already allows you to block this, I would appreciate a link to it.
     
  2. FrostedSnowman

    Resource Staff

    It appears you’re looking for a certain plugin rather than needing help in creating one. The correct section for your thread Spigot Plugin Help.

    I’ve gone ahead and reported the thread so a moderator can move it accordingly :)
     
  3. Either way, I'm fine with both. ^^
    The plugin is an easy solution, but in case I'm told how to do it, even though I suppose it has to go through the same mechanics as a testfor, I'd be fine with it as well.
    Anyway, thank you ^^
     
  4. Code (Java):
      private final Set<Predicate<Player>> teleportRestrictions;

      @EventHandler
      public void onTeleport(PlayerTeleportEvent event) {
        for (Predicate<Player> restriction : teleportRestrictions) {
          if (!restriction.test(player)) {
            event.setCancelled(true);
            return;
          }
        }
      }

    You can also have per player restrictions with a Map<UUID, Predicate<Player>>
     
    • Friendly Friendly x 1
  5. Thx so much !
     
  6. Just in case. Thats how you add something to the set:

    Code (Java):
    teleportRestrictions.add((pl) -> {
          if (pl.getInventory().contains(Material.DIAMOND_BLOCK)) {
            return false;
          }
          return true;
        });
    Code (Java):

    teleportRestrictions.add((pl) -> !pl.getInventory().contains(Material.DIAMOND_BLOCK));
     

    Now he cant tp with a diamond block in its inv