Skip to content

Commit

Permalink
prog
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldmensch committed Sep 14, 2024
1 parent 3757d83 commit 437eea2
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 80 deletions.
22 changes: 21 additions & 1 deletion src/main/java/club/devcord/gamejam/EventCancelers.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package club.devcord.gamejam;

import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -11,7 +12,16 @@
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.io.PrintWriter;
import java.io.StringWriter;

public class EventCancelers implements Listener {
private final Nigulpyggub plugin;

public EventCancelers(Nigulpyggub plugin) {
this.plugin = plugin;
}

@EventHandler
public void onFoodChange(FoodLevelChangeEvent event) {
event.setCancelled(true);
Expand All @@ -25,8 +35,18 @@ public void onDamage(EntityDamageEvent event) {

@EventHandler
public void onEndereye(PlayerInteractEvent event) {
if (event.getMaterial().equals(Material.ENDER_EYE)) {
if (event.getMaterial().equals(Material.ENDER_EYE) &&
(event.getClickedBlock() == null || event.getClickedBlock().getType() != Material.END_PORTAL_FRAME)) {
Exception exception = dasAugeBrauchstDuNoch();
Component component = plugin.exceptionToComponent(exception);
event.getPlayer().sendMessage(component);
event.setCancelled(true);
}
}

private Exception dasAugeBrauchstDuNoch() {
NullPointerException nullPointerException = new NullPointerException();
nullPointerException.printStackTrace(new PrintWriter(new StringWriter()));
return nullPointerException;
}
}
7 changes: 5 additions & 2 deletions src/main/java/club/devcord/gamejam/Nigulpyggub.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.PrintWriter;
Expand All @@ -20,8 +21,10 @@ public class Nigulpyggub extends JavaPlugin {

@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this);
getServer().getPluginManager().registerEvents(new EventCancelers(), this);
PluginManager pluginManager = getServer().getPluginManager();
pluginManager.registerEvents(new PlayerJoinListener(), this);
pluginManager.registerEvents(new EventCancelers(this), this);
pluginManager.registerEvents(new SantasBellRinger(), this);
getServer().getPluginCommand("team").setExecutor(new TeamCommand(this));
getServer().getPluginCommand("game").setExecutor(new GameCommand(this));
// lagger.start();
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/club/devcord/gamejam/SantasBellRinger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package club.devcord.gamejam;

import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class SantasBellRinger implements Listener {

public static final ItemStack THE_BELL;

static {
THE_BELL = new ItemStack(Material.IRON_SWORD);
ItemMeta itemMeta = THE_BELL.getItemMeta();
itemMeta.setCustomModelData(17);
itemMeta.displayName(Component.text("Santa's Bell").color(NamedTextColor.DARK_GREEN));
THE_BELL.setItemMeta(itemMeta);
}

@EventHandler
public void ringRingSantaRingRing(PlayerInteractEvent event) {
if (event.getPlayer().getInventory().getItemInMainHand().isSimilar(THE_BELL)) {
Sound sound = Sound.sound(Key.key("minecraft:item.santabell"), Sound.Source.MASTER, 1, 1);
Location loc = event.getPlayer().getLocation();
event.getPlayer().getWorld().playSound(sound, loc.x(), loc.y(), loc.z());
}
}
}
11 changes: 7 additions & 4 deletions src/main/java/club/devcord/gamejam/commands/GameCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}

if (args.length < 1) {
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>You have to use: /game start"));
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du musst: /game start/stop/skip nutzen"));
return false;
}

Expand All @@ -56,6 +56,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
LevelPipeline levelPipeline = new LevelPipeline(team, plugin);
levelPipeline.start();
plugin.teamPipelines().put(team, levelPipeline);

plugin.getServer().broadcast(MiniMessage.miniMessage().deserialize("<white><bold>Spiel gestartet!"));
}
}
case "stop" -> {
Expand All @@ -70,10 +72,11 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
playerLocation.setWorld(world);
p.teleport(playerLocation);
});
// plugin.teams().stream().map(Team::world).forEach(w -> plugin.getServer().unloadWorld(w, false));
plugin.teamPipelines().clear();

plugin.getServer().broadcast(MiniMessage.miniMessage().deserialize("<white><bold>Spiel gestoppt!"));
}
case "level" -> {
case "skip" -> {
Optional<Team> team = plugin.teamForPlayer(player);
LevelPipeline pipeline = plugin.teamPipelines().get(team.orElseThrow());

Expand All @@ -82,7 +85,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
pipeline.next();
}
}
default -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red> Unknown command."));
default -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Unbekannter Command."));
}
return true;
}
Expand Down
49 changes: 28 additions & 21 deletions src/main/java/club/devcord/gamejam/commands/TeamCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,54 +45,54 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
case "delete" -> plugin.teamForName(player.getName())
.ifPresentOrElse(team -> {
plugin.teams().remove(team);
player.sendMessage(MiniMessage.miniMessage().deserialize("<green>Your team was deleted!"));
}, () -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red>You're not the creator of a team.")));
player.sendMessage(MiniMessage.miniMessage().deserialize("<green>Dein Team wurde gelöscht!"));
}, () -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du bist in keinem Team!")));

case "create" -> {
boolean alreadyInTeam = plugin.teamForPlayer(player).isPresent();

if (alreadyInTeam) {
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>You are already in a team!"));
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 with name %s created".formatted(player.getName())));
player.sendMessage(MiniMessage.miniMessage().deserialize("<green>Team %s erstellt.".formatted(player.getName())));
}
case "join" -> {
if (args.length != 2) {
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>You have to use: /team join <creator>"));
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du musst: /team join <name> nutzen!"));
return false;
}

if(plugin.teamForPlayer(player).isPresent()) {
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>You are already in a team!"));
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du bist schon in einem Team!"));
return false;
}

plugin.teamForName(args[1]).ifPresentOrElse(team -> {
team.players().forEach(p -> p.sendMessage(MiniMessage.miniMessage().deserialize("<green>%s joined the team".formatted(player.getName()))));
team.players().forEach(p -> p.sendMessage(MiniMessage.miniMessage().deserialize("<green>%s ist dem Team beigetreten.".formatted(player.getName()))));
team.addPlayer(player);
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]))));
player.sendMessage(MiniMessage.miniMessage().deserialize("<green>Du bist dem Team %s beigetreten.".formatted(team.name())));
}, () -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Kein Team mit dem Namen %s gefunden.".formatted(args[1]))));
}
case "info" -> plugin.teamForPlayer(player)
.ifPresentOrElse(team -> {
TextComponent text = Component.text("Your team: %s".formatted(team.name()))
TextComponent text = Component.text("Dein Team: %s".formatted(team.name()))
.append(Component.newline())
.append(Component.text("Members: %s".formatted(team.players().stream().map(Player::getName).collect(Collectors.joining(", ")))));
.append(Component.text("Mitglieder: %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!")));
}, () -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du bist nicht in einem Team!")));
case "tp" -> {
if (!player.isOp()) {
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du musst mehr Rechte tanken."));
return false;
}

if (args.length != 2) {
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>You have to use: /team tp <team>"));
player.sendMessage(MiniMessage.miniMessage().deserialize("<red>Du musst: /team tp <team/welt> nutzen"));
}
String name = args[1];

Expand All @@ -104,8 +104,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
playerLocation.setWorld(world);
player.teleport(playerLocation);

player.sendMessage(MiniMessage.miniMessage().deserialize("You were teleport to world %s".formatted(world.getName())));
}, () -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red> Team with name %s not found".formatted(name))));
player.sendMessage(MiniMessage.miniMessage().deserialize("Du wurdest zur Welt %s teleportiert.".formatted(world.getName())));
}, () -> player.sendMessage(MiniMessage.miniMessage().deserialize("<red> Team mit name %s nicht gefunden.".formatted(name))));

}
case "world" -> {
Expand All @@ -114,9 +114,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return false;
}

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

return false;
Expand All @@ -125,29 +125,36 @@ 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", "info"), List.of("tp", "world"));
return completions(sender, label, 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)
.filter(s -> s.startsWith(args[0]))
.toList();
}

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

return List.of();
}

private List<String> completions(CommandSender player, List<String> normal, List<String> admin) {
private List<String> completions(CommandSender player, String current, List<String> normal, List<String> admin) {
if (!player.isOp()) {
return normal;
}

ArrayList<String> strings = new ArrayList<>(normal);
strings.addAll(admin);
return strings;
return strings
.stream()
.filter(s -> s.startsWith(current))
.toList();
}
}
15 changes: 11 additions & 4 deletions src/main/java/club/devcord/gamejam/level/eyes/BlockShower.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.scheduler.BukkitTask;

import java.util.Random;
Expand Down Expand Up @@ -39,13 +41,18 @@ public void stopItemSwitching() {

private void switchItems() {
team.players().forEach(player -> {
if(player.getInventory().getItemInMainHand().isSimilar(TheJumpLevel.THE_EYE) && random.nextInt(0, 100) < 40) {
PlayerInventory inventory = player.getInventory();
if(inventory.getItemInMainHand().isSimilar(TheJumpLevel.THE_EYE) && random.nextInt(0, 100) < 40) {
var newSlot = random.nextInt(0, 8);
while(newSlot == player.getInventory().getHeldItemSlot()) {
while(inventory.getItem(newSlot) != null
&& inventory.getItem(newSlot).isEmpty()) {
newSlot = random.nextInt(0, 8);
}

player.getInventory().setItem(player.getInventory().getHeldItemSlot(), );
var air = new ItemStack(Material.AIR);
inventory.setItem(inventory.getHeldItemSlot(), air);
inventory.setItem(newSlot, TheJumpLevel.THE_EYE);
setVisibility(player);
}
});
}
Expand Down Expand Up @@ -88,7 +95,7 @@ public void setVisibility(Player player) {
if(itemInHand.isSimilar(TheJumpLevel.THE_EYE)) {
showBlocks(player, Material.BONE_BLOCK.createBlockData());
} else {
showBlocks(player, Material.AIR.createBlockData());
showBlocks(player, Material.BARRIER.createBlockData());
}
}

Expand Down
41 changes: 41 additions & 0 deletions src/main/java/club/devcord/gamejam/level/eyes/EndListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package club.devcord.gamejam.level.eyes;

import club.devcord.gamejam.Team;
import club.devcord.gamejam.level.LevelPipeline;
import club.devcord.gamejam.level.thejump.TheJumpLevel;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

public class EndListener implements Listener {

private final Team team;
private final LevelPipeline levelPipeline;

public EndListener(Team team, LevelPipeline levelPipeline) {
this.team = team;
this.levelPipeline = levelPipeline;
}

@EventHandler
public void onEnderEyePlace(PlayerInteractEvent event) {
if (!team.players().contains(event.getPlayer())) return;

if (event.getMaterial() == Material.ENDER_EYE && event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.END_PORTAL_FRAME) {
var thropy = new ItemStack(Material.DIAMOND_HOE);
var meta = thropy.getItemMeta();
meta.displayName(MiniMessage.miniMessage().deserialize("<rainbow>You are a Bug survivor"));
meta.setCustomModelData(85);
thropy.setItemMeta(meta);
team.players().forEach(player -> {
player.getInventory().addItem(thropy);
player.getInventory().remove(TheJumpLevel.THE_EYE);
});

levelPipeline.next();
}
}
}
8 changes: 7 additions & 1 deletion src/main/java/club/devcord/gamejam/level/eyes/EyesLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
import org.bukkit.Location;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.PluginManager;

public class EyesLevel extends Level {

private final BlockShower blockShower;
private final GateOpener opener;
private final EndListener endListener;

public EyesLevel(Team team, Nigulpyggub plugin, LevelPipeline pipeline) {
super(team, plugin, pipeline);
this.opener = new GateOpener(team);
this.opener = new GateOpener(team, plugin);
this.blockShower = new BlockShower(team, plugin);
this.endListener = new EndListener(team, pipeline);
}

@Override
Expand All @@ -28,6 +31,7 @@ public void start() {
PluginManager pluginManager = plugin().getServer().getPluginManager();
pluginManager.registerEvents(blockShower, plugin());
pluginManager.registerEvents(opener, plugin());
pluginManager.registerEvents(endListener, plugin());
team().players().forEach(blockShower::setVisibility);

blockShower.startItemSwitching();
Expand All @@ -36,7 +40,9 @@ public void start() {
@Override
public void stop() {
PlayerItemHeldEvent.getHandlerList().unregister(blockShower);
PlayerMoveEvent.getHandlerList().unregister(blockShower);
PlayerInteractEvent.getHandlerList().unregister(opener);
PlayerInteractEvent.getHandlerList().unregister(endListener);

blockShower.stopItemSwitching();
}
Expand Down
Loading

0 comments on commit 437eea2

Please sign in to comment.