Advertisement
Guest User

Untitled

a guest
Jan 26th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.35 KB | None | 0 0
  1.  Player player = event.getCause().first(Player.class).get();
  2.         WorldWars.getInstance().getLogger().info("Player " + player.getName() + " opened an iron door at " + String.valueOf(event.getLocation().getPosition().getX()) + "," + String.valueOf(event.getLocation().getPosition().getY()) + "," + String.valueOf(event.getLocation().getPosition().getZ()));
  3.         OpenData data = Sponge.getGame().getDataManager().getManipulatorBuilder(OpenData.class).get().create();
  4.         data.set(data.open().set(!data.open().get())); //If close, make open. If open, make closed.
  5.         BlockState newState;
  6.         if(event.getTargetBlock().getState().with(data.asImmutable()).isPresent()) {
  7.             newState = event.getTargetBlock().getState().with(data.asImmutable()).get();
  8.             event.getTargetBlock().getLocation().get().setBlock(newState); //Open or close the door.
  9.  
  10.             UUID worldUuid = event.getTargetBlock().getWorldUniqueId();
  11.             World defaultWorld = null;
  12.             for (World w : Sponge.getGame().getServer().getWorlds()) { //Get the world the iron door is in
  13.                 if (w.getUniqueId().equals(worldUuid)) {
  14.                     defaultWorld = w;
  15.                     break;
  16.                 }
  17.             }
  18.  
  19.             if (defaultWorld != null) { //Should always execute
  20.                 Location<World> blockLoc = event.getTargetBlock().getLocation().get();
  21.                 Vector3d position = blockLoc.getPosition();
  22.                 //Check if the player right clicked the TOP HALF or BOTTOM HALF of the iron door.
  23.                 BlockState top = defaultWorld.getLocation(new Vector3d(position.getX(), position.getY() + 1, position.getZ())).getBlock();
  24.                 BlockState bottom = defaultWorld.getLocation(new Vector3d(position.getX(), position.getY() - 1, position.getZ())).getBlock();
  25.                 if (top.getType().equals(BlockTypes.IRON_DOOR)) { //Top
  26.                     defaultWorld.setBlock(new Vector3i(position.getX(), position.getY() + 1, position.getZ()), newState);
  27.                 } else if (bottom.getType().equals(BlockTypes.IRON_DOOR)) { //Bottom
  28.                     defaultWorld.setBlock(new Vector3i(position.getX(), position.getY() - 1, position.getZ()), newState);
  29.                 }
  30.                 player.sendMessage(ChatTypes.ACTION_BAR, Text.of("The door has been opened!"));
  31.             }
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement