/** Setup it so he can see himself when disguised */
 public static void setupFakeDisguise(final Disguise disguise) {
   Entity e = disguise.getEntity();
   // If the disguises entity is null, or the disguised entity isn't a player return
   if (e == null
       || !(e instanceof Player)
       || !getDisguises().containsKey(e.getUniqueId())
       || !getDisguises().get(e.getUniqueId()).contains(disguise)) {
     return;
   }
   Player player = (Player) e;
   // Check if he can even see this..
   if (!((TargetedDisguise) disguise).canSee(player)) {
     return;
   }
   // Remove the old disguise, else we have weird disguises around the place
   DisguiseUtilities.removeSelfDisguise(player);
   // If the disguised player can't see himself. Return
   if (!disguise.isSelfDisguiseVisible()
       || !PacketsManager.isViewDisguisesListenerEnabled()
       || player.getVehicle() != null) {
     return;
   }
   selfDisguised.add(player.getUniqueId());
   sendSelfDisguise(player, (TargetedDisguise) disguise);
   if (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()) {
     if (PacketsManager.isInventoryListenerEnabled()) {
       player.updateInventory();
     }
   }
 }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    Player targetPlayer = sender_p;

    if (args.length == 1) {

      targetPlayer = getPlayer(args[0]);

      if (targetPlayer == null) {
        sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
        return true;
      }
    }

    if (senderIsConsole) {
      if (targetPlayer == null) {
        sender.sendMessage(
            "When used from the console, you must define a target player: /cartsit <player>");
        return true;
      }
    } else if (targetPlayer != sender_p && !TFM_AdminList.isSuperAdmin(sender)) {
      sender.sendMessage("Only superadmins can select another player as a /cartsit target.");
      return true;
    }

    if (targetPlayer.isInsideVehicle()) {
      targetPlayer.getVehicle().eject();
    } else {
      Minecart nearest_cart = null;
      for (Minecart cart : targetPlayer.getWorld().getEntitiesByClass(Minecart.class)) {
        if (cart.isEmpty()) {
          if (nearest_cart == null) {
            nearest_cart = cart;
          } else {
            if (cart.getLocation().distanceSquared(targetPlayer.getLocation())
                < nearest_cart.getLocation().distanceSquared(targetPlayer.getLocation())) {
              nearest_cart = cart;
            }
          }
        }
      }

      if (nearest_cart != null) {
        nearest_cart.setPassenger(targetPlayer);
      } else {
        sender.sendMessage("There are no empty minecarts in the target world.");
      }
    }

    return true;
  }
示例#3
0
  public void enter(Player p1) {
    if (p1.getVehicle() == null) {
      p1.sendMessage(ChatColor.YELLOW + "Vous �tes entr� dans le training !");

      this.plugin.clearPlayer(p1);
      p1.getInventory().setItem(0, GameListener.soup);
      p1.getInventory().setHeldItemSlot(0);
      p1.getInventory().setItem(1, GameListener.vanilla1);
      p1.getInventory().setItem(2, GameListener.vanilla2);

      /** BLASTFIGHT ADD */
      p1.getInventory().setItem(4, GameListener.cheat);
      p1.getInventory().setItem(6, GameListener.soup2);
      p1.getInventory().setItem(7, GameListener.vanilla3);
      p1.getInventory().setItem(8, GameListener.vanilla4);
      p1.getInventory().setItem(3, GameListener.ranked);
      p1.getInventory().setItem(5, GameListener.rankedcheat);

      /** BLASTFIGHT ADD END */
      p1.teleport(this.plugin.getArena());
      p1.setHealth(20.0D);
      p1.setFoodLevel(20);

      ovo.add(p1.getName());

      Iterator<Duel> it = this.duels.iterator();
      while (it.hasNext()) {
        Duel d = (Duel) it.next();
        d.getPlayer1().hidePlayer(p1);
        d.getPlayer2().hidePlayer(p1);
      }
    } else {
      p1.sendMessage(
          ChatColor.RED
              + "Vous ne pouvez pas rejoindre en �tant sur un objets non identifi� "
              + p1.getVehicle().getType().toString().toLowerCase());
    }
  }
示例#4
0
 /**
  * Teleports a player to a location. Before teleporting the player is ejected if he uses any
  * vehicle, the warp-effect is played (if enabled) and chunks are loaded (if enabled and not
  * loaded before).
  *
  * @param player the player to teleport
  * @param to the location the player should be teleported to
  */
 private static void teleport(Player player, Location to) {
   Location from = player.getLocation();
   if (player.isInsideVehicle()) {
     player.getVehicle().eject();
   }
   if (WarpSettings.warpEffect) {
     from.getWorld().playEffect(from, Effect.SMOKE, 4);
     from.getWorld().playEffect(from, Effect.SMOKE, 4);
     from.getWorld().playEffect(from, Effect.SMOKE, 4);
   }
   if (WarpSettings.loadChunks && !to.getWorld().isChunkLoaded(to.getBlockX(), to.getBlockZ())) {
     to.getWorld().refreshChunk(to.getBlockX(), to.getBlockZ());
   }
   player.teleport(to);
 }
示例#5
0
  // set targetLoc only if not current player location; set returnLocationOnly to true to have new
  // Location returned if they need to be moved to one, instead of directly handling it
  public static Location checkPlayer(
      Player player, Location targetLoc, boolean returnLocationOnly) {
    if (player == null || !player.isOnline()) return null;

    Location loc = (targetLoc == null) ? player.getLocation() : targetLoc;
    if (loc == null) return null;

    World world = loc.getWorld();
    if (world == null) return null;
    BorderData border = Config.Border(world.getName());
    if (border == null) return null;

    if (border.insideBorder(loc.getX(), loc.getZ(), Config.ShapeRound())) return null;

    if (player.hasPermission("worldborder.ignoreborder")) return null;

    Location newLoc = newLocation(player, loc, border);

    if (Config
        .whooshEffect()) { // give some particle and sound effects where the player was beyond the
      // border
      world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
      world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
      world.playEffect(loc, Effect.SMOKE, 4);
      world.playEffect(loc, Effect.SMOKE, 4);
      world.playEffect(loc, Effect.SMOKE, 4);
      world.playEffect(loc, Effect.GHAST_SHOOT, 0);
    }

    if (returnLocationOnly) return newLoc;

    if (!player.isInsideVehicle()) player.teleport(newLoc);
    else {
      Vehicle ride = (Vehicle) player.getVehicle();
      if (ride != null) { // vehicles need to be offset vertically and have velocity stopped
        double vertOffset = ride.getLocation().getY() - loc.getY();
        newLoc.setY(newLoc.getY() + vertOffset);
        ride.setVelocity(new Vector(0, 0, 0));
        ride.teleport(newLoc);
      } else { // if player.getVehicle() returns null (when riding a pig on older Bukkit releases,
        // for instance), player has to be ejected
        player.leaveVehicle();
        player.teleport(newLoc);
      }
    }

    return null;
  }
示例#6
0
 /**
  * Intended for vehicle-move events.
  *
  * @param player
  * @param vehicle
  * @param from
  * @param to
  * @param fake true if the event was not fired by an external source (just gets noted).
  */
 public static void outputDebugVehicleMove(
     final Player player,
     final Entity vehicle,
     final Location from,
     final Location to,
     final boolean fake) {
   final StringBuilder builder = new StringBuilder(250);
   final Location vLoc = vehicle.getLocation();
   final Location loc = player.getLocation();
   // TODO: Differentiate debug levels (needs setting up some policy + document in
   // BuildParamteres)?
   final Entity actualVehicle = player.getVehicle();
   final boolean wrongVehicle =
       actualVehicle == null || actualVehicle.getEntityId() != vehicle.getEntityId();
   if (BuildParameters.debugLevel > 0) {
     builder.append(
         "\n-------------- VEHICLE MOVE " + (fake ? "(fake)" : "") + "--------------\n");
     builder.append(player.getName() + " " + from.getWorld().getName() + ":\n");
     addMove(from, to, null, builder);
     builder.append("\n Vehicle: ");
     addLocation(vLoc, builder);
     builder.append("\n Player: ");
     addLocation(loc, builder);
   } else {
     builder.append(
         player.getName()
             + " "
             + from.getWorld().getName()
             + "veh."
             + (fake ? "(fake)" : "")
             + " ");
     addFormattedMove(from, to, null, builder);
     builder.append("\n Vehicle: ");
     addFormattedLocation(vLoc, builder);
     builder.append(" Player: ");
     addFormattedLocation(loc, builder);
   }
   builder.append(
       "\n Vehicle type: "
           + vehicle.getType()
           + (wrongVehicle
               ? (actualVehicle == null ? " (exited?)" : " actual: " + actualVehicle.getType())
               : ""));
   NCPAPIProvider.getNoCheatPlusAPI()
       .getLogManager()
       .debug(Streams.TRACE_FILE, builder.toString());
 }
示例#7
0
  /**
   * Called on player movement.
   *
   * @param event Relevant event details
   */
  @EventHandler
  public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();

    if (player.getVehicle() != null) return; // handled in vehicle listener
    if (event.getFrom().getBlockX() != event.getTo().getBlockX()
        || event.getFrom().getBlockY() != event.getTo().getBlockY()
        || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {

      if (sessions.getAdminSession(player).isFrozen()) {

        player.sendMessage(ChatColor.RED + "You are frozen.");

        Location newLoc = event.getFrom();
        newLoc.setX(newLoc.getBlockX() + 0.5);
        newLoc.setY(newLoc.getBlockY());
        newLoc.setZ(newLoc.getBlockZ() + 0.5);
        event.setTo(newLoc);
      }
    }
  }
示例#8
0
  /**
   * Teleport a player to a location.
   *
   * @param player The player.
   * @param to The location to teleport to.
   * @param keepVehicle Whether or not to keep the vehicle.
   */
  public static void teleport(Player player, Location to, boolean keepVehicle) {
    if (to == null || player == null) return;

    if (player.isInsideVehicle()) {
      // Eject the vehicle...
      Entity vehicle = player.getVehicle();
      vehicle.eject();
      // Teleport the player...
      player.teleport(to);
      // Remove the vehicle if it's not persisting.
      if (!keepVehicle) vehicle.remove();
      else {
        // Otherwise teleport the vehicle and remount.
        vehicle.teleport(to);
        vehicle.setPassenger(player);
      }
      return;
    }

    player.teleport(to);
  }
示例#9
0
  private void makeItSo(Player player) {
    // start with the block shifted vertically from the player
    // to the destination sign's height (plus one).
    // check if this looks at all like something we're interested in first

    double toX = 0;
    double toY = 0;
    double toZ = 0;

    if (trigger.getState() instanceof Sign) {
      Sign s = (Sign) trigger.getState();
      String[] pos = s.getLine(2).split(":");
      if (pos.length > 2) {
        try {
          toX = Double.parseDouble(pos[0]);
          toY = Double.parseDouble(pos[1]);
          toZ = Double.parseDouble(pos[2]);
        } catch (Exception e) {
          return;
        }
      } else return;
    }

    Block floor =
        trigger
            .getWorld()
            .getBlockAt((int) Math.floor(toX), (int) (Math.floor(toY) + 1), (int) Math.floor(toZ));
    // well, unless that's already a ceiling.
    if (!occupiable(floor)) floor = floor.getRelative(BlockFace.DOWN);

    // now iterate down until we find enough open space to stand in
    // or until we're 5 blocks away, which we consider too far.
    int foundFree = 0;
    for (int i = 0; i < 5; i++) {
      if (occupiable(floor)) {
        foundFree++;
      } else {
        break;
      }
      if (floor.getY() == 0x0) // hit the bottom of the world
      break;
      floor = floor.getRelative(BlockFace.DOWN);
    }
    if (foundFree < 2) {
      player.sendMessage("mech.lift.obstruct");
      return;
    }

    // Teleport!
    Location subspaceRift = player.getLocation().clone();
    subspaceRift.setY(floor.getY() + 1);
    subspaceRift.setX(floor.getX());
    subspaceRift.setZ(floor.getZ());
    if (player.isInsideVehicle()) {
      subspaceRift = player.getVehicle().getLocation().clone();
      subspaceRift.setY(floor.getY() + 2);
      subspaceRift.setX(floor.getX());
      subspaceRift.setZ(floor.getZ());
      player.getVehicle().teleport(subspaceRift);
    }
    player.teleport(subspaceRift);

    player.sendMessage("mech.teleport.alert");
  }
示例#10
0
文件: Chairs.java 项目: uJisp/Server
 static void resitPlayer(Player player, Block block) {
   if (player.getVehicle() != null) player.getVehicle().remove();
   Location arrowLocation = block.getLocation().add(0.5, 0.2, 0.5);
   Arrow chairArrow = player.getWorld().spawnArrow(arrowLocation, new Vector(1, 0, 0), 1, 1);
   chairArrow.setPassenger(player);
 }
示例#11
0
文件: Chairs.java 项目: uJisp/Server
 public static boolean isSitting(Player player) {
   if (player.isOnline() && player.getVehicle() instanceof Arrow) return true;
   return false;
 }
示例#12
0
 @Override
 public Entity getVehicle() {
   // TODO Auto-generated method stub
   return caller.getVehicle();
 }
示例#13
0
  @Override
  public void execute(TeamAdvantage plugin, CommandSender sender, Player player, String[] args) {
    if (sender.hasPermission("teamadvantage.use")) {
      if (null != player) {
        TATeam teamOfPlayer = plugin.getTeamOfPlayer(player.getName());

        if (null != teamOfPlayer) {
          if (null != teamOfPlayer.getHome()) {
            if (checkIfTeleportDestinationIsSave(teamOfPlayer.getHome())) {
              // handle teleport with mount
              if (player.isInsideVehicle()) {
                if (player.getVehicle() instanceof Horse) {
                  Horse mount = (Horse) player.getVehicle();

                  if (mount.isTamed()
                      && (null
                          != mount
                              .getInventory()
                              .getSaddle())) // player may only warp with a tamed mount with a
                                             // saddle
                  {
                    // unmount player
                    boolean resUnmount = player.leaveVehicle();
                    // teleport horse and re-mount player (teleporting him in the proccess)
                    boolean resTele = mount.teleport(teamOfPlayer.getHome());
                    boolean resSetPassenger =
                        mount.setPassenger(player); // will teleport the player to the horses back

                    if (resUnmount && resTele && resSetPassenger) {
                      player.sendMessage(
                          "§a"
                              + "Willkommen beim Team-Home von "
                              + "§f"
                              + teamOfPlayer.getName()
                              + "§a"
                              + "!");
                    } else {
                      player.sendMessage("§4" + "Teleport fehlgeschlagen!");
                    }
                  } else {
                    player.sendMessage(
                        "§6"
                            + "Du kannst nur auf einem gezaehmten und besatteltem Reittier warpen!");
                  }
                } else {
                  player.sendMessage(
                      "§6" + "Du kannst nur auf einem gezaehmten und besatteltem Reittier warpen!");
                }
              } else {
                if (player.teleport(teamOfPlayer.getHome())) {
                  player.sendMessage(
                      "§a"
                          + "Willkommen beim Team-Home von "
                          + "§f"
                          + teamOfPlayer.getName()
                          + "§a"
                          + "!");
                } else {
                  player.sendMessage("§4" + "Warpen fehlgeschlagen!");
                }
              }
            } else {
              player.sendMessage(
                  "§6"
                      + "Der Home-Punkt ist moeglicherweise nicht sicher!\n"
                      + "Verwende 'home-force-to' um dennoch dorthin zu teleportieren.");
            }
          } else {
            player.sendMessage("§6" + "Es ist kein Home-Punkt fuer dein Team gesetzt!");
          }
        } else {
          player.sendMessage("§6" + "Du bist kein Mitglied eines Teams!");
        }
      } else {
        sender.sendMessage(TeamAdvantage.logPrefix + "Only players can use this command!");
      }
    }
  }
示例#14
0
  /** Sends the self disguise to the player */
  public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) {
    try {
      if (!disguise.isDisguiseInUse()
          || !player.isValid()
          || !player.isOnline()
          || !disguise.isSelfDisguiseVisible()
          || !disguise.canSee(player)) {
        return;
      }
      Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player);
      if (entityTrackerEntry == null) {
        // A check incase the tracker is null.
        // If it is, then this method will be run again in one tick. Which is when it should be
        // constructed.
        // Else its going to run in a infinite loop hue hue hue..
        // At least until this disguise is discarded
        Bukkit.getScheduler()
            .runTask(
                libsDisguises,
                new Runnable() {
                  public void run() {
                    if (DisguiseAPI.getDisguise(player, player) == disguise) {
                      sendSelfDisguise(player, disguise);
                    }
                  }
                });
        return;
      }
      // Add himself to his own entity tracker
      ((HashSet<Object>)
              ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
                  .get(entityTrackerEntry))
          .add(ReflectionManager.getNmsEntity(player));
      ProtocolManager manager = ProtocolLibrary.getProtocolManager();
      // Send the player a packet with himself being spawned
      manager.sendServerPacket(
          player,
          manager
              .createPacketConstructor(PacketType.Play.Server.NAMED_ENTITY_SPAWN, player)
              .createPacket(player));
      WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(player);
      sendSelfPacket(
          player,
          manager
              .createPacketConstructor(
                  PacketType.Play.Server.ENTITY_METADATA, player.getEntityId(), dataWatcher, true)
              .createPacket(player.getEntityId(), dataWatcher, true));

      boolean isMoving = false;
      try {
        Field field =
            ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("isMoving");
        field.setAccessible(true);
        isMoving = field.getBoolean(entityTrackerEntry);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
      // Send the velocity packets
      if (isMoving) {
        Vector velocity = player.getVelocity();
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.ENTITY_VELOCITY,
                    player.getEntityId(),
                    velocity.getX(),
                    velocity.getY(),
                    velocity.getZ())
                .createPacket(
                    player.getEntityId(), velocity.getX(), velocity.getY(), velocity.getZ()));
      }

      // Why the hell would he even need this. Meh.
      if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) {
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.ATTACH_ENTITY, 0, player, player.getVehicle())
                .createPacket(0, player, player.getVehicle()));
      } else if (player.getPassenger() != null
          && player.getEntityId() > player.getPassenger().getEntityId()) {
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.ATTACH_ENTITY, 0, player.getPassenger(), player)
                .createPacket(0, player.getPassenger(), player));
      }

      // Resend the armor
      for (int i = 0; i < 5; i++) {
        ItemStack item;
        if (i == 0) {
          item = player.getItemInHand();
        } else {
          item = player.getInventory().getArmorContents()[i - 1];
        }

        if (item != null && item.getType() != Material.AIR) {
          sendSelfPacket(
              player,
              manager
                  .createPacketConstructor(
                      PacketType.Play.Server.ENTITY_EQUIPMENT, player.getEntityId(), i, item)
                  .createPacket(player.getEntityId(), i, item));
        }
      }
      Location loc = player.getLocation();
      // If the disguised is sleeping for w/e reason
      if (player.isSleeping()) {
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.BED,
                    player,
                    loc.getBlockX(),
                    loc.getBlockY(),
                    loc.getBlockZ())
                .createPacket(player, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
      }

      // Resend any active potion effects
      for (Object potionEffect : player.getActivePotionEffects()) {
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.ENTITY_EFFECT, player.getEntityId(), potionEffect)
                .createPacket(player.getEntityId(), potionEffect));
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
示例#15
0
 public void switchUtil(Player player) {
   plugin.utility.message(ChatColor.BOLD + "Commencing swap!", player);
   if (player.getVehicle() != null) {
     player.leaveVehicle();
   }
 }