Ejemplo n.º 1
0
  public static void makeBankRefund(ICommandSender sender, Town town, int amount) {
    if (amount == 0) return;

    town.bank.addAmount(amount);
    getDatasource().saveTownBank(town.bank);
    sendMessageBackToSender(
        sender,
        MyTown.instance.LOCAL.getLocalization(
            "mytown.notification.town.refund", EconomyProxy.getCurrency(amount)));
  }
Ejemplo n.º 2
0
  public static void makeBankPayment(ICommandSender sender, Town town, int amount) {
    if (amount == 0) return;

    if (town.bank.getAmount() < amount)
      throw new MyTownCommandException(
          "mytown.cmd.err.town.payment", EconomyProxy.getCurrency(amount));

    town.bank.addAmount(-amount);
    getDatasource().saveTownBank(town.bank);
    sendMessageBackToSender(
        sender,
        MyTown.instance.LOCAL.getLocalization(
            "mytown.notification.town.payment", EconomyProxy.getCurrency(amount)));
  }
Ejemplo n.º 3
0
  public static void check(EntityPlayerMP player) {
    Town town =
        MyTownUtils.getTownAtPosition(
            player.dimension,
            (int) Math.floor(player.posX) >> 4,
            (int) Math.floor(player.posZ) >> 4);
    Resident res = MyTownUniverse.instance.getOrMakeResident(player);
    EntityPos lastTickPos = lastTickPlayerPos.get(player);

    if (res == null) {
      return;
    }

    if (!ProtectionManager.hasPermission(
        res,
        FlagType.ENTER,
        player.dimension,
        (int) Math.floor(player.posX),
        (int) Math.floor(player.posY),
        (int) Math.floor(player.posZ))) {
      if (lastTickPos == null) {
        res.knockbackPlayerToBorder(town);
      } else if (lastTickPos.getX() != player.posX
          || lastTickPos.getY() != player.posY
          || lastTickPos.getZ() != player.posZ
          || lastTickPos.getDim() != player.dimension) {
        PlayerUtils.teleport(
            player,
            lastTickPos.getDim(),
            lastTickPos.getX(),
            lastTickPos.getY(),
            lastTickPos.getZ());
      }
    } else {
      // TODO: Refactor so that it's understandable
      if (lastTickPos != null
          && (((int) Math.floor(lastTickPos.getX())) >> 4 != (int) (Math.floor(player.posX)) >> 4
              || ((int) Math.floor(lastTickPos.getZ())) >> 4
                  != (int) (Math.floor(player.posZ)) >> 4)) {
        if (lastTickPos.getDim() == player.dimension) {
          res.checkLocation(
              ((int) Math.floor(lastTickPos.getX())) >> 4,
              ((int) Math.floor(lastTickPos.getZ())) >> 4,
              ((int) Math.floor(player.posX)) >> 4,
              ((int) (Math.floor(player.posZ))) >> 4,
              player.dimension);
        } else {
          res.checkLocationOnDimensionChanged(
              (int) (Math.floor(player.posX)), (int) (Math.floor(player.posZ)), player.dimension);
        }
      }

      if (lastTickPos != null && town != null) {
        Plot currentPlot =
            town.plotsContainer.get(
                player.dimension,
                (int) Math.floor(player.posX),
                (int) Math.floor(player.posY),
                (int) Math.floor(player.posZ));
        Plot lastTickPlot =
            town.plotsContainer.get(
                lastTickPos.getDim(),
                (int) Math.floor(lastTickPos.getX()),
                (int) Math.floor(lastTickPos.getY()),
                (int) Math.floor(lastTickPos.getZ()));

        if (currentPlot != null && (lastTickPlot == null || currentPlot != lastTickPlot)) {
          res.sendMessage(
              MyTown.instance.LOCAL.getLocalization(
                  "mytown.notification.plot.enter", currentPlot.getName()));
        } else if (currentPlot == null && lastTickPlot != null) {
          res.sendMessage(
              MyTown.instance.LOCAL.getLocalization(
                  "mytown.notification.plot.enter", EnumChatFormatting.RED + "Unassigned"));
        }
      }
      lastTickPlayerPos.put(
          player, new EntityPos(player.posX, player.posY, player.posZ, player.dimension));
    }
  }