SQL DB - Coins not increasing bug

Discussion in 'Plugin Development' started by Andq1, Nov 16, 2013.

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

    Andq1

    Hello everyone.
    I'm writing here because i've encountered a bug that i can't fix.

    Im just going to explain it all.
    So this plugin is quite simple, whenever a player kills another player, 5 points will be added to hes account which is stored in a MySQL database. But there is a problem. Whenever the player kills another player, 5 coins is added. But if he kill a player more, hes credits will stay at 5 and not increase.
    Any help regarding this bug will be greatly appreciated. And as Bukkit forums attachment function dosen't work, im gonna leave a mediafile link to the source code.

    Thanks in advance!
    Link to the 4 src files
    <Edit by Moderator: Redacted mediafire url>

    The zip file includes the 4 files.
    ~DivineStudios
     
    Last edited by a moderator: Nov 4, 2016
  2. Offline

    GusGold

    Andq1
    Without looking at the source code, by the sounds of it, you are setting the players credits to 5, rather than adding 5 on. If you are using MySQL, try getting the players score, then adding 5 points, then set their score back in the table.
     
  3. Offline

    Ad237

    GusGold To optimise this you could do this in one query rather than one. For example use this:
    Code:java
    1. SET coins = coins + AMOUNT_TO_ADD

    This will set coins to the current coins value plus the amount to add.
     
  4. Offline

    GusGold

  5. Offline

    Andq1

    This is how the coin generating system works

    Code:java
    1. public void onEntityDeath(EntityDeathEvent evt) {
    2. try {
    3. if (evt instanceof PlayerDeathEvent) {
    4. PlayerDeathEvent event = (PlayerDeathEvent) evt;
    5. Player killer = event.getEntity().getKiller();
    6. String username = killer.getDisplayName();
    7. if (!database.checkUserExists(username))
    8. database.createUser(username);
    9. int current = database.getUsersCoinCount(username);
    10. int get = Integer.parseInt(database
    11. .getSetting("coins_per_kill"));
    12. database.setUsersCoinCount(username, current + get);
    13. }
    14. } catch (Exception e) {
    15.  
    16. }
    17.  
    18. }
     
  6. Offline

    CubieX

    1. You do not need this:
    Code:
     try {
    if (evt instanceof PlayerDeathEvent) {
    PlayerDeathEvent event = (PlayerDeathEvent) evt;
    Just use the PlayerDeathEvent directly.

    2. Check if the killer actually is a Player.
    Because if not, your code will cause an error when trying to assign this killer entity to a Player object.

    3.
    Code:
     int get = Integer.parseInt(database
    .getSetting("coins_per_kill"));
    I guess (and hope) your "coins_per_kill" setting is an integer in your DB.
    So you do not need to use "Integer.parseInt()". The DB will directly return an integer here.
    Storing this as String does not make sense. Use an integer or decimal value like float or double.
     
  7. Offline

    Andq1

    Im sorry for my lack of knowledge, but this plugin was developed by a private developer i had contact to. Now he can't assist me any longer. While i appreciate your help, i can't seem to get this working, using the feedback you gave me. If you could post the code, with the tweaks i'd be very greatfull. Anyways, thanks for your help.

    And yes coins_per_kill is a setting in the DB

    Bump

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

    Andq1

    Bump
     
  9. Offline

    Andq1

    Bump...
     
  10. Offline

    Ad237

    We are not here to give you the code. We help you with small things but asking to someone to fix your whole code is annoying. If this was developed by another developer and you have no knowledge in this then you need to contact them. It is hard for us to find the problem without knowing how your databases are set up and what errors your getting etc.
     
Thread Status:
Not open for further replies.

Share This Page