Guest User

Untitled

a guest
May 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. package me.wayche.TNTBlock;
  2.  
  3. import org.bukkit.ChatColor;
  4. import org.bukkit.Material;
  5. import org.bukkit.block.Block;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.event.block.BlockBreakEvent;
  8. import org.bukkit.event.block.BlockListener;
  9. import org.bukkit.event.block.BlockPlaceEvent;
  10. import org.bukkit.inventory.ItemStack;
  11.  
  12. public class TNTBlockBlockListener extends BlockListener {
  13.    
  14.     private TNTBlock plugin;
  15.     public TNTBlockBlockListener(TNTBlock instance){
  16.         this.plugin = instance;
  17.     }
  18.    
  19.     public void onBlockPlace(BlockPlaceEvent event){
  20.         if(event.isCancelled()) return;
  21.        
  22.         Block block = event.getBlock();
  23.         Player player = event.getPlayer();
  24.        
  25.         if (block.getType() == Material.TNT && player.hasPermission("tntblock.allow-tnt") == false){
  26.             String msg = player.getName() + " hat hier einen TNT Block gesetzt: " + block.getX() + "," + block.getY() + "," + block.getZ() + ".";
  27.            
  28.             block.setTypeId(plugin.config.getInt("place"));
  29.            
  30.             player.sendMessage(ChatColor.BLUE + player.getName() + " " + ChatColor.DARK_RED + "du darfst kein TNT benutzen!");
  31.            
  32.            
  33.             System.out.println("\033[31m\033[44m" + player.getName() + " hat hier einen TNT Block gesetzt: " + block.getX() + "," + block.getY() + "," + block.getZ() + "." + "\033[0m\n");
  34.             System.out.println(ChatColor.GREEN + "Blubb");
  35.             for (Player onlinePlayer : plugin.getServer().getOnlinePlayers()){
  36.                 if (onlinePlayer.hasPermission("tntblock.notify")){
  37.                     onlinePlayer.sendMessage(ChatColor.DARK_RED + msg);             }
  38.                
  39.             }
  40.         }
  41.     }
  42.    
  43.     public void onBlockBreak(BlockBreakEvent event){
  44.         if (event.isCancelled()) return;
  45.        
  46.         Block block = event.getBlock();
  47.  
  48.         if(block.getType() == Material.TNT){
  49.             event.setCancelled(true);
  50.             block.setType(Material.AIR);
  51.            
  52.            
  53.             block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(plugin.config.getInt("drop"), 1));
  54.         }
  55.     }
  56.  
  57.  
  58. }
Add Comment
Please, Sign In to add comment