Unexplainable bug

Discussion in 'Plugin Development' started by xDevious, May 6, 2014.

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

    xDevious

    I deleted the previous file and changed the version number and sure enough when the plugin loaded it showed the new version number, however redstone still won't payout when mined in survival mode .-.
     
  2. Offline

    metalhedd

    No, not correct. Essentially it's the 'instance' of the enum which is a singleton. There can be only 1 Material.COBBLESTONE, but its not the exact same object as Material.REDSTONE. This isn't entirely accurate, but its good enough to understand how it works.

    This isn't true at all, HashCode's are just 'first-attempt' to match objects. if there is only 1 matching hashcode in the collection, the more expensive .equals() operation can be avoided. if there is more than one, then the jvm will start using .equals() to compare them and determine which one you're looking for.


    There's not much truth to this at all actually. It's a good idea to use an EnumMap, but there is absolutely no chance you'll have any 'problems' with a HashMap.


    can you post the current code?

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

    Lecrayen

    on a side note, I hear your plugin is incompatible with worldguard. Your plugin doesn't check to see if a protection plugin canceled a break event before you pay the guy. This means a person could just sit there breaking a protected block all day for money.
     
  4. Offline

    metalhedd


    according to this: http://dev.bukkit.org/bukkit-plugins/minepay/files/5-mine-pay-v2-0/ it was fixed a while ago.

    I did notice however that the plugin is GPL3 but there's no source code link. tsk. tsk.

    For what it's worth. I did a quick test, the code below works in both creative and survival displaying the correct message when you break either type of redstone ore.

    Code:
    package me.metalhedd.miningforcash;
     
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import java.util.HashMap;
     
    public class MiningForCash extends JavaPlugin implements Listener {
        private static HashMap<Material, Double> payouts = new HashMap<Material, Double>();
        @Override
        public void onEnable() {
            payouts.put(Material.EMERALD_ORE, 100.0);
            payouts.put(Material.LAPIS_ORE, 50.0);
            payouts.put(Material.REDSTONE_ORE, 75.0);
            payouts.put(Material.GLOWING_REDSTONE_ORE, 75.0);
            payouts.put(Material.COAL_ORE, 10.0);
            getServer().getPluginManager().registerEvents(this, this);
        }
     
        @EventHandler(priority = EventPriority.MONITOR)
        public void onBlockBreak(BlockBreakEvent event) {
            if (!event.isCancelled()) {
                Material type = event.getBlock().getType();
                if (payouts.containsKey(type)) {
                    event.getPlayer().sendMessage("You broke " + type + " for " + payouts.get(type));
                }
            }
        }
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
    xTigerRebornx likes this.
  5. Offline

    minoneer

    Then I have no idea what's wrong. Could you please repost your whole code?
     
  6. metalhedd minoneer xize Since the debate mostly seems to be centred around the point that the enum keys will just override each other(?) rather than the actual benefits vs drawbacks of EnumMap, easiest way to solve this would be to prove xize wrong.

    PHP:
    import java.util.HashMap;
     
    public class 
    Main {
        public static 
    void main(String[] args) {
            
    HashMap<WordIntegermap = new HashMap<WordInteger>();
            
    map.put(Word.HEY1);
            
    map.put(Word.BYE1);
            for(
    Word word map.keySet()) {
                
    System.out.println(word);
            }
        }
    }
    enum Word HEYBYE }
    Output:

    Code:
    HEY
    BYE
     
  7. Offline

    minoneer

    AdamQpzm What I'm actually trying to do is to get back to toppic. Since the HashMap is not the cause of the error, it must be somewhere else. Originally this post was about xDevious plugin not functioning, not about teaching xize how Enums and HashMaps work ;)
     
  8. minoneer True, but surely the fastest way to derail that is with the fact that he was wrong? Since there was many posts already which could have been stopped with just one :p And since we have to wait for the up-to-date code anyway...
     
  9. Offline

    minoneer

    Also true :D
     
  10. Offline

    metalhedd

    I was disappointed with limited selection of plugins like this, (there are a few, but none are open source) So I ran with my example and created DigForDollars. The first release is still waiting for approval from bukkitdev staff.
     
  11. Offline

    xDevious

    minoneer

    Indentation is correct its just when i paste it.
    Code:
    package me.styltwist.minepay;
     
    import java.util.ArrayList;
    import java.util.HashMap;
     
    import net.milkbowl.vault.chat.Chat;
     
    import org.bukkit.enchantments.Enchantment;
     
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
     
    public class MyBlockListener implements Listener {
        public static Chat chat = null;
        public static MinePay plugin;
        public static HashMap<Material, Integer> orelist = new HashMap<Material, Integer>();
        ArrayList<Material> ingot = new ArrayList<Material>();
       
        public MyBlockListener(MinePay instance) {
    plugin = instance;
    int diamond = plugin.getConfig().getInt("diamond");
    int coal = plugin.getConfig().getInt("coal");
    int emerald = plugin.getConfig().getInt("emerald");
    int redstone = plugin.getConfig().getInt("redstone");
    int lapis = plugin.getConfig().getInt("lapis");
    int quartz = plugin.getConfig().getInt("quartz");
     
    orelist.put(Material.COAL_ORE, coal);
    orelist.put(Material.DIAMOND_ORE, diamond);
    orelist.put(Material.GLOWING_REDSTONE_ORE, redstone);
    orelist.put(Material.REDSTONE_ORE, redstone);
    orelist.put(Material.LAPIS_ORE, lapis);
    orelist.put(Material.EMERALD_ORE, emerald);
    orelist.put(Material.QUARTZ_ORE, quartz);
     
    }
     
    @EventHandler(priority=EventPriority.HIGH)
        public void onBlockBreak(BlockBreakEvent event){
      Material block = event.getBlock().getType();
            Player player = event.getPlayer();
            player.sendMessage("You mined" + block);
            if(event.isCancelled()){
             
            }else{
                if(player.hasPermission("minepay.reward")) {
              if(orelist.containsKey(block)){
              int Money = orelist.get(block);
                  if(player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)){
                  }else{
                  plugin.econ.depositPlayer(player.getName(), Money);
                  player.sendMessage("§3You recieved §b" + Money + " §3for mining §b" + block + "§3.");
                  }
              }else if(block == Material.IRON_ORE){
              if(player.hasPermission("minepay.reward")) {
              int iron = plugin.getConfig().getInt("iron");
              if(player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)){
                 
              }else{
              player.getWorld().dropItemNaturally(event.getBlock().getLocation(), new ItemStack(Material.IRON_INGOT, 1));
              event.setCancelled(true);
              event.getBlock().setType(Material.AIR);
              plugin.econ.depositPlayer(player.getName(), iron);
              player.sendMessage("§3You recieved §b" + iron + " §3for mining §b" + block + "§3.");
              }
              }
              }else if(block == Material.GOLD_ORE){
              if(player.hasPermission("minepay.reward")) {
              int gold = plugin.getConfig().getInt("gold");
              if(player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)){
                     
              }else{
              player.getWorld().dropItemNaturally(event.getBlock().getLocation(), new ItemStack(Material.GOLD_INGOT, 1));
              event.setCancelled(true);
              event.getBlock().setType(Material.AIR);
              plugin.econ.depositPlayer(player.getName(), gold);
              player.sendMessage("§3You recieved §b" + gold + " §3for mining §b" + block + "§3.");
              }
              }
              }
              }
                }
    }
    }
     
  12. Offline

    xDevious

    - BUMP -
     
  13. Offline

    minoneer

    xDevious
    Ok, try to clean and rebuild your Project. In Eclipse that is Project -> Clean...

    After that, reexport and see what happens. If you are still having that Duplicate Store_DS Problem, Navigate to your project folder and delete it there.
     
  14. Offline

    xDevious

    minoneer

    I cleaned the project and re-exported, and it resulted in this:

    JAR creation failed. See details for additional information.
    Class files on classpath not found or not accessible for: 'MinePay/src/me/styltwist/minepay/MyBlockListener.java'
    Class files on classpath not found or not accessible for: 'MinePay/src/me/styltwist/minepay/MinePay.java'
    Problem writing MinePay/.DS_Store to JAR: duplicate entry: .DS_Store
    duplicate entry: .DS_Store
     
  15. Offline

    minoneer

    Ok, then maybe your .classpath file got corrupted. You could try to go to your project folder, move the .classpath file somewhere (for backup), then clean the project again. See if that works.
     
  16. Offline

    xDevious

    Tried that, then put the classpath files back and got the same error on exportion of the jar file;/
     
  17. Offline

    minoneer

    hmmm, to be honest, I have no idea then. But to me it seems to be related to your plugin export, not to the code itself. Maybe someone else ( Azubuso ?) can help you - or you try the eclipse forum.
     
    xDevious likes this.
  18. Offline

    xDevious

    Okay, no worries pal, thanks for the help you've given me thus far:)
     
  19. Offline

    Azubuso

    xDevious So you've already tried rebuilding your project with the same export result? Strange indeed. Also, are you on OS X by any chance? (Since the duplicate .DS_Store)

    Well, try doing that again but delete that second .DS_Store files before you do. If all else fails, you might just have to completely recreate your project.

    On a side note, I hate Eclipse for having these annoying hidden file dependencies, I'm sure others do as well, and therefor recommend using something like IntelliJ - Haven't had a single issue with it.
     
  20. Offline

    evilmidget38

  21. Offline

    xDevious

    You are correct, I am on OS X. However there is no second DS_Store file, I may try recreating the entire project as you suggested and see how that works out and i'll let you know, thanks.

    evilmidget38

    I can't seem to get the page http://www.weston-fl.com/blog/?p=2835 to load?

    I'll try again later to try and work out the issue, however I can load any other webpages.

    EDIT: I followed the instructions on the thread, this has now fixed any issues with DS_Store duplicates however exportion returned these errors:

    JAR creation failed. See details for additional information.
    Resource is out of sync with the file system: '/MinePay/src/me/.DS_Store'.
    Resource is out of sync with the file system: '/MinePay/src/me/styltwist/.DS_Store'.
    Class files on classpath not found or not accessible for: 'MinePay/src/me/styltwist/minepay/MyBlockListener.java'
    Class files on classpath not found or not accessible for: 'MinePay/src/me/styltwist/minepay/MinePay.java'
    File not found: /Users/Jordan/Desktop/workspace/MinePay/src/me/styltwist/minepay/.DS_Store.
    Resource is out of sync with the file system: '/MinePay/src/.DS_Store'.
    Resource is out of sync with the file system: '/MinePay/.DS_Store'.

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

    minoneer

    Ok, Last thing I can think of: Create a completely new project, manually create all packages and then move your classes there. Maybe that'll fix it.
     
Thread Status:
Not open for further replies.

Share This Page