Advertisement
Guest User

Untitled

a guest
Aug 6th, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.77 KB | None | 0 0
  1. package guyk.castlebasher2;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.logging.Logger;
  6.  
  7. import org.bukkit.GameMode;
  8. import org.bukkit.Location; //
  9. import org.bukkit.Material;
  10. import org.bukkit.World;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.event.block.BlockPlaceEvent;
  15.  
  16. import com.sk89q.worldedit.BlockVector;
  17. import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
  18. import com.sk89q.worldguard.domains.DefaultDomain;
  19. import com.sk89q.worldguard.protection.flags.DefaultFlag;
  20. import com.sk89q.worldguard.protection.flags.StateFlag.State;
  21. import com.sk89q.worldguard.protection.managers.RegionManager;
  22. import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
  23.  
  24. public class blockListener implements Listener{
  25.    
  26.     public WorldGuardPlugin worldGuard;
  27.     public Logger logger;
  28.  
  29.     public com.sk89q.worldedit.BlockVector convertToSk89qBV(Location location){
  30.         return new com.sk89q.worldedit.BlockVector(location.getX(),location.getY(),location.getZ());
  31.     }
  32.    
  33.     @EventHandler
  34.     public void onBlockPlace(BlockPlaceEvent event) {
  35.         int block = event.getBlock().getTypeId();
  36.         if (block == 133) { // Is Emerald Block
  37.             int bx = event.getBlock().getX();
  38.             int by = event.getBlock().getY();
  39.             int bz = event.getBlock().getZ();
  40.            
  41.             Player player = event.getPlayer();
  42.            
  43.             World world = player.getWorld();
  44.            
  45.             boolean airAbove = true;
  46.             for (int i = by+1; i<128; i=i+1) {
  47.                 if (world.getBlockAt(bx, i, bz).getTypeId() != 0) {
  48.                     airAbove = false;
  49.                 }
  50.             }
  51.            
  52.             if (airAbove) {
  53.                 player.sendMessage("You placed the block!");
  54.                 logger.info("castlebasher: Block placed");
  55.                 event.getBlock().setType(Material.BOOKSHELF);
  56.                 player.setGameMode(GameMode.CREATIVE);
  57.  
  58.                 addProtectedRegion(player, world, 0, 0, 0, 5, 0);
  59.                 //Location f1 = new Location(world, 1.0, 1.0, 1.0);
  60.                 //Location f2 = new Location(world, 100.0, 100.0, 100.0);
  61.                 //BlockVector bv1 = new BlockVector(1.0, 1.0, 1.0);
  62.                 //BlockVector bv2 = new BlockVector(100.0, 100.0, 100.0);
  63.             }
  64.         }
  65.     }
  66.    
  67.     public void addProtectedRegion(Player player, World world, int x, int y, int z, int radius, int delay)
  68.     {  
  69.         logger.info("castlebasher: Adding region");
  70.         // get the region manager
  71.         RegionManager rm = worldGuard.getRegionManager(world);
  72.      
  73.         // make a cuboid with two points to create a 3d cube in the world
  74.         BlockVector b1 = new BlockVector(x + radius + 1, y + radius + 1, z + radius + 1);
  75.         BlockVector b2 = new BlockVector(x - radius - 1, y - radius - 1, z - radius - 1);
  76.      
  77.         // create the protected region
  78.         ProtectedCuboidRegion pr = new ProtectedCuboidRegion("testregion", b1, b2);
  79.         DefaultDomain dd = new DefaultDomain();
  80.      
  81.         // add the player to the region
  82.         dd.addPlayer(player.getName());
  83.      
  84.         // set the player as the owner
  85.         pr.setOwners(dd);
  86.      
  87.         /*
  88.         // set the flags
  89.         if (flags == null)
  90.         {
  91.             flags = new HashMap();
  92.             flags.put(DefaultFlag.BUILD, State.DENY);
  93.             flags.put(DefaultFlag.CREEPER_EXPLOSION, State.DENY);
  94.             //
  95.             //    put more flag definitions here
  96.             //
  97.         }
  98.      
  99.         pr.setFlags(flags);
  100.         */
  101.        
  102.         try
  103.         {
  104.             rm.save();
  105.         }
  106.         catch (Exception exp)
  107.         { }
  108.     }
  109.    
  110.     /*
  111.     public static void addProtectedRegion(Player player, World world, int x, int y, int z, int radius, int delay, Map flags)
  112.     {
  113.         // get the region manager
  114.         //RegionManager rm = castlebasher2.class.
  115.         RegionManager rm = worldGuard.getRegionManager(world);
  116.      
  117.         // make a cuboid with two points to create a 3d cube in the world
  118.         BlockVector b1 = new BlockVector(x + radius + 1, y + radius + 1, z + radius + 1);
  119.         BlockVector b2 = new BlockVector(x - radius - 1, y - radius - 1, z - radius - 1);
  120.      
  121.         // create the protected region
  122.         ProtectedCuboidRegion pr = new ProtectedCuboidRegion("testname", b1, b2);
  123.         DefaultDomain dd = new DefaultDomain();
  124.      
  125.         // add the player to the region
  126.         dd.addPlayer(player.getName());
  127.      
  128.         // set the player as the owner
  129.         pr.setOwners(dd);
  130.      
  131.         // set the flags
  132.         if (flags == null)
  133.         {
  134.             flags = new HashMap();
  135.             flags.put(DefaultFlag.BUILD, State.DENY);
  136.             flags.put(DefaultFlag.CREEPER_EXPLOSION, State.DENY);
  137.             //
  138.             //    put more flag definitions here
  139.             //
  140.         }
  141.      
  142.         pr.setFlags(flags);
  143.         try
  144.         {
  145.             rm.save();
  146.         }
  147.         catch (Exception exp)
  148.         { }
  149.     }
  150.     */
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement