1

I made a bukkit plugin that for some reason doesn't work. Here are some things I think will help: 1. The plugin doesn't appear in /plugins 2. The console is giving a major.minor error 3. The commands don't give any error; they just say unknown command. Here is my code:

package me.Orion31.broadcaster;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin {
    @Override
    public void onEnable() {
        getLogger().info("Enabled Broadcaster by Orion version " + getDescription().getVersion());
        getConfig().options().copyDefaults(false);
    } 
    @Override
    public void onDisable() {
        getLogger().info("Disabled Broadcaster!");
    }
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        Player player = (Player) sender;
        if (command.getName().equalsIgnoreCase("bc") || command.getName().equalsIgnoreCase("broadcast")) {
            if (player.hasPermission("broadcast.bc")) {
                if (args.length == 1) {
                    Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',
                            getConfig().getString("Tag") + getConfig().getString("Color") + " " + args[0]));
                    return true;
                } else {
                    player.sendMessage(ChatColor.DARK_RED + "Invalid Arguments!");
                    player.sendMessage(ChatColor.RED + "Usage: /broadcast <message>");
                    return true;
                }
            } else
                player.sendMessage(ChatColor.DARK_RED + "You don't have permissions!");
            return true;
        } else if (command.getName().equalsIgnoreCase("bcset")) {
            if (args.length == 2) {
                if (player.hasPermission("broadcast.bc")) {
                    if (args[0].equalsIgnoreCase("tag")) {
                        getConfig().set("Tag", args[1]);
                        saveConfig();
                    } else if(args[0].equalsIgnoreCase("color")){
                        getConfig().set("Color", args[1]);
                        saveConfig();
                    }
                } else
                    player.sendMessage(ChatColor.DARK_RED + "You don't have permissions!");

            } else {
                player.sendMessage(ChatColor.DARK_RED + "Invalid usage!");
                player.sendMessage(ChatColor.RED + "Usage: /bctag tag,color <new value>");
            }
        }
        return false;
    }
}

Plugin.yml:

name: Broadcaster
main: me.Orion31.broadcaster.Main
version: 1.0
commands:
   broadcast:
      description: Broadcast a message to the whole server!
      usage: /broadcast <message>
   bcset:
      description: Change the properties of the broadcaster.
      usage: /bcset tag,color <new value>

Thank you for your time!

Orion31
  • 556
  • 6
  • 28
  • How did you export it? Do the messages apper in the console, such as "Enabled broadcaster by..."? – LeoColman Jul 22 '16 at 22:24
  • @Kerooker I am using eclipse. There is no message about this plugin. It is in the /plugins directory – Orion31 Jul 22 '16 at 22:28
  • Your code is working for me, maybe you're exporting it wrongly, therefore it's not a plugin jar file... Also, are you remembering to reopen your server? – LeoColman Jul 22 '16 at 22:35
  • @Kerooker how do you think I should export it? I am on eclipse. And yes the server is on. – Orion31 Jul 22 '16 at 23:23
  • @Kerooker I tried exporting in Java 7 and Java 8 Now i'm getting a major.minor error – Orion31 Jul 23 '16 at 00:47
  • @Orion31 I think your "major.minor" error probably refers to unsupported major.minor version, which means you have compiled some files that are not supported due to their file version(e.g. too high). Also, you can have a look at the [official tutorial](http://wiki.bukkit.org/Plugin_Tutorial). – Cnly Jul 23 '16 at 06:04
  • @Cnly I compiled the whole thing in Java 7, the same version i needed to use to get my other plugin to work. I also tried Java 8. Here is the console error: http://paste.ubuntu.com/20605362/ – Orion31 Jul 23 '16 at 14:30
  • @Orion31 Your _server_ is using a version under 8. So _don't_ use Java 8 for your plugins. Also, can you include your .jar file structure in your post? And is there anything in the server.log like `[Broadcaster] Loading Broadcaster` or `[Broadcaster] Enabling Broadcaster v1.0`? – Cnly Jul 23 '16 at 14:40
  • @Orion31 the problem I see must be related to the way you're exporting, because your exact code compiles and runs on my home server. Maybe this video is of help? https://www.youtube.com/watch?v=6V0AmwgH7QU – LeoColman Jul 23 '16 at 16:52
  • @Cnly I think this is what you mean by jar structure: there is `plugin.yml` and `config.yml`. It is in the `/plugins` folder. The folder for it doesn't generate, and the console isn't giving me anything else besides from errors for this plugin. – Orion31 Jul 23 '16 at 17:35
  • What are the errors then? – LeoColman Jul 23 '16 at 19:27
  • @Kerooker I am getting an error that says: `Caused by: java.lang.UnsupportedClassVersionError: me/Orion31/broadcaster/Main : Unsupported major.minor version 52.0` – Orion31 Jul 23 '16 at 19:52
  • That error comes from your project having a Java version higher than your server supports. To fix that, you must change your Eclipse's project to use a different JDK, with a lower version. You're probrably exporting with Java 8, try exporting with Java 7 – LeoColman Jul 23 '16 at 20:12
  • @Kerooker tried downloading and exporting with Java 7. Same error as before. – Orion31 Jul 24 '16 at 03:07
  • @orion The major.minor error must be gone if you use a diferent JDK. You have to change your project's JDK to an earlier version – LeoColman Jul 24 '16 at 04:04
  • @Kerooker I tried using JDK 7, but it still won't work. I might rewrite it. – Orion31 Jul 24 '16 at 12:52
  • How did you actually changed the version, and how did you export? You might be doing it wrong. Maybe this helps? http://stackoverflow.com/questions/12588537/how-to-change-jdk-version-for-an-eclipse-project – LeoColman Jul 24 '16 at 16:11
  • Try exporting it using JDK 6 – ItzBenteThePig Jul 29 '16 at 15:54

1 Answers1

0

Simple error, even myself forget to do it often.

Change public class Main extends JavaPlugin to public class Main extends JavaPlugin implements CommandExecutor.

Once you do that you should be good.

ItzPam
  • 13
  • 1
  • 1