Ejemplo n.º 1
0
 @Listener
 public void onPlayerDeath(DestructEntityEvent event) {
   if (event.getTargetEntity() instanceof Player) {
     Player died = (Player) event.getTargetEntity();
     Utils.setLastDeathLocation(died.getUniqueId(), died.getLocation());
   }
 }
Ejemplo n.º 2
0
 /**
  * Teleports the player to the farthest extent in the direction they exceeded.
  *
  * @param player The player.
  * @param originX The X origin for this Border.
  * @param limitX The upper or lower limit for X.
  * @param positive True for positive//upper (+2000) and False for negative//lower (-2000)
  */
 public void postXPosTele(Player player, int originX, int limitX, boolean positive) {
   int X = originX;
   if (positive) {
     X = (originX + limitX);
   } else {
     X = (originX - limitX);
   }
   int Z = player.getLocation().getBlockZ();
   int Y = player.getLocation().getBlockY();
   Teleport(player, X, Y, Z);
   return;
 }
Ejemplo n.º 3
0
  /**
   * Teleports the player to the farthest extent in the direction they exceeded.
   *
   * @param player The player.
   * @param originZ The Z origin for this Border.
   * @param limitZ The upper or lower limit for Z.
   * @param positive True for positive//upper (+2000) and False for negative//lower (-2000)
   */
  public void postZPosTele(Player player, int originZ, int limitZ, boolean positive) {
    int Z = originZ;
    if (positive) {
      Z = (originZ + limitZ);
    } else {
      Z = (originZ - limitZ);
    }

    int X = player.getLocation().getBlockX();
    int Y = player.getLocation().getBlockY();
    Teleport(player, X, Y, Z);
    return;
  }
Ejemplo n.º 4
0
  @Listener
  public void onDamageEntity(final DamageEntityEvent event) {
    if (!(event.getTargetEntity() instanceof Player)) {
      return;
    }

    Optional<EntityDamageSource> optionalSource = event.getCause().first(EntityDamageSource.class);
    if (!optionalSource.isPresent()) {
      return;
    }

    Player attacker = null;

    if (optionalSource.get().getSource() instanceof Player) {
      attacker = (Player) optionalSource.get().getSource();
    } else if (optionalSource.get() instanceof IndirectEntityDamageSource) {
      Entity source = ((IndirectEntityDamageSource) optionalSource.get()).getIndirectSource();
      if (source instanceof Player) {
        attacker = (Player) source;
      }
    }

    if (attacker == null) {
      return;
    }

    Player victim = (Player) event.getTargetEntity();

    List<Zone> zones = SafeGuard.getZoneManager().getZones(victim.getLocation());
    if (zones.isEmpty()) {
      return;
    }

    for (Zone zone : zones) {
      if (!zone.allows(attacker, pvpFlag)) {
        attacker.sendMessage(Format.error("Victim is protected from damage by a zone."));
        event.setCancelled(true);
        break;
      }
    }
  }
  public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
    Optional<Player> optionalTarget = ctx.<Player>getOne("player");

    if (!optionalTarget.isPresent()) {
      if (src instanceof Player) {
        Player player = (Player) src;
        BlockRay<World> playerBlockRay = BlockRay.from(player).blockLimit(350).build();

        Location<World> spawnLocation = null;
        int i = 0;

        while (playerBlockRay.hasNext()) {
          // TODO: Come up with a better way of making sure it doesn't hit the player.
          i++;

          BlockRayHit<World> currentHitRay = playerBlockRay.next();

          if (i > 5) {
            // We can set the spawn location, so break here.
            spawnLocation = currentHitRay.getLocation();
            break;
          }
        }

        Vector3d velocity = player.getTransform().getRotationAsQuaternion().getDirection();
        spawnEntity(spawnLocation, velocity, player);
        player.sendMessage(
            Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Created Fireball!"));
      } else if (src instanceof ConsoleSource) {
        src.sendMessage(
            Text.of(
                TextColors.DARK_RED,
                "Error! ",
                TextColors.RED,
                "Must be an in-game player to use /fireball!"));
      } else if (src instanceof CommandBlockSource) {
        src.sendMessage(
            Text.of(
                TextColors.DARK_RED,
                "Error! ",
                TextColors.RED,
                "Must be an in-game player to use /fireball!"));
      }
    } else {
      Player player = optionalTarget.get();
      Location<World> playerLocation = player.getLocation();

      Vector3d velocity = player.getTransform().getRotationAsQuaternion().getDirection();
      spawnEntity(playerLocation, velocity, src);
      player.sendMessage(
          Text.of(
              TextColors.GRAY, src.getName(), TextColors.GOLD, " has struck you with a fireball."));
      src.sendMessage(
          Text.of(
              TextColors.GREEN,
              "Success! ",
              TextColors.YELLOW,
              "Struck " + player.getName() + " with fireball."));
    }

    return CommandResult.success();
  }
Ejemplo n.º 6
0
  @Override
  public CommandResult process(CommandSource sender, String arguments) throws CommandException {

    String[] args = arguments.split(" ");

    if (!PermissionsUtils.has(sender, "core.tp")) {
      sender.sendMessage(
          Texts.builder("You do not have permissions!").color(TextColors.RED).build());
      return CommandResult.success();
    }

    if (arguments.equalsIgnoreCase("")) {
      sender.sendMessage(
          Texts.of(TextColors.YELLOW, "Usage: ", TextColors.GRAY, "/tp <player> [target]"));
      return CommandResult.success();
    }
    if (args.length < 1 || args.length > 2) {
      sender.sendMessage(
          Texts.of(TextColors.YELLOW, "Usage: ", TextColors.GRAY, "/tp <player> [target]"));
      return CommandResult.success();
    }

    Player player = null;
    Player target = null;

    if (args.length == 1) {

      if (sender instanceof Player == false) {
        sender.sendMessage(
            Texts.builder("Cannot be run by the console!").color(TextColors.RED).build());
        return CommandResult.success();
      }

      player = (Player) sender;
      target = ServerUtils.getPlayer(args[0]);

    } else if (args.length == 2) {

      if (!PermissionsUtils.has(sender, "core.tp-others")) {
        sender.sendMessage(
            Texts.builder("You do not have permissions to teleport others!")
                .color(TextColors.RED)
                .build());
        return CommandResult.success();
      }

      player = ServerUtils.getPlayer(args[0]);
      target = ServerUtils.getPlayer(args[1]);
    }

    if (player == null) {
      sender.sendMessage(Texts.builder("Player not found!").color(TextColors.RED).build());
      return CommandResult.success();
    }

    if (target == null) {
      sender.sendMessage(Texts.builder("Target not found!").color(TextColors.RED).build());
      return CommandResult.success();
    }

    player.setLocation(target.getLocation());

    if (args.length == 1) {

      sender.sendMessage(
          Texts.of(TextColors.GRAY, "Teleported to ", TextColors.YELLOW, target.getName()));

    } else if (args.length == 2) {

      sender.sendMessage(
          Texts.of(
              TextColors.GRAY,
              "Teleported ",
              TextColors.YELLOW,
              player.getName(),
              TextColors.GRAY,
              " to ",
              TextColors.YELLOW,
              target.getName()));
    }

    return CommandResult.success();
  }
  @Override
  public CommandResult execute(CommandSource src, CommandContext ctx) {
    Player player;
    try {
      player = GriefPrevention.checkPlayer(src);
    } catch (CommandException e) {
      src.sendMessage(e.getText());
      return CommandResult.success();
    }
    // which claim is being abandoned?
    PlayerData playerData =
        GriefPrevention.instance.dataStore.getOrCreatePlayerData(
            player.getWorld(), player.getUniqueId());
    Claim claim =
        GriefPrevention.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation(), true);
    UUID ownerId = claim.ownerID;
    if (claim.parent != null) {
      ownerId = claim.parent.ownerID;
    }
    if (claim.isWildernessClaim()) {
      GriefPrevention.sendMessage(player, TextMode.Instr, Messages.AbandonClaimMissing);
      return CommandResult.success();
    } else if (claim.allowEdit(player) != null
        || (!claim.isAdminClaim() && !player.getUniqueId().equals(ownerId))) {
      // verify ownership
      GriefPrevention.sendMessage(player, TextMode.Err, Messages.NotYourClaim);
      return CommandResult.success();
    }

    // warn if has children and we're not explicitly deleting a top level claim
    else if (claim.children.size() > 0 && !deleteTopLevelClaim) {
      GriefPrevention.sendMessage(player, TextMode.Instr, Messages.DeleteTopLevelClaim);
      return CommandResult.empty();
    } else {
      // delete it
      claim.removeSurfaceFluids(null);
      // remove all context permissions
      player.getSubjectData().clearPermissions(ImmutableSet.of(claim.getContext()));
      GriefPrevention.GLOBAL_SUBJECT
          .getSubjectData()
          .clearPermissions(ImmutableSet.of(claim.getContext()));
      GriefPrevention.instance.dataStore.deleteClaim(claim, true);

      // if in a creative mode world, restore the claim area
      if (GriefPrevention.instance.claimModeIsActive(
          claim.getLesserBoundaryCorner().getExtent().getProperties(), ClaimsMode.Creative)) {
        GriefPrevention.addLogEntry(
            player.getName()
                + " abandoned a claim @ "
                + GriefPrevention.getfriendlyLocationString(claim.getLesserBoundaryCorner()));
        GriefPrevention.sendMessage(player, TextMode.Warn, Messages.UnclaimCleanupWarning);
        GriefPrevention.instance.restoreClaim(claim, 20L * 60 * 2);
      }

      // this prevents blocks being gained without spending adjust claim blocks when abandoning a
      // top level claim
      if (!claim.isSubdivision() && !claim.isAdminClaim()) {
        int newAccruedClaimCount =
            playerData.getAccruedClaimBlocks()
                - ((int) Math.ceil(claim.getArea() * (1 - playerData.optionAbandonReturnRatio)));
        playerData.setAccruedClaimBlocks(newAccruedClaimCount);
      }

      // tell the player how many claim blocks he has left
      int remainingBlocks = playerData.getRemainingClaimBlocks();
      GriefPrevention.sendMessage(
          player, TextMode.Success, Messages.AbandonSuccess, String.valueOf(remainingBlocks));
      // revert any current visualization
      playerData.revertActiveVisual(player);
      playerData.warnedAboutMajorDeletion = false;
    }

    return CommandResult.success();
  }
Ejemplo n.º 8
0
  public CommandTicketCreate(CommandSource sender, String[] args) {

    if (sender instanceof Player == false) {
      sender.sendMessage(
          Texts.builder("Cannot be run by the console!").color(TextColors.RED).build());
      return;
    }

    if (args.length < 2) {
      sender.sendMessage(
          Texts.of(TextColors.YELLOW, "Usage: ", TextColors.GRAY, "/ticket create <message>"));
      return;
    }

    Player player = (Player) sender;
    String message = CommandUtils.combineArgs(1, args);

    int tickets = 0;
    for (Entry<Integer, CoreTicket> e : CoreDatabase.getTickets().entrySet()) {
      CoreTicket ticket = e.getValue();
      if (!ticket.getStatus().equalsIgnoreCase("open")) continue;
      if (!ticket.getUUID().equalsIgnoreCase(player.getUniqueId().toString())) continue;
      tickets += 1;
    }

    int possible = 0;
    for (int i = 1; i <= 100; i++) {
      if (PermissionsUtils.has(player, "core.ticket.create." + i)) possible = i;
    }

    if (!PermissionsUtils.has(player, "core.ticket.create-unlimited") && possible <= tickets) {
      if (possible == 1)
        sender.sendMessage(
            Texts.builder("You are only allowed to own " + possible + " open tickets!")
                .color(TextColors.RED)
                .build());
      else
        sender.sendMessage(
            Texts.builder("You are only allowed to own " + possible + " open tickets!")
                .color(TextColors.RED)
                .build());
      return;
    }

    int id = CoreDatabase.getTickets().size() + 1;

    String world = player.getWorld().getName();

    double x = player.getLocation().getX();
    double y = player.getLocation().getY();
    double z = player.getLocation().getZ();
    double yaw = player.getRotation().getX();
    double pitch = player.getRotation().getY();

    double time = System.currentTimeMillis();

    CoreTicket ticket =
        new CoreTicket(
            id,
            player.getUniqueId().toString(),
            message,
            time,
            new ArrayList<String>(),
            world,
            x,
            y,
            z,
            yaw,
            pitch,
            "",
            "medium",
            "open");
    ticket.insert();

    sender.sendMessage(
        Texts.of(
            TextColors.GRAY,
            "Ticket ",
            TextColors.GREEN,
            "#",
            id,
            TextColors.GRAY,
            " has been created!"));
  }
Ejemplo n.º 9
0
 /**
  * Teleport to the player to X, Y, Z coordinate.
  *
  * @param player The player.
  * @param x The desired X coordinate.
  * @param y The desired Y coordinate.
  * @param z The desired Z coordinate.
  */
 public void Teleport(Player player, int x, int y, int z) {
   player.setLocation(
       player
           .getLocation()
           .setPosition(new Vector3d(Double.valueOf(x), Double.valueOf(y), Double.valueOf(z))));
 }