Need help finding error

Discussion in 'Plugin Development' started by mason1370, Jul 5, 2012.

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

    mason1370

    so this plugin when ran takes a diamond from there inventory and changes the time. When i boot it up it says that the plugin PayToCommand can not be started. Here's the code (fyi its using Pex so if you see any issue with that also can you please correct it :) )
    Code:
    package com.gmail.mason1224;
     
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import ru.tehkode.permissions.PermissionManager;
    import ru.tehkode.permissions.PermissionUser;
    import ru.tehkode.permissions.bukkit.PermissionsEx;
     
    public class PayToCommand extends JavaPlugin
    {
        String worldSel;
        public void onEnable()
        {
            getLogger().info("PayToCommand has started");
           
        }
     
        public boolean onCommand (CommandSender sender, Command cmd, String label, String[] args) {
            Player s = (Player)sender;
            PermissionManager pex = PermissionsEx.getPermissionManager();
            PermissionUser user  = PermissionsEx.getUser(s);
            boolean time = PermissionEx.has(s, "PTC.time");
            boolean timebyepass = PermissionEx.has(s, "PTC.time.free");
           
            if(!(sender instanceof Player)) {
                getLogger().info("Only players are supported for PayToCommand");
            if(cmd.getName().equalsIgnoreCase("daytime"))
                if(time) {
                    if(timebyepass){
                        worldSel = args[0];
                        World world = getServer().getWorld(worldSel);
                        world.setTime(14000);
                    }
                    PlayerInventory inventory = s.getInventory();
                    ItemStack icost = new ItemStack(Material.DIAMOND, 1);
                    if (inventory.contains(icost)){
                        inventory.remove(icost);
                        worldSel = args[0];
                        World world = getServer().getWorld(worldSel);
                        world.setTime(14000);
                    }
     
                }
            }
            if(cmd.getName().equalsIgnoreCase("nighttime"))
                if(time) {
                    if(timebyepass){
                        worldSel = args[0];
                        World world = getServer().getWorld(worldSel);
                        world.setTime(0);
                    }
                    PlayerInventory inventory = s.getInventory();
                    ItemStack icost = new ItemStack(Material.DIAMOND, 1);
                    if (inventory.contains(icost)){
                        inventory.remove(icost);
                        worldSel = args[0];
                        World world = getServer().getWorld(worldSel);
                        world.setTime(0);
                    }
                    else
                        s.sendMessage("You need a diamond to change the time");
                }
            return false;
        }
     
       
        public void onDisable()
        {
            getLogger().info("PayToCommand is now shutting down");
        }
    }
    
    Code:
    name: PayToCommand
    main: com.gmail.mason1224
    version: 1.0
    author: GultsGorge Plugin team
     
     
    commands:
      daytime:
        description: Change the time to day!
        usage: /daytime [world]
        permission: PTC.time
        permission-message: Im sorry you should donate
      nighttime:
        description: Change the time to night!
        usage: /nighttime [world]
        permission: PTC.time
        permission-message: Im sorry you should donate
     
    permissions:
      PTC.time.free:
        description: Users with this permission are not charged for time changes.
      PTC.time:
        description: Users with this permission can change the time to day or night
     
         
         
        
     
  2. Offline

    ColaCraft

    Code:
                    }
                    else
                        s.sendMessage("You need a diamond to change the time");
    Correct me if I am wrong, as I am new to Java, but shouldn't that read

    Code:
    player.sendMessage("You need a diamond!")
    meh..
     
  3. Offline

    mason1370

    Player s = (Player)sender;
    i set it up for a variable to make it easier for me to write

    that would not mess it up would it?

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

    Seadragon91

    Change this:
    Code:
    main: com.gmail.mason1224
    to:
    Code:
    main: com.gmail.mason1224.PayToCommand
    Then the plugin should be loaded ;)
     
  5. Offline

    mason1370

    god i feel stupid thank you though. everything else was fine though?
     
  6. Offline

    EnvisionRed

    I think so, but this line:
    Code:
    Player s = (Player) sender;
    shouldn't be before
    Code:
    if (!sender instanceof Player) {
    //tell console that console can't use your command
    }
    Because if the console sends the command, it will try to cast the console to Player, you'll get an error, and then it will check if the sender isn't a player.
     
  7. Offline

    mason1370

    when i put it below the if !sender it gives me errors
    also im getting errors on the boolean PermissionEx is that right?
    Code:
            boolean time = PermissionEx.has(s, "PTC.time");
            boolean timebyepass = PermissionEx.has(s, "PTC.time.free");
     
  8. Offline

    EnvisionRed

    Take a look at this:
    Code:
            Player s = (Player)sender;
            PermissionManager pex = PermissionsEx.getPermissionManager();
            PermissionUser user  = PermissionsEx.getUser(s);
    You can see that
    Code:
     PermissionUser user  = PermissionsEx.getUser(s);
    uses "s" which is declared in:
    Code:
    Player s = (Player)sender;
    However, if you take away the line it's declared in, but don't move/take away the lines that need it, they'll be trying to use nonexistant variables.

    tl;dr just move the PermissionsEX lines with the line where you declare "s"
     
  9. Offline

    mason1370

    ok thanks seems to be working great.
     
Thread Status:
Not open for further replies.

Share This Page