Help Please!

Discussion in 'Plugin Development' started by boysnnoco, Dec 7, 2013.

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

    boysnnoco

    I'm in the process of creating a economy plugin when I hit a bump in the road, the balance isn't being said the player correctly..
    This is what I have so far:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command command, String commandLabel,String[] args) {
    2. if(sender instanceof Player){
    3. final Player player = (Player)sender;
    4. File file = new File("plugins"+File.separator +"CheesyKits"+File.separator+"users" +File.separator+player.getName());
    5. FileConfiguration config = YamlConfiguration.loadConfiguration(file);
    6. if(command.getName().equalsIgnoreCase("soup")){
    7. if(!(plugin.list.soup.contains(player.getName()))){
    8. if(plugin.Sub(player, 8)){
    9. plugin.list.soup.add(player.getName());
    10. player.sendMessage(ChatColor.DARK_RED + plugin.getConfig().getString("Server.Name")+ChatColor.DARK_GRAY+"> " +ChatColor.RED + "You are now vulnerable for 5 seconds..");
    11. player.sendMessage(ChatColor.AQUA + "You now have " + config.getInt("Player.Balance") + " credits!");
    12. player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,100,3));
    13. player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,100,3));
    14. player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION,100,3));
    15. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
    16. public void run(){
    17. final Inventory i = player.getInventory();
    18. final ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP);
    19. if(plugin.list.soup.contains(player.getName())){
    20. plugin.list.soup.remove(player.getName());
    21. i.addItem(soup);
    22. i.addItem(soup);
    23. i.addItem(soup);
    24. i.addItem(soup);
    25. i.addItem(soup);
    26. i.addItem(soup);
    27. i.addItem(soup);
    28. i.addItem(soup);
    29. player.sendMessage(ChatColor.DARK_RED + plugin.getConfig().getString("Server.Name")+ChatColor.DARK_GRAY +"> " +ChatColor.GRAY +"Enjoy your soup!");
    30. }
    31. }
    32. },100);
    33. }else{
    34. player.sendMessage(ChatColor.DARK_RED + plugin.getConfig().getString("Server.Name") + ChatColor.DARK_GRAY+"> " +ChatColor.RED + "You do not have enough money!");
    35. }
    36. }else{
    37. player.sendMessage(ChatColor.DARK_RED + plugin.getConfig().getString("Server.Name") + ChatColor.DARK_GRAY+"> " +ChatColor.RED + "You are volnerable you cannot use that command!");
    38. }
    39. }
    40. }else{
    41. return false;
    42. }
    43. return false;
    44. }


    And for my subtracting method:
    Code:java
    1. public boolean Sub(final Player player, final int amount){
    2. File file = new File("plugins"+File.separator +"CheesyKits"+File.separator+"users" +File.separator+player.getName());
    3. FileConfiguration config = YamlConfiguration.loadConfiguration(file);
    4. boolean am = false;
    5. if(file.exists()){
    6. int g = config.getInt("Player.Balance");
    7. if(g >= amount){
    8. int a = config.getInt("Player.Balance") - amount;
    9. config.set("Player.Balance", a);
    10. try{
    11. config.save(file);
    12. }catch (IOException e){
    13. e.printStackTrace();
    14. }
    15. am = true;
    16.  
    17. }else{
    18. am = false;
    19. }
    20. }else{
    21. logger.info("Please Report This To Cheesy_Boy!");
    22. }
    23. return am;
    24. }

    If I had 8 credits and used /soup it would drop me too 0 credits but it would tell me that my balance is 8 still.
    **There is no errors in console or anything**

    Any help?

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

    HighOnSwiftness

    Hmm, i'm not sure about this one *wink* I can see that you've done most of this right..
     
  3. Offline

    boysnnoco

    I have no idea either
     
Thread Status:
Not open for further replies.

Share This Page