Хостинг серверов Minecraft playvds.com
  1. Вы находитесь в русском сообществе Bukkit. Мы - администраторы серверов Minecraft, разрабатываем собственные плагины и переводим на русский язык плагины наших собратьев из других стран.
    Скрыть объявление

Помогите Создание дефолт конфига с локацией

Тема в разделе "Разработка плагинов для новичков", создана пользователем ___Cracker___, 31 июл 2019.

  1. Автор темы
    ___Cracker___

    ___Cracker___ Участник

    Баллы:
    31
    Имя в Minecraft:
    ___Cracker___
    Нужно, чтобы при включении сервера появлялся конфиг с 2 локациями.

    Код:
    Location Spawnpoint1 = new Location(null, 0, 0, 0);
            Location Spawnpoint2 = new Location(null, 0, 0, 0);
            config.addDefault("Spawnpoint1", Spawnpoint1);
            config.addDefault("Spawnpoint2", Spawnpoint2);
            config.options().copyDefaults(true);
            saveConfig();
    С таким кодом при включении сервера в консоли выдаёт ошибку:
    [18:52:29 INFO]: [Main] Enabling Main v1.0-SNAPSHOT
    [18:52:29 ERROR]: Error occurred while enabling Main v1.0-SNAPSHOT (Is it up to
    date?)
    java.lang.NullPointerException: null
    at org.bukkit.Location.serialize(Location.java:607) ~[spigot.jar:git-Spi
    got-1a3504a-84f3da3]
    at org.bukkit.configuration.file.YamlRepresenter$RepresentConfigurationS
    erializable.representData(YamlRepresenter.java:38) ~[spigot.jar:git-Spigot-1a350
    4a-84f3da3]
    at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepr
    esenter.java:95) ~[spigot.jar:git-Spigot-1a3504a-84f3da3]
    at org.yaml.snakeyaml.representer.BaseRepresenter.representMapping(BaseR
    epresenter.java:157) ~[spigot.jar:git-Spigot-1a3504a-84f3da3]
    at org.yaml.snakeyaml.representer.SafeRepresenter$RepresentMap.represent
    Data(SafeRepresenter.java:315) ~[spigot.jar:git-Spigot-1a3504a-84f3da3]
    at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepr
    esenter.java:95) ~[spigot.jar:git-Spigot-1a3504a-84f3da3]
    at org.yaml.snakeyaml.representer.BaseRepresenter.represent(BaseRepresen
    ter.java:65) ~[spigot.jar:git-Spigot-1a3504a-84f3da3]
    at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:306) ~[spigot.jar:git-Spigo
    t-1a3504a-84f3da3]
    at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:270) ~[spigot.jar:git-Spigo
    t-1a3504a-84f3da3]
    at org.yaml.snakeyaml.Yaml.dump(Yaml.java:245) ~[spigot.jar:git-Spigot-1
    a3504a-84f3da3]
    at org.bukkit.configuration.file.YamlConfiguration.saveToString(YamlConf
    iguration.java:40) ~[spigot.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.configuration.file.FileConfiguration.save(FileConfiguratio
    n.java:68) ~[spigot.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.plugin.java.JavaPlugin.saveConfig(JavaPlugin.java:172) ~[s
    pigot.jar:git-Spigot-1a3504a-84f3da3]
    at ru.mail.veldyaev2013.duels.Main.AddDefaultConfig(Main.java:49) ~[?:?]

    at ru.mail.veldyaev2013.duels.Main.onEnable(Main.java:22) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:265) ~[s
    pigot.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:347) [spigot.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:410) [spigot.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugin(CraftServer.
    java:436) [spigot.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugins(CraftServer
    .java:350) [spigot.jar:git-Spigot-1a3504a-84f3da3]
    at net.minecraft.server.v1_13_R2.MinecraftServer.l(MinecraftServer.java:
    580) [spigot.jar:git-Spigot-1a3504a-84f3da3]
    at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:
    542) [spigot.jar:git-Spigot-1a3504a-84f3da3]
    at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:
    420) [spigot.jar:git-Spigot-1a3504a-84f3da3]
    at net.minecraft.server.v1_13_R2.DedicatedServer.init(DedicatedServer.ja
    va:294) [spigot.jar:git-Spigot-1a3504a-84f3da3]
    at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.jav
    a:698) [spigot.jar:git-Spigot-1a3504a-84f3da3]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_212]
     
  2. Хостинг MineCraft
    <
  3. JolyHoska

    JolyHoska Активный участник Пользователь

    Баллы:
    61
    Имя в Minecraft:
    JolyHohol
    Ток добавь float yaw/pitch
    Код:
    @SerializableAs("SerializableLocation")
    public class SerializableLocation implements ConfigurationSerializable {
        @NonNls
        private final String world;
        private final int x;
        private final int y;
        private final int z;
    
        /**
         * Constructs a ConfigurationSerializableLocation with the information of
         * the given Location.
         *
         * @param l
         *            Location to be serialized
         */
        public SerializableLocation(@NotNull Location l) {
            this.world = l.getWorld().getName();
            this.x = l.getBlockX();
            this.y = l.getBlockY();
            this.z = l.getBlockZ();
        }
    
        /**
         * Constructs a ConfigurationSerializableLocation with the given
         * Information. This constructor
         * is meant to be used if ConfigurationSerializableLocation is serialized in
         * another
         * ConfigurationSerializable class.
         *
         * @param map
         */
        public SerializableLocation(@NotNull Map<String, Object> map) {
            this.world = (String) map.get("world");
            this.x = (int)map.get("x");
            this.y = (int)map.get("y");
            this.z = (int)map.get("z");
        }
    
        /**
         * Restores from a map back into the class. Used with bukkit's
         * ConfigurationSerializable.
         *
         * @param map
         *            a Map which represents a ConfigurationSerializableLocation
         * @return A ConfigurationSerializableLocation
         */
        @Contract("_ -> new")
        public static @NotNull SerializableLocation deserialize(Map<String, Object> map) {
            return new SerializableLocation(map);
        }
    
        /**
         * Serialize this ConfigurationSerializableLocation into a Map which contain
         * the values of
         * this class
         *
         * @return Map<String, Object>
         */
        @Override
        public final @NotNull Map<String, Object> serialize() {
            Map<String, Object> map = new HashMap<>();
            map.put("world", this.world);
            map.put("x", this.x);
            map.put("y", this.y);
            map.put("z", this.z);
            return map;
        }
    
        /**
         * Resolves the World on the Server, as a proper location has a reference to
         * the world it belongs to.
         *
         * @param server
         *            The server which the map is on
         * @return Location represented
         */
        @Contract(" -> new")
        public final @NotNull Location getLocation() {
            return new Location(Bukkit.getWorld(this.world), x, y, z);
        }
    }
     
    ___Cracker___ нравится это.
  4. JolyHoska

    JolyHoska Активный участник Пользователь

    Баллы:
    61
    Имя в Minecraft:
    JolyHohol
    Регистрация
    Код:
        static {
         ConfigurationSerialization.registerClass(SerializableLocation.class);
        }
    Потом просто добавляешь в конфиг:
    Код:
    cfg.set("Название локации", new SerializableLocation(Location);
    saveConfig();
    
    Получить локацию:
    Код:
    SerializableLocation sloc = (SerializableLocation)cfg.get("Название локации);
    sloc.getLocation() - твоя локация 
    
     

Поделиться этой страницей