Já mám právo sedět!

master
jakub 3 weeks ago
parent 11f0a1e910
commit 64850aaf45
  1. 2
      src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java
  2. 142
      src/main/java/xyz/soukup/ecoCraftCore/sit/LetMeSit.java

@ -46,6 +46,7 @@ import xyz.soukup.ecoCraftCore.database.DaoRegistry;
import xyz.soukup.ecoCraftCore.messages.Messages;
import xyz.soukup.ecoCraftCore.shop.ShopLogic;
import xyz.soukup.ecoCraftCore.sign.SignEditCommand;
import xyz.soukup.ecoCraftCore.sit.LetMeSit;
import xyz.soukup.ecoCraftCore.virtualChest.VirtualChestLogic;
import java.io.IOException;
@ -303,6 +304,7 @@ public final class EcoCraftCore extends JavaPlugin {
pm.registerEvents(new RegionEvents(), this);
pm.registerEvents(new MineWorldManager(), this);
pm.registerEvents(new JoinLeaveMessageSupress(), this);
pm.registerEvents(new LetMeSit(), this);
EventManager events = PacketEvents.getAPI().getEventManager();
events.registerListener(new ChunkModifier(this), PacketListenerPriority.NORMAL);

@ -0,0 +1,142 @@
package xyz.soukup.ecoCraftCore.sit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.type.Stairs;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.persistence.PersistentDataType;
import xyz.soukup.ecoCraftCore.utilities.PDC;
public class LetMeSit implements Listener {
@EventHandler
public void onStairsClick(PlayerInteractEvent event){
Player player = event.getPlayer();
if (player.isSneaking()){
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK){
return;
}
Block block = event.getClickedBlock();
if (block == null){
return;
}
if (!(block.getBlockData() instanceof Stairs stairs)){
return;
}
if (stairs.getHalf() == Bisected.Half.TOP){
return;
}
switch (stairs.getShape()) {
case INNER_LEFT:
case INNER_RIGHT:
case OUTER_LEFT:
case OUTER_RIGHT:
return;
}
float yaw = switch (stairs.getFacing()) {
case NORTH -> 0f;
case WEST -> -90f;
case EAST -> 90f;
default -> 180f;
};
Location location = block.getLocation();
location.add(0.5, 0.5, 0.5);
location.setYaw(yaw);
World world = location.getWorld();
for (Entity entity : world.getNearbyEntities(location, 0.5, 1,0.5)){
if (!(entity instanceof ArmorStand armorStand)){
continue;
}
if (PDC.getUniversal(armorStand, "chair", PersistentDataType.BOOLEAN) == null){
continue;
}
if (!armorStand.getPassengers().isEmpty()){
return;
}
player.setRotation(armorStand.getYaw(), 0f);
armorStand.addPassenger(player);
event.setCancelled(true);
return;
}
ArmorStand armorStand = world.spawn(location, ArmorStand.class, stand -> {
stand.setInvisible(true);
stand.setInvulnerable(true);
stand.setGravity(false);
stand.setSilent(true);
stand.setMarker(true);
});
PDC.setUniversal(armorStand, "chair", true, PersistentDataType.BOOLEAN);
player.setRotation(yaw, 0f);
armorStand.addPassenger(player);
event.setCancelled(true);
}
@EventHandler
public void unmount(VehicleExitEvent event){
Location location = event.getVehicle().getLocation();
cleanArmorStand(location);
}
@EventHandler
public void playerLeave(PlayerQuitEvent event){
Location location = event.getPlayer().getLocation();
cleanArmorStand(location);
}
@EventHandler
public void teleport(PlayerTeleportEvent event){
Location location = event.getFrom();
cleanArmorStand(location);
}
private void cleanArmorStand(Location location){
World world = location.getWorld();
for (Entity entity : world.getNearbyEntities(location, 0.5, 1,0.5)){
if (!(entity instanceof ArmorStand armorStand)){
continue;
}
if (PDC.getUniversal(armorStand, "chair", PersistentDataType.BOOLEAN) == null){
continue;
}
if (!armorStand.getPassengers().isEmpty()){
continue;
}
armorStand.remove();
}
}
}
Loading…
Cancel
Save