org.bukkit.map.MapView Java Examples

The following examples show how to use org.bukkit.map.MapView. 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: GraphCommand.java    From LagMonitor with MIT License 6 votes vote down vote up
private void buildCombinedGraph(Player player, String[] args) {
    List<GraphRenderer> renderers = new ArrayList<>();
    for (String arg : args) {
        GraphRenderer renderer = graphTypes.get(arg);
        if (renderer == null) {
            sendError(player, "Unknown graph type " + arg);
            return;
        }

        renderers.add(renderer);
    }

    if (renderers.size() > MAX_COMBINED) {
        sendError(player, "Too many graphs");
    } else {
        CombinedGraph combinedGraph = new CombinedGraph(renderers.toArray(new GraphRenderer[0]));
        MapView view = installRenderer(player, combinedGraph);
        giveMap(player, view);
    }
}
 
Example #2
Source File: GraphListener.java    From LagMonitor with MIT License 6 votes vote down vote up
private boolean isOurGraph(ItemStack item) {
    if (!LagUtils.isFilledMapSupported()) {
        return isOurGraphLegacy(item);
    }

    if (item.getType() != Material.FILLED_MAP) {
        return false;
    }

    ItemMeta meta = item.getItemMeta();
    if (!(meta instanceof MapMeta)) {
        return false;
    }

    MapMeta mapMeta = (MapMeta) meta;
    MapView mapView = mapMeta.getMapView();
    return mapView != null && isOurRenderer(mapView);
}
 
Example #3
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 #4
Source File: GraphCommand.java    From LagMonitor with MIT License 6 votes vote down vote up
private void buildCombinedGraph(Player player, String[] args) {
    List<GraphRenderer> renderers = new ArrayList<>();
    for (String arg : args) {
        GraphRenderer renderer = graphTypes.get(arg);
        if (renderer == null) {
            sendError(player, "Unknown graph type " + arg);
            return;
        }

        renderers.add(renderer);
    }

    if (renderers.size() > MAX_COMBINED) {
        sendError(player, "Too many graphs");
    } else {
        CombinedGraph combinedGraph = new CombinedGraph(renderers.toArray(new GraphRenderer[0]));
        MapView view = installRenderer(player, combinedGraph);
        giveMap(player, view);
    }
}
 
Example #5
Source File: RFC6238.java    From MCAuthenticator with GNU General Public License v3.0 6 votes vote down vote up
private void sendAndRenderMap(User u, Player p, String newKey) {
    ImageMapRenderer mapRenderer;
    try {
        mapRenderer = new ImageMapRenderer(p.getName(), newKey, serverIp);
    } catch (WriterException e) {
        mcAuthenticator.getC().sendDirect(p,
                "&cThere was an error rendering your 2FA QR code!");
        mcAuthenticator.handleException(e);
        return;
    }

    if (!u.isInventoryStored())
        u.storeInventory(p);

    MapView map = Bukkit.createMap(p.getWorld());
    map.getRenderers().forEach(map::removeRenderer);
    map.addRenderer(mapRenderer);

    ItemStack mapItem = new ItemStack(Material.MAP, 1, map.getId());
    p.getInventory().setHeldItemSlot(0);
    p.getInventory().setItemInMainHand(mapItem);
    p.sendMap(map);
}
 
Example #6
Source File: GraphListener.java    From LagMonitor with MIT License 6 votes vote down vote up
private boolean isOurGraph(ItemStack item) {
    if (!LagUtils.isFilledMapSupported()) {
        return isOurGraphLegacy(item);
    }

    if (item.getType() != Material.FILLED_MAP) {
        return false;
    }

    ItemMeta meta = item.getItemMeta();
    if (!(meta instanceof MapMeta)) {
        return false;
    }

    MapMeta mapMeta = (MapMeta) meta;
    MapView mapView = mapMeta.getMapView();
    return mapView != null && isOurRenderer(mapView);
}
 
Example #7
Source File: GraphListener.java    From LagMonitor with MIT License 5 votes vote down vote up
private boolean isOurGraphLegacy(ItemStack mapItem) {
    if (mapItem.getType() != Material.MAP)
        return false;

    short mapId = mapItem.getDurability();
    MapView mapView = Bukkit.getMap(mapId);
    return mapView != null && isOurRenderer(mapView);
}
 
Example #8
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 #9
Source File: GraphCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
private MapView installRenderer(Player player, GraphRenderer graphType) {
    MapView mapView = Bukkit.createMap(player.getWorld());
    mapView.getRenderers().forEach(mapView::removeRenderer);

    mapView.addRenderer(graphType);
    return mapView;
}
 
Example #10
Source File: GraphCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!canExecute(sender, command)) {
        return true;
    }

    if (sender instanceof Player) {
        Player player = (Player) sender;

        if (args.length > 0) {
            if (args.length > 1) {
                buildCombinedGraph(player, args);
            } else {
                String graph = args[0];
                GraphRenderer renderer = graphTypes.get(graph);
                if (renderer == null) {
                    sendError(sender, "Unknown graph type");
                } else {
                    giveMap(player, installRenderer(player, renderer));
                }
            }

            return true;
        }

        //default is heap usage
        GraphRenderer graphRenderer = graphTypes.get("heap");
        MapView mapView = installRenderer(player, graphRenderer);
        giveMap(player, mapView);
    } else {
        sendError(sender, "Not implemented for the console");
    }

    return true;
}
 
Example #11
Source File: GraphListener.java    From LagMonitor with MIT License 5 votes vote down vote up
private boolean isOurGraphLegacy(ItemStack mapItem) {
    if (mapItem.getType() != Material.MAP)
        return false;

    short mapId = mapItem.getDurability();
    MapView mapView = Bukkit.getMap(mapId);
    return mapView != null && isOurRenderer(mapView);
}
 
Example #12
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 #13
Source File: CraftPlayer.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void sendMap(MapView map) {
    if (getHandle().playerNetServerHandler == 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.play.server.S34PacketMaps packet = new net.minecraft.network.play.server.S34PacketMaps(map.getId(), bytes);
        getHandle().playerNetServerHandler.sendPacket(packet);
    }
}
 
Example #14
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 #15
Source File: GraphCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
private MapView installRenderer(Player player, GraphRenderer graphType) {
    MapView mapView = Bukkit.createMap(player.getWorld());
    mapView.getRenderers().forEach(mapView::removeRenderer);

    mapView.addRenderer(graphType);
    return mapView;
}
 
Example #16
Source File: GraphCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!canExecute(sender, command)) {
        return true;
    }

    if (sender instanceof Player) {
        Player player = (Player) sender;

        if (args.length > 0) {
            if (args.length > 1) {
                buildCombinedGraph(player, args);
            } else {
                String graph = args[0];
                GraphRenderer renderer = graphTypes.get(graph);
                if (renderer == null) {
                    sendError(sender, "Unknown graph type");
                } else {
                    giveMap(player, installRenderer(player, renderer));
                }
            }

            return true;
        }

        //default is heap usage
        GraphRenderer graphRenderer = graphTypes.get("heap");
        MapView mapView = installRenderer(player, graphRenderer);
        giveMap(player, mapView);
    } else {
        sendError(sender, "Not implemented for the console");
    }

    return true;
}
 
Example #17
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 #18
Source File: MapBuilderTest.java    From Chimera with MIT License 5 votes vote down vote up
@Test
void build() {
    var view = mock(MapView.class);
    MapBuilder.of(WATER).self().colour(SILVER).view(view).location("name").scaling(true);
    
    verify(meta).setColor(SILVER);
    verify(meta).setMapView(view);
    verify(meta).setLocationName("name");
    verify(meta).setScaling(true);
}
 
Example #19
Source File: CraftPlayer.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void sendMap(MapView map) {
    if (getHandle().connection == null) return;

    RenderData data = ((CraftMapView) map).render(this);
    Collection<MapDecoration> icons = new ArrayList<>();
    for (MapCursor cursor : data.cursors) {
        if (cursor.isVisible()) {
            icons.add(new MapDecoration(MapDecoration.Type.byIcon(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection()));
        }
    }

    SPacketMaps packet = new SPacketMaps(map.getId(), map.getScale().getValue(), true, icons, data.buffer, 0, 0, 128, 128);
    getHandle().connection.sendPacket(packet);
}
 
Example #20
Source File: GraphListener.java    From LagMonitor with MIT License 4 votes vote down vote up
private boolean isOurRenderer(MapView mapView) {
    return mapView.getRenderers().stream()
            .anyMatch(GraphRenderer.class::isInstance);
}
 
Example #21
Source File: MapInitializeEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public MapInitializeEvent(final MapView mapView) {
    this.mapView = mapView;
}
 
Example #22
Source File: GraphListener.java    From LagMonitor with MIT License 4 votes vote down vote up
private boolean isOurRenderer(MapView mapView) {
    return mapView.getRenderers().stream()
            .anyMatch(GraphRenderer.class::isInstance);
}
 
Example #23
Source File: MapBuilder.java    From Chimera with MIT License 4 votes vote down vote up
public MapBuilder view(MapView map) {
    meta.setMapView(map);
    return this;
}
 
Example #24
Source File: MockServer.java    From SaneEconomy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public MapView createMap(World world) {
    return null;
}
 
Example #25
Source File: MockServer.java    From SaneEconomy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public MapView getMap(int id) {
    return null;
}
 
Example #26
Source File: MockServer.java    From Chimera with MIT License 4 votes vote down vote up
@Override
public MapView getMap(int id) {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
 
Example #27
Source File: MockServer.java    From Chimera with MIT License 4 votes vote down vote up
@Override
public MapView createMap(World world) {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
 
Example #28
Source File: Bukkit.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Create a new map with an automatically assigned ID.
 *
 * @param world the world the map will belong to
 * @return a newly created map view
 */
public static MapView createMap(World world) {
    return server.createMap(world);
}
 
Example #29
Source File: Bukkit.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the map from the given item ID.
 *
 * @param id the id of the map to get
 * @return a map view if it exists, or null otherwise
 * @deprecated Magic value
 */

public static MapView getMap(short id) {
    return server.getMap(id);
}
 
Example #30
Source File: MapInitializeEvent.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the map initialized in this event.
 *
 * @return Map for this event
 */
public MapView getMap() {
    return mapView;
}