Solved GPP API

Discussion in 'Spigot Plugin Development' started by MrWaffleman, May 25, 2016.

  1. Okay, so I'm using a Grief Prevention Plus API to make a plugin that claims lands for companies, whenever you claim land and you don't have enough blocks, it says you can't make a claim, and it never invokes the ClaimCreateEvent because it's cancelled way before then. So I went along trying to rewrite the Interact... which failed considering I had to go inside the API itself which I can't do. So I decided to give the player in accrued blocks (who is in Company Claim Mode) like 1,000,000 blocks so he could claim. Then once he made a claim, I would add the claim area to his accrued blocks, and removed 1,000,000, but this kept on giving me either a number of blocks that the player did not have previously, or give me a ridiculously low negative number.

    You might think a player can glitch somehow, or abuse something in order to get that 1,000,000 blocks without me subtracting it. But I already subtracted that amount whenever the player leaves or exits out of company claim mode (amongst other scenarios). But I don't understand what math I have to do in order to give the player blocks so he can claim for his company (like a placeholder), and redo the whole thing so he has the amount of personal blocks since he started.

    Note:
    The reason I'm handling blocks using "Accrued" blocks is because there's a method for retrieving total blocks, but not for setting total blocks because there are 3 types, bonus, accrued, and group. So I just decided to do all the transactions in accrued blocks.

    Methods/Fields From Company Plugin:

    CompanyData.claimBlocks (int)

    Code:

    When the player turns on Claim Mode: (pd being PlayerData)
    Code (Text):
    pd.setAccruedClaimBlocks(pd.getAccruedClaimBlocks() + 100000);
    Whenever a player successfully makes a claim for the company:
    Code (Text):
    pd.setAccruedClaimBlocks(pd.getAccruedClaimBlocks() + claim.getArea() - 100000);
    Thanks for help ;).

    EDIT: Math in Action:

    Let's say I have 10 accrued blocks, this is excluding any other types of blocks because of the reasons I already stated. I do /cpclaim which turns on Company Claiming mode, this adds 100,000 to my claim blocks so now I have 100,010 accrued blocks. Now let's say I claim land for my company, let's say that area of land is 100 blocks. So that automatically does 100,010 - 100 which is 99910. Now in ClaimCreateEvent I do 99910 + claim.getArea() which is 100,010. Then I subtract 100,000 for it which equals 10, which is what I had in the first place. I have no idea why it is not working then. Like I said, it mostly returns a negative number (if I have a low number of blocks). If I do have lots of personal claim blocks then it still is nowhere near the number I had previously.
     
    #1 MrWaffleman, May 25, 2016
    Last edited: May 25, 2016
  2. Never worked with the API, but I assume since you've given the player 100000 blocks it should be enough. You mention that it kept on giving you either a number of blocks that the player did not have previously, or give me a ridiculously low negative number. I would assume that this is due to you've perhaps exceeded the maximum of "Accrued" blocks that a player can have, so it messes it up? I'd suggest you make direct contact with the developer.
     
    #2 ExpDev, May 25, 2016
    Last edited: May 25, 2016
    • Informative Informative x 1
  3. Hm, you're right, the limit is apparently 80,010, I'll see other types of blocks I could add to that doesn't have a limit, or possibly if there's a setting in the config, I could change that.