Could not Saving an ArrayList

Discussion in 'Skript' started by ZettosHD, Jul 30, 2020.

  1. Hello, I tried to develope an Blacklist Plugin and it worked very well, but i have the Problem that i dont know
    how to save the Arraylist, that the Forbiddden-words does not get deleted on an reload oder server restart.
    I hope you can help me out.



    Command
    Code (Java):
    package commands;


    import java.awt.List;
    import java.util.ArrayList;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;


    import main.Main;


    public class Chatblock implements CommandExecutor{

     
        public static ArrayList<String> bl = new ArrayList<>();
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player p =(Player)sender;
         
         
         
            if(command.getName().equalsIgnoreCase("blacklist")) {
                if(p.hasPermission("Extras.blacklist")) {
                    if(args.length == 0) {
                        p.sendMessage(Main.pr+"§cBentutze: /blacklist oder bl add : remove : clear <Wort>");
                        return true;
                    }
                    if(args[0].equalsIgnoreCase("add")) {
         
                        if(args.length == 1) {
                            p.sendMessage(Main.pr+"§cBentutze: /blacklist oder bl add : remove : clear <Wort>");
                 
                            return true;
                        }else if(args.length == 2) {
                                    bl.add(args[1]);
                                    p.sendMessage(Main.pr+""+args[1]+" wurde zur Blacklist hinzugefügt!");
                                    return true;
                             
                                }else {
                                    p.sendMessage(Main.pr+"§cBentutze: /blacklist oder bl add : remove : clear <Wort>");
                                    return true;
                                }
                         
                            }else {
                                if(args[0].equalsIgnoreCase("remove")) {
                                    if(args.length == 1) {
                                        p.sendMessage(Main.pr+"§cBentutze: /blacklist oder bl add : remove : clear <Wort>");
                                        return true;
                                    }else if(args.length == 2) {
                                        bl.remove(args[1]);
                                     
                                        p.sendMessage(Main.pr+""+args[1]+" wurde von der Blacklist entfernt!");
                                        return true;
                                     
                                    }else {
                                        p.sendMessage(Main.pr+"§cBentutze: /blacklist oder bl add : remove : clear <Wort>");
                                        return true;
                                    }
                                }else {
                                    if(args[0].equalsIgnoreCase("clear")) {
                                        if(args.length == 1) {
                                            bl.clear();
                                            p.sendMessage(Main.pr+"§cDie Blacklist wurde geleert!");
                                            return true;
                                        }else {
                                            p.sendMessage(Main.pr+"§cBentutze: /blacklist oder bl add : remove : clear <Wort>");
                                            return true;
                                        }
                                    }else {
                                        p.sendMessage(Main.pr+"§cBentutze: /blacklist oder bl add : remove : clear <Wort>");
                                        return true;
                                    }
                                }
                            }
                         
                        }else {
                            p.sendMessage(Main.pr+"§cDazu hast du keine Berechtigung!");
                            return true;
                        }
            }
         
            return false;
        }

    }
     

    Listener
    Code (Java):
    package listeners;




    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;

    import commands.Chatblock;





    public class PlayerchatEvent implements Listener{
     
    @EventHandler
    public void onPlayerChatEvent(AsyncPlayerChatEvent e) {
        Player p = e.getPlayer();
     
     
        if(Chatblock.bl.contains(e.getMessage())) {
            p.sendMessage("§cDas darfst du nicht Sagen!");
            e.setCancelled(true);
         
         
         
        }
     
         
            }
     
     
    }

     
    Main
    Code (Java):
    package main;

    import java.io.FileWriter;
    import java.util.HashMap;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;

    import commands.Back;
    import commands.Bagpack;
    import commands.Build;
    import commands.ChatClear;
    import commands.Chatblock;
    import commands.Check;
    import commands.Fly;
    import commands.Freeze;
    import commands.Gamemode;
    import commands.Gospawn;
    import commands.Heal;
    import commands.Info;
    import commands.InventoryClear;
    import commands.Invsee;
    import commands.Mute;
    import commands.Setspawn;
    import commands.Spec;
    import commands.TPHere;
    import commands.Time;
    import commands.Vanish;
    import commands.Weather;
    import listeners.BuildEvent;
    import listeners.ChatListener;
    import listeners.DeathEvent;
    import listeners.Joinevent;
    import listeners.MoveEvent;
    import listeners.PlayerchatEvent;
    import listeners.RespawnEvent;



    public class Main extends JavaPlugin{
     
        public static HashMap<String, Location> back = new HashMap<>();
        public static HashMap<String, Location> spawn = new HashMap<>();
        public static String pr = "§8[§cExtras§8] §a";
     
     
    @Override
    public void onEnable() {
        registercommands();
        registerListeners();
     
    }
    @Override
        public void onDisable() {
     
        }
    public void registercommands() {
        getCommand("fly").setExecutor(new Fly());
        getCommand("gm").setExecutor(new Gamemode());
        getCommand("heal").setExecutor(new Heal());
        getCommand("bagpack").setExecutor(new Bagpack());
        getCommand("sun").setExecutor(new Weather());
        getCommand("rain").setExecutor(new Weather());
        getCommand("day").setExecutor(new Time());
        getCommand("night").setExecutor(new Time());
        getCommand("invsee").setExecutor(new Invsee());
        getCommand("spec").setExecutor(new Spec());
        getCommand("chatclear").setExecutor(new ChatClear());
        getCommand("vanish").setExecutor(new Vanish());
        getCommand("info").setExecutor(new Info());
        getCommand("back").setExecutor(new Back());
        getCommand("setspawn").setExecutor(new Setspawn());
        getCommand("spawn").setExecutor(new Gospawn());
        getCommand("delspawn").setExecutor(new Gospawn());
        getCommand("freeze").setExecutor(new Freeze());
        getCommand("mute").setExecutor(new Mute());
        getCommand("unmute").setExecutor(new Mute());
        getCommand("build").setExecutor(new Build());
        getCommand("check").setExecutor(new Check());
        getCommand("tphere").setExecutor(new TPHere());
        getCommand("clear").setExecutor(new InventoryClear());
        getCommand("blacklist").setExecutor(new Chatblock());
    }
    public void registerListeners() {
        Bukkit.getServer().getPluginManager().registerEvents(new Joinevent(), this);
        Bukkit.getServer().getPluginManager().registerEvents(new DeathEvent(), this);
        Bukkit.getServer().getPluginManager().registerEvents(new RespawnEvent(), this);
        Bukkit.getServer().getPluginManager().registerEvents(new MoveEvent(), this);
        Bukkit.getServer().getPluginManager().registerEvents(new ChatListener(), this);
        Bukkit.getServer().getPluginManager().registerEvents(new BuildEvent(), this);
        Bukkit.getServer().getPluginManager().registerEvents(new PlayerchatEvent(), this);
     
     
    }
    }
     
    Command:
    https://pastebin.com/E11tXLvA

    Listener:
    https://pastebin.com/GdFqdznV

    Main:
    https://pastebin.com/HGrAFcez


    PS: Sorry for my bad English
     
  2. I dont get it :C
     
  3. What do you not get? Also wrong forum section?

    Any data that's stored is lost when the server is reloaded, or restarted.
     
  4. 1. All variables set is lost when the plugin is reloaded.
    2. You can add all the values of the arrayList to a config file.
    3. What do you not get?
     
  5. Cant you just save it to a config
     
  6. this is skript section...
     
  7. Hey, this is Skript section. Also the way you save variables will cause them to be removed/deleted when you reload/restart your server. To prevent this, you will want to save the player data/variables in a file (ex. playerdata.txt, or playerdata.db, etc). You can also save player data in a MySQL Database.

    Raymond