org.bukkit.map.MapCanvas Java Examples

The following examples show how to use org.bukkit.map.MapCanvas. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HeapGraph.java    From LagMonitor with MIT License 6 votes vote down vote up
@Override
public int renderGraphTick(MapCanvas canvas, int nextPosX) {
    //byte -> mega byte
    int max = (int) (heapUsage.getHeapMemoryUsage().getCommitted() / 1024 / 1024);
    int used = (int) (heapUsage.getHeapMemoryUsage().getUsed() / 1024 / 1024);

    //round to the next 100 e.g. 801 -> 900
    int roundedMax = ((max + 99) / 100) * 100;

    int maxHeight = getHeightScaled(roundedMax, max);
    int usedHeight = getHeightScaled(roundedMax, used);

    //x=0 y=0 is the left top point so convert it
    int convertedMaxHeight = MAX_HEIGHT - maxHeight;
    int convertedUsedHeight = MAX_HEIGHT - usedHeight;

    fillBar(canvas, nextPosX, convertedMaxHeight, MAX_COLOR);
    fillBar(canvas, nextPosX, convertedUsedHeight, USED_COLOR);

    return maxHeight;
}
 
Example #2
Source File: ThreadsGraph.java    From LagMonitor with MIT License 6 votes vote down vote up
@Override
public int renderGraphTick(MapCanvas canvas, int nextPosX) {
    int threadCount = threadBean.getThreadCount();
    int daemonCount = threadBean.getDaemonThreadCount();

    //round up to the nearest multiple of 5
    int roundedMax = (int) (5 * (Math.ceil((float) threadCount / 5)));
    int threadHeight = getHeightScaled(roundedMax, threadCount);
    int daemonHeight = getHeightScaled(roundedMax, daemonCount);

    fillBar(canvas, nextPosX, MAX_HEIGHT - threadHeight, MAX_COLOR);
    fillBar(canvas, nextPosX, MAX_HEIGHT - daemonHeight, USED_COLOR);

    //these is the max number of all threads
    return threadCount;
}
 
Example #3
Source File: CombinedGraph.java    From LagMonitor with MIT License 6 votes vote down vote up
@Override
public int renderGraphTick(MapCanvas canvas, int nextPosX) {
    for (int i = 0; i < graphRenderers.length; i++) {
        GraphRenderer graphRenderer = graphRenderers[i];
        int position = this.componentLastPos[i];
        position++;

        //index starts with 0 so in the end - 1
        int maxComponentWidth = (i + 1) * componentWidth + i * SPACES - 1;
        if (position > maxComponentWidth) {
            //reset it to the start pos
            position = i * componentWidth + i * SPACES;
        }

        graphRenderer.renderGraphTick(canvas, position);
        this.componentLastPos[i] = position;
    }

    return 100;
}
 
Example #4
Source File: HeapGraph.java    From LagMonitor with MIT License 6 votes vote down vote up
@Override
public int renderGraphTick(MapCanvas canvas, int nextPosX) {
    //byte -> mega byte
    int max = (int) (heapUsage.getHeapMemoryUsage().getCommitted() / 1024 / 1024);
    int used = (int) (heapUsage.getHeapMemoryUsage().getUsed() / 1024 / 1024);

    //round to the next 100 e.g. 801 -> 900
    int roundedMax = ((max + 99) / 100) * 100;

    int maxHeight = getHeightScaled(roundedMax, max);
    int usedHeight = getHeightScaled(roundedMax, used);

    //x=0 y=0 is the left top point so convert it
    int convertedMaxHeight = MAX_HEIGHT - maxHeight;
    int convertedUsedHeight = MAX_HEIGHT - usedHeight;

    fillBar(canvas, nextPosX, convertedMaxHeight, MAX_COLOR);
    fillBar(canvas, nextPosX, convertedUsedHeight, USED_COLOR);

    return maxHeight;
}
 
Example #5
Source File: CombinedGraph.java    From LagMonitor with MIT License 6 votes vote down vote up
@Override
public int renderGraphTick(MapCanvas canvas, int nextPosX) {
    for (int i = 0; i < graphRenderers.length; i++) {
        GraphRenderer graphRenderer = graphRenderers[i];
        int position = this.componentLastPos[i];
        position++;

        //index starts with 0 so in the end - 1
        int maxComponentWidth = (i + 1) * componentWidth + i * SPACES - 1;
        if (position > maxComponentWidth) {
            //reset it to the start pos
            position = i * componentWidth + i * SPACES;
        }

        graphRenderer.renderGraphTick(canvas, position);
        this.componentLastPos[i] = position;
    }

    return 100;
}
 
Example #6
Source File: CraftMapRenderer.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void render(MapView map, MapCanvas canvas, Player player) {
    // Map
    for (int x = 0; x < 128; ++x) {
        for (int y = 0; y < 128; ++y) {
            canvas.setPixel(x, y, worldMap.colors[y * 128 + x]);
        }
    }

    // Cursors
    MapCursorCollection cursors = canvas.getCursors();
    while (cursors.size() > 0) {
        cursors.removeCursor(cursors.getCursor(0));
    }

    for (Object key : worldMap.mapDecorations.keySet()) {
        // If this cursor is for a player check visibility with vanish system
        Player other = Bukkit.getPlayerExact((String) key);
        if (other != null && !player.canSee(other)) {
            continue;
        }

        MapDecoration decoration = worldMap.mapDecorations.get(key);
        cursors.addCursor(decoration.getX(), decoration.getY(), (byte) (decoration.getRotation() & 15), decoration.getImage());
    }
}
 
Example #7
Source File: ThreadsGraph.java    From LagMonitor with MIT License 6 votes vote down vote up
@Override
public int renderGraphTick(MapCanvas canvas, int nextPosX) {
    int threadCount = threadBean.getThreadCount();
    int daemonCount = threadBean.getDaemonThreadCount();

    //round up to the nearest multiple of 5
    int roundedMax = (int) (5 * (Math.ceil((float) threadCount / 5)));
    int threadHeight = getHeightScaled(roundedMax, threadCount);
    int daemonHeight = getHeightScaled(roundedMax, daemonCount);

    fillBar(canvas, nextPosX, MAX_HEIGHT - threadHeight, MAX_COLOR);
    fillBar(canvas, nextPosX, MAX_HEIGHT - daemonHeight, USED_COLOR);

    //these is the max number of all threads
    return threadCount;
}
 
Example #8
Source File: ImageMapRenderer.java    From MCAuthenticator with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void render(MapView mapView, MapCanvas mapCanvas, Player player) {
    for (int x = 0; x < 128; x++) {
        for (int z = 0; z < 128; z++) {
            mapCanvas.setPixel(x, z, bitMatrix.get(x, z) ? FILL_COLOR : MapPalette.WHITE);
        }
    }
}
 
Example #9
Source File: ClassesGraph.java    From LagMonitor with MIT License 5 votes vote down vote up
@Override
public int renderGraphTick(MapCanvas canvas, int nextPosX) {
    int loadedClasses = classBean.getLoadedClassCount();

    //round up to the nearest multiple of 5
    int roundedMax = (int) (5 * (Math.ceil((float) loadedClasses / 5)));
    int loadedHeight = getHeightScaled(roundedMax, loadedClasses);

    fillBar(canvas, nextPosX, MAX_HEIGHT - loadedHeight, MAX_COLOR);

    //these is the max number
    return loadedClasses;
}
 
Example #10
Source File: CraftMapRenderer.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void render(MapView map, MapCanvas canvas, Player player) {
    if(CauldronCommand.debug) {
    System.out.println("Default Map Render called!");
    for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
        System.out.println(ste);
    } }


    // Map
    for (int x = 0; x < 128; ++x) {
        for (int y = 0; y < 128; ++y) {
            canvas.setPixel(x, y, worldMap.colors[y * 128 + x]);
        }
    }

    // Cursors
    MapCursorCollection cursors = canvas.getCursors();
    while (cursors.size() > 0) {
        cursors.removeCursor(cursors.getCursor(0));
    }

    for (UUID key : worldMap.playersVisibleOnMap.keySet()) { // Spigot string -> uuid
        // If this cursor is for a player check visibility with vanish system
        Player other = Bukkit.getPlayer(key); // Spigot
        if (other != null && !player.canSee(other)) {
            continue;
        }

        net.minecraft.world.storage.MapData.MapCoord decoration = (net.minecraft.world.storage.MapData.MapCoord) worldMap.playersVisibleOnMap.get(key);
        cursors.addCursor(decoration.centerX, decoration.centerZ, (byte) (decoration.iconRotation & 15), decoration.iconSize);
    }
}
 
Example #11
Source File: GraphRenderer.java    From LagMonitor with MIT License 5 votes vote down vote up
@Override
public void render(MapView map, MapCanvas canvas, Player player) {
    if (nextUpdate <= 0) {
        //paint only every half seconds (20 Ticks / 2)
        nextUpdate = 10;

        if (nextPosX >= MAX_WIDTH) {
            //start again from the beginning
            nextPosX = 0;
        }

        clearBar(canvas, nextPosX);
        //make it more visual where the renderer is at the moment
        clearBar(canvas, nextPosX + 1);
        int maxValue = renderGraphTick(canvas, nextPosX);

        //override the color
        drawText(canvas, MAX_WIDTH / 2, MAX_HEIGHT / 2, title);

        //count indicators
        String maxText = Integer.toString(maxValue);
        drawText(canvas, MAX_WIDTH - Math.floorDiv(getTextWidth(maxText), 2), TEXT_HEIGHT, maxText);

        String midText = Integer.toString(maxValue / 2);
        drawText(canvas, MAX_WIDTH - Math.floorDiv(getTextWidth(midText), 2), MAX_HEIGHT / 2, midText);

        String zeroText = Integer.toString(0);
        drawText(canvas, MAX_WIDTH - Math.floorDiv(getTextWidth(zeroText), 2), MAX_HEIGHT, zeroText);

        nextPosX++;
    }

    nextUpdate--;
}
 
Example #12
Source File: GraphRenderer.java    From LagMonitor with MIT License 5 votes vote down vote up
@Override
public void render(MapView map, MapCanvas canvas, Player player) {
    if (nextUpdate <= 0) {
        //paint only every half seconds (20 Ticks / 2)
        nextUpdate = 10;

        if (nextPosX >= MAX_WIDTH) {
            //start again from the beginning
            nextPosX = 0;
        }

        clearBar(canvas, nextPosX);
        //make it more visual where the renderer is at the moment
        clearBar(canvas, nextPosX + 1);
        int maxValue = renderGraphTick(canvas, nextPosX);

        //override the color
        drawText(canvas, MAX_WIDTH / 2, MAX_HEIGHT / 2, title);

        //count indicators
        String maxText = Integer.toString(maxValue);
        drawText(canvas, MAX_WIDTH - Math.floorDiv(getTextWidth(maxText), 2), TEXT_HEIGHT, maxText);

        String midText = Integer.toString(maxValue / 2);
        drawText(canvas, MAX_WIDTH - Math.floorDiv(getTextWidth(midText), 2), MAX_HEIGHT / 2, midText);

        String zeroText = Integer.toString(0);
        drawText(canvas, MAX_WIDTH - Math.floorDiv(getTextWidth(zeroText), 2), MAX_HEIGHT, zeroText);

        nextPosX++;
    }

    nextUpdate--;
}
 
Example #13
Source File: ClassesGraph.java    From LagMonitor with MIT License 5 votes vote down vote up
@Override
public int renderGraphTick(MapCanvas canvas, int nextPosX) {
    int loadedClasses = classBean.getLoadedClassCount();

    //round up to the nearest multiple of 5
    int roundedMax = (int) (5 * (Math.ceil((float) loadedClasses / 5)));
    int loadedHeight = getHeightScaled(roundedMax, loadedClasses);

    fillBar(canvas, nextPosX, MAX_HEIGHT - loadedHeight, MAX_COLOR);

    //these is the max number
    return loadedClasses;
}
 
Example #14
Source File: GraphRenderer.java    From LagMonitor with MIT License 4 votes vote down vote up
protected void clearBar(MapCanvas canvas, int posX) {
    //resets the complete y coordinates on this x in order to free unused
    for (int yPos = 0; yPos < MAX_HEIGHT; yPos++) {
        canvas.setPixel(posX, yPos, (byte) 0);
    }
}
 
Example #15
Source File: GraphRenderer.java    From LagMonitor with MIT License 4 votes vote down vote up
protected void clearMap(MapCanvas canvas) {
    for (int xPos = 0; xPos < MAX_WIDTH; xPos++) {
        fillBar(canvas, xPos, 0, (byte) 0);
    }
}
 
Example #16
Source File: GraphRenderer.java    From LagMonitor with MIT License 4 votes vote down vote up
protected void fillBar(MapCanvas canvas, int xPos, int yStart, byte color) {
    for (int yPos = yStart; yPos < MAX_HEIGHT; yPos++) {
        canvas.setPixel(xPos, yPos, color);
    }
}
 
Example #17
Source File: GraphRenderer.java    From LagMonitor with MIT License 4 votes vote down vote up
protected void drawText(MapCanvas canvas, int midX, int midY, String text) {
    int textWidth = getTextWidth(text);
    canvas.drawText(midX - (textWidth / 2), midY - (TEXT_HEIGHT / 2), MinecraftFont.Font, text);
}
 
Example #18
Source File: GraphRenderer.java    From LagMonitor with MIT License 4 votes vote down vote up
protected void drawText(MapCanvas canvas, int midX, int midY, String text) {
    int textWidth = getTextWidth(text);
    canvas.drawText(midX - (textWidth / 2), midY - (TEXT_HEIGHT / 2), MinecraftFont.Font, text);
}
 
Example #19
Source File: GraphRenderer.java    From LagMonitor with MIT License 4 votes vote down vote up
protected void fillBar(MapCanvas canvas, int xPos, int yStart, byte color) {
    for (int yPos = yStart; yPos < MAX_HEIGHT; yPos++) {
        canvas.setPixel(xPos, yPos, color);
    }
}
 
Example #20
Source File: GraphRenderer.java    From LagMonitor with MIT License 4 votes vote down vote up
protected void clearMap(MapCanvas canvas) {
    for (int xPos = 0; xPos < MAX_WIDTH; xPos++) {
        fillBar(canvas, xPos, 0, (byte) 0);
    }
}
 
Example #21
Source File: GraphRenderer.java    From LagMonitor with MIT License 4 votes vote down vote up
protected void clearBar(MapCanvas canvas, int posX) {
    //resets the complete y coordinates on this x in order to free unused
    for (int yPos = 0; yPos < MAX_HEIGHT; yPos++) {
        canvas.setPixel(posX, yPos, (byte) 0);
    }
}
 
Example #22
Source File: GraphRenderer.java    From LagMonitor with MIT License votes vote down vote up
public abstract int renderGraphTick(MapCanvas canvas, int nextPosX); 
Example #23
Source File: GraphRenderer.java    From LagMonitor with MIT License votes vote down vote up
public abstract int renderGraphTick(MapCanvas canvas, int nextPosX);