Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.michaelpriebe.chairs;
- import com.flowpowered.math.vector.Vector3d;
- import org.spongepowered.api.Sponge;
- import org.spongepowered.api.block.BlockTypes;
- import org.spongepowered.api.block.trait.EnumTraits;
- import org.spongepowered.api.entity.Entity;
- import org.spongepowered.api.entity.EntityTypes;
- import org.spongepowered.api.entity.living.player.Player;
- import org.spongepowered.api.event.Listener;
- import org.spongepowered.api.event.block.InteractBlockEvent;
- import org.spongepowered.api.event.cause.Cause;
- import org.spongepowered.api.plugin.Plugin;
- import org.spongepowered.api.world.Location;
- import org.spongepowered.api.world.World;
- import org.spongepowered.api.world.extent.Extent;
- import java.util.HashMap;
- import java.util.Optional;
- @Plugin(id = "chairs", name = "chairs", version = "1.0")
- public class Chairs {
- private static final HashMap<String, Double> rotation = new HashMap<String, Double>();
- private HashMap<Player, Entity> chairlist = new HashMap<Player, Entity>();
- static {
- rotation.put("north", 0.0);
- rotation.put("east", 90.0);
- rotation.put("south", 180.0);
- rotation.put("west", -90.0);
- }
- @Listener
- public void onRightClickBlock(InteractBlockEvent.Secondary event) {
- if (event.getTargetBlock().getState().getType().equals(BlockTypes.OAK_STAIRS)) {
- Optional<Location<World>> oLocation = event.getTargetBlock().getLocation();
- if (oLocation.isPresent()) {
- Location location = oLocation.get().add(0.5, -1.0, 0.5);
- Extent extent = location.getExtent();
- Optional<Entity> oEntity = extent.createEntity(EntityTypes.ARMOR_STAND, location.getPosition());
- Optional<Player> oPlayer = event.getCause().first(Player.class);
- if (oEntity.isPresent() && oPlayer.isPresent()) {
- Entity entity = oEntity.get();
- Player player = oPlayer.get();
- Optional oRotation = event.getTargetBlock().getState().getTraitValue(EnumTraits.OAK_STAIRS_FACING);
- if (oRotation.isPresent()) {
- entity.setRotation(new Vector3d(0.0, rotation.get(oRotation.get().toString()), 0.0));
- } else {
- entity.setRotation(player.getRotation().add(0.0, 180.0, 0.0));
- }
- if (!(player.getItemInHand().isPresent()) || (player.getItemInHand().isPresent() && !(player.getItemInHand().get().getItem().getBlock().isPresent()))) {
- extent.spawnEntity(entity, Cause.of(this));
- player.setRotation(entity.getRotation());
- Sponge.getGame().getScheduler().createTaskBuilder().delayTicks(1).execute(t -> player.setVehicle(entity)).submit(this);
- chairlist.put(player, entity);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment