Add EndEvent

This commit is contained in:
Mathieu Strypsteen 2024-09-22 15:28:49 +02:00
parent 25bffc9509
commit 2646b965ac
4 changed files with 80 additions and 2 deletions

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, 100, 1000, 500, 10000); public static List<Integer> startTimes = List.of(5000, 13000, 1000, 13000, 100, 1000, 500, 10000, 100);
private long day; private long day;
@ -48,6 +48,7 @@ public class EventRunner implements Runnable {
case 5 -> new KillPlayerEvent(team, difficulty, getDayScore()); case 5 -> new KillPlayerEvent(team, difficulty, getDayScore());
case 6 -> new StructureEvent(team, difficulty, getDayScore()); case 6 -> new StructureEvent(team, difficulty, getDayScore());
case 7 -> new KillSurvivingTeamEvent(team, difficulty, getDayScore()); case 7 -> new KillSurvivingTeamEvent(team, difficulty, getDayScore());
case 8 -> new EndEvent(team, difficulty, getDayScore()); // TODO: Move to last day
default -> throw new IllegalStateException("Unexpected day: " + (int) day); default -> throw new IllegalStateException("Unexpected day: " + (int) day);
}; };
event.start(); event.start();

View file

@ -0,0 +1,76 @@
package gent.zeus.mc13dtl.events.catalog;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scoreboard.Team;
import com.destroystokyo.paper.event.player.PlayerPostRespawnEvent;
import gent.zeus.mc13dtl.MC13DTL;
import gent.zeus.mc13dtl.events.Difficulty;
import gent.zeus.mc13dtl.events.Event;
public class EndEvent extends Event {
private PotionEffectType[] effects;
public EndEvent(Team team, Difficulty difficulty, int scoreOnSuccess) {
super(team, difficulty, scoreOnSuccess);
effects = switch (difficulty) {
case BABY -> new PotionEffectType[] { PotionEffectType.REGENERATION, PotionEffectType.JUMP_BOOST, PotionEffectType.STRENGTH };
case EASY -> new PotionEffectType[] { PotionEffectType.JUMP_BOOST, PotionEffectType.REGENERATION };
case MEDIUM -> new PotionEffectType[] {};
case HARD -> new PotionEffectType[] { PotionEffectType.SLOWNESS };
case SWEAT -> new PotionEffectType[] { PotionEffectType.HUNGER };
case IMPOSSIBLE -> new PotionEffectType[] { PotionEffectType.HUNGER, PotionEffectType.WEAKNESS };
};
}
@Override
public void start() {
World end = Bukkit.getWorld("world_the_end");
for (Player i : MC13DTL.board.getPlayers(team)) {
i.teleport(end.getSpawnLocation());
for (PotionEffectType j : effects) {
i.addPotionEffect(new PotionEffect(j, -1, 1));
}
}
super.start();
}
@EventHandler
public void onPlayerPostRespawn(PlayerPostRespawnEvent event) {
if (!MC13DTL.board.getPlayers(team).contains(event.getPlayer())) {
return;
}
World end = Bukkit.getWorld("world_the_end");
Player player = event.getPlayer();
player.teleport(end.getSpawnLocation());
for (PotionEffectType j : effects) {
event.getPlayer().addPotionEffect(new PotionEffect(j, -1, 1));
}
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntityType() == EntityType.ENDER_DRAGON) {
eventSuccess();
}
}
@Override
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
}
@Override
protected String getMessage() {
return "Can you free the end in a day?";
}
}

View file

@ -1,5 +1,6 @@
package gent.zeus.mc13dtl.gamestate; package gent.zeus.mc13dtl.gamestate;
import org.bukkit.GameRule;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -22,6 +23,7 @@ public class GameStateHandler implements Listener {
@EventHandler @EventHandler
public void onWorldLoad(WorldLoadEvent event) { public void onWorldLoad(WorldLoadEvent event) {
World world = event.getWorld(); World world = event.getWorld();
world.setGameRule(GameRule.KEEP_INVENTORY, true);
if (!world.getName().equals("world")) { if (!world.getName().equals("world")) {
return; return;
} }

View file

@ -40,7 +40,6 @@ public class GameStateUtil {
gameState = GameState.PAUSED; gameState = GameState.PAUSED;
break; break;
} }
world.setGameRule(GameRule.KEEP_INVENTORY, true);
if (gameState == GameState.LOBBY) { if (gameState == GameState.LOBBY) {
world.setDifficulty(Difficulty.PEACEFUL); world.setDifficulty(Difficulty.PEACEFUL);
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false); world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);