Add FallEvent

This commit is contained in:
Mathieu Strypsteen 2024-09-21 22:03:54 +02:00
parent 081502b64c
commit ed0a9659f7
5 changed files with 67 additions and 12 deletions

View file

@ -3,8 +3,6 @@ package gent.zeus.mc13dtl.events;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;

View file

@ -15,7 +15,7 @@ import gent.zeus.mc13dtl.MC13DTL;
public class EventRunner implements Runnable { public class EventRunner implements Runnable {
static List<Event> currentEvents = new ArrayList<>(); static List<Event> currentEvents = new ArrayList<>();
public static List<Integer> startTimes = List.of(5000, 13000, 1000, 13000, 1000, 500, 10000); public static List<Integer> startTimes = List.of(5000, 13000, 1000, 13000, 100, 1000, 500, 10000);
private long day; private long day;
@ -44,9 +44,10 @@ public class EventRunner implements Runnable {
case 1 -> new KillMobs1Event(team, difficulty, getDayScore()); case 1 -> new KillMobs1Event(team, difficulty, getDayScore());
case 2 -> new CraftEvent(team, difficulty, getDayScore()); case 2 -> new CraftEvent(team, difficulty, getDayScore());
case 3 -> new ClimbEvent(team, difficulty, getDayScore()); case 3 -> new ClimbEvent(team, difficulty, getDayScore());
case 4 -> new KillPlayerEvent(team, difficulty, getDayScore()); case 4 -> new FallEvent(team, difficulty, getDayScore());
case 5 -> new StructureEvent(team, difficulty, getDayScore()); case 5 -> new KillPlayerEvent(team, difficulty, getDayScore());
case 6 -> new KillSurvivingTeamEvent(team, difficulty, getDayScore()); case 6 -> new StructureEvent(team, difficulty, getDayScore());
case 7 -> new KillSurvivingTeamEvent(team, difficulty, getDayScore());
default -> throw new IllegalStateException("Unexpected day: " + (int) day); default -> throw new IllegalStateException("Unexpected day: " + (int) day);
}; };
event.start(); event.start();

View file

@ -31,7 +31,6 @@ public class ClimbEvent extends Event {
return; return;
} }
Player player = MC13DTL.board.getPlayers(team).getFirst(); Player player = MC13DTL.board.getPlayers(team).getFirst();
player.getLocation().x();
Location location = new Location(Bukkit.getWorld("world"), player.getX(), -50, player.getZ()); Location location = new Location(Bukkit.getWorld("world"), player.getX(), -50, player.getZ());
location.getBlock().setType(Material.AIR); location.getBlock().setType(Material.AIR);
location.add(0, -1, 0).getBlock().setType(Material.AIR); location.add(0, -1, 0).getBlock().setType(Material.AIR);

View file

@ -0,0 +1,61 @@
package gent.zeus.mc13dtl.events.catalog;
import gent.zeus.mc13dtl.MC13DTL;
import gent.zeus.mc13dtl.events.Difficulty;
import gent.zeus.mc13dtl.events.Event;
import org.bukkit.inventory.ItemStack;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Team;
public class FallEvent extends Event {
private final int extraHeight;
public FallEvent(Team team, Difficulty difficulty, int scoreOnSuccess) {
super(team, difficulty, scoreOnSuccess);
extraHeight = switch (difficulty) {
case BABY -> 20;
case EASY -> 35;
case MEDIUM -> 50;
case HARD -> 75;
case SWEAT -> 100;
case IMPOSSIBLE -> 200;
};
}
@Override
public void start() {
if (MC13DTL.board.getPlayers(team).size() == 0) {
return;
}
Player player = MC13DTL.board.getPlayers(team).getFirst();
Location location = player.getLocation();
World world = player.getWorld();
location.setY(300);
while (location.y() > 50 && world.getBlockAt(location).getType() == Material.AIR) {
location.setY(location.getY() - 1);
}
int blocksToIncrease = extraHeight;
while (location.y() < 315 && blocksToIncrease > 0) {
location.setY(location.getY() + 1);
blocksToIncrease--;
}
location.getBlock().setType(Material.STONE);
location.setY(location.getY() + 1);
for (Player p : MC13DTL.board.getPlayers(team)) {
p.teleport(location);
p.getInventory().addItem(new ItemStack(Material.WATER_BUCKET));
}
super.start();
}
@Override
protected String getMessage() {
return "And now you should get down again... safely";
}
}

View file

@ -3,9 +3,6 @@ package gent.zeus.mc13dtl.events.catalog;
import gent.zeus.mc13dtl.MC13DTL; import gent.zeus.mc13dtl.MC13DTL;
import gent.zeus.mc13dtl.events.Difficulty; import gent.zeus.mc13dtl.events.Difficulty;
import gent.zeus.mc13dtl.events.Event; import gent.zeus.mc13dtl.events.Event;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
@ -20,8 +17,7 @@ public class KillSurvivingTeamEvent extends Event {
for (Team t : MC13DTL.board.getTeams()) { for (Team t : MC13DTL.board.getTeams()) {
if (!MC13DTL.board.getPlayers(t).isEmpty() if (!MC13DTL.board.getPlayers(t).isEmpty()
&& (huntingTeam == null || MC13DTL.board.getDaysAlive(t) > MC13DTL.board.getDaysAlive(huntingTeam) && (huntingTeam == null || MC13DTL.board.getDaysAlive(t) > MC13DTL.board.getDaysAlive(huntingTeam))) {
)) {
huntingTeam = t; huntingTeam = t;
} }
} }