Jump to content
  • 0

pomoc FileManager - Java


Invouk

Dotaz

Ahojte,

Mám taký problém, chcem si vytvoriť súbor lang.yml do ktorého si už budem zapisovať multi language.
No problém je v tom, hľadám  asi 6 hodín cca. a stále som nič nenašiel, tak som sa rozhodol napísať sem.

Robil som to podla dosť tutorialov, ktoré bud mi vracali null, čiže nešlo z ních čítať, a ani zapisovať.
(Aktuálny kód nemám, kedže som to robil podla viac tutorialov a tie predchadzajuce som mazal)

Ďakujem za každú radu.

Link to comment
Share on other sites

6 odpovědí na tuto otázku

Recommended Posts

  • 0

 

 

package PluginConfigs;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;

import com.google.common.base.Charsets; 

public class lang implements Listener{

	//Final plugin var
    private Plugin plugin;

    //Config file variables, will never change therefore final
    private String configPath;
    private File configFile;

    //The config object
    private FileConfiguration config;

    public void CustomConfiguration(Plugin plugin, String name, boolean replace) {
        //Defining our variables
        this.plugin = plugin;
        configFile = new File("plugins/Custom/" + name + ".yml");

        create(replace);
    }

    private void create(boolean replace) {
        //Checking if the file exists, if not create the file.
        if(!configFile.exists()) {
            plugin.saveResource(configPath, replace);
        }

        //Loading the config.
        config = YamlConfiguration.loadConfiguration(configFile);

    }

    public void save() {
        //Gotta hate them IOExceptions.
        try {
            //Saving the config file.
            config.save(configFile);
        } catch(IOException e) {
            plugin.getLogger().severe("Failed to save " + configPath);

        }
    }

    public void reload() {
        //Reloading the config.
        config = YamlConfiguration.loadConfiguration(configFile);

        //Getting the local config file's input stream.
        InputStream defConfigStream = plugin.getResource(configPath);

        //Setting the config's defaults
        if(defConfigStream != null) {
            config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
        } else {
            plugin.getLogger().severe("Failed to reload " + configPath);
        }

    }

    //Getting the config object.
    public FileConfiguration getConfig() {
        return config;
    }

}

 


Tak skúsme tento teda,
v onEnable:
 

	@Override
	public void onEnable(){
		
		new lang().CustomConfiguration(this,"lang",  true);
		new lang().getConfig().addDefault("en-player_join", "Player %player has joined to the server%");
		
		
		conn.Connect();
		if(conn.isConnected()) Chat.print("§aDatabase has been connected to MySQL server !");
		else Chat.print("§cErrror while connecting to MySQL server !");
		
		instance = this;

		registerEvents();
	}

Ak máš nejaký nápad na zlepšenie kludne píš.

error:


Enabling CustomPlugin v0.001
[16:11:19] [server thread/ERROR]: Error occurred while enabling CustomPlugin v0.001 (Is it up to date?)
java.lang.IllegalArgumentException: ResourcePath cannot be null or empty
at org.bukkit.plugin.java.JavaPlugin.saveResource(JavaPlugin.java:196) ~[spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at PluginConfigs.playerdata.create(playerdata.java:38) ~[?:?]
at PluginConfigs.playerdata.CustomConfiguration(playerdata.java:32) ~[?:?]
at sk.xpress.custom.Main.onEnable(Main.java:36) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:271) ~[spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugin(CraftServer.java:376) [spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugins(CraftServer.java:326) [spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.reload(CraftServer.java:750) [spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.Bukkit.reload(Bukkit.java:540) [spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:650) [spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchServerCommand(CraftServer.java:636) [spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at net.minecraft.server.v1_11_R1.DedicatedServer.aM(DedicatedServer.java:437) [spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot-latest.jar:git-Spigot-3fb9445-2b6c9f4]
at net.minecraft.server.v1_11_

 

Edited by XpresS
Link to comment
Share on other sites

  • 0

No to som zistil z prekladu:

Kedtak podla tutorialu ktorého som to "robil":

https://www.spigotmc.org/threads/custom-configuration-files.174917/


Keby to niekoho zaujímalo 
tak problém ból v  tom, že čítanie zo súbora

sk-player_join

tam mala ísť botka miesto Pomlčky - 
a
 

lang cfg = new lang();

@Override
public onEnable()
}
    cfg.CustomConfiguration(this,"lang",  false);
}

Díky #Xogos
 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...