public boolean isProtected(World var1, Position var2, EntityHuman var3) {
   if (var1.worldProvider.getDimensionId() != 0) {
     return false;
   } else if (this.getDedicatedPlayerList().getOpList().isEmpty()) {
     return false;
   } else if (this.getDedicatedPlayerList().isOp(var3.getGameProfile())) {
     return false;
   } else if (this.isSpawnProtectionEnabled() <= 0) {
     return false;
   } else {
     Position var4 = var1.getSpawnPosition();
     int var5 = MathHelper.a(var2.getX() - var4.getX());
     int var6 = MathHelper.a(var2.getZ() - var4.getZ());
     int var7 = Math.max(var5, var6);
     return var7 <= this.isSpawnProtectionEnabled();
   }
 }
示例#2
0
    public void c() {
      if (this.f) {
        double d0 = this.b - this.g.s;
        double d1 = this.c - this.g.t;
        double d2 = this.d - this.g.u;
        double d3 = d0 * d0 + d1 * d1 + d2 * d2;

        if (this.h-- <= 0) {
          this.h += this.g.bb().nextInt(5) + 2;
          d3 = (double) MathHelper.a(d3);
          if (this.b(this.b, this.c, this.d, d3)) {
            this.g.v += d0 / d3 * 0.1D;
            this.g.w += d1 / d3 * 0.1D;
            this.g.x += d2 / d3 * 0.1D;
          } else {
            this.f = false;
          }
        }
      }
    }
示例#3
0
  protected void a(Entity entity, float f1) {
    if (f1 < 10.0F) {
      double d1 = entity.p - this.p;
      double d2 = entity.r - this.r;

      if (this.bf == 0) {
        EntityArrow entityarrow = new EntityArrow(this.l, this);

        ++entityarrow.q;
        double d3 = entity.q - 0.20000000298023224D - entityarrow.q;
        float f2 = MathHelper.a(d1 * d1 + d2 * d2) * 0.2F;

        this.l.a(this, "random.bow", 1.0F, 1.0F / (this.W.nextFloat() * 0.4F + 0.8F));
        this.l.a((Entity) entityarrow);
        entityarrow.a(d1, d3 + (double) f2, d2, 0.6F, 12.0F);
        this.bf = 30;
      }

      this.v = (float) (Math.atan2(d2, d1) * 180.0D / 3.1415927410125732D) - 90.0F;
      this.e = true;
    }
  }
示例#4
0
  /**
   * WASD Control.
   *
   * @param sideMot
   * @param forMot
   */
  @Override
  public void g(float sideMot, float forMot) {
    if (!CustomEntities.customEntities.contains(this)) {
      super.g(sideMot, forMot);
      return;
    }
    if (getSize() != 3) setSize(3);
    if (this.passenger != null
        && this.passenger instanceof EntityHuman
        && CustomEntities.customEntities.contains(this)) {
      this.lastYaw = this.yaw = this.passenger.yaw;
      this.pitch = this.passenger.pitch * 0.5F;
      this.setYawPitch(this.yaw, this.pitch); // Update the pitch and yaw
      this.aI = this.aG = this.yaw;
      sideMot = ((EntityLiving) this.passenger).aZ * 0.5F;
      forMot = ((EntityLiving) this.passenger).ba;

      Field jump = null; // Jumping
      try {
        jump = EntityLiving.class.getDeclaredField("aY");
      } catch (NoSuchFieldException | SecurityException e1) {
        e1.printStackTrace();
      }
      jump.setAccessible(true);

      if (jump != null && BlockUtils.isOnGround(this.getBukkitEntity())) {
        try {
          if (jump.getBoolean(this.passenger)) {
            double jumpHeight = 0.3D;
            this.motY = jumpHeight;
          }
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        }
      }

      this.S = 1.0F;
      this.aK = this.yaw;
      if (!this.world.isClientSide) {
        this.k(0.2f);

        if (bM()) {
          if (V()) {
            double d0 = locY;
            float f3 = 0.8F;
            float f4 = 0.02F;
            float f2 = EnchantmentManager.b(this);
            if (f2 > 3.0F) {
              f2 = 3.0F;
            }

            if (f2 > 0.0F) {
              f3 += (0.5460001F - f3) * f2 / 3.0F;
              f4 += (bI() * 1.0F - f4) * f2 / 3.0F;
            }

            a(sideMot, forMot, f4);
            move(motX, motY, motZ);
            motX *= f3;
            motY *= 0.800000011920929D;
            motZ *= f3;
            motY -= 0.02D;
            if ((positionChanged) && (c(motX, motY + 0.6000000238418579D - locY + d0, motZ)))
              motY = 0.300000011920929D;
          } else if (ab()) {
            double d0 = locY;
            a(sideMot, forMot, 0.02F);
            move(motX, motY, motZ);
            motX *= 0.5D;
            motY *= 0.5D;
            motZ *= 0.5D;
            motY -= 0.02D;
            if ((positionChanged) && (c(motX, motY + 0.6000000238418579D - locY + d0, motZ)))
              motY = 0.300000011920929D;
          } else {
            float f5 =
                world
                        .getType(
                            new BlockPosition(
                                MathHelper.floor(locX),
                                MathHelper.floor(getBoundingBox().b) - 1,
                                MathHelper.floor(locZ)))
                        .getBlock()
                        .frictionFactor
                    * 0.91F;

            float f6 = 0.1627714F / (f5 * f5 * f5);
            float f3 = bI() * f6;

            a(sideMot, forMot, f3);
            f5 =
                world
                        .getType(
                            new BlockPosition(
                                MathHelper.floor(locX),
                                MathHelper.floor(getBoundingBox().b) - 1,
                                MathHelper.floor(locZ)))
                        .getBlock()
                        .frictionFactor
                    * 0.91F;

            if (k_()) {
              float f4 = 0.15F;
              motX = MathHelper.a(motX, -f4, f4);
              motZ = MathHelper.a(motZ, -f4, f4);
              fallDistance = 0.0F;
              if (motY < -0.15D) {
                motY = -0.15D;
              }

              if (motY < 0.0D) {
                motY = 0.0D;
              }
            }

            move(motX, motY, motZ);
            if ((positionChanged) && (k_())) {
              motY = 0.2D;
            }

            if ((world.isClientSide)
                && ((!world.isLoaded(new BlockPosition((int) locX, 0, (int) locZ)))
                    || (!world
                        .getChunkAtWorldCoords(new BlockPosition((int) locX, 0, (int) locZ))
                        .o()))) {
              if (locY > 0.0D) motY = -0.1D;
              else motY = 0.0D;
            } else {
              motY += 0D;
            }

            motY *= 0.9800000190734863D;
            motX *= f5;
            motZ *= f5;
          }
        }

        ay = az;
        double d0 = locX - lastX;
        double d1 = locZ - lastZ;

        float f2 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
        if (f2 > 1.0F) {
          f2 = 1.0F;
        }

        az += (f2 - az) * 0.4F;
        aA += az;

        super.g(sideMot, forMot);
      }

      this.ay = this.az;
      double d0 = this.locX - this.lastX;
      double d1 = this.locZ - this.lastZ;
      float f4 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
      if (f4 > 1.0F) {
        f4 = 1.0F;
      }

      this.az += (f4 - this.az) * 0.4F;
      this.aA += this.az;
    } else {
      this.S = 0.5F;
      this.aK = 0.02F;
      super.g(sideMot, forMot);
    }
  }
  protected boolean startServer() throws UnknownHostException {
    ServerConsoleReader reader = new ServerConsoleReader(this, "Server console handler");
    reader.setDaemon(true);
    reader.start();
    logger.info("Starting minecraft server version 1.8");
    if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L) {
      logger.warn(
          "To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\"");
    }

    logger.info("Loading properties");
    this.serverProperties = new ServerProperties(new File("server.properties"));
    this.tehDramaDocument = new EulaAgreementChecker(new File("eula.txt"));
    if (!this.tehDramaDocument.isAgreed()) {
      logger.info(
          "You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
      this.tehDramaDocument.write();
      return false;
    } else {
      this.setOnlineMode(this.serverProperties.getBoolean("online-mode", true));
      this.setIp(this.serverProperties.getString("server-ip", ""));

      this.setAnimalSpawnEnabled(this.serverProperties.getBoolean("spawn-animals", true));
      this.setNPCSpawnEnabled(this.serverProperties.getBoolean("spawn-npcs", true));
      this.setPVP(this.serverProperties.getBoolean("pvp", true));
      this.setAllowFlight(this.serverProperties.getBoolean("allow-flight", false));
      this.setResourcePack(
          this.serverProperties.getString("resource-pack", ""),
          this.serverProperties.getString("resource-pack-hash", ""));
      this.setMotd(this.serverProperties.getString("motd", "A Minecraft Server"));
      this.setForceGameModeEnabled(this.serverProperties.getBoolean("force-gamemode", false));
      this.setIdleTimeout(this.serverProperties.getInt("player-idle-timeout", 0));
      if (this.serverProperties.getInt("difficulty", 1) < 0) {
        this.serverProperties.setProperty("difficulty", Integer.valueOf(0));
      } else if (this.serverProperties.getInt("difficulty", 1) > 3) {
        this.serverProperties.setProperty("difficulty", Integer.valueOf(3));
      }

      this.generateStructures = this.serverProperties.getBoolean("generate-structures", true);
      int gameMode = this.serverProperties.getInt("gamemode", EnumGameMode.SURVIVAL.getId());
      this.serverGameMode = EnumGameMode.getById(gameMode);
      logger.info("Default game type: " + this.serverGameMode);
      InetAddress address = null;
      if (this.getIp().length() > 0) {
        address = InetAddress.getByName(this.getIp());
      }

      if (this.getPort() < 0) {
        this.setPort(this.serverProperties.getInt("server-port", 25565));
      }

      logger.info("Generating keypair");
      this.setKeyPair(ServerCryptoUtils.generateKeyPair());
      logger.info(
          "Starting Minecraft server on "
              + (this.getIp().length() == 0 ? "*" : this.getIp())
              + ":"
              + this.getPort());

      try {
        this.getServerConnection().bindToPort(address, this.getPort());
      } catch (Exception ex) {
        logger.warn("**** FAILED TO BIND TO PORT!");
        logger.warn("The exception was: {}", new Object[] {ex.toString()});
        logger.warn("Perhaps a server is already running on that port?");
        return false;
      }

      if (!this.isOnlineMode()) {
        logger.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
        logger.warn("The server will make no attempt to authenticate usernames. Beware.");
        logger.warn(
            "While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.");
        logger.warn(
            "To change this, set \"online-mode\" to \"true\" in the server.properties file.");
      }

      if (this.convertDataLists()) {
        this.getUserCache().dumpCache();
      }

      if (!sf.a(this.serverProperties)) {
        return false;
      } else {
        this.setPlayerList(new DedicatedPlayerList(this));
        long nanoTime = System.nanoTime();
        if (this.getLevelName() == null) {
          this.setLevelName(this.serverProperties.getString("level-name", "world"));
        }

        String seed = this.serverProperties.getString("level-seed", "");
        String type = this.serverProperties.getString("level-type", "DEFAULT");
        String gensettings = this.serverProperties.getString("generator-settings", "");
        long randomLong = (new Random()).nextLong();
        if (seed.length() > 0) {
          try {
            long longSeed = Long.parseLong(seed);
            if (longSeed != 0L) {
              randomLong = longSeed;
            }
          } catch (NumberFormatException var16) {
            randomLong = seed.hashCode();
          }
        }

        LevelType var18 = LevelType.getByName(type);
        if (var18 == null) {
          var18 = LevelType.DEFAULT;
        }

        this.isAnnouncePlayerAchievmentsEnabled();
        this.isCommandBlockEnabled();
        this.getOpPermissionLevel();
        this.isSnooperEnabled();
        this.getCompressionThreshold();
        this.setMaxBuildHeight(this.serverProperties.getInt("max-build-height", 256));
        this.setMaxBuildHeight((this.getMaxBuildHeight() + 8) / 16 * 16);
        this.setMaxBuildHeight(MathHelper.a(this.getMaxBuildHeight(), 64, 256));
        this.serverProperties.setProperty(
            "max-build-height", (Object) Integer.valueOf(this.getMaxBuildHeight()));

        logger.info("Preparing level \"" + this.getLevelName() + "\"");
        this.loadWorlds(this.getLevelName(), randomLong, var18, gensettings);
        long var12 = System.nanoTime() - nanoTime;
        String var14 =
            String.format("%.3fs", new Object[] {Double.valueOf((double) var12 / 1.0E9D)});
        logger.info("Done (" + var14 + ")! For help, type \"help\" or \"?\"");

        if (this.serverProperties.getBoolean("enable-query", false)) {
          logger.info("Starting GS4 status listener");
          this.query = new QueryListener(this);
          this.query.a();
        }

        if (this.serverProperties.getBoolean("enable-rcon", false)) {
          logger.info("Starting remote control listener");
          this.rcon = new RconListener(this);
          this.rcon.a();
        }

        if (this.getMaxTickTime() > 0L) {
          Thread watchdog = new Thread(new ServerWatchdog(this));
          watchdog.setName("Server Watchdog");
          watchdog.setDaemon(true);
          watchdog.start();
        }

        return true;
      }
    }
  }