Skip to content

Commit 434acc7

Browse files
teenangstKrakenied
authored andcommitted
Introduce walking task type grouped modes
Added groups: - ground: sneaking, walking or running - manual_no_flight: sneaking, walking, running, or swimming - manual_no_swim: sneaking, walking, running, or flying (creative or elytra) - manual: sneaking, walking, running, swimming or flying (creative or elytra) - vehicle: any vehicle Added 1.21.11 support for Nautilus
1 parent 81ef9b5 commit 434acc7

File tree

5 files changed

+65
-6
lines changed

5 files changed

+65
-6
lines changed

bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/versionspecific/VersionSpecificHandler.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.bukkit.entity.Horse;
1717
import org.bukkit.entity.Llama;
1818
import org.bukkit.entity.Mule;
19+
import org.bukkit.entity.Nautilus;
1920
import org.bukkit.entity.Player;
2021
import org.bukkit.entity.SkeletonHorse;
2122
import org.bukkit.entity.Strider;
@@ -111,6 +112,13 @@ public interface VersionSpecificHandler {
111112
*/
112113
boolean isPlayerOnMule(Player player);
113114

115+
/**
116+
* Nautiluses were introduced in {@code 1.21.11}.
117+
*
118+
* @see Nautilus
119+
*/
120+
boolean isPlayerOnNautilus(Player player);
121+
114122
/**
115123
* Skeleton horses were introduced in {@code 1.6.1}.
116124
*

bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/versionspecific/VersionSpecificHandler21.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.leonardobishop.quests.bukkit.util.CompatUtils;
44
import org.bukkit.entity.HappyGhast;
5+
import org.bukkit.entity.Nautilus;
56
import org.bukkit.entity.Player;
67

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

15+
// Introduced in 1.21.11
16+
private static final Predicate<Player> NAUTILUS_PREDICATE;
17+
1418
static {
1519
if (CompatUtils.classExists("org.bukkit.entity.HappyGhast")) {
1620
HAPPY_GHAST_PREDICATE = player -> player.getVehicle() instanceof HappyGhast;
@@ -19,6 +23,14 @@ public class VersionSpecificHandler21 extends VersionSpecificHandler20 implement
1923
}
2024
}
2125

26+
static {
27+
if (CompatUtils.classExists("org.bukkit.entity.Nautilus")) {
28+
NAUTILUS_PREDICATE = player -> player.getVehicle() instanceof Nautilus;
29+
} else {
30+
NAUTILUS_PREDICATE = player -> Boolean.FALSE;
31+
}
32+
}
33+
2234
@Override
2335
public int getMinecraftVersion() {
2436
return 21;
@@ -28,4 +40,9 @@ public int getMinecraftVersion() {
2840
public boolean isPlayerOnHappyGhast(Player player) {
2941
return HAPPY_GHAST_PREDICATE.test(player);
3042
}
43+
44+
@Override
45+
public boolean isPlayerOnNautilus(Player player) {
46+
return NAUTILUS_PREDICATE.test(player);
47+
}
3148
}

bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/versionspecific/VersionSpecificHandler8.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public boolean isPlayerOnMule(Player player) {
6969
return player.getVehicle() instanceof Horse horse && horse.getVariant() == Horse.Variant.MULE;
7070
}
7171

72+
@Override
73+
public boolean isPlayerOnNautilus(Player player) {
74+
return false;
75+
}
76+
7277
@SuppressWarnings("deprecation")
7378
@Override
7479
public boolean isPlayerOnSkeletonHorse(Player player) {

bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/WalkingTaskType.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ private boolean validateMode(final @NotNull Player player, final @NotNull Mode m
127127
case LLAMA -> this.plugin.getVersionSpecificHandler().isPlayerOnLlama(player);
128128
case MINECART -> player.getVehicle() instanceof RideableMinecart;
129129
case MULE -> this.plugin.getVersionSpecificHandler().isPlayerOnMule(player);
130+
case NAUTILUS -> this.plugin.getVersionSpecificHandler().isPlayerOnNautilus(player);
130131
case PIG -> player.getVehicle() instanceof Pig;
131132
case SKELETON_HORSE -> this.plugin.getVersionSpecificHandler().isPlayerOnSkeletonHorse(player);
132133
case STRIDER -> this.plugin.getVersionSpecificHandler().isPlayerOnStrider(player);
@@ -166,6 +167,26 @@ private boolean validateMode(final @NotNull Player player, final @NotNull Mode m
166167
// we can safely ignore any other actions here as there is
167168
// really no better way to detect flying with elytra
168169
!player.isInsideVehicle() && this.plugin.getVersionSpecificHandler().isPlayerGliding(player);
170+
171+
// Grouped
172+
case GROUND ->
173+
// player is sneaking, walking or running
174+
!player.isInsideVehicle() && !player.isSwimming() && !player.isFlying()
175+
&& !this.plugin.getVersionSpecificHandler().isPlayerGliding(player);
176+
case MANUAL_NO_FLIGHT ->
177+
// player is sneaking, walking, running, or swimming
178+
!player.isInsideVehicle() && !player.isFlying()
179+
&& !this.plugin.getVersionSpecificHandler().isPlayerGliding(player);
180+
case MANUAL_NO_SWIM ->
181+
// player is sneaking, walking, running, or flying (creative or elytra)
182+
!player.isInsideVehicle() && (!player.isSwimming() || player.isFlying()
183+
|| this.plugin.getVersionSpecificHandler().isPlayerGliding(player));
184+
case MANUAL ->
185+
// player is sneaking, walking, running, swimming or flying (creative or elytra)
186+
!player.isInsideVehicle();
187+
case VEHICLE ->
188+
// player is in any vehicle
189+
player.isInsideVehicle();
169190
};
170191
}
171192

@@ -179,6 +200,7 @@ private enum Mode {
179200
LLAMA,
180201
MINECART,
181202
MULE,
203+
NAUTILUS,
182204
PIG,
183205
SKELETON_HORSE,
184206
STRIDER,
@@ -190,7 +212,14 @@ private enum Mode {
190212
RUNNING,
191213
SWIMMING,
192214
FLYING,
193-
ELYTRA;
215+
ELYTRA,
216+
217+
// Grouped
218+
GROUND, // walking, running, sneaking
219+
MANUAL_NO_FLIGHT, // walking, running, sneaking, swimming
220+
MANUAL_NO_SWIM, // walking, running, sneaking, flying
221+
MANUAL, // walking, running, sneaking, swimming, flying
222+
VEHICLE; // any vehicle
194223

195224
private static final Map<String, Mode> STRING_MODE_MAP = new HashMap<>() {{
196225
for (final Mode mode : Mode.values()) {

docs/task-types/walking-(task-type).md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Walk a set distance.
1313

1414
## Options
1515

16-
| Key | Description | Type | Required | Default | Notes |
17-
|------------|-------------------------------------------------|---------------------|----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
18-
| `distance` | The distance in metres to walk. | Integer | Yes | \- | 1 metre is equivalent to 1 block. |
19-
| `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. |
20-
| `worlds` | Worlds which should count towards the progress. | List of world names | No | \- | \- |
16+
| Key | Description | Type | Required | Default | Notes |
17+
|------------|-------------------------------------------------|---------------------|----------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
18+
| `distance` | The distance in metres to walk. | Integer | Yes | \- | 1 metre is equivalent to 1 block. |
19+
| `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. |
20+
| `worlds` | Worlds which should count towards the progress. | List of world names | No | \- | \- |
2121

2222
## Examples
2323

0 commit comments

Comments
 (0)