Guest User

Untitled

a guest
Jan 25th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.96 KB | None | 0 0
  1. package me.michaelpriebe.chairs;
  2.  
  3. import com.flowpowered.math.vector.Vector3d;
  4. import org.spongepowered.api.Sponge;
  5. import org.spongepowered.api.block.BlockTypes;
  6. import org.spongepowered.api.block.trait.EnumTraits;
  7. import org.spongepowered.api.entity.Entity;
  8. import org.spongepowered.api.entity.EntityTypes;
  9. import org.spongepowered.api.entity.living.player.Player;
  10. import org.spongepowered.api.event.Listener;
  11. import org.spongepowered.api.event.block.InteractBlockEvent;
  12. import org.spongepowered.api.event.cause.Cause;
  13. import org.spongepowered.api.plugin.Plugin;
  14. import org.spongepowered.api.world.Location;
  15. import org.spongepowered.api.world.World;
  16. import org.spongepowered.api.world.extent.Extent;
  17.  
  18. import java.util.HashMap;
  19. import java.util.Optional;
  20.  
  21. @Plugin(id = "chairs", name = "chairs", version = "1.0")
  22. public class Chairs {
  23.  
  24.     private static final HashMap<String, Double> rotation = new HashMap<String, Double>();
  25.  
  26.     private HashMap<Player, Entity> chairlist = new HashMap<Player, Entity>();
  27.  
  28.     static {
  29.         rotation.put("north", 0.0);
  30.         rotation.put("east", 90.0);
  31.         rotation.put("south", 180.0);
  32.         rotation.put("west", -90.0);
  33.     }
  34.  
  35.     @Listener
  36.     public void onRightClickBlock(InteractBlockEvent.Secondary event) {
  37.         if (event.getTargetBlock().getState().getType().equals(BlockTypes.OAK_STAIRS)) {
  38.             Optional<Location<World>> oLocation = event.getTargetBlock().getLocation();
  39.             if (oLocation.isPresent()) {
  40.                 Location location = oLocation.get().add(0.5, -1.0, 0.5);
  41.                 Extent extent = location.getExtent();
  42.                 Optional<Entity> oEntity = extent.createEntity(EntityTypes.ARMOR_STAND, location.getPosition());
  43.                 Optional<Player> oPlayer = event.getCause().first(Player.class);
  44.                 if (oEntity.isPresent() && oPlayer.isPresent()) {
  45.                     Entity entity = oEntity.get();
  46.                     Player player = oPlayer.get();
  47.                     Optional oRotation = event.getTargetBlock().getState().getTraitValue(EnumTraits.OAK_STAIRS_FACING);
  48.                     if (oRotation.isPresent()) {
  49.                         entity.setRotation(new Vector3d(0.0, rotation.get(oRotation.get().toString()), 0.0));
  50.                     } else {
  51.                         entity.setRotation(player.getRotation().add(0.0, 180.0, 0.0));
  52.                     }
  53.                     if (!(player.getItemInHand().isPresent()) || (player.getItemInHand().isPresent() && !(player.getItemInHand().get().getItem().getBlock().isPresent()))) {
  54.                         extent.spawnEntity(entity, Cause.of(this));
  55.                         player.setRotation(entity.getRotation());
  56.                         Sponge.getGame().getScheduler().createTaskBuilder().delayTicks(1).execute(t -> player.setVehicle(entity)).submit(this);
  57.                         chairlist.put(player, entity);
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment