org.bukkit.inventory.meta.MapMeta#org.bukkit.map.MapView源码实例Demo

下面列出了org.bukkit.inventory.meta.MapMeta#org.bukkit.map.MapView 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Kettle   文件: CraftMapRenderer.java
@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());
    }
}
 
源代码2 项目: MCAuthenticator   文件: RFC6238.java
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);
}
 
源代码3 项目: LagMonitor   文件: GraphListener.java
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);
}
 
源代码4 项目: LagMonitor   文件: GraphCommand.java
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);
    }
}
 
源代码5 项目: LagMonitor   文件: GraphListener.java
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);
}
 
源代码6 项目: LagMonitor   文件: GraphCommand.java
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);
    }
}
 
源代码7 项目: Kettle   文件: CraftPlayer.java
@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);
}
 
源代码8 项目: Chimera   文件: MapBuilderTest.java
@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);
}
 
源代码9 项目: MCAuthenticator   文件: ImageMapRenderer.java
@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);
        }
    }
}
 
源代码10 项目: LagMonitor   文件: GraphListener.java
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);
}
 
源代码11 项目: LagMonitor   文件: GraphCommand.java
@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;
}
 
源代码12 项目: LagMonitor   文件: GraphCommand.java
private MapView installRenderer(Player player, GraphRenderer graphType) {
    MapView mapView = Bukkit.createMap(player.getWorld());
    mapView.getRenderers().forEach(mapView::removeRenderer);

    mapView.addRenderer(graphType);
    return mapView;
}
 
源代码13 项目: LagMonitor   文件: GraphRenderer.java
@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--;
}
 
源代码14 项目: Thermos   文件: CraftPlayer.java
@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);
    }
}
 
源代码15 项目: Thermos   文件: CraftMapRenderer.java
@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);
    }
}
 
源代码16 项目: LagMonitor   文件: GraphListener.java
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);
}
 
源代码17 项目: LagMonitor   文件: GraphCommand.java
@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;
}
 
源代码18 项目: LagMonitor   文件: GraphCommand.java
private MapView installRenderer(Player player, GraphRenderer graphType) {
    MapView mapView = Bukkit.createMap(player.getWorld());
    mapView.getRenderers().forEach(mapView::removeRenderer);

    mapView.addRenderer(graphType);
    return mapView;
}
 
源代码19 项目: LagMonitor   文件: GraphRenderer.java
@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--;
}
 
源代码20 项目: Kettle   文件: MapInitializeEvent.java
public MapInitializeEvent(final MapView mapView) {
    this.mapView = mapView;
}
 
源代码21 项目: Chimera   文件: MapBuilder.java
public MapBuilder view(MapView map) {
    meta.setMapView(map);
    return this;
}
 
源代码22 项目: Chimera   文件: MockServer.java
@Override
public MapView getMap(int id) {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
 
源代码23 项目: Chimera   文件: MockServer.java
@Override
public MapView createMap(World world) {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
 
源代码24 项目: LagMonitor   文件: GraphListener.java
private boolean isOurRenderer(MapView mapView) {
    return mapView.getRenderers().stream()
            .anyMatch(GraphRenderer.class::isInstance);
}
 
源代码25 项目: SaneEconomy   文件: MockServer.java
@Override
public MapView getMap(int id) {
    return null;
}
 
源代码26 项目: SaneEconomy   文件: MockServer.java
@Override
public MapView createMap(World world) {
    return null;
}
 
源代码27 项目: LagMonitor   文件: GraphListener.java
private boolean isOurRenderer(MapView mapView) {
    return mapView.getRenderers().stream()
            .anyMatch(GraphRenderer.class::isInstance);
}
 
源代码28 项目: Kettle   文件: Player.java
/**
 * Render a map and send it to the player in its entirety. This may be
 * used when streaming the map in the normal manner is not desirable.
 *
 * @param map The map to be sent
 */
public void sendMap(MapView map);
 
源代码29 项目: Kettle   文件: Server.java
/**
 * 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
 */
@Deprecated
public MapView getMap(short id);
 
源代码30 项目: Kettle   文件: Server.java
/**
 * 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 MapView createMap(World world);