Search in sources :

Example 1 with ResourcePack

use of de.themoep.resourcepacksplugin.core.ResourcePack in project ResourcepacksPlugins by Phoenix616.

the class ProxyPackListener method onPluginMessageReceived.

@Override
public void onPluginMessageReceived(String channel, Player p, byte[] message) {
    if (!channel.equals("rp:plugin")) {
        return;
    }
    ByteArrayDataInput in = ByteStreams.newDataInput(message);
    String subchannel = in.readUTF();
    if (subchannel.equals("packChange")) {
        String playerName = in.readUTF();
        UUID playerUuid = new UUID(in.readLong(), in.readLong());
        String packName = in.readUTF();
        String packUrl = in.readUTF();
        String packHash = in.readUTF();
        Player player = plugin.getServer().getPlayer(playerUuid);
        if (player == null || !player.isOnline()) {
            plugin.logDebug("Proxy send pack " + packName + " (" + packUrl + ") to player " + playerName + " but they aren't online?");
        }
        ResourcePack pack = plugin.getPackManager().getByName(packName);
        if (pack == null) {
            try {
                pack = new ResourcePack(packName, packUrl, packHash);
                plugin.getPackManager().addPack(pack);
            } catch (IllegalArgumentException e) {
                pack = plugin.getPackManager().getByHash(packHash);
                if (pack == null) {
                    pack = plugin.getPackManager().getByUrl(packUrl);
                }
            }
        }
        plugin.logDebug("Proxy send pack " + pack.getName() + " (" + pack.getUrl() + ") to player " + playerName);
        plugin.getUserManager().setUserPack(playerUuid, pack);
    } else if (subchannel.equals("clearPack")) {
        String playerName = in.readUTF();
        UUID playerUuid = new UUID(in.readLong(), in.readLong());
        Player player = plugin.getServer().getPlayer(playerUuid);
        if (player == null || !player.isOnline()) {
            plugin.logDebug("Proxy send command to clear the pack of player " + playerName + " but they aren't online?");
        }
        plugin.logDebug("Proxy send command to clear the pack of player " + playerName);
        plugin.clearPack(playerUuid);
    } else if (subChannels.containsKey(subchannel)) {
        subChannels.get(subchannel).execute(p, in);
    } else {
        plugin.getLogger().log(Level.WARNING, "Unknown subchannel " + subchannel + "! Please make sure you are running a compatible plugin version on your Proxy!");
    }
}
Also used : Player(org.bukkit.entity.Player) ResourcePack(de.themoep.resourcepacksplugin.core.ResourcePack) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) UUID(java.util.UUID)

Example 2 with ResourcePack

use of de.themoep.resourcepacksplugin.core.ResourcePack in project ResourcepacksPlugins by Phoenix616.

the class BungeeResourcepacks method saveConfigChanges.

public void saveConfigChanges() {
    getConfig().set("packs", null);
    for (ResourcePack pack : getPackManager().getPacks()) {
        if (pack.getName().startsWith("backend-")) {
            continue;
        }
        String path = "packs." + pack.getName();
        if (pack.equals(getPackManager().getEmptyPack()) && getConfig().isSection("empty")) {
            path = "empty";
        }
        setConfigFlat(path, pack.serialize());
    }
    setConfigFlat(getPackManager().getGlobalAssignment().getName(), getPackManager().getGlobalAssignment().serialize());
    for (PackAssignment assignment : getPackManager().getAssignments()) {
        setConfigFlat("servers." + assignment.getName(), assignment.serialize());
    }
    getConfig().saveConfig();
}
Also used : ResourcePack(de.themoep.resourcepacksplugin.core.ResourcePack) PackAssignment(de.themoep.resourcepacksplugin.core.PackAssignment)

Example 3 with ResourcePack

use of de.themoep.resourcepacksplugin.core.ResourcePack in project ResourcepacksPlugins by Phoenix616.

the class BungeeResourcepacks method loadConfig.

public boolean loadConfig() {
    try {
        config = new FileConfiguration(this, new File(getDataFolder(), "config.yml"), "bungee-config.yml");
        getLogger().log(Level.INFO, "Loading config!");
    } catch (IOException e) {
        getLogger().log(Level.SEVERE, "Unable to load configuration! " + getDescription().getName() + " will not be enabled!", e);
        return false;
    }
    try {
        storedPacks = new FileConfiguration(this, new File(getDataFolder(), "players.yml"));
    } catch (IOException e) {
        getLogger().log(Level.SEVERE, "Unable to load players.yml! Stored player packs will not work!", e);
    }
    try {
        packetMap = new FileConfiguration(this, new File(getDataFolder(), "packetmap.yml"));
    } catch (IOException e) {
        getLogger().log(Level.SEVERE, "Unable to load packetmap.yml! The plugin will not work!", e);
        return false;
    }
    String debugString = getConfig().getString("debug");
    if (debugString.equalsIgnoreCase("true")) {
        loglevel = Level.INFO;
    } else if (debugString.equalsIgnoreCase("false") || debugString.equalsIgnoreCase("off")) {
        loglevel = Level.FINE;
    } else {
        try {
            loglevel = Level.parse(debugString.toUpperCase());
        } catch (IllegalArgumentException e) {
            getLogger().log(Level.SEVERE, "Wrong config value for debug! To disable debugging just set it to \"false\"! (" + e.getMessage() + ")");
        }
    }
    getLogger().log(Level.INFO, "Debug level: " + getLogLevel().getName());
    if (getConfig().getBoolean("use-auth-plugin", getConfig().getBoolean("useauth", false))) {
        getLogger().log(Level.INFO, "Compatibility with backend authentication plugin ('use-auth-plugin') is enabled.");
    }
    lm = new LanguageManager(this, getConfig().getString("default-language"));
    getPackManager().init();
    if (getConfig().isSet("packs", true) && getConfig().isSection("packs")) {
        getLogger().log(Level.INFO, "Loading packs:");
        Configuration packs = getConfig().getSection("packs");
        for (String s : packs.getKeys()) {
            if (packs.get(s) instanceof Configuration) {
                Configuration packSection = packs.getSection(s);
                try {
                    ResourcePack pack = getPackManager().loadPack(s, getConfigMap(packSection));
                    getLogger().log(Level.INFO, pack.getName() + " - " + (pack.getVariants().isEmpty() ? (pack.getUrl() + " - " + pack.getHash()) : pack.getVariants().size() + " variants"));
                    ResourcePack previous = getPackManager().addPack(pack);
                    if (previous != null) {
                        getLogger().log(Level.WARNING, "Multiple resource packs with name '" + previous.getName().toLowerCase() + "' found!");
                    }
                    logDebug(pack.serialize().toString());
                } catch (IllegalArgumentException e) {
                    getLogger().log(Level.SEVERE, e.getMessage());
                }
            }
        }
    } else {
        logDebug("No packs defined!");
    }
    if (getConfig().isSection("empty")) {
        Configuration packSection = getConfig().getSection("empty");
        try {
            ResourcePack pack = getPackManager().loadPack(PackManager.EMPTY_IDENTIFIER, getConfigMap(packSection));
            getLogger().log(Level.INFO, "Empty pack - " + (pack.getVariants().isEmpty() ? (pack.getUrl() + " - " + pack.getHash()) : pack.getVariants().size() + " variants"));
            getPackManager().addPack(pack);
            getPackManager().setEmptyPack(pack);
        } catch (IllegalArgumentException e) {
            getLogger().log(Level.SEVERE, e.getMessage());
        }
    } else {
        String emptypackname = getConfig().getString("empty");
        if (emptypackname != null && !emptypackname.isEmpty()) {
            ResourcePack ep = getPackManager().getByName(emptypackname);
            if (ep != null) {
                getLogger().log(Level.INFO, "Empty pack: " + ep.getName());
                getPackManager().setEmptyPack(ep);
            } else {
                getLogger().log(Level.WARNING, "Cannot set empty resourcepack as there is no pack with the name " + emptypackname + " defined!");
            }
        } else {
            getLogger().log(Level.WARNING, "No empty pack defined!");
        }
    }
    if (getConfig().isSet("global", true) && getConfig().isSection("global")) {
        getLogger().log(Level.INFO, "Loading global assignment...");
        Configuration globalSection = getConfig().getSection("global");
        PackAssignment globalAssignment = getPackManager().loadAssignment("global", getValues(globalSection));
        getPackManager().setGlobalAssignment(globalAssignment);
        logDebug("Loaded " + globalAssignment.toString());
    } else {
        logDebug("No global assignment defined!");
    }
    if (getConfig().isSet("servers", true) && getConfig().isSection("servers")) {
        getLogger().log(Level.INFO, "Loading server assignments...");
        Configuration servers = getConfig().getSection("servers");
        for (String server : servers.getKeys()) {
            if (servers.get(server) instanceof Configuration) {
                Configuration serverSection = servers.getSection(server);
                if (!serverSection.getKeys().isEmpty()) {
                    getLogger().log(Level.INFO, "Loading assignment for server " + server + "...");
                    PackAssignment serverAssignment = getPackManager().loadAssignment(server, getValues(serverSection));
                    getPackManager().addAssignment(serverAssignment);
                    logDebug("Loaded server assignment " + serverAssignment.toString());
                } else {
                    getLogger().log(Level.WARNING, "Config has entry for server " + server + " but it is not a configuration section?");
                }
            }
        }
    } else {
        logDebug("No server assignments defined!");
    }
    getPackManager().setStoredPacksOverride(getConfig().getBoolean("stored-packs-override-assignments"));
    logDebug("Stored packs override assignments: " + getPackManager().getStoredPacksOverride());
    return true;
}
Also used : FileConfiguration(de.themoep.bungeeplugin.FileConfiguration) Configuration(net.md_5.bungee.config.Configuration) FileConfiguration(de.themoep.bungeeplugin.FileConfiguration) ResourcePack(de.themoep.resourcepacksplugin.core.ResourcePack) LanguageManager(de.themoep.utils.lang.bungee.LanguageManager) IOException(java.io.IOException) File(java.io.File) PackAssignment(de.themoep.resourcepacksplugin.core.PackAssignment)

Example 4 with ResourcePack

use of de.themoep.resourcepacksplugin.core.ResourcePack in project ResourcepacksPlugins by Phoenix616.

the class SpongeResourcepacks method saveConfigChanges.

public void saveConfigChanges() {
    getConfig().set("packs", null);
    for (ResourcePack pack : getPackManager().getPacks()) {
        String path = "packs." + pack.getName();
        if (pack.equals(getPackManager().getEmptyPack()) && getConfig().isSection("empty")) {
            path = "empty";
        }
        setConfigFlat(path, pack.serialize());
    }
    setConfigFlat(getPackManager().getGlobalAssignment().getName(), getPackManager().getGlobalAssignment().serialize());
    for (PackAssignment assignment : getPackManager().getAssignments()) {
        setConfigFlat("worlds." + assignment.getName(), assignment.serialize());
    }
    getConfig().save();
}
Also used : ResourcePack(de.themoep.resourcepacksplugin.core.ResourcePack) PackAssignment(de.themoep.resourcepacksplugin.core.PackAssignment)

Example 5 with ResourcePack

use of de.themoep.resourcepacksplugin.core.ResourcePack in project ResourcepacksPlugins by Phoenix616.

the class SpongeResourcepacks method loadConfig.

public boolean loadConfig() {
    log(Level.INFO, "Loading config!");
    config = new PluginConfig(this, new File(getDataFolder(), "config.yml"), "sponge-config.yml");
    try {
        config.createDefaultConfig();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    if (!config.load()) {
        return false;
    }
    storedPacks = new PluginConfig(this, new File(getDataFolder(), "players.conf"), null);
    if (!storedPacks.load()) {
        log(Level.SEVERE, "Unable to load players.yml! Stored player packs will not apply!");
    }
    String debugString = getConfig().getString("debug");
    if (debugString.equalsIgnoreCase("true")) {
        loglevel = Level.INFO;
    } else if (debugString.equalsIgnoreCase("false") || debugString.equalsIgnoreCase("off")) {
        loglevel = Level.FINE;
    } else {
        try {
            loglevel = Level.parse(debugString.toUpperCase());
        } catch (IllegalArgumentException e) {
            log(Level.SEVERE, "Wrong config value for debug! To disable debugging just set it to \"false\"! (" + e.getMessage() + ")");
        }
    }
    log(Level.INFO, "Debug level: " + getLogLevel().getName());
    lm = new LanguageManager(this, getConfig().getString("default-language"));
    getPackManager().init();
    if (getConfig().isSection("packs")) {
        log(Level.INFO, "Loading packs:");
        ConfigurationNode packs = getConfig().getRawConfig("packs");
        for (Map.Entry<Object, ? extends ConfigurationNode> s : packs.getChildrenMap().entrySet()) {
            ConfigurationNode packSection = s.getValue();
            try {
                ResourcePack pack = getPackManager().loadPack((String) s.getKey(), getConfigMap(packSection));
                log(Level.INFO, pack.getName() + " - " + (pack.getVariants().isEmpty() ? (pack.getUrl() + " - " + pack.getHash()) : pack.getVariants().size() + " variants"));
                ResourcePack previous = getPackManager().addPack(pack);
                if (previous != null) {
                    log(Level.WARNING, "Multiple resource packs with name '" + previous.getName().toLowerCase() + "' found!");
                }
                logDebug(pack.serialize().toString());
            } catch (IllegalArgumentException e) {
                log(Level.SEVERE, e.getMessage());
            }
        }
    } else {
        logDebug("No packs defined!");
    }
    if (getConfig().isSection("empty")) {
        ConfigurationNode packSection = getConfig().getRawConfig("empty");
        try {
            ResourcePack pack = getPackManager().loadPack(PackManager.EMPTY_IDENTIFIER, getConfigMap(packSection));
            log(Level.INFO, "Empty pack - " + (pack.getVariants().isEmpty() ? (pack.getUrl() + " - " + pack.getHash()) : pack.getVariants().size() + " variants"));
            getPackManager().addPack(pack);
            getPackManager().setEmptyPack(pack);
        } catch (IllegalArgumentException e) {
            log(Level.SEVERE, e.getMessage());
        }
    } else {
        String emptypackname = getConfig().getString("empty", null);
        if (emptypackname != null && !emptypackname.isEmpty()) {
            ResourcePack ep = getPackManager().getByName(emptypackname);
            if (ep != null) {
                log(Level.INFO, "Empty pack: " + ep.getName());
                getPackManager().setEmptyPack(ep);
            } else {
                log(Level.WARNING, "Cannot set empty resourcepack as there is no pack with the name " + emptypackname + " defined!");
            }
        } else {
            log(Level.WARNING, "No empty pack defined!");
        }
    }
    if (getConfig().isSection("global")) {
        log(Level.INFO, "Loading global assignment...");
        ConfigurationNode globalSection = getConfig().getRawConfig("global");
        PackAssignment globalAssignment = getPackManager().loadAssignment("global", getValues(globalSection));
        getPackManager().setGlobalAssignment(globalAssignment);
        logDebug("Loaded " + globalAssignment.toString());
    } else {
        logDebug("No global server assignment defined!");
    }
    if (getConfig().isSection("worlds")) {
        log(Level.INFO, "Loading world assignments...");
        ConfigurationNode worlds = getConfig().getRawConfig("worlds");
        for (Map.Entry<Object, ? extends ConfigurationNode> world : worlds.getChildrenMap().entrySet()) {
            ConfigurationNode worldSection = world.getValue();
            if (worldSection != null) {
                log(Level.INFO, "Loading assignment for world " + world.getKey() + "...");
                PackAssignment worldAssignment = getPackManager().loadAssignment((String) world.getKey(), getValues(worldSection));
                getPackManager().addAssignment(worldAssignment);
                logDebug("Loaded " + worldAssignment.toString());
            } else {
                log(Level.WARNING, "Config has entry for world " + world + " but it is not a configuration section?");
            }
        }
    } else {
        logDebug("No world assignments defined!");
    }
    getPackManager().setStoredPacksOverride(getConfig().getBoolean("stored-packs-override-assignments"));
    logDebug("Stored packs override assignments: " + getPackManager().getStoredPacksOverride());
    return true;
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ResourcePack(de.themoep.resourcepacksplugin.core.ResourcePack) LanguageManager(de.themoep.utils.lang.sponge.LanguageManager) IOException(java.io.IOException) File(java.io.File) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) PackAssignment(de.themoep.resourcepacksplugin.core.PackAssignment)

Aggregations

ResourcePack (de.themoep.resourcepacksplugin.core.ResourcePack)15 PackAssignment (de.themoep.resourcepacksplugin.core.PackAssignment)8 UUID (java.util.UUID)4 File (java.io.File)3 IOException (java.io.IOException)3 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)2 Subscribe (com.velocitypowered.api.event.Subscribe)1 ServerConnection (com.velocitypowered.api.proxy.ServerConnection)1 FileConfiguration (de.themoep.bungeeplugin.FileConfiguration)1 AuthmeLoginListener (de.themoep.resourcepacksplugin.bukkit.listeners.AuthmeLoginListener)1 NLoginListener (de.themoep.resourcepacksplugin.bukkit.listeners.NLoginListener)1 OpeNLoginListener (de.themoep.resourcepacksplugin.bukkit.listeners.OpeNLoginListener)1 BungeeResourcepacks (de.themoep.resourcepacksplugin.bungee.BungeeResourcepacks)1 ResourcepacksPlayer (de.themoep.resourcepacksplugin.core.ResourcepacksPlayer)1 LanguageManager (de.themoep.utils.lang.bukkit.LanguageManager)1 LanguageManager (de.themoep.utils.lang.bungee.LanguageManager)1 LanguageManager (de.themoep.utils.lang.sponge.LanguageManager)1