Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package guyk.castlebasher2;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.logging.Logger;
- import org.bukkit.GameMode;
- import org.bukkit.Location; //
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.BlockPlaceEvent;
- import com.sk89q.worldedit.BlockVector;
- import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
- import com.sk89q.worldguard.domains.DefaultDomain;
- import com.sk89q.worldguard.protection.flags.DefaultFlag;
- import com.sk89q.worldguard.protection.flags.StateFlag.State;
- import com.sk89q.worldguard.protection.managers.RegionManager;
- import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
- public class blockListener implements Listener{
- public WorldGuardPlugin worldGuard;
- public Logger logger;
- public com.sk89q.worldedit.BlockVector convertToSk89qBV(Location location){
- return new com.sk89q.worldedit.BlockVector(location.getX(),location.getY(),location.getZ());
- }
- @EventHandler
- public void onBlockPlace(BlockPlaceEvent event) {
- int block = event.getBlock().getTypeId();
- if (block == 133) { // Is Emerald Block
- int bx = event.getBlock().getX();
- int by = event.getBlock().getY();
- int bz = event.getBlock().getZ();
- Player player = event.getPlayer();
- World world = player.getWorld();
- boolean airAbove = true;
- for (int i = by+1; i<128; i=i+1) {
- if (world.getBlockAt(bx, i, bz).getTypeId() != 0) {
- airAbove = false;
- }
- }
- if (airAbove) {
- player.sendMessage("You placed the block!");
- logger.info("castlebasher: Block placed");
- event.getBlock().setType(Material.BOOKSHELF);
- player.setGameMode(GameMode.CREATIVE);
- addProtectedRegion(player, world, 0, 0, 0, 5, 0);
- //Location f1 = new Location(world, 1.0, 1.0, 1.0);
- //Location f2 = new Location(world, 100.0, 100.0, 100.0);
- //BlockVector bv1 = new BlockVector(1.0, 1.0, 1.0);
- //BlockVector bv2 = new BlockVector(100.0, 100.0, 100.0);
- }
- }
- }
- public void addProtectedRegion(Player player, World world, int x, int y, int z, int radius, int delay)
- {
- logger.info("castlebasher: Adding region");
- // get the region manager
- RegionManager rm = worldGuard.getRegionManager(world);
- // make a cuboid with two points to create a 3d cube in the world
- BlockVector b1 = new BlockVector(x + radius + 1, y + radius + 1, z + radius + 1);
- BlockVector b2 = new BlockVector(x - radius - 1, y - radius - 1, z - radius - 1);
- // create the protected region
- ProtectedCuboidRegion pr = new ProtectedCuboidRegion("testregion", b1, b2);
- DefaultDomain dd = new DefaultDomain();
- // add the player to the region
- dd.addPlayer(player.getName());
- // set the player as the owner
- pr.setOwners(dd);
- /*
- // set the flags
- if (flags == null)
- {
- flags = new HashMap();
- flags.put(DefaultFlag.BUILD, State.DENY);
- flags.put(DefaultFlag.CREEPER_EXPLOSION, State.DENY);
- //
- // put more flag definitions here
- //
- }
- pr.setFlags(flags);
- */
- try
- {
- rm.save();
- }
- catch (Exception exp)
- { }
- }
- /*
- public static void addProtectedRegion(Player player, World world, int x, int y, int z, int radius, int delay, Map flags)
- {
- // get the region manager
- //RegionManager rm = castlebasher2.class.
- RegionManager rm = worldGuard.getRegionManager(world);
- // make a cuboid with two points to create a 3d cube in the world
- BlockVector b1 = new BlockVector(x + radius + 1, y + radius + 1, z + radius + 1);
- BlockVector b2 = new BlockVector(x - radius - 1, y - radius - 1, z - radius - 1);
- // create the protected region
- ProtectedCuboidRegion pr = new ProtectedCuboidRegion("testname", b1, b2);
- DefaultDomain dd = new DefaultDomain();
- // add the player to the region
- dd.addPlayer(player.getName());
- // set the player as the owner
- pr.setOwners(dd);
- // set the flags
- if (flags == null)
- {
- flags = new HashMap();
- flags.put(DefaultFlag.BUILD, State.DENY);
- flags.put(DefaultFlag.CREEPER_EXPLOSION, State.DENY);
- //
- // put more flag definitions here
- //
- }
- pr.setFlags(flags);
- try
- {
- rm.save();
- }
- catch (Exception exp)
- { }
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement