SellAll Messages

Discussion in 'Plugin Development' started by Dirtcraft24, Oct 23, 2014.

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

    Dirtcraft24

  2. Offline

    Funergy

    Dirtcraft24 Are you copying???? thats REALLY bad! You should only use someones code to see how they've did it. But you shouldn't be copying somebodies code. The way your going is the bad way. to become a bad coder... uhum I can't really name it a coder. but okay if thats your choice.
     
  3. Offline

    Dirtcraft24

    I bought it from someone -.-
     
  4. Offline

    WesJD

    @Dirtcraft24​
    Remove the spaces.​
     
  5. Offline

    bwfcwalshy Retired Staff

    Dirtcraft24 You can not take to Skype, all talk must be on the forums.
     
  6. Offline

    ChipDev

    You bought code? Learn code...
    You can buy some code, or learn some code for your own.
     
    Funergy likes this.
  7. Offline

    Dirtcraft24

    Im learning. I have a server that needed a certain plugin quickly so i bought it. I just need that thing changed.
     
  8. Offline

    ChipDev

    Ok.
     
  9. Offline

    ProtoTempus

    Dirtcraft24 This is the section that controls the output of messages and the selling of a users items. Modifying this without really knowing what it does could break the plugin. I am just making an educated guess.
    Code:java
    1. for (int i = 0; i < player.getInventory().getSize(); i++) {
    2. ItemStack item = player.getInventory().getItem(i);
    3. if (item != null) {
    4. int itemAmount = item.getAmount();
    5. if (config.contains("shops." + shopName + ".items." + item.getType().toString())) {
    6. hasSelled = true;
    7. double multiplier = 1.00;
    8. for (String mult : config.getConfigurationSection("multiplier").getKeys(false)){
    9. if (player.isOp()){
    10. multiplier = 1.0;
    11. }
    12. else if (player.hasPermission("signsellall.multiplier." + mult)){
    13. multiplier = config.getDouble("multiplier." + mult);
    14. }
    15. }
    16. double price = config.getDouble("shops." + shopName + ".items." + item.getType().toString()) * itemAmount * multiplier;
    17. EconomyResponse r = economy.depositPlayer(player.getName(), price);
    18. if (r.transactionSuccess()) {
    19. player.sendMessage(ChatColor.translateAlternateColorCodes('&',
    20. config.getString("messages.sell.success").replace("%item", item.getType().toString()).replace("%price", (int)price + "").replace("%amount", String.valueOf(itemAmount))));
    21. player.getInventory().setItem(i, new ItemStack(Material.AIR));
    22. player.updateInventory();
    23. } else {
    24. fail = true;
    25. }
    26. }
    27. }
    28. }


    As you can see on line 19 the player is sent a message that tells them what was sold and how much. If we were to take that output and save it as a string until the end and them print the output it should give us the result you want. So... (This may or may not work. I did not compile this to test).
    Code:java
    1. config.addDefault("messages.sell.bulksuccess", "x%amount %item ($%price)"); //Added to the top for the config...
    2.  
    3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4.  
    5. string bulkSuccess = ""; //New string to collect sold messages...
    6. for (int i = 0; i < player.getInventory().getSize(); i++) {
    7. ItemStack item = player.getInventory().getItem(i);
    8. if (item != null) {
    9. int itemAmount = item.getAmount();
    10. if (config.contains("shops." + shopName + ".items." + item.getType().toString())) {
    11. hasSelled = true;
    12. double multiplier = 1.00;
    13. for (String mult : config.getConfigurationSection("multiplier").getKeys(false)){
    14. if (player.isOp()){
    15. multiplier = 1.0;
    16. }
    17. else if (player.hasPermission("signsellall.multiplier." + mult)){
    18. multiplier = config.getDouble("multiplier." + mult);
    19. }
    20. }
    21. double price = config.getDouble("shops." + shopName + ".items." + item.getType().toString()) * itemAmount * multiplier;
    22. EconomyResponse r = economy.depositPlayer(player.getName(), price);
    23. if (r.transactionSuccess()) {
    24. bulkSuccess += ChatColor.translateAlternateColorCodes('&',
    25. config.getString("messages.sell.bulksuccess").replace("%item", item.getType().toString()).replace("%price", (int)price + "").replace("%amount", String.valueOf(itemAmount)));
    26. player.getInventory().setItem(i, new ItemStack(Material.AIR));
    27. player.updateInventory();
    28. } else {
    29. fail = true;
    30. }
    31. }
    32. }
    33. }
    34. if(bulkSuccess != null && !bulkSuccess.equals("")){ //Did anything actually sell?
    35. player.sendMessage("Bulk sale: " + bulkSuccess); //Yup! Let's display the collected message.
    36. }


    Not editing my last post again or i'll have to re-add all the spaces...

    Dirtcraft24 Because of how it is written(not that's it's written poorly) this is the simplest way I can see how to do it... Additional modifications would allow for a final total on $$ earned as well, but let's make sure this would work first.

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

    Dirtcraft24

    Ok Ill try it
     
  11. Offline

    ProtoTempus

  12. Offline

    Dirtcraft24

    No :c Too many errors man.
     
  13. Offline

    ProtoTempus

    Dirtcraft24 So you copy-pasted the code? The idea was to give you a rough 'draft' of what should work. I can't compile or test it because I don't have the original code. This is a "help me code" section, not a "can you do this for me" section. 0.o
     
Thread Status:
Not open for further replies.

Share This Page