Update team and roles API/implementation
This commit is contained in:
parent
74f3d71f2e
commit
177d35f097
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
@ -1,5 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<writeAnnotations>
|
||||||
|
<writeAnnotation name="lombok.Getter" />
|
||||||
|
</writeAnnotations>
|
||||||
|
</component>
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
@ -8,10 +8,12 @@ version = '0.1.0'
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
maven { url 'https://jitpack.io' }
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "net.minestom:minestom-snapshots:${minestom_version}"
|
implementation "net.minestom:minestom-snapshots:${minestom_version}"
|
||||||
|
implementation "com.github.TogAr2:MinestomPvP:${minestompvp_version}"
|
||||||
|
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.34'
|
compileOnly 'org.projectlombok:lombok:1.18.34'
|
||||||
annotationProcessor 'org.projectlombok:lombok:1.18.34'
|
annotationProcessor 'org.projectlombok:lombok:1.18.34'
|
||||||
@ -26,7 +28,7 @@ java {
|
|||||||
tasks {
|
tasks {
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes["Main-Class"] = "dev.ninjdai.lgohc.Main" // Change this to your main class
|
attributes["Main-Class"] = "dev.ninjdai.werewolf.Main" // Change this to your main class
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
|
|
||||||
minestom_version = d0754f2a15
|
minestom_version = d0754f2a15
|
||||||
|
minestompvp_version = 547b6e95af
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package dev.ninjdai.werewolf;
|
package dev.ninjdai.werewolf;
|
||||||
|
|
||||||
|
import io.github.togar2.pvp.MinestomPvP;
|
||||||
|
import io.github.togar2.pvp.feature.CombatFeatureSet;
|
||||||
|
import io.github.togar2.pvp.feature.CombatFeatures;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
@ -26,6 +29,10 @@ public class Main {
|
|||||||
player.setRespawnPoint(new Pos(0, 42, 0));
|
player.setRespawnPoint(new Pos(0, 42, 0));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
MinestomPvP.init();
|
||||||
|
|
||||||
|
CombatFeatureSet legacyVanilla = CombatFeatures.legacyVanilla();
|
||||||
|
MinecraftServer.getGlobalEventHandler().addChild(legacyVanilla.createNode());
|
||||||
|
|
||||||
minecraftServer.start("0.0.0.0", 30065);
|
minecraftServer.start("0.0.0.0", 30065);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
package dev.ninjdai.werewolf.uhc.events;
|
||||||
|
|
||||||
|
import dev.ninjdai.werewolf.uhc.roles.Role;
|
||||||
|
import dev.ninjdai.werewolf.uhc.roles.RoleProperties;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.entity.Entity;
|
||||||
|
import net.minestom.server.entity.ItemEntity;
|
||||||
|
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.timer.TaskSchedule;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class TimedPlayerDeath {
|
||||||
|
private final ItemStack[] inventory;
|
||||||
|
private final Instance instance;
|
||||||
|
private final Player targetPlayer;
|
||||||
|
|
||||||
|
public TimedPlayerDeath(@NotNull Player player, @NotNull Damage damage, int seconds) {
|
||||||
|
this.inventory = player.getInventory().getItemStacks();
|
||||||
|
this.instance = player.getInstance();
|
||||||
|
this.targetPlayer = player;
|
||||||
|
|
||||||
|
MinecraftServer.getSchedulerManager().scheduleTask(this::trigger, TaskSchedule.seconds(seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
private TaskSchedule trigger(){
|
||||||
|
for (ItemStack itemStack: inventory) {
|
||||||
|
instance.getEntities().add(new ItemEntity(itemStack));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!this.targetPlayer.getTag(Role.roleTag).isBlank())
|
||||||
|
&& (!Role.roleMap.get(targetPlayer.getTag(Role.roleTag)).getRoleProperties().contains(RoleProperties.NO_DEATH_MESSAGE))) {
|
||||||
|
this.instance.sendMessage(Component.text(targetPlayer.getUsername()).append(Component.text(" died")));
|
||||||
|
}
|
||||||
|
|
||||||
|
return TaskSchedule.stop();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package dev.ninjdai.werewolf.uhc.events;
|
||||||
|
|
||||||
|
import dev.ninjdai.werewolf.uhc.teams.Team;
|
||||||
|
import dev.ninjdai.werewolf.uhc.teams.WinCondition;
|
||||||
|
import io.github.togar2.pvp.events.EntityPreDeathEvent;
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.entity.GameMode;
|
||||||
|
import net.minestom.server.entity.Player;
|
||||||
|
import net.minestom.server.event.EventFilter;
|
||||||
|
import net.minestom.server.event.EventNode;
|
||||||
|
import net.minestom.server.event.trait.EntityEvent;
|
||||||
|
|
||||||
|
public class UHCPlayerDeathEvent {
|
||||||
|
public void onPlayerDeath(EntityPreDeathEvent event) {
|
||||||
|
Player player = (Player) event.getEntity();
|
||||||
|
if(event.getDamage().getAttacker() instanceof Player killer && !killer.getTag(Team.teamTag).isBlank()) {
|
||||||
|
Team team = Team.teamMap.get(killer.getTag(Team.teamTag));
|
||||||
|
WinCondition.checkTeamWin(team, event.getInstance().getPlayers());
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setCancelDeath(true);
|
||||||
|
player.setGameMode(GameMode.SPECTATOR);
|
||||||
|
|
||||||
|
new TimedPlayerDeath(player, event.getDamage(), 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register() {
|
||||||
|
EventNode<EntityEvent> playerNode = EventNode.type("player-listener", EventFilter.ENTITY);
|
||||||
|
MinecraftServer.getGlobalEventHandler().addChild(playerNode);
|
||||||
|
|
||||||
|
playerNode.addListener(EntityPreDeathEvent.class, event -> {
|
||||||
|
if (event.getEntity() instanceof Player) onPlayerDeath(event);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,28 +1,60 @@
|
|||||||
package dev.ninjdai.werewolf.uhc.roles;
|
package dev.ninjdai.werewolf.uhc.roles;
|
||||||
|
|
||||||
import dev.ninjdai.werewolf.uhc.effects.Effect;
|
import dev.ninjdai.werewolf.uhc.effects.Effect;
|
||||||
|
import lombok.Getter;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
|
import net.minestom.server.tag.Tag;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Role {
|
public class Role {
|
||||||
public Role(List<ItemStack> roleItems, List<Effect> roleEffects) {
|
public Role(String id, String name, List<ItemStack> roleItems, List<Effect> roleEffects, Set<RoleProperties> roleProperties) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
this.roleItems = roleItems;
|
this.roleItems = roleItems;
|
||||||
this.roleEffects = roleEffects;
|
this.roleEffects = roleEffects;
|
||||||
|
this.roleProperties = roleProperties;
|
||||||
|
|
||||||
|
roleMap.put(this.id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Role(Builder builder) {
|
Role(Builder builder) {
|
||||||
|
this.id = builder.id;
|
||||||
|
this.name = builder.name;
|
||||||
this.roleItems = builder.roleItems;
|
this.roleItems = builder.roleItems;
|
||||||
this.roleEffects = builder.roleEffects;
|
this.roleEffects = builder.roleEffects;
|
||||||
|
this.roleProperties = builder.roleProperties;
|
||||||
|
|
||||||
|
roleMap.put(this.id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ItemStack> roleItems;
|
@Getter private String id;
|
||||||
List<Effect> roleEffects;
|
@Getter private String name;
|
||||||
|
@Getter private List<ItemStack> roleItems;
|
||||||
|
@Getter private List<Effect> roleEffects;
|
||||||
|
@Getter private Set<RoleProperties> roleProperties;
|
||||||
|
|
||||||
|
public static Tag<String> roleTag = Tag.String("role");
|
||||||
|
|
||||||
|
// ID: Role
|
||||||
|
public static Map<String, Role> roleMap = new HashMap<>();
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
String id = "dummy";
|
||||||
|
String name = "Dummy";
|
||||||
private List<ItemStack> roleItems = List.of();
|
private List<ItemStack> roleItems = List.of();
|
||||||
private List<Effect> roleEffects = List.of();
|
private List<Effect> roleEffects = List.of();
|
||||||
|
Set<RoleProperties> roleProperties = new HashSet<>();
|
||||||
|
|
||||||
|
public Builder setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder setRoleItems(List<ItemStack> roleItems) {
|
public Builder setRoleItems(List<ItemStack> roleItems) {
|
||||||
this.roleItems = roleItems;
|
this.roleItems = roleItems;
|
||||||
@ -44,6 +76,16 @@ public class Role {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder setRoleProperties(Set<RoleProperties> roleProperties) {
|
||||||
|
this.roleProperties = roleProperties;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addRoleProperties(RoleProperties ... roleProperties) {
|
||||||
|
this.roleProperties.addAll(List.of(roleProperties));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Role build() {
|
public Role build() {
|
||||||
return new Role(this);
|
return new Role(this);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package dev.ninjdai.werewolf.uhc.roles;
|
|
||||||
|
|
||||||
public abstract class RoleMetadata {
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,5 @@
|
|||||||
|
package dev.ninjdai.werewolf.uhc.roles;
|
||||||
|
|
||||||
|
public enum RoleProperties {
|
||||||
|
NO_DEATH_MESSAGE,
|
||||||
|
}
|
@ -1,14 +1,20 @@
|
|||||||
package dev.ninjdai.werewolf.uhc.teams;
|
package dev.ninjdai.werewolf.uhc.teams;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import net.minestom.server.color.Color;
|
import net.minestom.server.color.Color;
|
||||||
import net.minestom.server.tag.Tag;
|
import net.minestom.server.tag.Tag;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class Team {
|
public class Team {
|
||||||
public Team(String id, String name, Color color, WinCondition.WinConditionType winConditionType) {
|
public Team(String id, String name, Color color, WinCondition.WinConditionType winConditionType) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.winConditionType = winConditionType;
|
this.winConditionType = winConditionType;
|
||||||
|
|
||||||
|
teamMap.put(this.id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Team(Builder builder){
|
public Team(Builder builder){
|
||||||
@ -16,15 +22,20 @@ public class Team {
|
|||||||
this.name = builder.name;
|
this.name = builder.name;
|
||||||
this.color = builder.color;
|
this.color = builder.color;
|
||||||
this.winConditionType = builder.winConditionType;
|
this.winConditionType = builder.winConditionType;
|
||||||
|
|
||||||
|
teamMap.put(this.id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
String id;
|
@Getter private String id;
|
||||||
String name;
|
@Getter private String name;
|
||||||
Color color;
|
@Getter private Color color;
|
||||||
WinCondition.WinConditionType winConditionType;
|
@Getter private WinCondition.WinConditionType winConditionType;
|
||||||
|
|
||||||
public static Tag<String> teamTag = Tag.String("team");
|
public static Tag<String> teamTag = Tag.String("team");
|
||||||
|
|
||||||
|
// ID: Team
|
||||||
|
public static Map<String, Team> teamMap = new HashMap<>();
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private String id = "dummy";
|
private String id = "dummy";
|
||||||
private String name = "Dummy";
|
private String name = "Dummy";
|
||||||
|
@ -4,13 +4,14 @@ import net.minestom.server.entity.Player;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class WinCondition {
|
public class WinCondition {
|
||||||
public static boolean checkTeamWin(Team team, List<Player> players){
|
public static boolean checkTeamWin(Team team, Set<Player> players){
|
||||||
switch (team.winConditionType){
|
switch (team.getWinConditionType()){
|
||||||
case WinConditionType.ONLY_TEAM_REMAINING -> {
|
case WinConditionType.ONLY_TEAM_REMAINING -> {
|
||||||
for (Player player: players) {
|
for (Player player: players) {
|
||||||
if (! Objects.equals(player.getTag(Team.teamTag), team.id)) return false;
|
if (! Objects.equals(player.getTag(Team.teamTag), team.getId())) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user