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())); } }
@Override public boolean execute(ViaCommandSender sender, String[] args) { Map<ProtocolVersion, Set<String>> playerVersions = new TreeMap<>(new Comparator<ProtocolVersion>() { @Override public int compare(ProtocolVersion o1, ProtocolVersion o2) { return ProtocolVersion.getIndex(o2) - ProtocolVersion.getIndex(o1); } }); for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) { int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID()); ProtocolVersion key = ProtocolVersion.getProtocol(playerVersion); if (!playerVersions.containsKey(key)) playerVersions.put(key, new HashSet<String>()); playerVersions.get(key).add(p.getName()); } for (Map.Entry<ProtocolVersion, Set<String>> entry : playerVersions.entrySet()) sendMessage(sender, "&8[&6%s&8] (&7%d&8): &b%s", entry.getKey().getName(), entry.getValue().size(), entry.getValue()); playerVersions.clear(); return true; } }
public static void init() { if (init) return; synchronized (Ticker.class) { if (init) return; init = true; } Via.getPlatform().runRepeatingSync(() -> { Via.getManager().getPortedPlayers().values().forEach(user -> { user.getStoredObjects().values().stream().filter(Tickable.class::isInstance).map(Tickable.class::cast).forEach(Tickable::tick); }); }, 1L); } }
public static String fixJson(String line) { if (line == null || line.equalsIgnoreCase("null")) { line = "{\"text\":\"\"}"; } else { if ((!line.startsWith("\"") || !line.endsWith("\"")) && (!line.startsWith("{") || !line.endsWith("}"))) { return constructJson(line); } if (line.startsWith("\"") && line.endsWith("\"")) { line = "{\"text\":" + line + "}"; } } try { GsonUtil.getGson().fromJson(line, JsonObject.class); } catch (Exception e) { if (Via.getConfig().isForceJsonTransform()) { return constructJson(line); } else { Via.getPlatform().getLogger().warning("Invalid JSON String: \"" + line + "\" Please report this issue to the ViaVersion Github: " + e.getMessage()); return "{\"text\":\"\"}"; } } return line; }
@Override public void onEnable() { // Inject Via.getManager().init(); }
/** * add multiple players * * @param players list of players * @return The BossBar object * @deprecated Deprecated use UUID's instead of Player objects {@link #addPlayer(UUID)} */ @Deprecated public BossBar addPlayers(T... players) { throw new UnsupportedOperationException("This method is not implemented for the platform " + Via.getPlatform().getPlatformName()); }
private BlockMappingsShortArray(JsonObject mapping1_12, JsonObject mapping1_13) { Arrays.fill(oldToNew, (short) -1); mapIdentifiers(oldToNew, mapping1_12, mapping1_13); // Map minecraft:snow[layers=1] of 1.12 to minecraft:snow[layers=2] in 1.13 if (Via.getConfig().isSnowCollisionFix()) { oldToNew[1248] = 3416; } }
long max = 0; for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) { int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID()); if (!playerVersions.containsKey(playerVersion)) playerVersions.put(playerVersion, new HashSet<String>()); UserConnection uc = Via.getManager().getConnection(p.getUUID()); if (uc != null && uc.getPacketsPerSecond() > -1) { playerVersions.get(playerVersion).add(p.getName() + " (" + uc.getPacketsPerSecond() + " PPS)");
public static Integer getProtocolId(String serverName) { // Step 1. Check Config Map<String, Integer> servers = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols(); Integer protocol = servers.get(serverName); if (protocol != null) { return protocol; } // Step 2. Check Detected Integer detectedProtocol = detectedProtocolIds.get(serverName); if (detectedProtocol != null) { return detectedProtocol; } // Step 3. Use Default Integer defaultProtocol = servers.get("default"); if (defaultProtocol != null) { return defaultProtocol; } // Step 4: Use bungee lowest supported... *cries* try { return Via.getManager().getInjector().getServerProtocolVersion(); } catch (Exception e) { e.printStackTrace(); return ProtocolVersion.v1_8.getId(); } }
if (entityID != getProvidedEntityId() && Via.getConfig().isShieldBlocking()) { if ((data & 0x10) == 0x10) { if (validBlocking.contains(entityID)) { if (type == Entity1_10Types.EntityType.ARMOR_STAND && Via.getConfig().isHologramPatch()) { if (metadata.getId() == 0 && getMetaByIndex(metadataList, 10) != null) { Metadata meta = getMetaByIndex(metadataList, 10); //Only happens if the armorstand is small wrapper.write(Type.VAR_INT, entityID); wrapper.write(Type.SHORT, (short) 0); wrapper.write(Type.SHORT, (short) (128D * (Via.getConfig().getHologramYOffset() * 32D))); wrapper.write(Type.SHORT, (short) 0); wrapper.write(Type.BOOLEAN, true); if (Via.getConfig().isBossbarPatch()) { if (type == Entity1_10Types.EntityType.ENDER_DRAGON || type == Entity1_10Types.EntityType.WITHER) { if (metadata.getId() == 2) { title = title.isEmpty() ? (type == Entity1_10Types.EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title; if (bar == null) { bar = Via.getAPI().createBossBar(title, BossColor.PINK, BossStyle.SOLID); bossBarMap.put(entityID, bar); bar.addPlayer(uuid); Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(getUser(), bar.getId()); } else { bar.setTitle(title); } else if (metadata.getId() == 6 && !Via.getConfig().isBossbarAntiflicker()) { // If anti flicker is enabled, don't update health
@Subscribe public void onProxyInit(ProxyInitializeEvent e) { PROXY = proxy; VelocityCommandHandler commandHandler = new VelocityCommandHandler(); PROXY.getCommandManager().register(commandHandler, "viaver", "vvvelocity", "viaversion"); api = new VelocityViaAPI(); conf = new VelocityViaConfig(configDir.toFile()); logger = new LoggerWrapper(loggerslf4j); Via.init(ViaManager.builder() .platform(this) .commandHandler(commandHandler) .loader(new VelocityViaLoader()) .injector(new VelocityViaInjector()).build()); Via.getManager().init(); }
@Listener public void onGameStart(GameInitializationEvent event) { // Setup Logger logger = new LoggerWrapper(container.getLogger()); // Setup Plugin conf = new SpongeViaConfig(container, defaultConfig.getParentFile()); SpongeCommandHandler commandHandler = new SpongeCommandHandler(); game.getCommandManager().register(this, commandHandler, "viaversion", "viaver", "vvsponge"); getLogger().info("ViaVersion " + getPluginVersion() + " is now loaded!"); // Init platform Via.init(ViaManager.builder() .platform(this) .commandHandler(commandHandler) .injector(new SpongeViaInjector()) .loader(new SpongeViaLoader(this)) .build()); }
/** * Get the UserConnection from an UUID * * @param uuid UUID object * @return The UserConnection */ protected UserConnection getUserConnection(@NonNull UUID uuid) { return Via.getManager().getConnection(uuid); }
/** * Remove the bossbar from a player * * @param player The player * @return The BossBar object * @deprecated Deprecated use UUID's instead of Player objects {@link #removePlayer(UUID)} */ @Deprecated public BossBar removePlayer(T player) { throw new UnsupportedOperationException("This method is not implemented for the platform " + Via.getPlatform().getPlatformName()); }
@Override public boolean execute(ViaCommandSender sender, String[] args) { ConfigurationProvider provider = Via.getPlatform().getConfigurationProvider(); boolean newValue = !Via.getConfig().isCheckForUpdates(); provider.set("checkforupdates", newValue); provider.saveConfig(); sendMessage(sender, "&6We will %snotify you about updates.", (newValue ? "&a" : "&cnot ")); return true; } }
@Override public String description() { return "Forces ViaVersion to scan server protocol versions " + (((VelocityViaConfig) Via.getConfig()).getVelocityPingInterval() == -1 ? "" : "(Also happens at an interval)"); }
@Override public void init(UserConnection userConnection) { userConnection.put(new EntityTracker(userConnection)); userConnection.put(new TabCompleteTracker(userConnection)); if (!userConnection.has(ClientWorld.class)) userConnection.put(new ClientWorld(userConnection)); userConnection.put(new BlockStorage(userConnection)); if (Via.getConfig().isServersideBlockConnections()) { if (Via.getManager().getProviders().get(BlockConnectionProvider.class) instanceof PacketBlockConnectionProvider) { userConnection.put(new BlockConnectionStorage(userConnection)); } } }
public ViaVersionPlugin() { // Command handler commandHandler = new BukkitCommandHandler(); // Init platform Via.init(ViaManager.builder() .platform(this) .commandHandler(commandHandler) .injector(new BukkitViaInjector()) .loader(new BukkitViaLoader(this)) .build()); // Config magic conf = new BukkitViaConfig(); // For compatibility ViaVersion.setInstance(this); // Check if we're using protocol support too protocolSupport = Bukkit.getPluginManager().getPlugin("ProtocolSupport") != null; if (protocolSupport) { getLogger().info("Hooking into ProtocolSupport, to prevent issues!"); try { BukkitViaInjector.patchLists(); } catch (Exception e) { e.printStackTrace(); } } }
@Nonnull @Override public BossBar newBossBar() { return new ViaBossBar(Via.getAPI().createBossBar("null", convertColor(BossBarColor.defaultColor()), convertStyle(BossBarStyle.defaultStyle()))); }