/* * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion * Copyright (C) 2016-2024 ViaVersion and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package com.viaversion.viaversion.bungee.platform; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.bungee.providers.BungeeVersionProvider; import com.viaversion.viaversion.configuration.AbstractViaConfig; import java.io.File; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; public class BungeeViaConfig extends AbstractViaConfig { private static final List UNSUPPORTED = Arrays.asList("nms-player-ticking", "item-cache", "quick-move-action-fix", "velocity-ping-interval", "velocity-ping-save", "velocity-servers", "blockconnection-method", "change-1_9-hitbox", "change-1_14-hitbox"); private int bungeePingInterval; private boolean bungeePingSave; private Map bungeeServerProtocols; public BungeeViaConfig(File configFile) { super(new File(configFile, "config.yml")); reload(); } @Override protected void loadFields() { super.loadFields(); bungeePingInterval = getInt("bungee-ping-interval", 60); bungeePingSave = getBoolean("bungee-ping-save", true); bungeeServerProtocols = get("bungee-servers", Map.class, new HashMap<>()); } @Override protected void handleConfig(Map config) { // Parse servers Map servers; if (!(config.get("bungee-servers") instanceof Map)) { servers = new HashMap<>(); } else { servers = (Map) config.get("bungee-servers"); } // Convert any bad Protocol Ids for (Map.Entry entry : new HashSet<>(servers.entrySet())) { if (!(entry.getValue() instanceof Integer)) { if (entry.getValue() instanceof String) { ProtocolVersion found = ProtocolVersion.getClosest((String) entry.getValue()); if (found != null) { servers.put(entry.getKey(), found.getVersion()); } else { servers.remove(entry.getKey()); // Remove! } } else { servers.remove(entry.getKey()); // Remove! } } } // Ensure default exists if (!servers.containsKey("default")) { servers.put("default", BungeeVersionProvider.getLowestSupportedVersion()); } // Put back config.put("bungee-servers", servers); } @Override public List getUnsupportedOptions() { return UNSUPPORTED; } @Override public boolean isItemCache() { return false; } @Override public boolean isNMSPlayerTicking() { return false; } /** * What is the interval for checking servers via ping * -1 for disabled * * @return Ping interval in seconds */ public int getBungeePingInterval() { return bungeePingInterval; } /** * Should the bungee ping be saved to the config on change. * * @return True if it should save */ public boolean isBungeePingSave() { return bungeePingSave; } /** * Get the listed server protocols in the config. * default will be listed as default. * * @return Map of String, Integer */ public Map getBungeeServerProtocols() { return bungeeServerProtocols; } }