@Override public boolean isDebug() { return Via.getManager().isDebug(); }
private static void mapIdentifiers(Map<Integer, Integer> output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) { Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString()); if (value == null) { if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); } continue; } output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey())); } }
private static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) { Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString()); if (value == null) { if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); } continue; } output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey()); } }
private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) { for (int i = 0; i < oldIdentifiers.size(); i++) { JsonElement v = oldIdentifiers.get(i); Integer index = findIndex(newIdentifiers, v.getAsString()); if (index == null) { if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("No key for " + v + " :( "); } continue; } output[i] = index.shortValue(); } }
@Override public int transform(UserConnection user, CompoundTag tag) { Object item = tag.get("Item").getValue(); byte data = ((Number) tag.get("Data").getValue()).byteValue(); Pair<?, Byte> pair = item instanceof Number ? new Pair<>(((Number) item).byteValue(), data) : new Pair<>((String) item, data); // Return air on empty string if (item instanceof String && ((String) item).isEmpty()) return 5265; else if (flowers.containsKey(pair)) { return flowers.get(pair); } else if (flowersNumberId.containsKey(pair)) { return flowersNumberId.get(pair); } else { if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Could not find flowerpot content " + item + " for " + tag); } } return -1; } }
@Override public Item getHandItem(final UserConnection info) { if (HandItemCache.CACHE) { return HandItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid()); } else { try { return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable<Item>() { @Override public Item call() throws Exception { UUID playerUUID = info.get(ProtocolInfo.class).getUuid(); if (Bukkit.getPlayer(playerUUID) != null) { return HandItemCache.convert(Bukkit.getPlayer(playerUUID).getItemInHand()); } return null; } }).get(10, TimeUnit.SECONDS); } catch (Exception e) { Via.getPlatform().getLogger().severe("Error fetching hand item: " + e.getClass().getName()); if (Via.getManager().isDebug()) e.printStackTrace(); return null; } } } });
if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
public static int toNewId(int oldId) { if (oldId < 0) { oldId = 0; // Some plugins use negative numbers to clear blocks, remap them to air. } int newId = MappingData.blockMappings.getNewBlock(oldId); if (newId != -1) { return newId; } newId = MappingData.blockMappings.getNewBlock(oldId & ~0xF); // Remove data if (newId != -1) { if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Missing block " + oldId); } return newId; } if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Missing block completely " + oldId); } // Default stone return 1; }
public static void handle(List<CompoundTag> tags, UserConnection connection) { for (CompoundTag tag : tags) { try { if (!tag.contains("id")) throw new Exception("NBT tag not handled because the id key is missing"); String id = (String) tag.get("id").getValue(); if (!types.containsKey(id)) throw new Exception("Not handled id: " + id); int newId = types.get(id); if (newId == -1) continue; int x = (int) tag.get("x").getValue(); int y = (int) tag.get("y").getValue(); int z = (int) tag.get("z").getValue(); Position pos = new Position((long) x, (long) y, (long) z); updateBlockEntity(pos, (short) newId, tag, connection); } catch (Exception e) { if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Block Entity: " + e.getMessage() + ": " + tag); } } } }
/** * Transforms the BlockEntities to blocks! * * @param user UserConnection instance * @param position Block Position - WARNING: Position is null when called from a chunk * @param tag BlockEntity NBT * @param sendUpdate send a block change update * @return new block id * @throws Exception Gotta throw that exception */ public int transform(UserConnection user, Position position, CompoundTag tag, boolean sendUpdate) throws Exception { if (!tag.contains("id")) return -1; String id = (String) tag.get("id").getValue(); BlockEntityHandler handler = handlers.get(id); if (handler == null) { if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag); } return -1; } int newBlock = handler.transform(user, tag); if (sendUpdate && newBlock != -1) sendBlockChange(user, position, newBlock); return newBlock; }
public static void handleMetadata(int entityId, Entity1_12Types.EntityType type, List<Metadata> metadatas, UserConnection connection) { for (Metadata metadata : new ArrayList<>(metadatas)) { try { if (metadata.getValue() instanceof Item) { // Apply rewrite BedRewriter.toClientItem((Item) metadata.getValue()); } // Evocation Illager aggressive property became 13 if (type.is(Entity1_12Types.EntityType.EVOCATION_ILLAGER)) { if (metadata.getId() == 12) { metadata.setId(13); } } } catch (Exception e) { metadatas.remove(metadata); if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler"); Via.getPlatform().getLogger().warning("Metadata: " + metadata); e.printStackTrace(); } } } } }
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("An error occurred with entity type rewriter"); Via.getPlatform().getLogger().warning("Metadata: " + metadata);
} catch (RemovedValueException ignored) { } catch (Exception e) { if (Via.getManager().isDebug()) { Logger log = ViaBackwards.getPlatform().getLogger(); log.warning("Unable to handle metadata " + nmd);
public static void handleMetadata(int entityId, Entity1_13Types.EntityType type, List<Metadata> metadatas, UserConnection connection) { for (Metadata metadata : new ArrayList<>(metadatas)) { try { // 1.13 changed item to flat item (no data) if (metadata.getMetaType() == MetaType1_13.Slot) { InventoryPackets.toClient((Item) metadata.getValue()); } else if (metadata.getMetaType() == MetaType1_13.BlockID) { // Convert to new block id int data = (int) metadata.getValue(); metadata.setValue(Protocol1_13_1To1_13.getNewBlockStateId(data)); } if (type == null) continue; if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) { // New block format int data = (int) metadata.getValue(); metadata.setValue(Protocol1_13_1To1_13.getNewBlockStateId(data)); } if (type.isOrHasParent(EntityType.ABSTRACT_ARROW) && metadata.getId() >= 7) { metadata.setId(metadata.getId() + 1); // New shooter UUID } } catch (Exception e) { metadatas.remove(metadata); if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler"); Via.getPlatform().getLogger().warning("Metadata: " + metadata); e.printStackTrace(); } } } }
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { Logger log = Via.getPlatform().getLogger();
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler"); Via.getPlatform().getLogger().warning("Metadata: " + metadata);
super.transform(direction, state, packetWrapper); if (Via.getManager().isDebug()) {
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler"); Via.getPlatform().getLogger().warning("Metadata: " + metadata);