Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.entity.Horse;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Mule;
import org.bukkit.entity.Nautilus;
import org.bukkit.entity.Player;
import org.bukkit.entity.SkeletonHorse;
import org.bukkit.entity.Strider;
Expand Down Expand Up @@ -111,6 +112,13 @@ public interface VersionSpecificHandler {
*/
boolean isPlayerOnMule(Player player);

/**
* Nautiluses were introduced in {@code 1.21.11}.
*
* @see Nautilus
*/
boolean isPlayerOnNautilus(Player player);

/**
* Skeleton horses were introduced in {@code 1.6.1}.
*
Expand Down Expand Up @@ -245,7 +253,6 @@ public interface VersionSpecificHandler {
/**
* {@link DamageSource}s were introduced in {@code 1.20.4}.
*/
@SuppressWarnings("UnstableApiUsage")
@Nullable Player getDamager(@Nullable EntityDamageEvent lastDamageCause);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.leonardobishop.quests.bukkit.util.CompatUtils;
import org.bukkit.entity.HappyGhast;
import org.bukkit.entity.Nautilus;
import org.bukkit.entity.Player;

import java.util.function.Predicate;
Expand All @@ -11,6 +12,9 @@ public class VersionSpecificHandler21 extends VersionSpecificHandler20 implement
// Introduced in 1.21.6
private static final Predicate<Player> HAPPY_GHAST_PREDICATE;

// Introduced in 1.21.11
private static final Predicate<Player> NAUTILUS_PREDICATE;

static {
if (CompatUtils.classExists("org.bukkit.entity.HappyGhast")) {
HAPPY_GHAST_PREDICATE = player -> player.getVehicle() instanceof HappyGhast;
Expand All @@ -19,6 +23,14 @@ public class VersionSpecificHandler21 extends VersionSpecificHandler20 implement
}
}

static {
if (CompatUtils.classExists("org.bukkit.entity.Nautilus")) {
NAUTILUS_PREDICATE = player -> player.getVehicle() instanceof Nautilus;
} else {
NAUTILUS_PREDICATE = player -> Boolean.FALSE;
}
}

@Override
public int getMinecraftVersion() {
return 21;
Expand All @@ -28,4 +40,9 @@ public int getMinecraftVersion() {
public boolean isPlayerOnHappyGhast(Player player) {
return HAPPY_GHAST_PREDICATE.test(player);
}

@Override
public boolean isPlayerOnNautilus(Player player) {
return NAUTILUS_PREDICATE.test(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public boolean isPlayerOnMule(Player player) {
return player.getVehicle() instanceof Horse horse && horse.getVariant() == Horse.Variant.MULE;
}

@Override
public boolean isPlayerOnNautilus(Player player) {
return false;
}

@SuppressWarnings("deprecation")
@Override
public boolean isPlayerOnSkeletonHorse(Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private boolean validateMode(final @NotNull Player player, final @NotNull Mode m
case LLAMA -> this.plugin.getVersionSpecificHandler().isPlayerOnLlama(player);
case MINECART -> player.getVehicle() instanceof RideableMinecart;
case MULE -> this.plugin.getVersionSpecificHandler().isPlayerOnMule(player);
case NAUTILUS -> this.plugin.getVersionSpecificHandler().isPlayerOnNautilus(player);
case PIG -> player.getVehicle() instanceof Pig;
case SKELETON_HORSE -> this.plugin.getVersionSpecificHandler().isPlayerOnSkeletonHorse(player);
case STRIDER -> this.plugin.getVersionSpecificHandler().isPlayerOnStrider(player);
Expand Down Expand Up @@ -166,6 +167,26 @@ private boolean validateMode(final @NotNull Player player, final @NotNull Mode m
// we can safely ignore any other actions here as there is
// really no better way to detect flying with elytra
!player.isInsideVehicle() && this.plugin.getVersionSpecificHandler().isPlayerGliding(player);

// Grouped
case GROUND ->
// player is sneaking, walking or running
!player.isInsideVehicle() && !player.isSwimming() && !player.isFlying()
&& !this.plugin.getVersionSpecificHandler().isPlayerGliding(player);
case MANUAL_NO_FLIGHT ->
// player is sneaking, walking, running, or swimming
!player.isInsideVehicle() && !player.isFlying()
&& !this.plugin.getVersionSpecificHandler().isPlayerGliding(player);
case MANUAL_NO_SWIM ->
// player is sneaking, walking, running, or flying (creative or elytra)
!player.isInsideVehicle() && (!player.isSwimming() || player.isFlying()
|| this.plugin.getVersionSpecificHandler().isPlayerGliding(player));
case MANUAL ->
// player is sneaking, walking, running, swimming or flying (creative or elytra)
!player.isInsideVehicle();
case VEHICLE ->
// player is in any vehicle
player.isInsideVehicle();
};
}

Expand All @@ -179,6 +200,7 @@ private enum Mode {
LLAMA,
MINECART,
MULE,
NAUTILUS,
PIG,
SKELETON_HORSE,
STRIDER,
Expand All @@ -190,7 +212,14 @@ private enum Mode {
RUNNING,
SWIMMING,
FLYING,
ELYTRA;
ELYTRA,

// Grouped
GROUND, // walking, running, sneaking
MANUAL_NO_FLIGHT, // walking, running, sneaking, swimming
MANUAL_NO_SWIM, // walking, running, sneaking, flying
MANUAL, // walking, running, sneaking, swimming, flying
VEHICLE; // any vehicle

private static final Map<String, Mode> STRING_MODE_MAP = new HashMap<>() {{
for (final Mode mode : Mode.values()) {
Expand Down
10 changes: 5 additions & 5 deletions docs/task-types/walking-(task-type).md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Walk a set distance.

## Options

| Key | Description | Type | Required | Default | Notes |
|------------|-------------------------------------------------|---------------------|----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `distance` | The distance in metres to walk. | Integer | Yes | \- | 1 metre is equivalent to 1 block. |
| `mode` | The specific mode to travel | String | No | \- | One of: `boat`, `camel`, `donkey`, `happy_ghast`, `horse`, `llama`, `minecart`, `mule`, `pig`, `skeleton_horse`, `strider`, `zombie_horse`, `sneaking`, `walking`, `running`, `swimming`, `flying`, `elytra`. Not specifying a mode will allow any of these modes to count. |
| `worlds` | Worlds which should count towards the progress. | List of world names | No | \- | \- |
| Key | Description | Type | Required | Default | Notes |
|------------|-------------------------------------------------|---------------------|----------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `distance` | The distance in metres to walk. | Integer | Yes | \- | 1 metre is equivalent to 1 block. |
| `mode` | The specific mode to travel | String | No | \- | One of: `boat`, `camel`, `donkey`, `happy_ghast`, `horse`, `llama`, `minecart`, `mule`, `nautilus` `pig`, `skeleton_horse`, `strider`, `zombie_horse`, `sneaking`, `walking`, `running`, `swimming`, `flying`, `elytra`. Alternatively one of groups: `ground`, `manual_no_flight`, `manual_no_swim`, `manual` or `vehicle`. Not specifying a mode will allow any of these modes to count. |
| `worlds` | Worlds which should count towards the progress. | List of world names | No | \- | \- |

## Examples

Expand Down