Solved Config values help

Discussion in 'Plugin Development' started by sniddunc, Dec 20, 2015.

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

    sniddunc

    Hello everyone,

    I am trying to make a money printer plugin but am running into some trouble.

    When I place the printer block, it should raise the printer count variable in the data file by 1, and when it is broken, it should remove 1 from that count.

    However, the count value goes up, but it doesn't decrease.

    This is my code:
    PHP:
    public class printerListener implements Listener {
       
        public static 
    HashMap<LocationIntegermoneymap = new HashMap<LocationInteger>();
        public static 
    HashMap<PlayerIntegerprinterinfo = new HashMap<PlayerInteger>();
       
        @
    EventHandler
        
    public void onPrinterPlace(BlockPlaceEvent event) {
           
            
    Player player event.getPlayer();
            
    Block block event.getBlock();
           
            
    String originalPrinterCount PlayerData.getData().getString("players." player.getUniqueId() + "." player.getName() + ".printers");
            
    int printerCount Integer.parseInt(originalPrinterCount);
           
            if (
    block.getType().equals(Material.IRON_BLOCK)) {
               
                
    moneymap.put(block.getLocation(), printerCount 1);
                
    printerinfo.put(playerprinterCount 1);
                
    PlayerData.getData().set("players." player.getUniqueId() + "." player.getName() + ".printers", (printerCount 1));

            }
           
        }
       
       
        public 
    void onPrinterBreak(BlockBreakEvent event) {
           
            
    Player player event.getPlayer();
            
    Block block event.getBlock();
           
            
    String originalPrinterCount PlayerData.getData().getString("players." player.getUniqueId() + "." player.getName() + ".printers");
            
    int printerCount Integer.parseInt(originalPrinterCount);
           
            if (
    block.getType().equals(Material.IRON_BLOCK)) {
               
                
    this.moneymap.remove(block.getLocation());
                
    PlayerData.getData().set("players." player.getUniqueId() + "." player.getName() + ".printers", (printerCount 1));
                
    printerCount--;
               
               
            }
           
        }
       
       
        @
    EventHandler
        
    public void onPlayerInteract(PlayerInteractEvent event) {
           
            
    Player player event.getPlayer();
           
            if (
    event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (
    event.getClickedBlock().getType().equals(Material.IRON_BLOCK)) {
                   
                    
    player.sendMessage("You right clicked a Money Printer");
                   
                }
            }
        }
    }
    If you find the problem, please let me know.

    Thank you in advance for any help. :)
     
  2. Offline

    teej107

  3. Offline

    sniddunc

    I called the save method after it changes the value but the issue still persists.
     
  4. Offline

    teej107

    @sniddunc Perhaps you should print out debug messages to tell if your event is even being fired.
     
  5. Offline

    Zombie_Striker

    May I point out it can be write as such:
    BTW: You have printcount--; But you do not have printercount++;
     
  6. Offline

    sniddunc

    I got it working. @teej107 was right, the event was not getting fired. Turns out I forgot the leading @EventHandler before declaring the method. Thanks for the help!
     
  7. Offline

    teej107

    @sniddunc Glad I could help. Please mark this thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page