I'm a newbie

Discussion in 'Plugin Development' started by Brugz, Jun 16, 2012.

  1. Offline

    Brugz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Hey guys i want to make kinda Loterry system.
    and i need some help.

    What i want to do is if some player type /lottery [number 0-35]
    and if he have the Material diamond its will allow him to type and then there will be random numbers and if his number will be the last the player will get 3 diamonds.

    currectly the main is this script there is nothing in it.
    PHP:
    package me.lotto;
     
    import java.util.logging.Logger;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class 
    Lotto extends JavaPlugin{
        public final 
    Logger logger Logger.getLogger("MineCraft");
       
        @
    Override
        
    public void onDisable() {
            
    PluginDescriptionFile p this.getDescription();
            
    this.logger.info(p.getName() + "V" p.getVersion() + " Has Been Disabled!");
        }
       
        @
    Override
        
    public void onEnable() {
            
    PluginDescriptionFile p this.getDescription();
            
    this.logger.info(p.getName() + "V" p.getVersion() + " Has Been Enabled!");
     
        }   
        public 
    boolean onCommand(CommandSender senderCommand cmdString commandLabelString[]args) {
        if(
    commandLabel.equalsIgnoreCase("lotto")){
        
    Player player = (Playersender;
     
        }
        return 
    false;
      }
    }
  2. Offline

    Theodossis

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    1. To check if a player have diamond:
    Code:
    if(player.getInventory().contains(new ItemStack(Material.DIAMOND, 1))) {
      
    2.To remove 1 diamond:
    Code:
    player.getInventory().removeItem(new ItemStack(Material.DIAMOND, 1));
    For random numbers from 0-35 check this page:
    http://www.cs.geneseo.edu/~baldwin/reference/random.html
  3. Offline

    Brugz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I have error in this lines
    PHP:
    if(player.getInventory().contains(new ItemStack(Material.DIAMOND1))) {
        
    player.getInventory().removeItem(new ItemStack(Material.DIAMOND1));
    in .contains(new ItemStack.......
    and in the second line removeItem(new ItemStack....

    This post has been edited 1 time. It was last edited by Brugz Jun 16, 2012.
  4. Offline

    Theodossis

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Sorry but i ment:
    Code:
    if(player.getInventory().contains(Material.DIAMOND, 1)) {
  5. Offline

    Brugz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Now i did that at the other line:
    PHP:
    player.getInventory().removeItem(Material.DIAMOND1));
    and i got error on removeItem

    This post has been edited 1 time. It was last edited by Brugz Jun 16, 2012.
  6. Offline

    Theodossis

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Can you send me your error?
  7. Offline

    Brugz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Currectly i typed that:
    PHP:
        public boolean onCommand(CommandSender senderCommand cmdString commandLabelString[]args) {
        if(
    commandLabel.equalsIgnoreCase("lotto")){
        
    Player player = (Playersender;
        if(
    player.getInventory().contains(Material.DIAMOND1)) {
        
    player.getInventory().removeItem(Material.DIAMOND1);
        
    player.sendMessage(ChatColor.GREEN "You have paid for the lottery Good Luck!");
        }else{
        
    player.sendMessage(ChatColor.RED "You have no diamond to pay!");
        }
        return 
    false;
      }
    }
    }

    And the error is here.
    player.getInventory().removeItem(Material.DIAMOND, 1);

    This post has been edited 1 time. It was last edited by Brugz Jun 16, 2012.
  8. Offline

    Theodossis

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Try this:
    Code:
    player.getInventory().removeItem(new ItemStack(Material.DIAMOND, 1));
  9. Offline

    Brugz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Now i have error here
    removeItem(new ItemStack(Material.DIAMOND, 1))
  10. Offline

    Codex Arcanum

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Could you please post the actual error in the server console? Saying "There is an error here" is not terribly useful if we don't know what the error is.
  11. Offline

    Theodossis

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    import ItemStack to
    Code:
    org.bukkit.Inventory.ItemStack;
  12. Offline

    Brugz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    But there isnt error at the console the error is at the script.. i mean just line with error
    and its in this line:
    [IMG]

    This post has been edited 1 time. It was last edited by Brugz Jun 16, 2012.
  13. Offline

    Brugz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I Imported it but its says there is no such import like that but now its doing errror just on ItemStack
  14. Offline

    Codex Arcanum

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I'm sorry but that doesn't really make sense. Are you saying that it throws an error when you try and compile the source code into a .jar file? or that it throws an error when you run it on the server?
  15. Offline

    TheGreenGamerHD

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Import Material as well.
  16. Offline

    Brugz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Anyways guys thanks i fixed it :D
    i imported that
    import org.bukkit.inventory.*;

Share This Page