Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 1.20 r2 support #896

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bedwars-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bedwars-api</artifactId>
Expand Down
7 changes: 6 additions & 1 deletion bedwars-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bedwars-plugin</artifactId>
Expand Down Expand Up @@ -187,6 +187,11 @@
<artifactId>versionsupport_v1_20_R1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>versionsupport_v1_20_R2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>versionsupport-common</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>BedWars1058</artifactId>
<packaging>pom</packaging>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -112,6 +112,7 @@
<module>versionsupport_v1_19_R2</module>
<module>versionsupport_v1_19_R3</module>
<module>versionsupport_v1_20_R1</module>
<module>versionsupport_v1_20_R2</module>
</modules>

<distributionManagement>
Expand Down
2 changes: 1 addition & 1 deletion resetadapter_aswm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>

<artifactId>resetadapter-aswm</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion resetadapter_slime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>

<artifactId>resetadapter-slime</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion resetadapter_slimepaper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>

<artifactId>resetadapter-slimepaper</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion versionsupport_1_12_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion versionsupport_1_8_R3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>

<artifactId>versionsupport_1_8_R3</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion versionsupport_common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion versionsupport_v1_16_R3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion versionsupport_v1_17_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion versionsupport_v1_18_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion versionsupport_v1_19_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>BedWars1058</artifactId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>

<artifactId>versionsupport_v1_19_R2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion versionsupport_v1_19_R3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>BedWars1058</artifactId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>

<artifactId>versionsupport_v1_19_R3</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion versionsupport_v1_20_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>BedWars1058</artifactId>
<version>23.10-SNAPSHOT</version>
<version>23.10.1-SNAPSHOT</version>
</parent>

<artifactId>versionsupport_v1_20_R1</artifactId>
Expand Down
64 changes: 64 additions & 0 deletions versionsupport_v1_20_R2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>BedWars1058</artifactId>
<version>23.10.1-SNAPSHOT</version>
</parent>

<artifactId>versionsupport_v1_20_R2</artifactId>

<properties>
<maven.compiler.source>1.19</maven.compiler.source>
<maven.compiler.target>1.19</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>bedwars-api</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>versionsupport-common</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.20.2-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.andrei1058.bedwars.support.version.v1_20_R2.despawnable;

public record DespawnableAttributes(DespawnableType type, double speed, double health, double damage, int despawnSeconds) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.andrei1058.bedwars.support.version.v1_20_R2.despawnable;

import com.andrei1058.bedwars.api.arena.team.ITeam;
import com.andrei1058.bedwars.api.server.VersionSupport;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class DespawnableFactory {

private final VersionSupport versionSupport;
private final List<DespawnableProvider<? extends LivingEntity>> providers = new ArrayList<>();

public DespawnableFactory(VersionSupport versionSupport) {
this.versionSupport = versionSupport;
providers.add(new TeamIronGolem());
providers.add(new TeamSilverfish());
}

public LivingEntity spawn(@NotNull DespawnableAttributes attr, @NotNull Location location, @NotNull ITeam team){
return providers.stream().filter(provider -> provider.getType() == attr.type())
.findFirst().orElseThrow().spawn(attr, location,team, versionSupport);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.andrei1058.bedwars.support.version.v1_20_R2.despawnable;

import com.andrei1058.bedwars.api.arena.team.ITeam;
import com.andrei1058.bedwars.api.server.VersionSupport;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityCreature;
import net.minecraft.world.entity.EntityInsentient;
import net.minecraft.world.entity.EntityLiving;
import net.minecraft.world.entity.ai.attributes.GenericAttributes;
import net.minecraft.world.entity.ai.goal.PathfinderGoal;
import net.minecraft.world.entity.ai.goal.PathfinderGoalSelector;
import net.minecraft.world.entity.ai.goal.target.PathfinderGoalNearestAttackableTarget;
import net.minecraft.world.entity.player.EntityHuman;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public abstract class DespawnableProvider<T> {

abstract DespawnableType getType();

abstract String getDisplayName(DespawnableAttributes attr, ITeam team);

abstract T spawn(@NotNull DespawnableAttributes attr, @NotNull Location location, @NotNull ITeam team, VersionSupport api);

protected boolean notSameTeam(@NotNull Entity entity, ITeam team, @NotNull VersionSupport api) {
var despawnable = api.getDespawnablesList().getOrDefault(entity.getBukkitEntity().getUniqueId(), null);
return null == despawnable || despawnable.getTeam() != team;
}

protected PathfinderGoalSelector getTargetSelector(@NotNull EntityCreature entityLiving) {
return entityLiving.bP;
}

protected PathfinderGoalSelector getGoalSelector(@NotNull EntityCreature entityLiving) {
return entityLiving.bO;
}

protected void clearSelectors(@NotNull EntityCreature entityLiving) {
entityLiving.bO.b().clear();
entityLiving.bP.b().clear();
}

protected PathfinderGoal getTargetGoal(EntityInsentient entity, ITeam team, VersionSupport api) {
return new PathfinderGoalNearestAttackableTarget<>(entity, EntityLiving.class, 20, true, false,
entityLiving -> {
if (entityLiving instanceof EntityHuman) {
return !((EntityHuman) entityLiving).getBukkitEntity().isDead() &&
!team.wasMember(((EntityHuman) entityLiving).getBukkitEntity().getUniqueId()) &&
!team.getArena().isReSpawning(((EntityHuman) entityLiving).getBukkitEntity().getUniqueId())
&& !team.getArena().isSpectator(((EntityHuman) entityLiving).getBukkitEntity().getUniqueId());
}
return notSameTeam(entityLiving, team, api);
});
}

protected void applyDefaultSettings(org.bukkit.entity.@NotNull LivingEntity bukkitEntity, DespawnableAttributes attr,
ITeam team) {
bukkitEntity.setRemoveWhenFarAway(false);
bukkitEntity.setPersistent(true);
bukkitEntity.setCustomNameVisible(true);
bukkitEntity.setCustomName(getDisplayName(attr, team));

var entity = ((EntityInsentient)((CraftEntity)bukkitEntity).getHandle());
Objects.requireNonNull(entity.a(GenericAttributes.a)).a(attr.health());
Objects.requireNonNull(entity.a(GenericAttributes.d)).a(attr.speed());
Objects.requireNonNull(entity.a(GenericAttributes.f)).a(attr.damage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.andrei1058.bedwars.support.version.v1_20_R2.despawnable;

public enum DespawnableType {
IRON_GOLEM,
SILVERFISH
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.andrei1058.bedwars.support.version.v1_20_R2.despawnable;

import com.andrei1058.bedwars.api.arena.team.ITeam;
import com.andrei1058.bedwars.api.language.Language;
import com.andrei1058.bedwars.api.language.Messages;
import com.andrei1058.bedwars.api.server.VersionSupport;
import net.minecraft.world.entity.ai.goal.PathfinderGoalFloat;
import net.minecraft.world.entity.ai.goal.PathfinderGoalMeleeAttack;
import net.minecraft.world.entity.ai.goal.PathfinderGoalRandomLookaround;
import net.minecraft.world.entity.ai.goal.PathfinderGoalRandomStroll;
import net.minecraft.world.entity.ai.goal.target.PathfinderGoalHurtByTarget;
import net.minecraft.world.entity.animal.EntityIronGolem;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.IronGolem;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class TeamIronGolem extends DespawnableProvider<IronGolem> {

@Override
public DespawnableType getType() {
return DespawnableType.IRON_GOLEM;
}

@Override
String getDisplayName(@NotNull DespawnableAttributes attr, @NotNull ITeam team) {
Language lang = Language.getDefaultLanguage();
return lang.m(Messages.SHOP_UTILITY_NPC_IRON_GOLEM_NAME).replace("{despawn}", String.valueOf(attr.despawnSeconds())
.replace("{health}", StringUtils.repeat(lang.m(Messages.FORMATTING_DESPAWNABLE_UTILITY_NPC_HEALTH) + " ", 10))
.replace("{TeamColor}", team.getColor().chat().toString())
);
}

public @NotNull IronGolem spawn(@NotNull DespawnableAttributes attr, @NotNull Location location, @NotNull ITeam team, VersionSupport api) {

var bukkitEntity = (IronGolem) Objects.requireNonNull(location.getWorld()).spawnEntity(location, EntityType.IRON_GOLEM);
applyDefaultSettings(bukkitEntity, attr, team);

var entity = (EntityIronGolem) ((CraftEntity) bukkitEntity).getHandle();

clearSelectors(entity);
var goalSelector = getGoalSelector(entity);
var targetSelector = getTargetSelector(entity);

goalSelector.a(1, new PathfinderGoalFloat(entity));
goalSelector.a(2, new PathfinderGoalMeleeAttack(entity, 1.5D, false));
goalSelector.a(3, new PathfinderGoalRandomStroll(entity, 1D));
goalSelector.a(4, new PathfinderGoalRandomLookaround(entity));
targetSelector.a(1, new PathfinderGoalHurtByTarget(entity));
targetSelector.a(2, getTargetGoal(entity, team, api));

return bukkitEntity;
}
}
Loading
Loading