Skip to content

Commit

Permalink
the last prog
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldmensch committed Sep 15, 2024
1 parent dfee576 commit eb4cf41
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 19 deletions.
10 changes: 9 additions & 1 deletion src/main/java/club/devcord/gamejam/Nigulpyggub.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

public class Nigulpyggub extends JavaPlugin {

private boolean inGame = false;
private final Map<Team, LevelPipeline> teamPipelines = new HashMap<>();

@Override
Expand All @@ -29,7 +30,14 @@ public void onEnable() {
getServer().getPluginCommand("game").setExecutor(new GameCommand(this));

new TabList(this).start();
// lagger.start();
}

public void setInGame(boolean inGame) {
this.inGame = inGame;
}

public boolean inGame() {
return inGame;
}

public Optional<Team> teamForName(String name) {
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/club/devcord/gamejam/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
import org.bukkit.World;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public record Team(
String name,
List<UUID> playerUUIDS,
Set<UUID> playerUUIDS,
World world,
TextColor color
) {
Expand All @@ -27,8 +24,8 @@ private static TextColor randomColor() {
return TextColor.color(red, yellow, blue);
}

public Team(Player creator, World world) {
this(creator.getName(), new ArrayList<>(), world, randomColor());
public Team(String name, Player creator, World world) {
this(name, new HashSet<>(), world, randomColor());
playerUUIDS.add(creator.getUniqueId());
}

Expand All @@ -37,10 +34,15 @@ public List<Player> players() {
return playerUUIDS
.stream()
.map(Bukkit::getPlayer)
.filter(Objects::nonNull)
.toList();
}

public void addPlayer(Player player) {
playerUUIDS.add(player.getUniqueId());
}

public void removePlayer(Player player) {
playerUUIDS.remove(player.getUniqueId());
}
}
4 changes: 4 additions & 0 deletions src/main/java/club/devcord/gamejam/commands/GameCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
switch (args[0].toLowerCase()) {
case "start" -> {
BukkitScheduler scheduler = plugin.getServer().getScheduler();
plugin.setInGame(true);
for (Team team : plugin.teams()) {
team.players().forEach(teamPlayer -> {
teamPlayer.setGameMode(GameMode.ADVENTURE);
Expand All @@ -74,6 +75,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
}
case "stop" -> {
plugin.setInGame(false);
plugin.teams()
.stream()
.peek(team -> plugin.teamPipelines().get(team).stop())
Expand All @@ -82,6 +84,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
.forEach(p -> {
p.teleport(new Location(plugin.getServer().getWorld("world"), 90, 43, -475));
p.getInventory().clear();
p.setFlying(false);
p.setAllowFlight(false);
});
plugin.teamPipelines().clear();

Expand Down
60 changes: 49 additions & 11 deletions src/main/java/club/devcord/gamejam/commands/TeamCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,66 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (!(sender instanceof Player player)) return true;

if (args.length < 1) {
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>You have to use: /team create"));
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du musst: /team create <name>, /team leave oder /team join <name> nutzen"));
return false;
}

switch (args[0].toLowerCase()) {
case "leave" -> {
if (plugin.inGame()) {
sendInGame(player);
return false;
}

case "delete" -> plugin.teamForName(player.getName())
.ifPresentOrElse(team -> {
plugin.teams().remove(team);
player.sendMessage(MiniMessage.miniMessage().deserialize("<green>Dein Team wurde gelöscht!"));
}, () -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du bist in keinem Team!")));
plugin.teamForPlayer(player)
.ifPresentOrElse(team -> {
if (team.players().size() == 1) {
plugin.teamPipelines().remove(team);
}

team.removePlayer(player);

player.sendMessage(MiniMessage.miniMessage().deserialize("<green>Du hast das Team verlassen!"));

player.playerListName(player.name());
}, () -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du bist in keinem Team!")));
}

case "create" -> {
if (plugin.inGame()) {
sendInGame(player);
return false;
}

boolean alreadyInTeam = plugin.teamForPlayer(player).isPresent();

if (alreadyInTeam) {
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du bist schon in einem Team!"));
return true;
}

World teamWorld = duplicator.duplicate(player.getName());
Team team = new Team(player, teamWorld);
plugin.teamPipelines().put(team, null);
player.sendMessage(MiniMessage.miniMessage().deserialize("<green>Team %s erstellt.".formatted(player.getName())));
if (args.length != 2) {
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du musst: /team create <name> nutzen!"));
return false;
}

String teamName = args[1];

plugin.teamForName(teamName)
.ifPresentOrElse(team -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Team mit Namen %s existiert bereits.".formatted(teamName))),
() -> {
World teamWorld = duplicator.duplicate(teamName);
Team team = new Team(teamName, player, teamWorld);
plugin.teamPipelines().put(team, null);
player.sendMessage(MiniMessage.miniMessage().deserialize("<green>Team %s erstellt.".formatted(teamName)));
});
}
case "join" -> {
if (plugin.inGame()) {
sendInGame(player);
return false;
}

if (args.length != 2) {
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du musst: /team join <name> nutzen!"));
return false;
Expand Down Expand Up @@ -125,7 +159,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length <= 1) {
return completions(sender, args[0], List.of("create", "join", "delete", "info"), List.of("tp", "world"));
return completions(sender, args[0], List.of("create", "join", "leave", "info"), List.of("tp", "world"));
}

if (args[0].equalsIgnoreCase("tp") && sender.isOp()) {
Expand Down Expand Up @@ -157,4 +191,8 @@ private List<String> completions(CommandSender player, String current, List<Stri
.filter(s -> s.startsWith(current))
.toList();
}

private void sendInGame(CommandSender sender) {
sender.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du kannst dein Team nicht ändern, solange das Spiel läuft."));
}
}

0 comments on commit eb4cf41

Please sign in to comment.