Help me :>

Discussion in 'Spigot Plugin Development' started by IllegalSloth, Jun 3, 2017.

  1. The error shows me that there is an error with line 10 in the main class.
    That line is:
    Code (Text):
            getCommand("announce").setExecutor(new AnnouncementCmd());
    The class (AnnouncementCmd):

    Code (Text):
    package me.illegaldev.battleadmin;

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

    public class AnnouncementCmd implements CommandExecutor {

        @SuppressWarnings("deprecation")
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            Player allonline = (Player) Bukkit.getOnlinePlayers();
           
            if (args.length >= 0) {
                StringBuilder message = new StringBuilder();
                for (int i = 0; i < args.length; i++) {
                    message.append(args[i]).append(" ");
                }
               
                Bukkit.getServer().broadcastMessage("§e§lANNOUNCEMENT > §7" + message);
                allonline.sendTitle("§e§lANNOUNCEMENT", "§7" + message);
                allonline.playSound(allonline.getLocation(), Sound.LEVEL_UP, 50L, 30L);
            }
            return false;
        }

    }
     
    ~Illegal
     
  2. Change
    Code (Text):
    Player allonline = (Player) Bukkit.getOnlinePlayers();
    to
    Code (Text):
     Player allonline = (Player) sender;
    Check before whether the CommandSender is a player or the console will get an error if he executes this command.
     
  3. If you'd like the exact error here it is:
    Code (Text):
    [14:33:51 ERROR]: Error occurred while enabling BattleAdmin v1.0 (Is it up to date?)
    java.lang.NullPointerException
            at me.illegaldev.battleadmin.main.onEnable(main.java:10) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
     
  4. How do i make the title go to all online players though?
     
  5. Show me your plugin.yml
     
  6. Code (Text):
    main: me.illegaldev.battleadmin.main
    author: IllegalDev
    name: BattleAdmin
    version: 1.0
    commands:
      announcement:
        description: Announce something
     
  7. Code (Text):
    for(Player all : Bukkit.getOnlinePlayers()) {
      // SEND TITLTE
    }
     
    #7 ExoticDev, Jun 3, 2017
    Last edited by a moderator: Jun 3, 2017
  8. Isn't much different from my other plugin that works fine
     
  9. Thank you :)
     
  10. There is the problem @IllegalSloth
    You are registering in plugin.yml the command "announcement" but on main class you are using
    Code (Text):
     getCommand("announce").setExecutor(new AnnouncementCmd());
    Just change announcement in plugin.yml to announce and it should work.
     
  11. - Thanks for your input @Drajsor however it still spits the same error out -
     
  12. Welp im blind. - Edit: Going to specsavers
     
  13. And how do i fix my title? - Doesn't do it -
    (Message works fine)
    Code (Text):
    package me.illegaldev.battleadmin;

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

    public class AnnouncementCmd implements CommandExecutor {

        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (args.length >= 0) {
                StringBuilder message = new StringBuilder();
                for (int i = 0; i < args.length; i++) {
                    message.append(args[i]).append(" ");
                }
               
                for(Player all : Bukkit.getOnlinePlayers()) {
                      all.sendTitle("§e§lANNOUNCEMENT", "§7" + message);
                      all.sendMessage("§e§lANNOUNCEMENT> §7" + message );
                    }
            }
            return false;
        }

    }
     
     
  14. The method i use:
    Code (Text):
      public static void sendTitle(Player player, String title, String subtitle) {
        IChatBaseComponent titleJSON = IChatBaseComponent.ChatSerializer.a("{'text': '" + title + "'}");
        IChatBaseComponent subtitleJSON = IChatBaseComponent.ChatSerializer.a("{'text': '" + subtitle + "'}");
        PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, titleJSON, 20, 30, 20);
        PacketPlayOutTitle subtitlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, subtitleJSON, 20, 30, 20);
        PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
        connection.sendPacket(titlePacket);
        connection.sendPacket(subtitlePacket);
      }
     
  15. Command in plugin.yml has to be the same as reffered to in the main class.
    So change announcement in plugin.yml to announce