コード例 #1
0
  /**
   * Load and return all warps
   *
   * @return An ArrayList containing all loaded Warp instances.
   */
  public List<Warp> loadWarps() {
    List<Warp> warps = Lists.newArrayList();
    List<DataAccess> daos = Lists.newArrayList();
    boolean needsUpdate = false;

    try {
      Database.get().loadAll(schema, daos, new HashMap<String, Object>());
      for (DataAccess dao : daos) {
        WarpDataAccess data = (WarpDataAccess) dao;
        Group[] groups = makeGroupArray(data.groups);
        String owner = ToolBox.stringToNull(data.owner);
        String name = data.name;
        boolean playerHome = data.isPlayerHome;
        Location loc = null;
        if (((WarpDataAccess) dao).location.equals("N/A")) {
          loc = Location.fromDataAccess((LocationDataAccess) dao);
        } else {
          needsUpdate = true;
          loc = Location.fromString(data.location);
        }
        Warp warp;

        if (owner != null) {
          warp = new Warp(loc, name, owner, playerHome);
        } else if (groups != null && groups.length > 0) {
          warp = new Warp(loc, groups, name);
        } else {
          // assume this is a public warp
          warp = new Warp(loc, name);
        }
        warps.add(warp);
      }
    } catch (DatabaseReadException e) {
      log.error(e.getMessage(), e);
    }

    // Apply pending updates
    if (needsUpdate) {
      Canary.log.debug("Updating data for Warps...");
      for (Warp warp : warps) {
        this.updateWarp(warp);
      }
    }
    return warps;
  }
コード例 #2
0
  // Respawn player
  public OEntityPlayerMP a(OEntityPlayerMP var1, int var2, boolean var3, Location spawnLocation) {
    var1.getDimension().getEntityTracker().untrackPlayerSymmetrics(var1.getPlayer());
    var1.getDimension().getEntityTracker().untrackEntity(var1.getCanaryEntity());
    var1.getDimension().getPlayerManager().removePlayer(var1.getPlayer());
    this.b.remove(var1);
    var1.getDimension()
        .removePlayerFromWorld(var1.getPlayer()); // This calls the despawn method in world!

    OChunkCoordinates var4 = var1.ab();
    var1.w = var2; // Set new dimension
    CanaryWorld cworld = (CanaryWorld) var1.getDimension().getWorld();
    CanaryDimension dim = (CanaryDimension) cworld.getDimension(Type.fromId(var2));
    OEntityPlayerMP var5 =
        new OEntityPlayerMP(
            this.c, dim.getHandle(), var1.v, new OItemInWorldManager(dim.getHandle()));
    var5.w = var2;
    if (var3) {
      // copy player
      var5.c((OEntityPlayer) var1);
    }

    var5.bd = var1.bd;
    // Set NetServerHandler
    var5.a = var1.a;
    var5.setServerHandler(var5.a.getCanaryNetServerHandler());
    var5.a.setUser(var5.getPlayer());

    OWorldServer var6 = (OWorldServer) dim.getHandle();
    var5.c.a(var1.c.a());
    var5.c.b(var6.s().getGameMode());
    if (var4 != null) {
      OChunkCoordinates var7 =
          OEntityPlayer.a(((CanaryDimension) var1.getDimension()).getHandle(), var4);
      if (var7 != null) {
        var5.c((var7.a + 0.5F), (var7.b + 0.1F), (var7.c + 0.5F), 0.0F, 0.0F);
        var5.a(var4);
      } else {
        var5.a.b((new OPacket70Bed(0, 0)));
      }
    }

    // CanaryMod set player location and angle if a spawn location is defined
    if (spawnLocation != null) {
      var5.c(
          spawnLocation.getX(),
          spawnLocation.getY(),
          spawnLocation.getZ(),
          spawnLocation.getRotation(),
          spawnLocation.getPitch());
    }

    var6.G.c((int) var5.bm >> 4, (int) var5.bo >> 4);

    while (var6.a(var5, var5.bw).size()
        != 0) { // This is the checks for canSpawnHere  should we do something with this so players
      // don't end up on roofs?
      var5.c(var5.bm, var5.bn + 1.0D, var5.bo);
    }

    // respawn packet
    var5.a.b(
        (new OPacket9Respawn(
            var5.w, (byte) var5.bi.q, var5.bi.s().getWorldType(), var5.bi.y(), var5.c.a())));
    // teleport to spawn location
    var5.a.a(
        var5.bm,
        var5.bn,
        var5.bo,
        var5.bs,
        var5.bt,
        var5.w,
        var5.bi.getCanaryDimension().getName());
    // something
    this.a(var5, var6);
    var5.getDimension().getPlayerManager().addPlayer((Player) var5.getPlayer());
    var5.getDimension()
        .addPlayerToWorld(var5.getPlayer()); // This also calls the spawn method in world!
    this.b.add(var5);
    var5.x();
    var5.E();
    return var5;
  }
コード例 #3
0
  public void a(boolean var1) {
    super.F_();

    for (int var2 = 0; var2 < this.k.c(); ++var2) {
      OItemStack var3 = this.k.g_(var2);
      if (var3 != null && OItem.d[var3.c].t_() && this.a.b() <= 2) {
        OPacket var4 = ((OItemMapBase) OItem.d[var3.c]).c(var3, this.bi, this);
        if (var4 != null) {
          this.a.b(var4);
        }
      }
    }

    if (var1 && !this.f.isEmpty()) {
      OChunkCoordIntPair var14 = (OChunkCoordIntPair) this.f.get(0);
      double var5 = var14.a(this);

      for (int var7 = 0; var7 < this.f.size(); ++var7) {
        OChunkCoordIntPair var8 = (OChunkCoordIntPair) this.f.get(var7);
        double var9 = var8.a(this);
        if (var9 < var5) {
          var14 = var8;
          var5 = var9;
        }
      }

      if (var14 != null) {
        boolean var17 = false;
        if (this.a.b() < 4) {
          var17 = true;
        }

        if (var17) {
          OWorldServer var18 = (OWorldServer) getDimension().getHandle(); // this.b.a(this.w);
          if (var18.i(var14.a << 4, 0, var14.b << 4)) {
            OChunk var11 = var18.d(var14.a, var14.b);
            if (var11.k) {
              this.f.remove(var14);
              this.a.b((new OPacket51MapChunk(var18.d(var14.a, var14.b), true, 0)));
              List var12 =
                  var18.c(var14.a * 16, 0, var14.b * 16, var14.a * 16 + 16, 256, var14.b * 16 + 16);

              for (int var13 = 0; var13 < var12.size(); ++var13) {
                this.a((OTileEntity) var12.get(var13));
              }
            }
          }
        }
      }
    }

    if (this.J) {
      if (this.m != this.l) {
        this.F();
      }

      if (this.bh != null) {
        this.b(this.bh);
      } else {
        this.K += 0.0125F;
        if (this.K >= 1.0F) {
          this.K = 1.0F;
          this.I = 10;
          boolean var15 = false;
          byte var16;
          if (this.w == -1) {
            var16 = 0;
          } else {
            var16 = -1;
          }
          Location location = getPlayer().getLocation();
          int currDim = getPlayer().getDimension().getType().getId();
          location.setDimensionId(currDim == 0 ? -1 : 0);
          CancelableHook hook =
              (CancelableHook)
                  Canary.hooks().callCancelableHook(new TeleportHook(getPlayer(), location, true));
          if (!hook.isCanceled()) {
            this.b.h.switchDimension(this, var16, true);
            this.ci = -1;
            this.cf = -1;
            this.cg = -1;
            this.a(OAchievementList.x);
          }
        }
      }

      this.J = false;
    } else {
      if (this.K > 0.0F) {
        this.K -= 0.05F;
      }

      if (this.K < 0.0F) {
        this.K = 0.0F;
      }
    }

    if (this.I > 0) {
      --this.I;
    }

    if (this.ap != this.cf) {
      // Check if health is enabled
      if (!Configuration.getWorldConfig(bi.getCanaryDimension().getName()).isHealthEnabled()) {
        ap = 20;
        az = false;
      } else {
        // Call hook
        // CancelableHook hook = Canary.hooks().callCancelableHook(new HealthChangeHook());
        // if(hook.isCancelled){
        //  ap = cf;
        // }
      }
    }

    if (this.aD() != this.cf
        || this.cg != this.foodStats.getFoodLevel()
        || this.foodStats.getFoodSaturationLevel() == 0.0F != this.ch) {
      this.a.b(
          (new OPacket8UpdateHealth(
              this.aD(), this.foodStats.getFoodLevel(), this.foodStats.getFoodSaturationLevel())));
      this.cf = this.aD();
      this.cg = this.foodStats.getFoodLevel();
      this.ch = this.foodStats.getFoodSaturationLevel() == 0.0F;
    }

    // CanaryMod start - Experience Update
    if (this.N != this.ci) {
      if (!Configuration.getWorldConfig(bi.getCanaryDimension().getName())
          .isExperienceEnabled()) { // CanaryMod - check if Experience is enabled
        N = 0;
        M = 0;
      } else { // Call hook
        CancelableHook hook =
            (CancelableHook)
                Canary.hooks().callCancelableHook(new ExperienceHook(canaryPlayer, ci, N));
        if (hook.isCanceled()) {
          N = ci;
        }
      }
    }

    if (this.N != this.ci) {
      this.ci = this.N;
      this.a.b((new OPacket43Experience(this.O, this.N, this.M)));
    }
  }