Solved Need help with ArrayList

Discussion in 'Spigot Plugin Help' started by Strum, Jun 15, 2018.

  1. Hello there, I need help with my fake Join/Plugin. It was working fine until I added the ArrayList. I added the ArrayList to make it so if the user did the /silentq already once he wouldn't be able to do it twice in a row to prevent making him "quit" the game twice. Here is my code


    Code (Java):
    package com.joinleave.plugin;

    import java.util.ArrayList;

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

    import net.md_5.bungee.api.ChatColor;

    public class SilentJoin implements CommandExecutor {
        public static ArrayList<Player> Silentplayers;
       
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String labels, String[] args) {
            if(sender instanceof Player) {
            Player player = (Player) sender;
       
        if(cmd.getName().equalsIgnoreCase("silentq")){
           
            if(player.hasPermission("staff.staff")){
                if(!SilentJoin.Silentplayers.contains(player)) {
       
                    SilentJoin.Silentplayers.add(player);
                    player.performCommand("staff:staff " + player.getName() + " enable");
                    Bukkit.broadcastMessage(ChatColor.RED + "[Quit] " + ChatColor.GRAY + player.getName());
           
            }else {
               
                    player.sendMessage("You're already quit");
            }
           
            }else {
               
                    player.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You do not have permission to execute this command.");
            }
       
        }
           
        if(cmd.getName().equalsIgnoreCase("silentj")){
               
            if(player.hasPermission("staff.staff")){
                if(SilentJoin.Silentplayers.contains(player)) {
                       
                    SilentJoin.Silentplayers.remove(player);
                    player.performCommand("staff:staff " + player.getName() + " disable");
                    Bukkit.broadcastMessage(ChatColor.RED + "[Join] " + ChatColor.GRAY + player.getName());
                   
               
            }else {
                   
                    player.sendMessage("you're already joined");
            }
                   
                   
        }else {
           
                player.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You do not have permission to execute this command.");
           
           
       
                }
            }
        }
       
            return false;
        }
    }
     
    And here is my error (same error for both commands, they block at the arraylist):

    Code (Text):
    org.bukkit.command.CommandException: Unhandled exception executing command 'silentj' in plugin JoinLeave v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_161]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_161]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_161]
    Caused by: java.lang.NullPointerException
            at com.joinleave.plugin.SilentJoin.onCommand(SilentJoin.java:39) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.8.jar:git-Spigot-21fe707-e1ebe52]
            ... 15 more
     
  2. Benz56

    Moderator Supporter

    Remember to initialize the list.
    Code (Java):
    public static List<Player> yourList = new ArrayList<>();
     
  3. I found my mistake, thanks for the help!!