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() {
player.getInventory().clear();
player.updateInventory();
player.setHealth(20);
if (TowerRun.getTowerGenerator() != null) {
player.teleport(TowerRun.getTowerGenerator().getSpawn());
} else {

Datei anzeigen

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

Datei anzeigen

@ -25,10 +25,7 @@ import de.steamwar.towerrun.config.Config;
import de.steamwar.towerrun.config.WorldConfig;
import de.steamwar.towerrun.state.GameStateBukkitListener;
import de.steamwar.towerrun.state.GameStates;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
@ -44,6 +41,7 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.*;
import java.util.stream.Stream;
public class IngameListener extends GameStateBukkitListener {
@ -88,6 +86,11 @@ public class IngameListener extends GameStateBukkitListener {
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
event.setDeathMessage(null);
if (TowerRun.getTowerGenerator() != null) {
event.getEntity().teleport(TowerRun.getTowerGenerator().getSpawn());
} else {
event.getEntity().teleport(WorldConfig.SPAWN);
}
event.getEntity().setGameMode(GameMode.SPECTATOR);
Bukkit.getOnlinePlayers().forEach(player -> {
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
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) {
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasBlock()) {
return;
}
@ -138,13 +145,15 @@ public class IngameListener extends GameStateBukkitListener {
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;
}
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);
TowerRun.getMessage().broadcast("KEY_FOUND", event.getPlayer().getName());
}