From dc1286a6f336d7894549eb19816d1fd2166b3985 Mon Sep 17 00:00:00 2001 From: Heath Logan Campbell Date: Sat, 8 Feb 2020 13:06:11 +1300 Subject: [PATCH] add sun death --- .../bevs/minecraftbut/MinecraftButPlugin.java | 24 ++----- .../senerario/senerarios/SunDeath.java | 65 +++++++++++++++++++ 2 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 src/main/java/games/bevs/minecraftbut/senerario/senerarios/SunDeath.java diff --git a/src/main/java/games/bevs/minecraftbut/MinecraftButPlugin.java b/src/main/java/games/bevs/minecraftbut/MinecraftButPlugin.java index c56f9e6..6f4c1f6 100644 --- a/src/main/java/games/bevs/minecraftbut/MinecraftButPlugin.java +++ b/src/main/java/games/bevs/minecraftbut/MinecraftButPlugin.java @@ -2,6 +2,7 @@ import java.lang.reflect.Field; +import games.bevs.minecraftbut.senerario.senerarios.*; import games.bevs.minecraftbut.senerario.senerarios.mathorstop.MathOrStop; import org.bukkit.Bukkit; import org.bukkit.command.CommandMap; @@ -10,24 +11,6 @@ import games.bevs.minecraftbut.commands.MinecraftButCommand; import games.bevs.minecraftbut.listeners.WelcomeListener; import games.bevs.minecraftbut.senerario.ScenerarioManager; -import games.bevs.minecraftbut.senerario.senerarios.AnvilRain; -import games.bevs.minecraftbut.senerario.senerarios.BedRockTrail; -import games.bevs.minecraftbut.senerario.senerarios.BlockPotions; -import games.bevs.minecraftbut.senerario.senerarios.EnderDragonAppears; -import games.bevs.minecraftbut.senerario.senerarios.FasterAndFaster; -import games.bevs.minecraftbut.senerario.senerarios.LinkedDeaths; -import games.bevs.minecraftbut.senerario.senerarios.LinkedHealth; -import games.bevs.minecraftbut.senerario.senerarios.MaducerWorld; -import games.bevs.minecraftbut.senerario.senerarios.MobsMultiple; -import games.bevs.minecraftbut.senerario.senerarios.NoJump; -import games.bevs.minecraftbut.senerario.senerarios.OneHit; -import games.bevs.minecraftbut.senerario.senerarios.RainingBlocks; -import games.bevs.minecraftbut.senerario.senerarios.ShrinkingInventory; -import games.bevs.minecraftbut.senerario.senerarios.TNTOnSelf; -import games.bevs.minecraftbut.senerario.senerarios.TNTRain; -import games.bevs.minecraftbut.senerario.senerarios.TheLavaRises; -import games.bevs.minecraftbut.senerario.senerarios.TheWaterRises; -import games.bevs.minecraftbut.senerario.senerarios.WorldDecay; import games.bevs.minecraftbut.senerario.senerarios.deathout.DeathOut; import games.bevs.minecraftbut.senerario.senerarios.gemeater.GemEater; import games.bevs.minecraftbut.senerario.senerarios.linkedinvs.LinkedInventories; @@ -87,9 +70,10 @@ private void populateScenerarios(ButWorld butWorld) this.scenerarioManager.registerSenerario(new LinkedHealth(butWorld)); this.scenerarioManager.registerSenerario(new ShrinkingInventory(butWorld)); this.scenerarioManager.registerSenerario(new MobsMultiple(butWorld)); + this.scenerarioManager.registerSenerario(new SunDeath(butWorld)); + + - - if(minecraft18) { this.scenerarioManager.registerSenerario(new MathOrStop(butWorld)); diff --git a/src/main/java/games/bevs/minecraftbut/senerario/senerarios/SunDeath.java b/src/main/java/games/bevs/minecraftbut/senerario/senerarios/SunDeath.java new file mode 100644 index 0000000..cb53765 --- /dev/null +++ b/src/main/java/games/bevs/minecraftbut/senerario/senerarios/SunDeath.java @@ -0,0 +1,65 @@ +package games.bevs.minecraftbut.senerario.senerarios; + +import games.bevs.minecraftbut.senerario.Senerario; +import games.bevs.minecraftbut.world.ButWorld; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerMoveEvent; + +public class SunDeath extends Senerario +{ + + public SunDeath(ButWorld butWorld) + { + super("Sun Death", butWorld, Material.LAVA_BUCKET, new String[] {"You die in the sun"}, "Sprock"); + } + + + @Override + public void onStart() + { + this.repeat(() -> { + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) + { + long worldTime = onlinePlayer.getWorld().getTime() % 24_000; + if(!(worldTime > 0 && worldTime < 12_800)) + return; + + if(onlinePlayer.getGameMode() != GameMode.SURVIVAL) + continue; + + if(onlinePlayer.isDead()) + continue; + + if(this.underSunLight(onlinePlayer)) + onlinePlayer.damage(1000000.0); + } + }, 10l); + } + + @Override + public void onFinish() + { + + } + + public boolean underSunLight(Player player) + { + Location loc = player.getLocation(); + Block currentBlock = loc.getBlock(); + while(currentBlock.getY() < 255) + { + if(currentBlock.getType() != Material.AIR) + return false; + currentBlock = currentBlock.getRelative(BlockFace.UP); + } + return true; + } +}