예제 #1
0
 public static TownBlock getBlockAtResident(Resident res) {
   TownBlock block =
       getUniverse()
           .blocks
           .get(
               res.getPlayer().dimension,
               ((int) res.getPlayer().posX) >> 4,
               ((int) res.getPlayer().posZ >> 4));
   if (block == null)
     throw new MyTownCommandException(
         "mytown.cmd.err.claim.notexist", res.townsContainer.getMainTown().getName());
   return block;
 }
예제 #2
0
  /** Checking right click actions on blocks. */
  public boolean checkBlockInteraction(
      Resident res, BlockPos bp, PlayerInteractEvent.Action action) {
    Block blockType =
        DimensionManager.getWorld(bp.getDim()).getBlock(bp.getX(), bp.getY(), bp.getZ());
    for (SegmentBlock segment : segmentsBlocks) {
      if (segment.getCheckClass().isAssignableFrom(blockType.getClass())
          && (segment.getMeta() == -1
              || segment.getMeta()
                  == DimensionManager.getWorld(bp.getDim())
                      .getBlockMetadata(bp.getX(), bp.getY(), bp.getZ()))
          && (segment.getType() == BlockType.ANY_CLICK
              || segment.getType() == BlockType.RIGHT_CLICK
                  && action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK
              || segment.getType() == BlockType.LEFT_CLICK
                  && action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK)) {
        int dim = bp.getDim();
        int x = bp.getX();
        int y = bp.getY();
        int z = bp.getZ();

        if (!hasPermission(res, segment, dim, x, y, z)) {
          if (segment.hasClientUpdate())
            sendClientUpdate(
                segment.getClientUpdateCoords(), bp, (EntityPlayerMP) res.getPlayer(), null);
          return true;
        }
      }
    }

    return false;
  }
예제 #3
0
  @Command(
      name = "withdraw",
      permission = "mytown.cmd.assistant.bank.withdraw",
      parentName = "mytown.cmd.everyone.bank",
      syntax = "/town bank withdraw <amount>")
  public static CommandResponse bankWithdrawCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

    if (!StringUtils.tryParseInt(args.get(0)))
      throw new MyTownCommandException("mytown.cmd.err.notPositiveInteger", args.get(0));

    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);

    if (town instanceof AdminTown)
      throw new MyTownCommandException("mytown.cmd.err.adminTown", town.getName());

    int amount = Integer.parseInt(args.get(0));
    if (town.bank.getAmount() < amount)
      throw new MyTownCommandException(
          "mytown.cmd.err.bank.withdraw", EconomyProxy.getCurrency(town.bank.getAmount()));

    makeRefund(res.getPlayer(), amount);
    town.bank.addAmount(-amount);
    getDatasource().saveTownBank(town.bank);
    return CommandResponse.DONE;
  }
예제 #4
0
  /** Checking item usage for right click on air */
  public boolean checkItem(ItemStack item, Resident res) {
    for (Iterator<SegmentItem> it = segmentsItems.iterator(); it.hasNext(); ) {
      SegmentItem segment = it.next();
      if (segment.getType() == ItemType.RIGHT_CLICK_AIR
          && segment.getCheckClass().isAssignableFrom(item.getItem().getClass())) {
        EntityPlayer entity = res.getPlayer();

        try {
          if (segment.checkCondition(item)) {
            int range = segment.getRange(item);
            int dim = entity.dimension;
            int x = (int) Math.floor(entity.posX);
            int y = (int) Math.floor(entity.posY);
            int z = (int) Math.floor(entity.posZ);

            if (range == 0) {
              if (!hasPermission(res, segment, dim, x, y, z)) {
                return true;
              }
            } else {
              Volume rangeBox =
                  new Volume(x - range, y - range, z - range, x + range, y + range, z + range);
              if (!hasPermission(res, segment, dim, rangeBox)) {
                return true;
              }
            }
          }
        } catch (Exception ex) {
          MyTown.instance.LOG.error(
              "Failed to check item use on {} at the player {} ({}, {}, {} | Dim: {})",
              item.getDisplayName(),
              res.getPlayerName(),
              entity.posX,
              entity.posY,
              entity.posZ,
              entity.dimension);

          if (ex instanceof GetterException || ex instanceof ConditionException) {
            this.disableSegment(it, segment, ex.getMessage());
          }
        }
      }
    }
    return false;
  }
예제 #5
0
  /** Checking item usage for left or right click on block */
  public boolean checkItem(ItemStack item, ItemType type, Resident res, BlockPos bp, int face) {

    for (Iterator<SegmentItem> it = segmentsItems.iterator(); it.hasNext(); ) {
      SegmentItem segment = it.next();
      if (segment.getType() == type
          && segment.getCheckClass().isAssignableFrom(item.getItem().getClass())) {
        ForgeDirection direction = ForgeDirection.getOrientation(face);
        if (segment.isOnAdjacent()) {
          bp =
              new BlockPos(
                  bp.getX() + direction.offsetX,
                  bp.getY() + direction.offsetY,
                  bp.getZ() + direction.offsetZ,
                  bp.getDim());
        }
        if (!segment.isDirectionalClientUpdate()) {
          direction = null;
        }
        try {
          if (segment.checkCondition(item)) {
            int range = segment.getRange(item);
            int dim = bp.getDim();
            int x = bp.getX();
            int y = bp.getY();
            int z = bp.getZ();
            boolean isProtected;

            if (range == 0) {
              isProtected = !hasPermission(res, segment, dim, x, y, z);
            } else {
              Volume rangeBox =
                  new Volume(x - range, y - range, z - range, x + range, y + range, z + range);
              isProtected = !hasPermission(res, segment, dim, rangeBox);
            }

            if (isProtected) {
              if (segment.hasClientUpdate()) {
                sendClientUpdate(
                    segment.getClientUpdateCoords(),
                    bp,
                    (EntityPlayerMP) res.getPlayer(),
                    direction);
              }
              return true;
            }
          }
        } catch (Exception ex) {
          MyTown.instance.LOG.error(
              "Failed to check item use on {} at the player {} ({})",
              item.getDisplayName(),
              res.getPlayerName(),
              bp);
          MyTown.instance.LOG.error(ExceptionUtils.getStackTrace(ex));
          if (ex instanceof GetterException || ex instanceof ConditionException) {
            this.disableSegment(it, segment, ex.getMessage());
          }
        }
      }
    }
    return false;
  }
 public void hide(Resident caller) {
   if (caller.getPlayer() instanceof EntityPlayerMP)
     VisualsHandler.instance.unmarkBlocks((EntityPlayerMP) caller.getPlayer(), this);
 }
 public void show(Resident caller) {
   if (caller.getPlayer() instanceof EntityPlayerMP)
     VisualsHandler.instance.markTownBorders(this, (EntityPlayerMP) caller.getPlayer());
 }