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

Помогите Пропажа данных

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

  1. dark32

    dark32 А где твой ТЗ? Пользователь

    Баллы:
    123
    Имя в Minecraft:
    dark32
    Дебаг в лоб - ставить бряк на изменение переменной или пошаговая отладка.
     
    Larin нравится это.
  2. Хостинг MineCraft
    <
  3. Larin

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

    Баллы:
    103
    Кинь весь код, может там что-то не так.
     
  4. Автор темы
    serega6531

    serega6531 Старожил Девелопер Пользователь

    Баллы:
    173
    Skype:
    shkurovs
    Код:
    Код:
    package ServerInfo;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.comphenix.protocol.PacketType;
    import com.comphenix.protocol.ProtocolLibrary;
    import com.comphenix.protocol.events.ListenerOptions;
    import com.comphenix.protocol.events.ListenerPriority;
    import com.comphenix.protocol.events.PacketAdapter;
    import com.comphenix.protocol.events.PacketEvent;
    import com.comphenix.protocol.wrappers.WrappedGameProfile;
    import com.comphenix.protocol.wrappers.WrappedServerPing;
    
    public class ServerInfo extends JavaPlugin {
       
        Logger log;
        private List<WrappedGameProfile> Text = new ArrayList<WrappedGameProfile>();
        FileConfiguration config;
       
        protected String ConvertFormat(String format){
            return format.replace("#0", ""+ChatColor.BLACK).replace("#1", ""+ChatColor.DARK_BLUE).replace("#2", ""+ChatColor.DARK_GREEN).replace("#3", ""+ChatColor.DARK_AQUA).replace("#4", ""+ChatColor.DARK_RED).replace("#5", ""+ChatColor.DARK_PURPLE).replace("#6", ""+ChatColor.GOLD).replace("#7", ""+ChatColor.GRAY).replace("#8", ""+ChatColor.DARK_GRAY).replace("#9", ""+ChatColor.BLUE).replace("#a", ""+ChatColor.GREEN).replace("#b", ""+ChatColor.AQUA).replace("#c", ""+ChatColor.RED).replace("#d", ""+ChatColor.LIGHT_PURPLE).replace("#e", ""+ChatColor.YELLOW).replace("#f", ""+ChatColor.WHITE);
        }
       
        protected List<WrappedGameProfile> getList(){
            return Text;
        }
       
        protected void setText(List<WrappedGameProfile> Text){
            this.Text = Text;
        }
       
        public void onEnable(){
            log = getLogger();
            log.info("GuiServerInfo activating...");
            this.saveDefaultConfig();
            config = getConfig();
            ProtocolLibrary.getProtocolManager().addPacketListener(
                new PacketAdapter(this, ListenerPriority.NORMAL,
                Arrays.asList(PacketType.Status.Server.OUT_SERVER_INFO), ListenerOptions.ASYNC) {
                    @Override
                    public void onPacketSending(PacketEvent event) {
                        handlePing(event.getPacket().getServerPings().read(0));
                    }
                }
            );
            for (int i = 0; i < config.getStringList("Text").size();i++){
                Text.add(
                        new WrappedGameProfile(
                                "id" + i + 1,
                                ConvertFormat(config.getStringList("Text").get(i)))
                        );
                }
            log.info("GuiServerInfo active!");
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (sender.isOp()){
                if (args.length > 0){
                    if (args[0].equalsIgnoreCase("set")){
                        Text.clear();
                        List<String> newConf = new ArrayList<String>();
                        for (int i = 1; i < args.length; i++){
                            Text.add(new WrappedGameProfile("id" + Text.size() + 1, ConvertFormat(args[i])));
                            newConf.add(args[i]);
                            log.info("Add ServerInfo: " + args[i]);
                        }
                        config.set("Text", newConf);
                        sender.sendMessage("Successful!");
                        return true;
                    }
                }
                return false;
            } else {
                sender.sendMessage("You not op!");
                return true;
            }
        }
       
        private void handlePing(WrappedServerPing ping) {
            ping.setPlayers(Text);
        }
       
        public void onDisable(){
            saveConfig();
            log.info("GuiServerInfo disabled!");
        }
    }

    Код:
    package ServerInfo;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import com.comphenix.protocol.wrappers.WrappedGameProfile;
    
    public class ServerInfoAPI extends ServerInfo {
       
        public void setServerInfo(List<WrappedGameProfile> Text){
            super.setText(Text);
            super.log.info("Set new ServerInfo");
        }
       
        public void setServerInfo(String[] Text){
            List<WrappedGameProfile> tmp = new ArrayList<WrappedGameProfile>();
            for (int i = 0; i < Text.length; i++) {
                tmp.set(i, new WrappedGameProfile("id" + i + 1, ConvertFormat(Text[i])));
            }
            super.setText(tmp);
            super.log.info("Set new ServerInfo");
        }
       
        public void insertServerInfoString(String str, int num){
            getList().set(num, new WrappedGameProfile("id" + num, ConvertFormat(str)));
            super.log.info("Add new ServerInfo - num:" + num + ", Text:" + str);
        }
       
        public void addServerInfoString(String str){
            super.getList().add(new WrappedGameProfile("id" + super.getList().size() + 1, ConvertFormat(str)));
            super.log.info("Add new ServerInfo: " + str);
        }
       
        public int getServerInfoSize(){
            return super.getList().size();
        }
       
        public String getServerInfoString(int num){
            return super.getList().get(num).getName();
        }
       
        public int getServerInfoStringNum(WrappedGameProfile pr){
            return super.getList().indexOf(pr);
        }
    
    }
     

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