Solved Quick question and perhaps some help

Discussion in 'Plugin Development' started by DoggyCode™, Jul 26, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    DoggyCode™

    So I've always used the Craftbukkit jar (as library for my plugins and as the build for my server), I've recently changed to spigot. What my question is that in my plugins, if I don't import spigot, like just craftbukkit.jar, will that affect my plugins? Like, will my plugin don't work at the spigot server? And if I were to add spigot to my external library, would I also have to add craftbukkit? Does it matter if I have both jars in my library (both spiggot and craftbukkit)? Because I tried just using one, my plugin wouldn't work, I tried using both, my plugin would still not work.

    Any help would greatly be appreciated!
     
  2. Offline

    leet4044

    This is a better question to post on the Spigot Forums, but to answer your question, any bukkit plugin will work on a spigot server, providing that the plugin is compiled using the same bukkit/spigot version the server is running, but I'm not sure it's backwards compatible meaning I don't know if you can take a spigot plugin and run it on bukkit. Since that spigot plugin could be using spigot's methods.
     
  3. Offline

    mariosunny

    Spigot is a wrapper for Bukkit. The spigot jar should contain the entire Bukkit API.

    The problem you are having seems to be an issue with your setup, not spigot. I was able to remove the bukkit.jar from my buildpath and replace it with the spigot.jar with no problems whatsoever.

    What is your error in particular? Can you give us a screenshot, or a description?
     
  4. Offline

    DoggyCode™

    @leet4044 I seriously can't spot what's wrong then.. Information:

    Code:
    Code:
    package me.pvpdog.itemmod;
    
    import net.milkbowl.vault.economy.Economy;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
      
        public static FileConfiguration config;
        public static Main plugin = null;
      
        public static Economy econ = null;
      
        public static String prefix = config.getString("prefix") + ChatColor.RESET + " ";
      
        public void onEnable() {
            getLogger().info("Plugin Enabled");
            config = getConfig();
            plugin = this;
          
            saveDefaultConfig();
            config.options().header("By: PvPdog");
            config.options().header("Default configuration file");
            config.addDefault("prefix", "&3[ItemMod]");
          
            config.options().copyDefaults(true);
            saveConfig();
          
            if (!setupEconomy() ) {
                getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
        }
      
        public void onDisable() {
            getLogger().info("Plugin Disabled");
        }
      
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                return false;
            }
            econ = rsp.getProvider();
            return econ != null;
        }
      
        public static void saveFile() {
            plugin.saveConfig();
        }
      
        public boolean onCommand(CommandSender sender, Command cmd,
                String label, String[] args) {
          
            if(cmd.getName().equalsIgnoreCase("rename")) {
                if(sender instanceof Player) {
                    Player p = (Player)sender;
                    if(p.hasPermission("itemmod.rename")) {
                        if(args.length == 0) {
                            p.sendMessage(prefix + ChatColor.RED + "/rename <new name>");
                            return true;
                        } else if(args.length >= 1) {
                            String name = "";
                            for(int i = 0; i < args.length; i++) {
                                name = name + args[i] + " ";
                            }
                            ItemStack hand = p.getItemInHand();
                            hand.getItemMeta().setDisplayName(name);
                            p.sendMessage(prefix + ChatColor.GREEN + "Item's Displayname was set to: " + ChatColor.GOLD + name);
                            return true;
                        }
                    } else if(p.hasPermission("itemmod.rename.color")) {
                        if(args.length == 0) {
                            p.sendMessage(prefix + ChatColor.RED + "/rename <new name>");
                            return true;
                        } else if(args.length >= 1) {
                            String name = "";
                            for(int i = 0; i < args.length; i++) {
                                name = name + args[i] + " ";
                            }
                            ItemStack hand = p.getItemInHand();
                            hand.getItemMeta().setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
                            p.sendMessage(prefix + ChatColor.GRAY + "Item's Displayname was set to: " + ChatColor.GOLD + "" + ChatColor.translateAlternateColorCodes('&', name));
                            return true;
                        }
                    } else {
                        p.sendMessage(prefix + ChatColor.RED + "You don't have the proper permission!");
                        return true;
                    }
                } else {
                    sender.sendMessage(prefix + ChatColor.RED + "No console");
                    return true;
                }
            }
            return false;
        }
    }
    Packages/Classes
    [​IMG]

    plugin.yml:
    Code:
    name: ItemMod
    author: PvPdog
    version: 1
    description: ItemModification
    main: me.pvpdog.itemmod.Main
    depend: [Vault]
    commands:
      rename:
        description: Main command
    config.yml:
    is empty (using config#addDefault(...); and config.options().copyDefaults(true);)

    Java Build Path > Library:
    [​IMG]

    Hopefully you guys can spot something that I can't see!

    EDIT:
    Tags:
    @mariosunny

    There's no Errors! Plugin won't load (it doesn't even attempt to load), I've seen through the console multiple times, it just doesn't show there, but the .jar is in the plugins folder.
     
  5. I only had a quick look, but I assume it has something to do with economy.

    Also, you should log enable / disable messages, bukkit already does this
     
  6. Offline

    leet4044

    Can you show me the jar artifact
     
  7. Offline

    DoggyCode™

    I don't see how it can have anything with the economy to do though.. everything should be fine, but I'll try to remove the entire economy part.

    @leet4044 ??
     
  8. Offline

    mariosunny

    @DoggyCode™

    The most common causes of a plugin not loading are:
    1) The "main" node in your plugin.yml is wrong.
    2) You exported your jar wrong. Ensure you are exporting a non-runnable jar which includes your .classpath and that you are placing it in your /plugins/ folder in your server directory.

    Try typing /reload in your server and see if your plugin shows up.
     
  9. Offline

    DoggyCode™

    @MrBlackIsBack Hmm, nvm, I fixed it. Apparantly this didn't work:
    Code:
    public static String prefix = config.getString("prefix") + ChatColor.RESET + " ";
    [/code]
    I think it's because the string gets something from the config, and the config wasn't generated before the plugin was enabled..

    @mariosunny I did everything correct ^
     
  10. Offline

    mariosunny

    Good to know. Though I would have expected the server to crash, not simply not recognize your plugin.
     
  11. Offline

    DoggyCode™

    Solved!

    Thanks anyways if you tried to help!

    @mariosunny Ikr..

    Anyways, @mariosunny @leet4044 @MrBlackIsBack

    if (Player#getItemInHand()==null) {

    checks if the player has nothing it its hand, right? Because I try it and apparantly that doesn't work, because it thinks that I have a item in my hand?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  12. Offline

    leet4044

    check if it isn't air after

    if (Player#getItemInHand() == null || Player#getItemInHand().getType != Material.AIR) {
     
Thread Status:
Not open for further replies.

Share This Page