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 support #814

Merged
merged 3 commits into from
Jun 25, 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
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,18 @@ core team. |
| `under-review` | Pull requests being reviewed by maintainers. |
| `requires-changes` | Pull requests which need to be updated based on review comments and then reviewed again. |
| `needs-testing` | Pull requests which need manual testing. |

# How to add support for a new Minecraft version

First give a look at the project structure above on this page, clone the versionsupport of
the latest supported version and then make sure to rename the package and class, plus update
the pom file with the new version name.

At this point make sure to map the following aspects on the new NMS:
- Pathfinders for goals and targets in `DespawnableProvider`
- `PlayerConnection` used to send packets in `v1_nn_Rx` class
- Glass and other modified blocks in `v1_nn_Rx#registerTntWhitelist`
- NBTTags in `v1_nn_Rx` for Item, Entity and ItemStacks
- eventually other functions that were not mapped yet by spigot

For your update to go live, [SidebarLib](https://github.com/andrei1058/SidebarLib) needs to be updated to your new version as well.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Any help is appreciated, just give a quick look at [CONTRIBUTING.md](https://git
If you are not a programmer you can help answering people in the [Issues](https://github.com/andrei1058/BedWars1058/issues) section or even [translate the plugin in your languae on Crowdin](https://crowdin.com/project/bedwars1058).

### Translation progress
[![Translation Chart](https://badges.awesome-crowdin.com/translation-12780139-594479.png)]
[Translation Chart](https://badges.awesome-crowdin.com/translation-12780139-594479.png)

# 3rd party libraries
- [bStats](https://bstats.org/getting-started/include-metrics)
Expand All @@ -139,3 +139,8 @@ If you are not a programmer you can help answering people in the [Issues](https:

# Contact
[![Discord Server](https://discordapp.com/api/guilds/201345265821679617/widget.png?style=banner3)](https://discord.gg/XdJfN2X)

# Special Thanks To
[<img src="https://user-images.githubusercontent.com/21148213/121807008-8ffc6700-cc52-11eb-96a7-2f6f260f8fda.png" alt="" width="150">](https://www.jetbrains.com)

Jetbrains supports BedWars1058 with their [Open Source Licenses](https://www.jetbrains.com/opensource/).
27 changes: 19 additions & 8 deletions bedwars-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@
<artifactId>versionsupport_v1_19_R3</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>versionsupport_v1_20_R1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>versionsupport-common</artifactId>
Expand Down Expand Up @@ -237,49 +242,55 @@
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-base</artifactId>
<version>23.4</version>
<version>23.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_8_R3</artifactId>
<version>23.4</version>
<version>23.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_12_R1</artifactId>
<version>23.4</version>
<version>23.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_16_R1</artifactId>
<version>23.4</version>
<version>23.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_17_R1</artifactId>
<version>23.4</version>
<version>23.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_18_R2</artifactId>
<version>23.4</version>
<version>23.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_19_R2</artifactId>
<version>23.4</version>
<version>23.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_19_R3</artifactId>
<version>23.4</version>
<version>23.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_20_R1</artifactId>
<version>23.6</version>
<scope>compile</scope>
</dependency>
<!-- End of Sidebar LIB-->
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<module>versionsupport_v1_18_R2</module>
<module>versionsupport_v1_19_R2</module>
<module>versionsupport_v1_19_R3</module>
<module>versionsupport_v1_20_R1</module>
</modules>

<distributionManagement>
Expand Down
64 changes: 64 additions & 0 deletions versionsupport_v1_20_R1/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>22.9-SNAPSHOT</version>
</parent>

<artifactId>versionsupport_v1_20_R1</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-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_R1.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_R1.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_R1.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_R1.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_R1.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_R1.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_R1.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