Limiting Fortune

Discussion in 'Archived: Plugin Requests' started by np98765, Sep 29, 2012.

  1. Offline

    np98765

    Hey everyone, I have a really urgent request -- Limiting the fortune enchantment. I'm not entirely sure how the game calculates how many extra drops per block depending on level, but I'd like to cut that in about half.

    A config where I can change some options is preferred.

    When I'd like it by: Tomorrow :O

    Sorry for the unspecific request but I really do need this urgently. Thanks!
     
    hawkfalcon likes this.
  2. Offline

    Vandrake

    why not limit the amount of bookshelves around the enchantment table? it would limit all enchantments but should work till you code/find a permanent solution?
     
  3. Offline

    np98765

    People already have the picks. -_-

    For example, someone just got 88 lapis from a vein of 6. This is why the request is urgent. -_- :3

    With that being said...
    WarmakerT Woobiesharp237 calebbfmv Omnitv MrBluebear3 -_Husky_- Sushi

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

    Hoolean Retired Staff

    I can think of a way to do it... You would have to do something like onBlockBreak you could either...

    1. Check the picks enchantment level and change it
    2. Get the drops and if there is more than 'x' and the pick is enchanted with fortune then remove half of them
     
  5. Offline

    np98765


    Hmm... I may have to try that tomorrow. But it's 1:45AM here, so I'd better go to...
    *me falls asleep*
     
  6. Offline

    -_Husky_-

    np98765 likes this.
  7. Offline

    Vandrake

    on block break event check if the itemin hand has enchantment fortune and set the amount of drops to whatever you want ? :3
     
  8. Offline

    Woobie

    Whats up with all these requests? Isnt this like the 5th from you this week?
    np98765
     
  9. Offline

    -_Husky_-

    I didn't forget about this while I played BF3...
     
  10. Offline

    Vandrake

    sure you didnt xD hey :confused: THink you could help me alittle with worldguard API? or not in the mood?
     
  11. Offline

    -_Husky_-

    Sure, I'll help! =)

    //EDIT - You doing this?

    If you are, just

    Code:
    if(!e.isCancelled()) {
    //continue here
    }
    Worldguard will simply cancel the event, so you don't need to hook into it ;) (So will any protection plugin)
     
  12. Offline

    Deathmarine Retired Staff

    Code:java
    1. import java.util.Map;
    2.  
    3. import org.bukkit.enchantments.Enchantment;
    4. import org.bukkit.entity.Entity;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.BlockBreakEvent;
    9. import org.bukkit.event.enchantment.EnchantItemEvent;
    10. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13.  
    14. public class Default extends JavaPlugin implements Listener{
    15. Enchantment[] es = {Enchantment.LOOT_BONUS_BLOCKS,Enchantment.LOOT_BONUS_BLOCKS};
    16. public void onEnable(){
    17. this.getServer().getPluginManager().registerEvents(this, this);
    18. }
    19. @EventHandler
    20. public void onBlockBreak(BlockBreakEvent e){
    21. Player p =e.getPlayer();
    22. Map<Enchantment, Integer> ec=p.getItemInHand().getEnchantments();
    23. for(Enchantment ecs:es){
    24. if(ec.containsKey(ecs)){
    25. p.getItemInHand().removeEnchantment(ecs);
    26. }
    27. }
    28. }
    29. @EventHandler
    30. public void onEntityDamage(EntityDamageByEntityEvent e){
    31. Entity eb =e.getDamager();
    32. if(eb instanceof Player){
    33. Player p = (Player) eb;
    34. Map<Enchantment, Integer> ec=p.getItemInHand().getEnchantments();
    35. for(Enchantment ecs:es){
    36. if(ec.containsKey(ecs)){
    37. p.getItemInHand().removeEnchantment(ecs);
    38. }
    39. }
    40. }
    41. }
    42.  
    43. //OR
    44.  
    45. @EventHandler
    46. public void onEnchant(EnchantItemEvent e){
    47. Map<Enchantment, Integer> ec=e.getEnchantsToAdd();
    48. if(ec.containsKey(Enchantment.LOOT_BONUS_MOBS)){
    49. //Limit level of enchantment
    50. int lvl = ec.get(Enchantment.LOOT_BONUS_MOBS);
    51. if(lvl>5)lvl=5;
    52. /*
    53. * OR
    54. */
    55. }else if(ec.containsKey(Enchantment.LOOT_BONUS_BLOCKS)){
    56. //Remove enchantment
    57. ec.remove(Enchantment.LOOT_BONUS_BLOCKS);
    58.  
    59. }
    60. }
    61. }


    Sorry np98765 I'll make you edit it to what you want it to do exactly.
     
  13. Offline

    Vandrake

    No I'm not doing this xP so many ppl offered to help. One more would only be a bother. I was actually doing another request "Change gamemode to survival on a wg region". Aparently the implemented one wasn't workign so well lol
    My problem was checking if the player was inside the region but After a loong time searching XD I managed to understand how it works :3 Thank you anyways :3 [diamond][diamond][diamond]
     
  14. Offline

    -_Husky_-

    isn't it
    Code:
    if(region.contains(player))
    Or am I derping.
     
  15. Offline

    Vandrake

    I tried that contains and only vectors and locations show up :3 So I'm guessing you're derping xD I used a check on players location. If he can build tehre do this if not do that
     
    -_Husky_- likes this.
  16. Offline

    Sushi

    Whats up with all this being nosy in other people's requests? Isnt this like the 5th from you this week?
    Woobie
     
    kroltan, -_Husky_- and afistofirony like this.
  17. Offline

    calebbfmv

    Hey np, since you happen to tag me on my day off, I guess I have to make this.
     
  18. Offline

    Hoolean Retired Staff

    It's true!
     
    calebbfmv likes this.
  19. Offline

    np98765

    3rd one this week*

    My server has gotten a bit busier than normal, and I've discovered some problems with excessive item gains -- Cocoa beans and everything with Fortune picks. I've also gotten so much busier, so I can't work on much of anything.

    The StaffChat addition one is still needed. :|

    Oh, and I'll probably be posting another one today. It regards chat.
     
  20. Offline

    calebbfmv

    StaffChat? I shall do that, AND this one for you, sometime this week. LIKE I SAID, today is my day off (date day) so me and my girl are going to hang out and go have lunch, then go to the mall. So, whenever I get the time this week, I shall make these plugins for you.
     
    np98765 likes this.
  21. Offline

    np98765

    <3
     
  22. Offline

    sharp237

    I just coded this:

    There are 2 variables you can change, "uses" and "plus". Every time you mine a block it will cumulatively add the "plus" variable. If you mine a block and this comulative number is greater than or equal to the "uses" variable then the fortune enchantment will not take effect on the block break and the 'cumulative number' is reset.

    Code:
    package me.sharp237.fortunecontrol;
     
    import java.util.HashMap;
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class FortuneControl extends JavaPlugin implements Listener {
        public static HashMap<String, Double> Loot = new HashMap<String, Double>();
        public static HashMap<String, Double> Loot2 = new HashMap<String, Double>();
        public final Logger logger = Logger.getLogger("Minecraft");
     
        //Plus
        public double plus = 1;
        //Uses
        public double uses = 2;
     
        public void onDisable() {
            PluginDescriptionFile pdfFile = getDescription();
            this.logger.info(pdfFile.getName() + " Has Been Disabled");
        }
     
        public void onEnable() {
            PluginDescriptionFile pdfFile = getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled");
            getServer().getPluginManager().registerEvents(this, this);
        }
        @EventHandler
        public void onBlockBreak(BlockBreakEvent event){
            final Player player = event.getPlayer();
            int check;
            check = 0;
            if(player.getItemInHand().containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS) && check == 0){
                if(!Loot.containsKey(player.getName())){
                    Loot.put(player.getName(), plus);
                    check = 1;
                }
                if(Loot.containsKey(player.getName()) && check == 0){
                    double num = Loot.get(player.getName());
                    double added = num + plus;
                    if(added != uses){
                        Loot2.put(player.getName(), added);
                        Loot.remove(player.getName());
                        Loot.put(player.getName(), Loot2.get(player.getName()));
                        Loot2.remove(player.getName());
                    }
                    if(added >= uses){
                        int level = player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
                        if(level == 1){
                            player.getItemInHand().removeEnchantment(Enchantment.LOOT_BONUS_BLOCKS);
                            Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                  @Override
                                  public void run() {
                                      player.getItemInHand().addEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 1);
                                  }
                            });
                        }
                        if(level == 2){
                            player.getItemInHand().removeEnchantment(Enchantment.LOOT_BONUS_BLOCKS);
                            Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                  @Override
                                  public void run() {
                                      player.getItemInHand().addEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 2);
                                  }
                            });
                        }
                        if(level == 3){
                            player.getItemInHand().removeEnchantment(Enchantment.LOOT_BONUS_BLOCKS);
                            Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                  @Override
                                  public void run() {
                                      player.getItemInHand().addEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 3);
                                  }
                            });
                        }
                        Loot.remove(player.getName());
                    }
                    check = 1;
                }
            }
        }
    }
    Edit: Do I need to make a dev page for this?
     
    np98765 likes this.
  23. Offline

    Woobie

    Actually its 1st
    Havent been on for a while.
     
  24. Offline

    np98765

    Please do. I remember at least one other request for this. :)

    (If not, I can quickly whip one up when I get home if you'd like.)
     
  25. Offline

    sharp237

    Ok, do you want to make it? I find making dev pages incredibly boring :/
     
  26. Offline

    Woobie

    ALSO why did you quote and tag me in the same post? Bad attempt at trying to be funny.
     
  27. Offline

    calebbfmv

    WHY DID YOU STEAL MY THUNDER?!?!?!?!

    Eh, staff chat is mine, I claim it!

    Just tell me what it needs to do. :p
     
  28. Offline

    np98765

    Ok, so I tested the plugin pretty thoroughly. It works amazingly, sharp237 -- Very creative way of doing it. :)

    I've created a Dev page for it, which can be found here.

    If you'd like to see the results of the latest quick test, I made a quick table on the page. :D

    Sharp: I changed the name/used my domain, edited the onEnable/onDisable, and made the code good for my eyes. You can decompile it or I'll send/post the source if you'd like. ^_^

    Is the GPL(v3) license is fine?
     
  29. Offline

    sharp237

    Wow, thanks :D
    Yea I tried to do your request and then I realised that 'getDrop()' doesn't work for Fortune :( So it became a sort of personal challenge to find a way of doing this, lol.
    I don't really mind how you change the code, make it whatever you want. Oh, and I also don't care what the license is, its not like I made the next version of Microsoft Word :p.
     
    np98765 likes this.

Share This Page