Archiviert
13
0

tower-generator #6

Zusammengeführt
YoyoNow hat 16 Commits von tower-generator nach master 2023-09-23 21:29:06 +02:00 zusammengeführt
3 geänderte Dateien mit 29 neuen und 15 gelöschten Zeilen
Nur Änderungen aus Commit 99994de4fd werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -44,6 +44,9 @@ public record TowerRunPlayer(Player player) {
} }
public void reset() { public void reset() {
player.getInventory().clear();
player.updateInventory();
player.setHealth(20);
if (TowerRun.getTowerGenerator() != null) { if (TowerRun.getTowerGenerator() != null) {
player.teleport(TowerRun.getTowerGenerator().getSpawn()); player.teleport(TowerRun.getTowerGenerator().getSpawn());
} else { } else {

Datei anzeigen

@ -21,8 +21,6 @@ import org.bukkit.Material;
import org.bukkit.block.*; import org.bukkit.block.*;
import org.bukkit.block.data.Bisected; import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.type.Door; import org.bukkit.block.data.type.Door;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.io.File; import java.io.File;
@ -46,6 +44,9 @@ public class TowerGenerator {
@Getter @Getter
private Location spawn; private Location spawn;
@Getter
private List<Location> keys = new ArrayList<>();
public TowerGenerator(WorldConfig.TowerGeneratorConfig config) { public TowerGenerator(WorldConfig.TowerGeneratorConfig config) {
File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "Roof.schem"); File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "Roof.schem");
if (!file.exists()) { if (!file.exists()) {
@ -80,6 +81,7 @@ public class TowerGenerator {
{ {
noBombFloors = random.nextInt(config.maxNoBombFloors - config.minNoBombFloors) + config.minNoBombFloors; noBombFloors = random.nextInt(config.maxNoBombFloors - config.minNoBombFloors) + config.minNoBombFloors;
noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors; noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors;
keys.clear();
} }
@Override @Override
@ -137,8 +139,8 @@ public class TowerGenerator {
noKeyFloors--; noKeyFloors--;
if (!chestBlocks.isEmpty() && noKeyFloors < 0 && random.nextDouble() < config.keyChance) { if (!chestBlocks.isEmpty() && noKeyFloors < 0 && random.nextDouble() < config.keyChance) {
noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors; noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors;
Inventory inventory = chestBlocks.get(random.nextInt(chestBlocks.size())).getInventory(); Container container = chestBlocks.get(random.nextInt(chestBlocks.size()));
inventory.addItem(new ItemStack(Material.LEVER, 1)); keys.add(container.getLocation());
for (WorldConfig.TowerGeneratorDoorBlock doorBlock : config.doorBlocks) { for (WorldConfig.TowerGeneratorDoorBlock doorBlock : config.doorBlocks) {
int x = doorBlock.getX(); int x = doorBlock.getX();
@ -147,7 +149,7 @@ public class TowerGenerator {
Block block = Bukkit.getWorlds().get(0).getBlockAt(x, y, z); Block block = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
if (block.getType().isAir()) { if (block.getType().isAir()) {
block.setType(Material.IRON_BLOCK, true); block.setType(Material.IRON_BLOCK, false);
block = block.getRelative(0, 1, 0); block = block.getRelative(0, 1, 0);
} else { } else {
break; break;
@ -156,21 +158,21 @@ public class TowerGenerator {
Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> { Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> {
Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z); Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
door.setType(Material.IRON_DOOR, true); door.setType(Material.IRON_DOOR, false);
door = door.getRelative(0, 1, 0); door = door.getRelative(0, 1, 0);
door.setType(Material.IRON_DOOR, true); door.setType(Material.IRON_DOOR, false);
}, 10); }, 10);
Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> { Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> {
Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z); Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
Door doorState = (Door) door.getBlockData(); Door doorState = (Door) door.getBlockData();
doorState.setFacing(BlockFace.EAST); doorState.setFacing(BlockFace.EAST);
door.setBlockData(doorState, true); door.setBlockData(doorState, false);
door = door.getRelative(0, 1, 0); door = door.getRelative(0, 1, 0);
doorState = (Door) door.getBlockData(); doorState = (Door) door.getBlockData();
doorState.setFacing(BlockFace.EAST); doorState.setFacing(BlockFace.EAST);
doorState.setHalf(Bisected.Half.TOP); doorState.setHalf(Bisected.Half.TOP);
door.setBlockData(doorState, true); door.setBlockData(doorState, false);
}, 20); }, 20);
} }
} }

Datei anzeigen

@ -25,10 +25,7 @@ import de.steamwar.towerrun.config.Config;
import de.steamwar.towerrun.config.WorldConfig; import de.steamwar.towerrun.config.WorldConfig;
import de.steamwar.towerrun.state.GameStateBukkitListener; import de.steamwar.towerrun.state.GameStateBukkitListener;
import de.steamwar.towerrun.state.GameStates; import de.steamwar.towerrun.state.GameStates;
import org.bukkit.Bukkit; import org.bukkit.*;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -44,6 +41,7 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.util.*; import java.util.*;
import java.util.stream.Stream;
public class IngameListener extends GameStateBukkitListener { public class IngameListener extends GameStateBukkitListener {
@ -88,6 +86,11 @@ public class IngameListener extends GameStateBukkitListener {
@EventHandler @EventHandler
public void onPlayerDeath(PlayerDeathEvent event) { public void onPlayerDeath(PlayerDeathEvent event) {
event.setDeathMessage(null); event.setDeathMessage(null);
if (TowerRun.getTowerGenerator() != null) {
event.getEntity().teleport(TowerRun.getTowerGenerator().getSpawn());
} else {
event.getEntity().teleport(WorldConfig.SPAWN);
}
event.getEntity().setGameMode(GameMode.SPECTATOR); event.getEntity().setGameMode(GameMode.SPECTATOR);
Bukkit.getOnlinePlayers().forEach(player -> { Bukkit.getOnlinePlayers().forEach(player -> {
player.sendTitle("", TowerRun.getMessage().parse("PLAYER_DIED", player, event.getEntity().getPlayer().getName()), 10, 70, 20); player.sendTitle("", TowerRun.getMessage().parse("PLAYER_DIED", player, event.getEntity().getPlayer().getName()), 10, 70, 20);
@ -130,6 +133,10 @@ public class IngameListener extends GameStateBukkitListener {
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) {
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasBlock()) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasBlock()) {
return; return;
} }
@ -138,13 +145,15 @@ public class IngameListener extends GameStateBukkitListener {
return; return;
} }
if (Arrays.stream(WorldConfig.KEYS).noneMatch(location -> location.equals(event.getClickedBlock().getLocation()))) { Stream<Location> locations = TowerRun.getTowerGenerator() == null ? Arrays.stream(WorldConfig.KEYS) : TowerRun.getTowerGenerator().getKeys().stream();
if (locations.noneMatch(location -> location.equals(event.getClickedBlock().getLocation()))) {
event.getClickedBlock().setType(Material.AIR);
return; return;
} }
event.getPlayer().getInventory().addItem(new SWItem(Material.LEVER, TowerRun.getMessage().parse("KEY_NAME", event.getPlayer())).getItemStack()); event.getPlayer().getInventory().addItem(new SWItem(Material.LEVER, TowerRun.getMessage().parse("KEY_NAME", event.getPlayer())).getItemStack());
event.getClickedBlock().setType(Material.AIR); event.getClickedBlock().setType(Material.ENDER_CHEST);
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1, 1); event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1, 1);
TowerRun.getMessage().broadcast("KEY_FOUND", event.getPlayer().getName()); TowerRun.getMessage().broadcast("KEY_FOUND", event.getPlayer().getName());
} }