Skip to content

Commit

Permalink
proeg
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldmensch committed Sep 14, 2024
1 parent 281ac32 commit 75e841e
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 46 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tasks {
val client = HttpClient.newHttpClient()
val request = HttpRequest.newBuilder()
.uri(URI.create(apiUrl))
//.uri(URI.create("$apiUrl?restart=true"))
// .uri(URI.create("$apiUrl?restart=true"))
.header("Content-Type", "application/octet-stream")
.POST(HttpRequest.BodyPublishers.ofByteArray(Files.readAllBytes(filePath)))
.build()
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/club/devcord/gamejam/Nigulpyggub.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,19 @@

import club.devcord.gamejam.commands.GameCommand;
import club.devcord.gamejam.commands.TeamCommand;
import club.devcord.gamejam.level.LevelPipeline;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.units.qual.C;

import java.awt.*;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.*;

public class Nigulpyggub extends JavaPlugin {

private final List<Team> teams = new ArrayList<>();
private final Map<Team, LevelPipeline> teamPipelines = new HashMap<>();
private final Lagger lagger = new Lagger(this);

@Override
Expand All @@ -39,19 +32,25 @@ public void onEnable() {
}

public Optional<Team> teamForName(String name) {
return teams.stream()
.filter(team -> team.creator().getName().equalsIgnoreCase(name))
return teamPipelines.keySet()
.stream()
.filter(team -> team.name().equalsIgnoreCase(name))
.findAny();
}

public Optional<Team> teamForPlayer(Player player) {
return teams.stream()
return teamPipelines.keySet()
.stream()
.filter(team -> team.players().contains(player))
.findAny();
}

public List<Team> teams() {
return teams;
public Set<Team> teams() {
return teamPipelines.keySet();
}

public Map<Team, LevelPipeline> teamPipelines() {
return teamPipelines;
}

public Lagger lagger() {
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/club/devcord/gamejam/Team.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
package club.devcord.gamejam;

import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;

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

public record Team(
Player creator,
List<Player> players,
String name,
List<UUID> playerUUIDS,
World world
) {

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


public List<Player> players() {
var list = new ArrayList<>(players);
list.addFirst(creator);
return list;
return playerUUIDS
.stream()
.map(Bukkit::getPlayer)
.toList();
}

public void addPlayer(Player player) {
players.add(player);
playerUUIDS.add(player.getUniqueId());
}
}
29 changes: 25 additions & 4 deletions src/main/java/club/devcord/gamejam/commands/GameCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
import club.devcord.gamejam.Nigulpyggub;
import club.devcord.gamejam.Team;
import club.devcord.gamejam.level.Level;
import club.devcord.gamejam.level.LevelPipeline;
import club.devcord.gamejam.level.poempel.PoempelLevel;
import club.devcord.gamejam.world.WorldDuplicator;
import io.papermc.paper.configuration.type.fallback.FallbackValue;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Map;

public class GameCommand implements CommandExecutor {
Expand All @@ -41,12 +44,30 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
switch (args[0].toLowerCase()) {
case "start" -> {
for (Team team : plugin.teams()) {
team.players().forEach(teamPlayer -> teamPlayer.setGameMode(GameMode.ADVENTURE));
team.players().forEach(teamPlayer -> {
teamPlayer.setGameMode(GameMode.ADVENTURE);
Location playerLocation = teamPlayer.getLocation();
playerLocation.setWorld(team.world());
teamPlayer.teleport(playerLocation);
});

PoempelLevel poempelLevel = new PoempelLevel(team, plugin);
poempelLevel.start();
LevelPipeline levelPipeline = new LevelPipeline(team, plugin);
levelPipeline.start();
plugin.teamPipelines().put(team, levelPipeline);
}

}
case "stop" -> {
var world = plugin.getServer().getWorld("world");
plugin.teams()
.stream()
.peek(team -> plugin.teamPipelines().get(team).stop())
.map(Team::players)
.flatMap(List::stream)
.forEach(p -> {
Location playerLocation = p.getLocation();
playerLocation.setWorld(world);
p.teleport(playerLocation);
});
}
default -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red> Unknown command."));
}
Expand Down
34 changes: 30 additions & 4 deletions src/main/java/club/devcord/gamejam/commands/TeamCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import club.devcord.gamejam.Nigulpyggub;
import club.devcord.gamejam.Team;
import club.devcord.gamejam.world.WorldDuplicator;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.minecraft.world.scores.PlayerTeam;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
Expand All @@ -15,6 +18,8 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class TeamCommand implements TabExecutor {

Expand Down Expand Up @@ -52,8 +57,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}

World teamWorld = duplicator.duplicate(player.getName());
Team team = new Team(player, new ArrayList<>(), teamWorld);
plugin.teams().add(team);
Team team = new Team(player, teamWorld);
plugin.teamPipelines().put(team, null);
player.sendMessage(MiniMessage.miniMessage().deserialize("<green>Team with name %s created".formatted(player.getName())));
}
case "join" -> {
Expand All @@ -68,10 +73,18 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}

plugin.teamForName(args[1]).ifPresentOrElse(team -> {
team.players().forEach(p -> p.sendMessage(MiniMessage.miniMessage().deserialize("<green>%s joined the team".formatted(player.getName()))));
team.addPlayer(player);
player.sendMessage(MiniMessage.miniMessage().deserialize("<green>You joined the team of %s".formatted(team.creator().getName())));
player.sendMessage(MiniMessage.miniMessage().deserialize("<green>You joined the team %s".formatted(team.name())));
}, () -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red>No team found for creator %s".formatted(args[1]))));
}
case "info" -> plugin.teamForPlayer(player)
.ifPresentOrElse(team -> {
TextComponent text = Component.text("Your team: %s".formatted(team.name()))
.append(Component.newline())
.append(Component.text("Members: %s".formatted(team.players().stream().map(Player::getName).collect(Collectors.joining(", ")))));
player.sendMessage(text);
}, () -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red>You're not in a team!")));
case "tp" -> {
if (!player.isOp()) {
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du musst mehr Rechte tanken."));
Expand All @@ -95,6 +108,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}, () -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red> Team with name %s not found".formatted(name))));

}
case "world" -> {
if (!player.isOp()) {
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du musst mehr Rechte tanken."));
return false;
}

player.sendMessage(MiniMessage.miniMessage().deserialize("Current world: %s".formatted(player.getWorld().getName())));
}
default -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Unknown command"));
}

Expand All @@ -104,14 +125,19 @@ 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, List.of("create", "join", "delete"), List.of("tp"));
return completions(sender, List.of("create", "join", "delete", "info"), List.of("tp", "world"));
}

if (args[0].equalsIgnoreCase("tp") && sender.isOp()) {
return plugin.getServer().getWorlds().stream()
.map(World::getName)
.toList();
}

if (args[0].equalsIgnoreCase("join")) {
return plugin.teams().stream().map(Team::name).toList();
}

return List.of();
}

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/club/devcord/gamejam/level/Level.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package club.devcord.gamejam.level;

import club.devcord.gamejam.Nigulpyggub;
import club.devcord.gamejam.Team;

public abstract class Level {

private final Team team;
private final Nigulpyggub plugin;
private final LevelPipeline pipeline;

public Level(Team team) {
public Level(Team team, Nigulpyggub plugin, LevelPipeline pipeline) {
this.team = team;
this.plugin = plugin;
this.pipeline = pipeline;
}

abstract public void start();
Expand All @@ -17,4 +22,8 @@ public Level(Team team) {
public Team team() {
return team;
}

public Nigulpyggub plugin() {
return plugin;
}
}
46 changes: 46 additions & 0 deletions src/main/java/club/devcord/gamejam/level/LevelPipeline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package club.devcord.gamejam.level;

import club.devcord.gamejam.Nigulpyggub;
import club.devcord.gamejam.Team;
import club.devcord.gamejam.level.poempel.PoempelLevel;
import club.devcord.gamejam.level.thejump.TheJumpLevel;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;

import java.util.ArrayDeque;
import java.util.List;
import java.util.Queue;

public class LevelPipeline {
private final Team team;
private final Queue<Level> levels;

public LevelPipeline(Team team, Nigulpyggub plugin) {
this.team = team;
var levels = List.of(
new PoempelLevel(team, plugin, this),
new TheJumpLevel(team, plugin, this)
);
this.levels = new ArrayDeque<>(levels);
}

public void next() {
team.players().forEach(
p -> p.playSound(Sound.sound(Key.key("minecraft:effect.achievementcompleted"), Sound.Source.MASTER, 100, 1))
);
levels.poll().stop();
if(!levels.isEmpty()) {
start();
} else {

}
}

public void start() {
levels.peek().start();
}

public void stop() {
levels.peek().stop();
}
}
Loading

0 comments on commit 75e841e

Please sign in to comment.