Files
Project-CrankedPvP/Voyages/src/main/java/net/crankedpvp/voyages/rooms/DropperRoom.java
T
2026-10-12 13:57:05 -03:00

61 lines
2.0 KiB
Java

package net.crankedpvp.voyages.rooms;
import net.crankedpvp.voyages.struct.annotations.ConfigValue;
import net.crankedpvp.voyages.struct.player.DropperPlayer;
import net.crankedpvp.voyages.struct.room.Room;
import net.crankedpvp.voyages.struct.room.RoomOptions;
import net.crankedpvp.voyages.struct.room.VoyageRoom;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class DropperRoom extends VoyageRoom<DropperPlayer> {
@ConfigValue
private List<Location> spawnPoints = Collections.singletonList(new Location(Bukkit.getWorld("world_voyage"), 16, 5, -36));
private Location spawnPointLocation = this.spawnPoints.get(new Random().nextInt(spawnPoints.size()));
public DropperRoom(final Location spawnLocation) {
super(spawnLocation, "Dropper", Room.DROPPER,300, RoomOptions.builder().fallDamage(true).build(), "Reach the bottom of the dropper");
}
@Override
protected void startVoyageRoom() {
this.spawnPointLocation = this.spawnPoints.get(new Random().nextInt(spawnPoints.size()));
super.teleportParticipantsTo(spawnPointLocation);
}
@Override
public void stopVoyageRoom() {
super.nextRoom();
}
@Override
public void addParticipant(Player player) {
super.addParticipant(new DropperPlayer(player));
}
@EventHandler
public void checkReachedBottom(EntityDamageEvent event) {
if(event.getEntity() == null) return;
if(!(event.getEntity() instanceof Player)) return;
if(!this.isParticipant((Player) event.getEntity())) return;
if(event.getCause() == EntityDamageEvent.DamageCause.FALL) {
event.setCancelled(true);
event.getEntity().teleport(this.spawnPointLocation);
return;
}
this.stopVoyageRoom();
}
}