package com.archivesmc.painter.listeners;

import com.archivesmc.painter.Painter;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
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.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

import java.util.HashMap;
import java.util.Map;

public class PlayerInteractListener implements Listener {
    Painter plugin;

    public PlayerInteractListener(Painter plugin) {
        this.plugin = plugin;
    }

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onPlayerInteractEvent(PlayerInteractEvent event) {
//        if(! event.isCancelled()) {
            Player player = event.getPlayer();

            if (this.plugin.range_painters.contains(player.getUniqueId()) &&
                    event.getAction() == Action.LEFT_CLICK_AIR
            ) {
                this.plugin.getLogger().info("Event!");
                if (! this.plugin.permissions.has(player, "painter.replace.range")) {
                    this.plugin.range_painters.remove(player.getUniqueId());

                    Map<String, String> args = new HashMap<>();
                    args.put("permission", "painter.replace.range");
                    args.put("name", player.getName());

                    this.plugin.sendMessage(player, "range_replace_perm_lost", args);
                    return;
                }

                ItemStack items = player.getItemInHand();
                Material heldMat = items.getType();

                if (heldMat.isBlock()) {
                    this.plugin.getLogger().info("It's a block!");
                    Block block = player.getTargetBlock(null, 100);
                    BlockState oldBlockState = block.getState();

                    block.setType(heldMat);
                    block.setData(items.getData().getData());

                    event.setCancelled(true);

                    // Log it if it's being logged
                    this.plugin.blockPainted(player, oldBlockState, block.getState(), block);
                }
            }
//        }
    }
}

@@ -784,50 +784,8 @@
 ) %7B%0A
-//        if(! event.isCancelled()) %7B%0A    
     
@@ -828,28 +828,24 @@
 );%0A%0A        
-    
 if (this.plu
@@ -909,28 +909,24 @@
             
-    
 event.getAct
@@ -968,76 +968,12 @@
     
-   
- 
 ) %7B%0A
-                this.plugin.getLogger().info(%22Event!%22);%0A    
     
@@ -1058,36 +1058,32 @@
                 
-  
-  
 this.plugin.rang
@@ -1140,20 +1140,16 @@
         
-    
 Map%3CStri
@@ -1180,28 +1180,24 @@
 ashMap%3C%3E();%0A
-    
             
@@ -1257,36 +1257,32 @@
                 
-    
 args.put(%22name%22,
@@ -1298,28 +1298,24 @@
 etName());%0A%0A
-    
             
@@ -1400,20 +1400,16 @@
         
-   
- 
 return;%0A
@@ -1420,27 +1420,19 @@
         
-    %7D%0A%0A    
+%7D%0A%0A
         
@@ -1489,20 +1489,16 @@
         
- 
-   
 Material
@@ -1522,28 +1522,24 @@
 getType();%0A%0A
-    
             
@@ -1583,59 +1583,57 @@
     
-    this.plugin.getLogger().info(%22It's a block!%22
+Block block = player.getTargetBlock(null, 100
 );%0A
+%0A
     
@@ -1648,58 +1648,55 @@
     
-    Block block = player.getTargetBlock(null, 100)
+if (block == null) %7B%0A                    return
 ;%0A  
@@ -1693,32 +1693,43 @@
 return;%0A        
+ 
+       %7D%0A%0A
             Bloc
@@ -1720,24 +1720,28 @@
             
+    
 BlockState o
@@ -1782,36 +1782,32 @@
                 
-    
 block.setType(he
@@ -1822,36 +1822,32 @@
                 
-   
- 
 block.setData(it
@@ -1869,28 +1869,24 @@
 etData());%0A%0A
-    
             
@@ -1932,20 +1932,16 @@
         
-    
 // Log i
@@ -1971,36 +1971,32 @@
                 
- 
-   
 this.plugin.bloc
@@ -2053,34 +2053,16 @@
 block);%0A
-                %7D%0A
         
@@ -2067,18 +2067,16 @@
       %7D%0A
-//
         

Comment formatting