Exemple #1
0
  @Override
  public void render(MapView view, MapCanvas canvas, Player player) {
    if (renderTask == null) return;

    ChunkInfoRenderingRequest request = renderedRequests.get(view.getId());
    if (request == null) {
      request =
          new ChunkInfoRenderingRequest(
              view.getId(), view.getCenterX(), view.getCenterZ(), view.getWorld().getName());
      renderedRequests.put(view.getId(), request);
      renderTask.add(request);
    }

    MapCursor cursor;

    final Location location = player.getLocation();
    final int playerX = ((location.getBlockX() - view.getCenterX()) >> 3) /*
                                                                               * +
                                                                               * 128
                                                                               */;
    final int playerZ = ((location.getBlockZ() - view.getCenterZ()) >> 3) /*
                                                                               * +
                                                                               * 128
                                                                               */;
    if (playerX < 128 && playerX >= -128 && playerZ < 128 || playerZ >= -128) {
      final byte direction = (byte) (((int) location.getYaw() + 360) % 360 * 16 / 360);
      if (canvas.getCursors().size() == 0) {
        canvas
            .getCursors()
            .addCursor(playerX, playerZ, direction, MapCursor.Type.WHITE_POINTER.getValue());
      } else {
        cursor = canvas.getCursors().getCursor(0);
        cursor.setDirection(direction);
        cursor.setX((byte) (playerX));
        cursor.setY((byte) (playerZ));
      }
    }

    if (!request.isDone()) return;

    final byte[][] data = request.getData();
    for (int ii = 0; ii < 2; ii++) {
      int currentLine = request.nextLine();
      for (int i = 0; i < 128; i++) {
        canvas.setPixel(i, currentLine, data[currentLine][i]);
      }
    }
  }
  public void sendMap(MapView map) {
    if (getHandle().playerNetServerHandler == null) return;

    RenderData data = ((BukkitMapView) map).render(this);
    for (int x = 0; x < 128; ++x) {
      byte[] bytes = new byte[131];
      bytes[1] = (byte) x;
      for (int y = 0; y < 128; ++y) {
        bytes[y + 3] = data.buffer[y * 128 + x];
      }
      Packet131MapData packet =
          new Packet131MapData((short) Material.MAP.getId(), map.getId(), bytes);
      getHandle().playerNetServerHandler.sendPacketToPlayer(packet);
    }
  }
Exemple #3
0
  public void sendMap(MapView map) {
    if (getHandle().field_71135_a == null) return;

    RenderData data = ((CraftMapView) map).render(this);
    for (int x = 0; x < 128; ++x) {
      byte[] bytes = new byte[131];
      bytes[1] = (byte) x;
      for (int y = 0; y < 128; ++y) {
        bytes[y + 3] = data.buffer[y * 128 + x];
      }
      net.minecraft.network.packet.Packet131MapData packet =
          new net.minecraft.network.packet.Packet131MapData(
              (short) Material.MAP.getId(), map.getId(), bytes);
      getHandle().field_71135_a.func_72567_b(packet);
    }
  }
 @EventHandler
 public void onMapInit(MapInitializeEvent event) {
   MapView mv = event.getMap();
   mv.setScale(Scale.FAR);
 }
Exemple #5
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

    Element id = scriptEntry.getElement("map-id");
    dWorld create = scriptEntry.getdObject("new");
    Element reset = scriptEntry.getElement("reset");
    dLocation resetLoc = scriptEntry.getdObject("reset-loc");
    Element image = scriptEntry.getElement("image");
    dScript script = scriptEntry.getdObject("script");
    Element resize = scriptEntry.getElement("resize");
    Element width = scriptEntry.getElement("width");
    Element height = scriptEntry.getElement("height");
    Element x = scriptEntry.getElement("x-value");
    Element y = scriptEntry.getElement("y-value");

    dB.report(
        scriptEntry,
        getName(),
        (id != null ? id.debug() : "")
            + (create != null ? create.debug() : "")
            + reset.debug()
            + (resetLoc != null ? resetLoc.debug() : "")
            + (image != null ? image.debug() : "")
            + (script != null ? script.debug() : "")
            + resize.debug()
            + (width != null ? width.debug() : "")
            + (height != null ? height.debug() : "")
            + x.debug()
            + y.debug());

    MapView map = null;
    if (create != null) {
      map = Bukkit.getServer().createMap(create.getWorld());
      scriptEntry.addObject("created_map", new Element(map.getId()));
    } else if (id != null) {
      map = Bukkit.getServer().getMap((short) id.asInt());
      if (map == null)
        throw new CommandExecutionException("No map found for ID '" + id.asInt() + "'!");
    } else {
      throw new CommandExecutionException(
          "The map command failed somehow! Report this to a developer!");
    }

    if (reset.asBoolean()) {
      List<MapRenderer> oldRenderers = DenizenMapManager.removeDenizenRenderers(map);
      for (MapRenderer renderer : oldRenderers) {
        map.addRenderer(renderer);
      }
      if (resetLoc != null) {
        map.setCenterX(resetLoc.getBlockX());
        map.setCenterZ(resetLoc.getBlockZ());
        map.setWorld(resetLoc.getWorld());
      }
    } else if (script != null) {
      DenizenMapManager.removeDenizenRenderers(map);
      ((MapScriptContainer) script.getContainer()).applyTo(map);
    } else {
      DenizenMapRenderer dmr = DenizenMapManager.getDenizenRenderer(map);
      if (image != null) {
        int wide = width != null ? width.asInt() : resize.asBoolean() ? 128 : 0;
        int high = height != null ? height.asInt() : resize.asBoolean() ? 128 : 0;
        if (CoreUtilities.toLowerCase(image.asString()).endsWith(".gif"))
          dmr.addObject(
              new MapAnimatedImage(
                  x.asString(), y.asString(), "true", false, image.asString(), wide, high));
        else
          dmr.addObject(
              new MapImage(
                  x.asString(), y.asString(), "true", false, image.asString(), wide, high));
      }
    }
  }
 public static void drawToMap(MapView map) {
   for (MapRenderer renderer : map.getRenderers()) {
     map.removeRenderer(renderer);
   }
   map.addRenderer(new TownMapRenderer());
 }
  // This method gets called at 20tps whenever a map is in a players inventory. Bail out as quickly
  // as possible if we
  // shouldn't do anything with it.
  // https://bukkit.atlassian.net/browse/BUKKIT-476
  @Override
  public void render(MapView map, MapCanvas canvas, Player player) {
    if (map.getCenterX() == Courier.MAGIC_NUMBER
        && map.getId() != plugin.getCourierdb().getCourierMapId()) {
      // it's a Courier map in an ItemFrame. We get called when it's in a loaded chunk. Player
      // doesn't
      // even need to be near it. Performance issues galore ...
      Letter letter = plugin.getTracker().getLetter(map.getCenterZ());
      if (letter != null && letter.getDirty()) {
        plugin
            .getCConfig()
            .clog(
                Level.FINE,
                "Rendering a Courier ItemFrame Letter ("
                    + letter.getId()
                    + ") on Map ("
                    + map.getId()
                    + ")");
        for (int j = 0; j < CANVAS_HEIGHT; j++) {
          for (int i = 0; i < CANVAS_WIDTH; i++) {
            canvas.setPixel(i, j, clearImage[j * 128 + i]);
            //                        canvas.setPixel(i, j, MapPalette.TRANSPARENT);
            //                        canvas.setPixel(i, j, MapPalette.LIGHT_BROWN);
          }
        }

        int drawPos = HEADER_POS;

        if (letter.getHeader() != null) {
          canvas.drawText(
              0, MinecraftFont.Font.getHeight() * drawPos, MinecraftFont.Font, letter.getHeader());
          LetterRenderer.drawLine(
              canvas,
              10,
              MinecraftFont.Font.getHeight() * (drawPos + 1)
                  + (int) (MinecraftFont.Font.getHeight() * 0.4),
              CANVAS_WIDTH - 11,
              MapPalette.DARK_BROWN);
          drawPos = BODY_POS;
        }

        canvas.drawText(
            letter.getLeftMarkerPos(),
            MinecraftFont.Font.getHeight(),
            MinecraftFont.Font,
            letter.getLeftMarker());
        canvas.drawText(
            letter.getRightMarkerPos(),
            MinecraftFont.Font.getHeight(),
            MinecraftFont.Font,
            letter.getRightMarker());

        if (letter.getMessage() != null) {
          canvas.drawText(
              0,
              MinecraftFont.Font.getHeight() * drawPos,
              MinecraftFont.Font,
              Letter.MESSAGE_COLOR + letter.getMessage());
        }

        if (letter.getDisplayDate() != null) {
          canvas.drawText(
              letter.getDisplayDatePos(),
              0,
              MinecraftFont.Font,
              Letter.DATE_COLOR + letter.getDisplayDate());
        }
        letter.setDirty(false);
        player.sendMap(map);
      }
    }
  }