Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Player player = event.getCause().first(Player.class).get();
- 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()));
- OpenData data = Sponge.getGame().getDataManager().getManipulatorBuilder(OpenData.class).get().create();
- data.set(data.open().set(!data.open().get())); //If close, make open. If open, make closed.
- BlockState newState;
- if(event.getTargetBlock().getState().with(data.asImmutable()).isPresent()) {
- newState = event.getTargetBlock().getState().with(data.asImmutable()).get();
- event.getTargetBlock().getLocation().get().setBlock(newState); //Open or close the door.
- UUID worldUuid = event.getTargetBlock().getWorldUniqueId();
- World defaultWorld = null;
- for (World w : Sponge.getGame().getServer().getWorlds()) { //Get the world the iron door is in
- if (w.getUniqueId().equals(worldUuid)) {
- defaultWorld = w;
- break;
- }
- }
- if (defaultWorld != null) { //Should always execute
- Location<World> blockLoc = event.getTargetBlock().getLocation().get();
- Vector3d position = blockLoc.getPosition();
- //Check if the player right clicked the TOP HALF or BOTTOM HALF of the iron door.
- BlockState top = defaultWorld.getLocation(new Vector3d(position.getX(), position.getY() + 1, position.getZ())).getBlock();
- BlockState bottom = defaultWorld.getLocation(new Vector3d(position.getX(), position.getY() - 1, position.getZ())).getBlock();
- if (top.getType().equals(BlockTypes.IRON_DOOR)) { //Top
- defaultWorld.setBlock(new Vector3i(position.getX(), position.getY() + 1, position.getZ()), newState);
- } else if (bottom.getType().equals(BlockTypes.IRON_DOOR)) { //Bottom
- defaultWorld.setBlock(new Vector3i(position.getX(), position.getY() - 1, position.getZ()), newState);
- }
- player.sendMessage(ChatTypes.ACTION_BAR, Text.of("The door has been opened!"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement