feat: better win checking and test pllayer kill command
This commit is contained in:
parent
66fd30d8b3
commit
eb0f26d371
@ -1,6 +1,7 @@
|
||||
package dev.ninjdai.werewolf;
|
||||
|
||||
import dev.ninjdai.werewolf.commands.LGCommand;
|
||||
import dev.ninjdai.werewolf.commands.PlayerKillCommand;
|
||||
import dev.ninjdai.werewolf.uhc.UHCPlayer;
|
||||
import dev.ninjdai.werewolf.uhc.events.UHCPlayerDeathEvent;
|
||||
import io.github.togar2.pvp.MinestomPvP;
|
||||
@ -43,7 +44,7 @@ public class Main {
|
||||
player.setRespawnPoint(new Pos(0, 42, 0));
|
||||
});
|
||||
|
||||
MinecraftServer.getCommandManager().register(new LGCommand());
|
||||
MinecraftServer.getCommandManager().register(new LGCommand(), new PlayerKillCommand());
|
||||
|
||||
MinestomPvP.init();
|
||||
CombatFeatureSet legacyVanilla = CombatFeatures.legacyVanilla();
|
||||
@ -55,7 +56,7 @@ public class Main {
|
||||
|
||||
OpenToLAN.open();
|
||||
MinecraftServer.setBrandName("Playground");
|
||||
VelocityProxy.enable("cMkrrJ8tdUS6");
|
||||
//VelocityProxy.enable("cMkrrJ8tdUS6");
|
||||
|
||||
minecraftServer.start("0.0.0.0", 30065);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
package dev.ninjdai.werewolf.commands;
|
||||
|
||||
import dev.ninjdai.werewolf.uhc.UHCPlayer;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.command.builder.arguments.minecraft.ArgumentEntity;
|
||||
import net.minestom.server.entity.damage.Damage;
|
||||
import net.minestom.server.entity.damage.DamageType;
|
||||
import net.minestom.server.utils.entity.EntityFinder;
|
||||
|
||||
public class PlayerKillCommand extends Command {
|
||||
static final ArgumentEntity singlePlayerArgument = ArgumentType.Entity("player").onlyPlayers(true).singleEntity(true);
|
||||
public PlayerKillCommand() {
|
||||
super("playerkill");
|
||||
|
||||
|
||||
addSyntax(((sender, context) -> {
|
||||
if(! (sender instanceof UHCPlayer senderPlayer)) return;
|
||||
EntityFinder finder = context.get(singlePlayerArgument);
|
||||
UHCPlayer player = (UHCPlayer) finder.findFirstPlayer(sender);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage("Couldn't find player");
|
||||
return;
|
||||
}
|
||||
player.damage(new Damage(DamageType.MOB_ATTACK, senderPlayer, senderPlayer, senderPlayer.getPosition(), 40));
|
||||
}), singlePlayerArgument);
|
||||
}
|
||||
}
|
@ -4,7 +4,10 @@ import dev.ninjdai.werewolf.uhc.UHCPlayer;
|
||||
import dev.ninjdai.werewolf.uhc.roles.Role;
|
||||
import dev.ninjdai.werewolf.uhc.roles.RoleProperties;
|
||||
import dev.ninjdai.werewolf.uhc.roles.Roles;
|
||||
import dev.ninjdai.werewolf.uhc.teams.WinCondition;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Entity;
|
||||
@ -13,11 +16,13 @@ import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.damage.Damage;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.sound.SoundEvent;
|
||||
import net.minestom.server.timer.Task;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Set;
|
||||
|
||||
public class TimedPlayerDeath {
|
||||
private final ItemStack[] inventory;
|
||||
@ -25,12 +30,14 @@ public class TimedPlayerDeath {
|
||||
private final Pos deathPos;
|
||||
private final UHCPlayer targetPlayer;
|
||||
private final Task triggerTask;
|
||||
private final Set<UHCPlayer> playersAtDeath;
|
||||
|
||||
public TimedPlayerDeath(@NotNull Player player, @NotNull Damage damage, int seconds) {
|
||||
this.inventory = player.getInventory().getItemStacks();
|
||||
this.instance = player.getInstance();
|
||||
this.deathPos = player.getPosition();
|
||||
this.targetPlayer = (UHCPlayer) player;
|
||||
this.playersAtDeath = WinCondition.inGamePlayers(instance);
|
||||
|
||||
this.triggerTask = MinecraftServer.getSchedulerManager().scheduleTask(this::trigger, TaskSchedule.seconds(seconds));
|
||||
}
|
||||
@ -40,16 +47,26 @@ public class TimedPlayerDeath {
|
||||
}
|
||||
|
||||
private TaskSchedule trigger(){
|
||||
if(!targetPlayer.getUHCRole().getRoleProperties().contains(RoleProperties.NO_DEATH_MESSAGE)) {
|
||||
this.instance.sendMessage(Component.text(targetPlayer.getUsername()).append(Component.text(" died")));
|
||||
}
|
||||
|
||||
if(WinCondition.checkWin(playersAtDeath)) {
|
||||
instance.playSound(Sound.sound().type(SoundEvent.ENTITY_ENDER_DRAGON_GROWL).source(Sound.Source.PLAYER).build());
|
||||
instance.sendMessage(Component.empty()
|
||||
.append(Component.text("Team "))
|
||||
.append(Component.text(WinCondition.winningTeam.getName(), TextColor.color(WinCondition.winningTeam.getColor())))
|
||||
.append(Component.text(" wins !"))
|
||||
);
|
||||
return TaskSchedule.stop();
|
||||
}
|
||||
|
||||
for (ItemStack itemStack: inventory) {
|
||||
ItemEntity e = new ItemEntity(itemStack);
|
||||
e.setPickupDelay(Duration.ofSeconds(1));
|
||||
e.setInstance(this.instance, deathPos);
|
||||
}
|
||||
|
||||
if(!targetPlayer.getUHCRole().getRoleProperties().contains(RoleProperties.NO_DEATH_MESSAGE)) {
|
||||
this.instance.sendMessage(Component.text(targetPlayer.getUsername()).append(Component.text(" died")));
|
||||
}
|
||||
|
||||
return TaskSchedule.stop();
|
||||
}
|
||||
}
|
||||
|
@ -27,19 +27,10 @@ import java.util.stream.Stream;
|
||||
public class UHCPlayerDeathEvent {
|
||||
public static void onPlayerDeath(EntityPreDeathEvent event) {
|
||||
UHCPlayer player = (UHCPlayer) event.getEntity();
|
||||
if(WinCondition.checkWin(event.getInstance())) {
|
||||
event.getInstance().playSound(Sound.sound().type(SoundEvent.ENTITY_ENDER_DRAGON_GROWL).source(Sound.Source.PLAYER).build());
|
||||
event.getInstance().sendMessage(Component.empty()
|
||||
.append(Component.text("Team "))
|
||||
.append(Component.text(WinCondition.winningTeam.getName(), TextColor.color(WinCondition.winningTeam.getColor())))
|
||||
.append(Component.text(" wins !"))
|
||||
);
|
||||
}
|
||||
|
||||
event.setCancelDeath(true);
|
||||
player.toggleSpectating();
|
||||
|
||||
|
||||
var timedPlayerDeath = new TimedPlayerDeath(player, event.getDamage(), 15);
|
||||
|
||||
player.getUHCRole().onPlayerDeath(player, timedPlayerDeath);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.ninjdai.werewolf.uhc.teams;
|
||||
|
||||
import dev.ninjdai.werewolf.Main;
|
||||
import dev.ninjdai.werewolf.uhc.UHCPlayer;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.instance.Instance;
|
||||
@ -23,11 +24,13 @@ public class WinCondition {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean checkWin(Instance instance) {
|
||||
Set<UHCPlayer> inGamePlayers = inGamePlayers(instance);
|
||||
public static boolean checkWin(Set<UHCPlayer> inGamePlayers) {
|
||||
Main.LOGGER.info(inGamePlayers.toString());
|
||||
for (Teams team: Teams.values()) {
|
||||
Main.LOGGER.info("Checking if team {} wins...", team.team.getName());
|
||||
if(checkTeamWin(team.team, inGamePlayers)){
|
||||
winningTeam = team.team;
|
||||
Main.LOGGER.info("Team {} wins !", team.team.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user