org.bukkit.map.MapPalette Java Examples

The following examples show how to use org.bukkit.map.MapPalette. 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: CraftMapCanvas.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public void drawImage(int x, int y, Image image) {
    byte[] bytes = MapPalette.imageToBytes(image);
    for (int x2 = 0; x2 < image.getWidth(null); ++x2) {
        for (int y2 = 0; y2 < image.getHeight(null); ++y2) {
            setPixel(x + x2, y + y2, bytes[y2 * image.getWidth(null) + x2]);
        }
    }
}
 
Example #2
Source File: CraftMapCanvas.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public void drawText(int x, int y, MapFont font, String text) {
    int xStart = x;
    byte color = MapPalette.DARK_GRAY;
    if (!font.isValid(text)) {
        throw new IllegalArgumentException("text contains invalid characters");
    }

    for (int i = 0; i < text.length(); ++i) {
        char ch = text.charAt(i);
        if (ch == '\n') {
            x = xStart;
            y += font.getHeight() + 1;
            continue;
        } else if (ch == '\u00A7') {
            int j = text.indexOf(';', i);
            if (j >= 0) {
                try {
                    color = Byte.parseByte(text.substring(i + 1, j));
                    i = j;
                    continue;
                } catch (NumberFormatException ex) {
                }
            }
            throw new IllegalArgumentException("Text contains unterminated color string");
        }

        CharacterSprite sprite = font.getChar(text.charAt(i));
        for (int r = 0; r < font.getHeight(); ++r) {
            for (int c = 0; c < sprite.getWidth(); ++c) {
                if (sprite.get(r, c)) {
                    setPixel(x + c, y + r, color);
                }
            }
        }
        x += sprite.getWidth() + 1;
    }
}
 
Example #3
Source File: MCSDGenBukkit.java    From MapManager with MIT License 5 votes vote down vote up
public void generate() {
    this.clear();
    for (int i = 0; i < 256; i++) {
        try {
            setColor((byte) i, MapPalette.getColor((byte) i));
        } catch (Throwable t) {}
    }
    for (int r = 0; r < 256; r++) {
        for (int g = 0; g < 256; g++) {
            for (int b = 0; b < 256; b++) {
                set(r, g, b, MapPalette.matchColor(r, g, b));
            }
        }
    }
}
 
Example #4
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 #5
Source File: CraftMapCanvas.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void drawImage(int x, int y, Image image) {
    byte[] bytes = MapPalette.imageToBytes(image);
    for (int x2 = 0; x2 < image.getWidth(null); ++x2) {
        for (int y2 = 0; y2 < image.getHeight(null); ++y2) {
            setPixel(x + x2, y + y2, bytes[y2 * image.getWidth(null) + x2]);
        }
    }
}
 
Example #6
Source File: CraftMapCanvas.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void drawText(int x, int y, MapFont font, String text) {
    int xStart = x;
    byte color = MapPalette.DARK_GRAY;
    if (!font.isValid(text)) {
        throw new IllegalArgumentException("text contains invalid characters");
    }

    for (int i = 0; i < text.length(); ++i) {
        char ch = text.charAt(i);
        if (ch == '\n') {
            x = xStart;
            y += font.getHeight() + 1;
            continue;
        } else if (ch == '\u00A7') {
            int j = text.indexOf(';', i);
            if (j >= 0) {
                try {
                    color = Byte.parseByte(text.substring(i + 1, j));
                    i = j;
                    continue;
                }
                catch (NumberFormatException ex) {}
            }
        }

        CharacterSprite sprite = font.getChar(text.charAt(i));
        for (int r = 0; r < font.getHeight(); ++r) {
            for (int c = 0; c < sprite.getWidth(); ++c) {
                if (sprite.get(r, c)) {
                    setPixel(x + c, y + r, color);
                }
            }
        }
        x += sprite.getWidth() + 1;
    }
}