Accept rules plugin

Discussion in 'Spigot Plugin Development' started by Tomdaarom, Apr 16, 2017.

  1. Hello, my plugin isn't working and when I try to perform the command /acceptrules an internal error occurs.

    This is my Code :
    Code (Text):
    package me.officialnl.main;

    import net.md_5.bungee.api.ChatColor;

    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin{
       
        public void onEnable(){
            getLogger().info("BizzCraft First Join plugin enabled");
        }
       
        public void onDisable(){
            getLogger().info("BizzCraft First Join plugin disabled");
        }
       
        private void teleportInWorld(Player p, int x, int y, int z){
            p.teleport(new Location(p.getWorld(), x, y, z));
        }
       
        @EventHandler
        public void PlayerJoin(PlayerLoginEvent event) {
        Player p = event.getPlayer();
        if(!p.hasPlayedBefore()) {
        teleportInWorld(p, 149,33,170);
        p.sendMessage("You have to accept the rules before you can play");
        }
      }
       
        public boolean onCommand(CommandSender s, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("acceptrules")){
                if (!(s instanceof Player)){
                    getLogger().info("Only players are allowed to use this command");
                    return true;
                }
                Player p = (Player) s;
                p.performCommand("help");
                p.sendMessage(ChatColor.GREEN + "You accepted the rules");
                }
            return false;
            }
        }
    And this is the Error I get when I try to perform the /acceptrules command :
    Code (Text):
    [02:39:05 INFO]: OfficialNL issued server command: /acceptrules
    [02:39:05 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'acceptrules' in plugin Particles v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:629) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PlayerConnection.handleCommand(PlayerConnection.java:1286) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1146) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
            at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:695) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:360) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:650) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:554) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.NoClassDefFoundError: net/md_5/bungee/api/ChatColor
            at me.officialnl.main.Main.onCommand(Main.java:45) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            ... 15 more
    Caused by: java.lang.ClassNotFoundException: net.md_5.bungee.api.ChatColor
            at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_111]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:77) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:62) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_111]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_111]
            at me.officialnl.main.Main.onCommand(Main.java:45) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            ... 15 more
     
  2. Could you post your plugin.yml?
     
  3. You're trying to use net.md_5.bungee.api.ChatColor on a Bukkit only server. That class isn't available, so there's an error. Fixes would be either using Spigot server, or using org.bukkit.ChatColor
     
    • Agree Agree x 2
  4. I added the org.bukkit.chatcolor and I'm still having errors, this is my error:
    Code (Text):
    03:39:14 INFO]: OfficialNL issued server command: /acceptrules
    [03:39:14 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'acceptrules' in plugin Particles v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:629) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PlayerConnection.handleCommand(PlayerConnection.java:1286) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1146) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
            at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:695) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:360) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:650) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:554) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.NoClassDefFoundError: net/md_5/bungee/api/ChatColor
            at me.officialnl.main.Main.onCommand(Main.java:45) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            ... 15 more
    Caused by: java.lang.ClassNotFoundException: net.md_5.bungee.api.ChatColor
            at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_111]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:77) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:62) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_111]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_111]
            at me.officialnl.main.Main.onCommand(Main.java:45) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            ... 15 more
     
  5. You get rid of line three and add
    Code (Text):
    import org.bukit.ChatColor;
    instead
     
    • Agree Agree x 1
  6. This is my plugin.yml
    Code (Text):
    name: Particles
    main: me.officialnl.main.Main
    version: 1.0
    description: FirstJoinEvent
    commands:
       acceptrules:
     
  7. I already did that, like I said in the reply to Redfield
     
  8. Then you have either failed to export of failed to restart your server correctly, because if net.md_5.bungee.api.ChatColor is nowhere in your files, you will never get this error. :p
     
    • Funny Funny x 1
  9. "ctrl + f" for "net.md_5.bungee.api.ChatColor" in your project and replace it with the Bukkit API one. If you're still getting the error, you're still using it somewhere within your project. You most likely are still importing it.
     
    • Useful Useful x 1
  10. I copied your code and removed line 3 and re imported color from bukkit, works like a charm buddy, The ticket is solved it actually was as early as RedrieldĀ“s comment.
     
  11. Well, did you fix your plugin.yml (I nearly wrote pom.xml xD) and did you register the event in the first place? Even if the listener is in the main class, you still need to register it.
     
  12. Hello, thank you for all the help. The plugin still isn't working :
    The code :
    Code (Text):
    package me.officialnl.main;

    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin{
       
        public void onEnable(){
            getLogger().info("BizzCraft First Join plugin enabled");
        }
       
        public void onDisable(){
            getLogger().info("BizzCraft First Join plugin disabled");
        }
       
        private void teleportInWorld(Player p, int x, int y, int z){
            p.teleport(new Location(p.getWorld(), x, y, z));
        }
       
        @EventHandler
        public void PlayerJoin(PlayerLoginEvent event) {
        Player p = event.getPlayer();
        if(!p.hasPlayedBefore()) {
        teleportInWorld(p, 149,33,170);
        p.sendMessage("You have to accept the rules before you can play");
        }
      }
       
        public boolean onCommand(CommandSender s, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("acceptrules")){
                if (!(s instanceof Player)){
                    getLogger().info("Only players are allowed to use this command");
                    return true;
                }
                Player p = (Player) s;
                p.performCommand("help");
                p.sendMessage(ChatColor.GREEN + "You accepted the rules");
                }
            return false;
            }
        }
    The error in the console :
    Code (Text):
    [20:49:48 INFO]: OfficialNL issued server command: /acceptrules
    [20:49:48 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'acceptrules' in plugin Particles v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:629) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PlayerConnection.handleCommand(PlayerConnection.java:1286) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1146) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
            at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:695) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:360) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:650) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:554) [craftbukkit.jar:git-Bukkit-2ad21b8]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.NoClassDefFoundError: net/md_5/bungee/api/ChatColor
            at me.officialnl.main.Main.onCommand(Main.java:45) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            ... 15 more
    Caused by: java.lang.ClassNotFoundException: net.md_5.bungee.api.ChatColor
            at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_111]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:77) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:62) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_111]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_111]
            at me.officialnl.main.Main.onCommand(Main.java:45) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-2ad21b8]
            ... 15 more
    >
     
  13. WHat is on line 45 of Main class?
     
  14. It still apears youre using the wrong import, try completely deleting the current import, and reimport. Maybe youre complining to the wrong place? Not sure what would keep causing this issue

    Also, you need to register your events
     
    • Like Like x 1
  15. Guess who forgot to register the event... Pff.
    I'm sorry, the plugin is working now Thankyou
     
    • Friendly Friendly x 1
  16. Glad we could all help :)