SHARE
TWEET

Untitled

a guest Jan 24th, 2020 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.iran.factions.listeners;
  2.  
  3. import java.util.List;
  4. import me.iran.factions.Factions;
  5. import me.iran.factions.faction.Faction;
  6. import me.iran.factions.faction.FactionManager;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Material;
  9. import org.bukkit.block.BlockState;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.event.EventHandler;
  12. import org.bukkit.event.Listener;
  13. import org.bukkit.event.block.Action;
  14. import org.bukkit.event.player.PlayerInteractEvent;
  15.  
  16. public class InteractWithItemsInClaim implements Listener {
  17.  
  18.     @EventHandler
  19.     public void onInteract(PlayerInteractEvent event) {
  20.         Player player = event.getPlayer();
  21.        
  22.         if (event.getAction() == null) {
  23.             return;
  24.         }
  25.        
  26.         if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  27.            
  28.             BlockState block = event.getClickedBlock().getState();
  29.            
  30.             if (FactionManager.getManager().isPlayerInFaction(player)) {
  31.                
  32.                 Faction faction = FactionManager.getManager().getFactionByPlayer(player);
  33.                
  34.                 if (FactionManager.getManager().insideClaim(block.getLocation())) {
  35.                    
  36.                     if (!FactionManager.getManager().getClaimByLocation(block.getLocation()).getName().equalsIgnoreCase(faction.getName())) {
  37.                        
  38.                         Faction blockFac = FactionManager.getManager().getClaimByLocation(block.getLocation());
  39.  
  40.                         List<String> materialList = Factions.getInstance().getConfig().getStringList("interact-in-claim");
  41.                         for (String s : materialList) {
  42.  
  43.                             Material material = Material.getMaterial(s);
  44.                            
  45.                             if (block.getType() == material) {
  46.                                 event.setCancelled(true);
  47.                                 player.sendMessage(ChatColor.RED + "Can't touch " + ChatColor.LIGHT_PURPLE+ s.replace("_", " ").toLowerCase() + ChatColor.RED + " inside the claim of " + ChatColor.YELLOW + blockFac.getName());
  48.                                 return;
  49.                             }
  50.                         }
  51.                     }
  52.                 }
  53.            
  54.             } else {
  55.                 Faction blockFac = FactionManager.getManager().getClaimByLocation(block.getLocation());
  56.  
  57.                 List<String> materialList = Factions.getInstance().getConfig().getStringList("interact-in-claim");
  58.                
  59.                 for (String s : materialList) {
  60.  
  61.                     Material material = Material.getMaterial(s);
  62.                    
  63.                     if (block.getType() == material) {
  64.                         event.setCancelled(true);
  65.                         player.sendMessage(ChatColor.RED + "Can't touch " + ChatColor.LIGHT_PURPLE+ s.replace("_", " ").toLowerCase() + ChatColor.RED + " inside the claim of " + ChatColor.YELLOW + blockFac.getName());
  66.                         return;
  67.                     }
  68.                 }
  69.             }
  70.         }
  71.     }
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top