something is wrong with my plugin and i have absolutely no idea what

Discussion in 'Plugin Development' started by tommycake50, Sep 2, 2012.

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

    tommycake50

    OK so i was just creating a plugin called enchant4cash the name explains all well when the server is starting up it doesn't say 23:11:45 [INFO] [Enchant4Cash] Enchant4Cash v1.0 has been enabled! it says 23:11:45 [INFO] [Enchant4Cash] Enabling Enchant4Cash v1.0 and it doesn't generate a config i have kept looking over my code time and time again but i cant find the bug nor does it return an error.
    edit:and the money doesn't come out of my account on minecraft :C
    code for my plugin
    Code:
    package me.tommycake50.enchant4cash;
     
    import java.util.logging.Logger;
     
    import net.milkbowl.vault.economy.Economy;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Enchant4cash /* makes it recognisable to bukkit as a plugin */ extends JavaPlugin{
    /* gets the minecraft logger */
    public final Logger logger = Logger.getLogger("Minecraft");
    /* declares the variable econ for further use */
    public Economy econ;
    /* does the stuff in the body when the plugin gets enabled */
    public void OnEnable(){
    /* instantializes the plugin description file thinger */
    PluginDescriptionFile pdffile = this.getDescription();
    /* gets the name and version from plugin.yml and prints it to the console using the logger we instantialized earlier */
    this.logger.info(pdffile.getName() + " version " + pdffile.getVersion() + " Has been enabled");
    /* gets the config.yml's options */
    getConfig().options().copyDefaults(true);
    saveConfig();
    setupEconomy();
    }
    public boolean setupEconomy()
    {
      RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
      if(rsp == null)
      {
          return false;
      }
      econ = rsp.getProvider();
      return econ != null;
    }
    public void OnDisable(){
    PluginDescriptionFile pdffile = this.getDescription();
    this.logger.info(pdffile.getName() + " version " + pdffile.getVersion() + " Has been disabled");
    }
    public boolean OnCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
     
    /* gets the player name */
    Player player = (Player) sender;
    /* gets the name of the player */
    String playername = player.getDisplayName();
    /* sets wht  you type in after the slash to activate this plugins features */
    if(args.length == 1 && player.hasPermission("enchant.use") && CommandLabel.equalsIgnoreCase("enchant4cash")){
    /* gets the players inventory */
    PlayerInventory pi = player.getInventory();
    /* enchans the item that the player is holding after checking what enchantment he wants */
    switch(args[1]){
    case "unbreaking":
    /* withdraws money from the sender's account */
    econ.withdrawPlayer(playername, getConfig().getDouble("priceunbreaking"));
    /* enchants the item */
    player.getInventory().getItemInHand().addEnchantment(Enchantment.DURABILITY, getConfig().getInt("enchantlevel"));
    /* sends a notifying message */
    player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("priceunbreaking"));
    break;
    case "efficiency":
    econ.withdrawPlayer(playername, getConfig().getDouble("priceefficiency"));
    player.getInventory().getItemInHand().addEnchantment(Enchantment.DIG_SPEED, getConfig().getInt("enchantlevel"));
     
    player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("priceefficiency"));
    break;
    case "silktouch":
    /* withdraws money from the sender's account */
    econ.withdrawPlayer(playername, getConfig().getDouble("pricesilktouch"));
    player.getInventory().getItemInHand().addEnchantment(Enchantment.SILK_TOUCH, getConfig().getInt("enchantlevel"));
     
    player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("pricesilktouch"));
    break;
    case "fireaspect":
    econ.withdrawPlayer(playername, getConfig().getDouble("pricefireaspect"));
                        player.getInventory().getItemInHand().addEnchantment(Enchantment.FIRE_ASPECT, getConfig().getInt("enchantlevel"));
     
    player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("pricefireaspect"));
    break;
    case "knockback":
    econ.withdrawPlayer(playername, getConfig().getDouble("priceknockback"));
                        player.getInventory().getItemInHand().addEnchantment(Enchantment.KNOCKBACK, getConfig().getInt("enchantlevel"));
     
    player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("priceknockback"));
    break;
    case "smite":
    econ.withdrawPlayer(playername, getConfig().getDouble("pricesmite"));
                        player.getInventory().getItemInHand().addEnchantment(Enchantment.DAMAGE_ALL, getConfig().getInt("enchantlevel"));
     
    player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("pricesmite"));
    }
     
      /* sends a message to the player */
    player.sendMessage("your " + pi.getItemInHand() + " has been enchanted!");
    /* sends a message to the player if they dont have the correct perms */
    }else if (player.hasPermission("enchant.use") == false){
    player.sendMessage(ChatColor.RED + "You do not have permission to enchant items this way sorry." );
    }else{
    player.sendMessage(ChatColor.RED + "wrong number of args");
    }
     
     
    return true;
     
    }
     
    }
    
    just realized that withdrawplayer doesn't work with some plugins is there a better way than that?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  2. Offline

    the_merciless

    Show the startup log and the full code. No one can help you otherwise

    Oh that is the full code. I would repaste it without all the comments, they make it very difficult to read
     
  3. Offline

    tommycake50

    thats the full code ill show startup log
    Code:
    195 recipes
    27 achievements
    01:01:25 [INFO] Starting minecraft server version 1.3.1
    01:01:25 [INFO] Loading properties
    01:01:25 [INFO] Default game type: CREATIVE
    01:01:25 [INFO] Generating keypair
    01:01:27 [INFO] Starting Minecraft server on localhost:25565
    01:01:27 [WARNING] **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!
    01:01:27 [WARNING] The server will make no attempt to authenticate usernames. Beware.
    01:01:27 [WARNING] While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.
    01:01:27 [WARNING] To change this, set "online-mode" to "true" in the server.properties file.
    01:01:27 [INFO] This server is running CraftBukkit version git-Bukkit-1.3.1-R1.0-b2320jnks (MC: 1.3.1) (Implementing API version 1.3.1-R1.0)
    01:01:28 [INFO] [GroupManager] Loading GroupManager v2.0.35 (Phoenix)
    01:01:28 [INFO] [Vault] Loading Vault v1.2.18-b229
    01:01:28 [INFO] [Essentials] Loading Essentials v2.9.1
    01:01:28 [INFO] [EssentialsChat] Loading EssentialsChat v2.9.1
    01:01:28 [INFO] [Enchant4Cash] Loading Enchant4Cash v1.0
    01:01:28 [INFO] [EssentialsSpawn] Loading EssentialsSpawn v2.9.1
    01:01:28 [INFO] [Vault] Enabling Vault v1.2.18-b229
    01:01:28 [WARNING] ----- Bukkit Auto Updater -----
    01:01:28 [WARNING] Your version of CraftBukkit is out of date. Version 1.3.1-R2.0 (build #2340) was released on Sun Aug 19 12:52:49 BST 2012.
    01:01:28 [WARNING] Details: http://dl.bukkit.org/downloads/craftbukkit/view/01371_1.3.1-R2.0/
    01:01:28 [WARNING] Download: http://dl.bukkit.org/downloads/craftbukkit/get/01371_1.3.1-R2.0/craftbukkit.jar
    01:01:28 [WARNING] ----- ------------------- -----
    01:01:28 [INFO] [Vault][Economy] Essentials Economy found: Waiting
    01:01:28 [INFO] [Vault][Permission] GroupManager found: Waiting
    01:01:28 [INFO] [Vault][Permission] SuperPermissions loaded as backup permission system.
    01:01:28 [INFO] [Vault][Chat] GroupManager found: Waiting
    01:01:28 [INFO] [Vault] Enabled Version 1.2.18-b229
    01:01:28 [INFO] Preparing level "gfyfyf"
    01:01:29 [INFO] Preparing start region for level 0 (Seed: -992740883)
    01:01:30 [INFO] Preparing spawn area: 32%
    01:01:30 [INFO] Preparing start region for level 1 (Seed: -992740883)
    01:01:31 [INFO] [GroupManager] Enabling GroupManager v2.0.35 (Phoenix)
    01:01:31 [INFO] GroupManager - INFO - World Found: gfyfyf_the_end
    01:01:31 [INFO] GroupManager - INFO - World Found: world
    01:01:31 [INFO] GroupManager - INFO - World Found: gfyfyf
    01:01:31 [INFO] GroupManager - INFO - Superperms support enabled.
    01:01:31 [INFO] GroupManager - INFO - Scheduled Data Saving is set for every 10 minutes!
    01:01:31 [INFO] GroupManager - INFO - Backups will be retained for 24 hours!
    01:01:31 [INFO] GroupManager version 2.0.35 (Phoenix) is enabled!
    01:01:31 [INFO] [Vault][Permission] GroupManager hooked.
    01:01:31 [INFO] [Vault][Chat] GroupManager - Chat hooked.
    01:01:31 [INFO] [Essentials] Enabling Essentials v2.9.1
    01:01:32 [INFO] [Vault][Economy] Essentials Economy hooked.
    01:01:32 [INFO] Essentials: Using GroupManager based permissions.
    01:01:32 [INFO] [EssentialsChat] Enabling EssentialsChat v2.9.1
    01:01:32 [INFO] [Enchant4Cash] Enabling Enchant4Cash v1.0
    01:01:32 [INFO] [EssentialsSpawn] Enabling EssentialsSpawn v2.9.1
    01:01:32 [INFO] Server permissions file permissions.yml is empty, ignoring it
    01:01:32 [INFO] Done (3.498s)! For help, type "help" or "?"
    01:01:32 [INFO] GroupManager - INFO - Bukkit Permissions Updated!
    
    i don't see how it helps in any way :/
     
  4. Offline

    the_merciless

    Is that from the console or server.log
     
  5. Offline

    tommycake50

    console the server.log says the same :confused:
     
  6. Offline

    the_merciless

    You need this in where your variables are
    Code:
    public static PluginDescriptionFile info;
    Your onenable should look something like this

    Code:
    @Override
        public void onEnable() {
           
            Enchant4cash.plugin = this;
            info = getDescription();
            logger = Logger.getLogger("Minecraft");
            Log(Level.INFO, " is enabled, version: " + info.getVersion());
            Log(Level.INFO, " written by [The_Merciless]");
            new File(mainDirectory).mkdir();
            getConfig().options().copyDefaults(true);
            saveConfig();
         //register events here
        }
    Then you need

    Code:
    public static void Log(String message){
              Log(Level.INFO, message);
        }
     
        public static void Log(Level logLevel, String message){
            logger.log(logLevel, "[" +info.getName() + "]" + message);
        }
    repaste your code without all the comments, they make it very difficult to read

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  7. Offline

    PogoStick29

    Try
    EconomyResponse r = econ.withdrawPlayer(player.getName(), getConfig().getDouble("priceefficiency"));

    Then,

    Code:
    if (r.transactionSuccess()) {
                          //Stuff
                  }
                 else {
                    //Stuff
                }
     
  8. Offline

    tommycake50

    thanks everyone for the help trying now.
     
  9. public void OnEnable(){

    your trying to override onEnable()
    you can better place @Override at the start of a function if the use is to override 1, like
    @Override public void OnEnable(){
    you will see that it gives of an error, because, OnEnable isn't overriding onEnable (notice case)
    hoping you know now what the problem is
     
  10. Offline

    tommycake50

    im getting a few errors
    - mainDirectory cannot be resolved to a
    variable
    - File cannot be resolved to a type

    and thanks that helped.

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

    the_merciless

    File just needs to be imported, for maindirectory you will need to put this with your variables

    public static final String mainDirectory = "plugins/Your_plugin_name";
     
Thread Status:
Not open for further replies.

Share This Page