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

Помогите [SPONGE] Ошибка компиляции, как всегда - черная магия.

Тема в разделе "Разработка плагинов для новичков", создана пользователем Mr_RoboMan, 12 ноя 2016.

Статус темы:
Закрыта.
  1. Автор темы
    Mr_RoboMan

    Mr_RoboMan Старожил Пользователь

    Баллы:
    123
    Драсти.
    Как всегда черная
    магия.
    Код:
    package ua.gwm.sponge_plugin.mc_nevendaar.config.type_serilizers;
    
    import com.google.common.reflect.TypeToken;
    import ninja.leaping.configurate.ConfigurationNode;
    import ninja.leaping.configurate.objectmapping.ObjectMappingException;
    import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer;
    import org.spongepowered.api.Sponge;
    import org.spongepowered.api.world.Location;
    import org.spongepowered.api.world.World;
    
    import java.util.Optional;
    
    public class LocationSerializer implements TypeSerializer<Location<World>> {
    
        @Override
        public Location<World> deserialize(TypeToken<?> token, ConfigurationNode node) throws ObjectMappingException {
            if (!node.getNode("WORLD").isVirtual()) {
                throw new ObjectMappingException("World does not specified!");
            }
            if (!node.getNode("X").isVirtual()) {
                throw new ObjectMappingException("X coordinate does not specified!");
            }
            if (!node.getNode("Y").isVirtual()) {
                throw new ObjectMappingException("Y coordinate does not specified");
            }
            if (!node.getNode("Z").isVirtual()) {
                throw new ObjectMappingException("Z coordinate does not specified!");
            }
            String world_name = node.getNode("WORLD").getString();
            Optional<World> optional_world = Sponge.getServer().getWorld(world_name);
            if (!optional_world.isPresent()) {
                throw new ObjectMappingException("World \"" + world_name + "\" does not exist!");
            }
            World world = optional_world.get();
            double x = node.getNode("X").getDouble();
            double y = node.getNode("Y").getDouble();
            double z = node.getNode("Z").getDouble();
            Location<World> location = new Location<World>(world, x, y, z);
            return location;
        }
    
        @Override
        public void serialize(TypeToken<?> token, Location<World> location, ConfigurationNode node) throws ObjectMappingException {
            World world = location.getExtent();
            double x = location.getX();
            double y = location.getY();
            double z = location.getZ();
            String world_name = world.getName();
            node.getNode("WORLD").setValue(world_name);
            node.getNode("X").setValue(x);
            node.getNode("Y").setValue(y);
            node.getNode("Z").setValue(z);
        }
    }
    111 строчка - видна на скрине,
    116 & 188 - идентичные, только для других конфигов.
    [​IMG]
    Код:
    package ua.gwm.sponge_plugin.mc_nevendaar;
    
    import com.google.common.reflect.TypeToken;
    import com.google.inject.Inject;
    import org.slf4j.Logger;
    import org.spongepowered.api.Sponge;
    import org.spongepowered.api.config.ConfigDir;
    import org.spongepowered.api.event.Listener;
    import org.spongepowered.api.event.entity.MoveEntityEvent;
    import org.spongepowered.api.event.game.state.*;
    import org.spongepowered.api.event.message.MessageChannelEvent;
    import org.spongepowered.api.event.server.ClientPingServerEvent;
    import org.spongepowered.api.plugin.Plugin;
    import org.spongepowered.api.world.Location;
    import ua.gwm.sponge_plugin.mc_nevendaar.commands.auth.ConfirmEmailCommand;
    import ua.gwm.sponge_plugin.mc_nevendaar.commands.auth.LoginCommand;
    import ua.gwm.sponge_plugin.mc_nevendaar.commands.auth.RegisterCommand;
    import ua.gwm.sponge_plugin.mc_nevendaar.commands.info.FactionsTopCommand;
    import ua.gwm.sponge_plugin.mc_nevendaar.commands.info.PlayersTopCommand;
    import ua.gwm.sponge_plugin.mc_nevendaar.commands.info.RacesTopCommand;
    import ua.gwm.sponge_plugin.mc_nevendaar.commands.teleportation.WarpsCommand;
    import ua.gwm.sponge_plugin.mc_nevendaar.commands.teleportation.*;
    import ua.gwm.sponge_plugin.mc_nevendaar.config.Config;
    import ua.gwm.sponge_plugin.mc_nevendaar.config.type_serilizers.EntityArchetypeSerializer;
    import ua.gwm.sponge_plugin.mc_nevendaar.config.type_serilizers.ItemStackSerializer;
    import ua.gwm.sponge_plugin.mc_nevendaar.config.type_serilizers.LocationSerializer;
    import ua.gwm.sponge_plugin.mc_nevendaar.handlers.ChatHandler;
    import ua.gwm.sponge_plugin.mc_nevendaar.handlers.TeleportHandler;
    import ua.gwm.sponge_plugin.mc_nevendaar.listeners.AuthListener;
    import ua.gwm.sponge_plugin.mc_nevendaar.listeners.RaceListener;
    import ua.gwm.sponge_plugin.mc_nevendaar.managers.AuthManager;
    import ua.gwm.sponge_plugin.mc_nevendaar.managers.EmailManager;
    import ua.gwm.sponge_plugin.mc_nevendaar.managers.TeleportManager;
    
    import java.io.File;
    import java.nio.file.Path;
    import java.util.HashMap;
    import java.util.Map;
    
    @Plugin(id = "mcnevendaar", name = "MC-NEVENDAAR", version = "1.0alpha", description = "Welcome to Nevendaar universe.")
    public class MCNEVENDAAR {
    
        private static MCNEVENDAAR plugin;
    
        public static MCNEVENDAAR getPlugin() {
            return plugin;
        }
    
        @Inject
        @ConfigDir(sharedRoot = false)
        private Path config_directory;
    
        @Inject
        private Logger logger;
    
        private final Map<String, Config> languages = new HashMap<String, Config>();
    
        private final Config config = new Config("config.conf");
        private final Config faction_config = new Config("factions.conf");
        private final Config permission_config = new Config("permissions.conf");
        private final Config race_config = new Config("races.conf");
        private final Config user_config = new Config("users.conf");
        private final Config warp_config = new Config("warps.conf");
        private final Config email_config = new Config("email.conf");
    
        private final AuthListener auth_listener = new AuthListener();
        private final RaceListener race_listener = new RaceListener();
    
        private final ChatHandler chat_handler = new ChatHandler();
        private final TeleportHandler teleport_handler = new TeleportHandler();
    
        private final TeleportManager teleport_manager = new TeleportManager();
        private final AuthManager auth_manager = new AuthManager();
        private final EmailManager email_manager = new EmailManager("email", "password");
    
        private final RegisterCommand register_command = new RegisterCommand();
        private final LoginCommand login_command = new LoginCommand();
        private final ConfirmEmailCommand confirm_email_command = new ConfirmEmailCommand();
        private final PlayersTopCommand players_top_command = new PlayersTopCommand();
        private final RacesTopCommand races_top_command = new RacesTopCommand();
        private final FactionsTopCommand factions_top_command = new FactionsTopCommand();
        private final SetSpawnCommand set_spawn_command = new SetSpawnCommand();
        private final SpawnCommand spawn_command = new SpawnCommand();
        private final SetHomeCommand set_home_command = new SetHomeCommand();
        private final HomeCommand home_command = new HomeCommand();
        private final CreateWarpCommand create_warp_command = new CreateWarpCommand();
        private final DeleteWarpCommand delete_warp_command = new DeleteWarpCommand();
        private final WarpCommand warp_command = new WarpCommand();
        private final WarpsCommand warps_command = new WarpsCommand();
    
        private final LocationSerializer location_serializer = new LocationSerializer();
        private final ItemStackSerializer item_stack_serializer = new ItemStackSerializer();
        private final EntityArchetypeSerializer entity_archetype_serializer = new EntityArchetypeSerializer();
    
        @Listener
        public void construction(GameConstructionEvent event) {
            plugin = this;
        }
    
        @Listener
        public void preInitialization(GamePreInitializationEvent event) {
            File file_config_directory = getConfigDirectory().toFile();
            if (!file_config_directory.exists()) {
                file_config_directory.mkdirs();
            }
            File file_languages = new File(file_config_directory, "languages");
            if (!file_languages.exists()) {
                file_languages.mkdirs();
            }
            getConfig().activate();
            getConfig().getNode().getOptions().getSerializers().registerType(TypeToken.of(Location.class), location_serializer);
            getFactionConfig().activate();
            getPermissionConfig().activate();
            getRaceConfig().activate();
            getUserConfig().activate();
            getConfig().getNode().getOptions().getSerializers().registerType(TypeToken.of(Location.class), location_serializer);
            getWarpConfig().activate();
            getWarpConfig().getNode().getOptions().getSerializers().registerType(TypeToken.of(Location.class), location_serializer);
            getEmailConfig().activate();
            Config ru_RU_config = new Config("languages/ru_RU.conf");
            ru_RU_config.activate();
            Config en_US_config = new Config("languages/en_US.conf");
            en_US_config.activate();
            getLanguages().put("ru_RU", ru_RU_config);
            getLanguages().put("en_US", en_US_config);
            getEmailManager().setEmail(getEmailConfig().getNode("ADDRESS").getString());
            getEmailManager().setPassword(getEmailConfig().getNode("PASSWORD").getString());
            getLogger().info("Pre-Initialization complete!");
        }
    
        @Listener
        public void initialization(GameInitializationEvent event) {
            Sponge.getCommandManager().register(this, getRegisterCommand(), "register", "reg");
            Sponge.getCommandManager().register(this, getLoginCommand(), "login", "l");
            Sponge.getCommandManager().register(this, getConfirmEmailCommand(), "confirmemail");
            Sponge.getCommandManager().register(this, getPlayersTopCommand(), "playerstop", "ptop");
            Sponge.getCommandManager().register(this, getRacesTopCommand(), "racestop", "rtop");
            Sponge.getCommandManager().register(this, getFactionsTopCommand(), "factionstop", "ftop");
            Sponge.getCommandManager().register(this, set_spawn_command, "setspawn");
            Sponge.getCommandManager().register(this, spawn_command, "spawn");
            Sponge.getCommandManager().register(this, set_home_command, "sethome");
            Sponge.getCommandManager().register(this, home_command, "home");
            Sponge.getCommandManager().register(this, create_warp_command, "createwarp", "cwarp");
            Sponge.getCommandManager().register(this, delete_warp_command, "deletewarp", "dwarp");
            Sponge.getCommandManager().register(this, warp_command, "warp");
            Sponge.getCommandManager().register(this, warps_command, "warps");
            Sponge.getEventManager().registerListeners(this, auth_listener);
            Sponge.getEventManager().registerListeners(this, race_listener);
            Sponge.getEventManager().registerListener(this, MessageChannelEvent.Chat.class, chat_handler);
            Sponge.getEventManager().registerListener(this, MoveEntityEvent.class, teleport_handler);
            getLogger().info("Initialization complete!");
        }
    
        @Listener
        public void started(GameStartedServerEvent event) {
            getLogger().info("Enabled!");
        }
    
        @Listener
        public void stopping(GameStoppingServerEvent event) {
            getConfig().save();
            getFactionConfig().save();
            getPermissionConfig().save();
            getRaceConfig().save();
            getUserConfig().save();
            getWarpConfig().save();
            getLogger().info("Disabling!");
        }
    
        @Listener
        public void online(ClientPingServerEvent event) {
            if (event.getResponse().getPlayers().isPresent()) {
                ClientPingServerEvent.Response.Players players = event.getResponse().getPlayers().get();
                players.setMax(-1);
            }
        }
    
        public Path getConfigDirectory() {
            return this.config_directory;
        }
    
        public Logger getLogger() {
            return this.logger;
        }
    
        public Map<String, Config> getLanguages() {
            return this.languages;
        }
    
        public Config getConfig() {
            return this.config;
        }
    
        public Config getFactionConfig() {
            return this.faction_config;
        }
    
        public Config getPermissionConfig() {
            return this.permission_config;
        }
    
        public Config getRaceConfig() {
            return this.race_config;
        }
    
        public Config getUserConfig() {
            return this.user_config;
        }
    
        public Config getWarpConfig() {
            return this.warp_config;
        }
    
        public Config getEmailConfig() {
            return this.email_config;
        }
    
        public AuthListener getAuthListener() {
            return this.auth_listener;
        }
    
        public RaceListener getRaceListener() {
            return this.race_listener;
        }
    
        public ChatHandler getChatHandler() {
            return this.chat_handler;
        }
    
        public TeleportHandler getTeleportHandler() {
            return this.teleport_handler;
        }
    
        public TeleportManager getTeleportManager() {
            return this.teleport_manager;
        }
    
        public AuthManager getAuthManager() {
            return this.auth_manager;
        }
    
        public EmailManager getEmailManager() {
            return this.email_manager;
        }
    
        public RegisterCommand getRegisterCommand() {
            return this.register_command;
        }
    
        public LoginCommand getLoginCommand() {
            return this.login_command;
        }
    
        public ConfirmEmailCommand getConfirmEmailCommand() {
            return this.confirm_email_command;
        }
    
        public PlayersTopCommand getPlayersTopCommand() {
            return this.players_top_command;
        }
    
        public RacesTopCommand getRacesTopCommand() {
            return this.races_top_command;
        }
    
        public FactionsTopCommand getFactionsTopCommand() {
            return this.factions_top_command;
        }
    }
    Я вот не понимаю, чего не так то? :-(
     
  2. Хостинг MineCraft
    <
  3. Автор темы
    Mr_RoboMan

    Mr_RoboMan Старожил Пользователь

    Баллы:
    123
    Я вроде понимаю что оно пишет про то что не может кастануть типы.. Но почему это не может!?!
    Ведь у меня мой LocationSerializer нормально унаследован, от TypeSerializer<Lcoation>..[DOUBLEPOST=1478977647,1478977520][/DOUBLEPOST]Хотя у меня появилось предположение что это из-за того что я унаследовал именно от Location<World>...
    Хм, т.е. получается я не могу сделать сериализатор именно для Location<World>, а только для Location? :-([DOUBLEPOST=1478977909][/DOUBLEPOST]Мхм... Да, как я и думал, унаследовал просто от TypeSerializer<Location>, и все чики-пуки, но всё-же..
    Как-то, не сахар...
     
  4. alexandrage

    alexandrage Администратор

    Баллы:
    173
    Skype:
    alexandr0116
    Тебе же белым по черному написали, зарегистрируй токен.
     
  5. Автор темы
    Mr_RoboMan

    Mr_RoboMan Старожил Пользователь

    Баллы:
    123
    Эм.. Хм.. Так я его как раз и регистрирую в 112, 116, 118 строках..
    Проблема решилась заменой "TypeToken.of(Location.class)" на "new TypeToken<Location<World>>(){}".
     
Статус темы:
Закрыта.

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