Fixing hidePlayer

Discussion in 'Plugin Development' started by funkystudios, Sep 7, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    funkystudios

    I have made a plugin that runs "The Walls" with spectators. The spectators are invisible, not meant to interact with the terrain, or to harm players. Some issues with hidePlayer...
    • Projectiles are stopped when a spectator is in the way
    • Blocks cant be placed where a spectator is
    • Spectators can push players off a ledge (not tested)
    I think this could all be fixed by adding a check during PlayerMoveEvent by pushing a spectator away when a gamer is near them. How would I be able to do this without doing too many CPU intensive checks?
     
  2. Offline

    VoidWhisperer

    You could try something using PlayerVelocityEvent and check to see if a player is in the spot where the player previously was, to stop the pushing.
     
  3. Offline

    funkystudios

    Thanks for the help! That is one solution to a small part of the problem and doesn't seem very practical. The pushing isn't the biggest issue, mostly the block placement. Any other help?

    Perhaps, when a spectator is within 10 blocks of a gamer, push the spectator away from the gamer. Not sure how to accomplish this :/
     
  4. Offline

    Zidkon

  5. Offline

    libraryaddict

    I didn't have a fix for the player pushing, So heres my fix for the block placing.

    Code:
     @EventHandler(priority = EventPriority.LOWEST)
      public void onInteract(PlayerInteractEvent event) {
        Player p = event.getPlayer();
        if ((!spectate(p) || plugin.buildMode.contains(p.getName()))
            && !event.isCancelled()) {
          // Check for entity
          Location sLoc = event.getClickedBlock().getLocation();
          BlockFace blockFace = event.getBlockFace();
          sLoc.add(blockFace.getModX() + 0.5, blockFace.getModY() + 0.5,
              blockFace.getModZ() + 0.5);
          for (Player player : Bukkit.getOnlinePlayers()) {
            if (spectate(player)) {
              Location loc = player.getLocation();
              if (sLoc.getX() + 2 > loc.getX() && loc.getX() > sLoc.getX() - 2
                  && sLoc.getZ() + 2 > loc.getZ() && loc.getZ() > sLoc.getZ() - 2
                  && sLoc.getY() + 2 > loc.getY() && loc.getY() > sLoc.getY() - 2) {
                loc.setY(loc.getWorld().getHighestBlockYAt(loc) + 5);
                player.teleport(loc);
                player.setFlying(true);
                player.sendMessage(ChatColor.GREEN + "Stay away from gamers!");
              }
            }
          }
        }
      }
    This only works for invisible players.

    As for players standing in front of projectiles.

    In the end I just made them get banned from the rest of the game on contact.

    I maintain a server called "Archergames"

    If you want to see what I've done with it, Just google the name. You should be able to find it.
     
    Bone008 likes this.
Thread Status:
Not open for further replies.

Share This Page