Beispiel #1
0
 public void render2d(GL2 g) {
   for (Entry<EntityData, TileEntity> e : entities.entrySet()) {
     EntityData key = e.getKey();
     TileEntity entity = e.getValue();
     g.glPushMatrix();
     switch (key.getType()) {
       case VBORDER:
         g.glRotatef(90, 0, 0, 1);
         BorderData vBorder = (BorderData) entity;
         if (Globals.upCamera) {
           vBorder.render(g, this);
         }
         g.glColor3f(1, 1, 1);
         break;
       case HBORDER:
         BorderData hBorder = (BorderData) entity;
         if (Globals.upCamera) {
           hBorder.render(g, this);
         }
         g.glColor3f(1, 1, 1);
         break;
     }
     g.glPopMatrix();
     g.glColor3f(1, 1, 1);
   }
 }
  // set targetLoc only if not current player location; set returnLocationOnly to true to have new
  // Location returned if they need to be moved to one, instead of directly handling it
  public static Location checkPlayer(
      Player player, Location targetLoc, boolean returnLocationOnly) {
    if (player == null || !player.isOnline()) return null;

    Location loc = (targetLoc == null) ? player.getLocation() : targetLoc;
    if (loc == null) return null;

    World world = loc.getWorld();
    if (world == null) return null;
    BorderData border = Config.Border(world.getName());
    if (border == null) return null;

    if (border.insideBorder(loc.getX(), loc.getZ(), Config.ShapeRound())) return null;

    if (player.hasPermission("worldborder.ignoreborder")) return null;

    Location newLoc = newLocation(player, loc, border);

    if (Config
        .whooshEffect()) { // give some particle and sound effects where the player was beyond the
      // border
      world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
      world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
      world.playEffect(loc, Effect.SMOKE, 4);
      world.playEffect(loc, Effect.SMOKE, 4);
      world.playEffect(loc, Effect.SMOKE, 4);
      world.playEffect(loc, Effect.GHAST_SHOOT, 0);
    }

    if (returnLocationOnly) return newLoc;

    if (!player.isInsideVehicle()) player.teleport(newLoc);
    else {
      Vehicle ride = (Vehicle) player.getVehicle();
      if (ride != null) { // vehicles need to be offset vertically and have velocity stopped
        double vertOffset = ride.getLocation().getY() - loc.getY();
        newLoc.setY(newLoc.getY() + vertOffset);
        ride.setVelocity(new Vector(0, 0, 0));
        ride.teleport(newLoc);
      } else { // if player.getVehicle() returns null (when riding a pig on older Bukkit releases,
        // for instance), player has to be ejected
        player.leaveVehicle();
        player.teleport(newLoc);
      }
    }

    return null;
  }
  private static Location newLocation(Player player, Location loc, BorderData border) {
    if (Config.Debug()) {
      Config.LogWarn(
          "Border crossing in \"" + loc.getWorld().getName() + "\". Border " + border.toString());
      Config.LogWarn(
          "Player position X: "
              + Config.coord.format(loc.getX())
              + " Y: "
              + Config.coord.format(loc.getY())
              + " Z: "
              + Config.coord.format(loc.getZ()));
    }

    Location newLoc = border.correctedPosition(loc, Config.ShapeRound());

    // it's remotely possible (such as in the Nether) a suitable location isn't available, in which
    // case...
    if (newLoc == null) {
      if (Config.Debug()) Config.LogWarn("Target new location unviable, using spawn.");
      newLoc = player.getWorld().getSpawnLocation();
    }

    if (Config.Debug())
      Config.LogWarn(
          "New position in world \""
              + newLoc.getWorld().getName()
              + "\" at X: "
              + Config.coord.format(newLoc.getX())
              + " Y: "
              + Config.coord.format(newLoc.getY())
              + " Z: "
              + Config.coord.format(newLoc.getZ()));

    player.sendMessage(ChatColor.RED + Config.Message());

    return newLoc;
  }
Beispiel #4
0
  public Tile(Map map, int x, int y, Element tile) {
    this.map = map;
    this.x = x;
    this.y = y;
    height = (int) Float.parseFloat(tile.getAttribute("height"));
    if (!tile.getAttribute("caveHeight").equals("")) {
      caveHeight = (int) Float.parseFloat(tile.getAttribute("caveHeight"));
    }
    if (!tile.getAttribute("caveSize").equals("")) {
      caveSize = (int) Float.parseFloat(tile.getAttribute("caveSize"));
    }
    ground = new Ground((Element) tile.getElementsByTagName("ground").item(0));
    if (tile.getElementsByTagName("cave").getLength() != 0) {
      cave = CaveData.get((Element) tile.getElementsByTagName("cave").item(0));
    }

    NodeList labels = tile.getElementsByTagName("label");
    if (labels.getLength() != 0) {
      label = new Label((Element) labels.item(0));
    }
    NodeList caveLabels = tile.getElementsByTagName("caveLabel");
    if (caveLabels.getLength() != 0) {
      caveLabel = new Label((Element) caveLabels.item(0));
    }

    entities = new HashMap<>();

    NodeList list = tile.getElementsByTagName("level");
    for (int i = 0; i < list.getLength(); i++) {
      Element level = (Element) list.item(i);
      int floor = Integer.parseInt(level.getAttribute("value"));
      NodeList childNodes = level.getElementsByTagName("*");
      for (int i2 = 0; i2 < childNodes.getLength(); i2++) {
        Element entity = (Element) childNodes.item(i2);
        switch (entity.getNodeName().toLowerCase()) {
          case "floor":
            entities.put(new EntityData(floor, EntityType.FLOORROOF), new Floor(entity));
            break;
          case "hwall":
            Wall hwall = new Wall(entity);
            if (hwall.data.houseWall) {
              entities.put(new EntityData(floor, EntityType.HWALL), hwall);
            } else {
              entities.put(new EntityData(floor, EntityType.HFENCE), hwall);
            }
            break;
          case "vwall":
            Wall vwall = new Wall(entity);
            if (vwall.data.houseWall) {
              entities.put(new EntityData(floor, EntityType.VWALL), vwall);
            } else {
              entities.put(new EntityData(floor, EntityType.VFENCE), vwall);
            }
            break;
          case "hborder":
            entities.put(new EntityData(0, EntityType.HBORDER), BorderData.get(entity));
            break;
          case "vborder":
            entities.put(new EntityData(0, EntityType.VBORDER), BorderData.get(entity));
            break;
          case "roof":
            entities.put(new EntityData(floor, EntityType.FLOORROOF), new Roof(entity));
            break;
          case "object":
            ObjectLocation loc = ObjectLocation.parse(entity.getAttribute("position"));
            entities.put(new ObjectEntityData(floor, loc), new GameObject(entity));
            break;
          case "cave":
            cave = CaveData.get(entity);
            break;
        }
      }
    }
  }