Skip to content

Commit fa93363

Browse files
committed
Support leashable boats
1 parent 4e87b72 commit fa93363

File tree

6 files changed

+58
-24
lines changed

6 files changed

+58
-24
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.laytonsmith.abstraction;
2+
public interface MCLeashable {
3+
MCEntity getLeashHolder();
4+
boolean isLeashed();
5+
void setLeashHolder(MCEntity holder);
6+
}

src/main/java/com/laytonsmith/abstraction/MCLivingEntity.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.HashSet;
1010
import java.util.List;
1111

12-
public interface MCLivingEntity extends MCEntity, MCProjectileSource {
12+
public interface MCLivingEntity extends MCEntity, MCLeashable, MCProjectileSource {
1313

1414
boolean addEffect(MCPotionEffectType type, int strength, int ticks, boolean ambient, boolean particles, boolean icon);
1515

@@ -47,8 +47,6 @@ public interface MCLivingEntity extends MCEntity, MCProjectileSource {
4747

4848
double getLastDamage();
4949

50-
MCEntity getLeashHolder();
51-
5250
MCLivingEntity getTarget(Target t);
5351

5452
MCBlock getTargetBlock(HashSet<MCMaterial> transparent, int maxDistance);
@@ -69,8 +67,6 @@ public interface MCLivingEntity extends MCEntity, MCProjectileSource {
6967

7068
boolean isGliding();
7169

72-
boolean isLeashed();
73-
7470
boolean hasAI();
7571

7672
void resetMaxHealth();
@@ -83,8 +79,6 @@ public interface MCLivingEntity extends MCEntity, MCProjectileSource {
8379

8480
void setLastDamage(double damage);
8581

86-
void setLeashHolder(MCEntity holder);
87-
8882
void setMaxHealth(double health);
8983

9084
void setMaximumAir(int ticks);

src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCBoat.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.laytonsmith.abstraction.bukkit.entities;
22

3+
import com.laytonsmith.abstraction.MCEntity;
4+
import com.laytonsmith.abstraction.bukkit.BukkitMCServer;
35
import com.laytonsmith.abstraction.entities.MCBoat;
46
import com.laytonsmith.abstraction.enums.MCTreeSpecies;
57
import com.laytonsmith.abstraction.enums.MCVersion;
@@ -34,4 +36,31 @@ public void setWoodType(MCTreeSpecies type) {
3436
}
3537
}
3638

39+
@Override
40+
public MCEntity getLeashHolder() {
41+
return new BukkitMCEntity(b.getLeashHolder());
42+
}
43+
44+
@Override
45+
public boolean isLeashed() {
46+
if(((BukkitMCServer) Static.getServer()).isPaper()
47+
&& Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21_3)
48+
|| Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21_10)) {
49+
return b.isLeashed();
50+
}
51+
return false;
52+
}
53+
54+
@Override
55+
public void setLeashHolder(MCEntity holder) {
56+
if(((BukkitMCServer) Static.getServer()).isPaper()
57+
&& Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21_3)
58+
|| Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21_10)) {
59+
if(holder == null) {
60+
b.setLeashHolder(null);
61+
} else {
62+
b.setLeashHolder((Entity) holder.getHandle());
63+
}
64+
}
65+
}
3766
}

src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCLivingEntity.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,7 @@ public void kill() {
381381

382382
@Override
383383
public MCEntity getLeashHolder() {
384-
if(le.isLeashed()) {
385-
return BukkitConvertor.BukkitGetCorrectEntity(le.getLeashHolder());
386-
}
387-
return null;
384+
return new BukkitMCEntity(le.getLeashHolder());
388385
}
389386

390387
@Override
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.laytonsmith.abstraction.entities;
22

3+
import com.laytonsmith.abstraction.MCLeashable;
34
import com.laytonsmith.abstraction.enums.MCTreeSpecies;
45

5-
public interface MCBoat extends MCVehicle {
6+
public interface MCBoat extends MCVehicle, MCLeashable {
67
MCTreeSpecies getWoodType();
78
void setWoodType(MCTreeSpecies type);
89
}

src/main/java/com/laytonsmith/core/functions/MobManagement.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.laytonsmith.PureUtilities.Common.StringUtils;
44
import com.laytonsmith.PureUtilities.Version;
55
import com.laytonsmith.abstraction.MCAttributeModifier;
6+
import com.laytonsmith.abstraction.MCLeashable;
67
import com.laytonsmith.abstraction.MCNamespacedKey;
78
import com.laytonsmith.abstraction.blocks.MCMaterial;
89
import com.laytonsmith.abstraction.MCAnimalTamer;
@@ -1062,11 +1063,14 @@ public static class get_leashholder extends EntityManagement.EntityGetterFunctio
10621063

10631064
@Override
10641065
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
1065-
MCLivingEntity le = Static.getLivingEntity(args[0], t);
1066-
if(!le.isLeashed()) {
1066+
MCEntity e = Static.getEntity(args[0], t);
1067+
if(!(e instanceof MCLeashable)) {
1068+
throw new CREBadEntityException("Entity type is not leashable.", t);
1069+
}
1070+
if(!((MCLeashable) e).isLeashed()) {
10671071
return CNull.NULL;
10681072
}
1069-
return new CString(le.getLeashHolder().getUniqueId().toString(), t);
1073+
return new CString(((MCLeashable) e).getLeashHolder().getUniqueId().toString(), t);
10701074
}
10711075

10721076
@Override
@@ -1076,8 +1080,9 @@ public String getName() {
10761080

10771081
@Override
10781082
public String docs() {
1079-
return "string {entityUUID} Returns the UUID of the entity that is holding the given living entity's leash,"
1080-
+ " or null if it isn't being held.";
1083+
return "string {entityUUID} Returns the UUID of the entity that is holding the given entity's leash,"
1084+
+ " or null if it isn't being held. Only mobs and boats can be leashed, otherwise a"
1085+
+ " BadEntityException is thrown. Boats are only supported on Paper 1.21.3+ and Spigot 1.21.10+.";
10811086
}
10821087

10831088
@Override
@@ -1091,14 +1096,17 @@ public static class set_leashholder extends EntityManagement.EntitySetterFunctio
10911096

10921097
@Override
10931098
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
1094-
MCLivingEntity le = Static.getLivingEntity(args[0], t);
1099+
MCEntity e = Static.getEntity(args[0], t);
10951100
MCEntity holder;
10961101
if(args[1] instanceof CNull) {
10971102
holder = null;
10981103
} else {
10991104
holder = Static.getEntity(args[1], t);
11001105
}
1101-
le.setLeashHolder(holder);
1106+
if(!(e instanceof MCLeashable)) {
1107+
throw new CREBadEntityException("Entity type is not leashable.", t);
1108+
}
1109+
((MCLeashable) e).setLeashHolder(holder);
11021110
return CVoid.VOID;
11031111
}
11041112

@@ -1109,11 +1117,10 @@ public String getName() {
11091117

11101118
@Override
11111119
public String docs() {
1112-
return "void {entityUUID, entityUUID} The first argument is the entity to be held on a leash,"
1113-
+ " and must be living. The second is the holder of the leash. This does not have to be living,"
1114-
+ " but the only non-living entity that will persist as a holder across restarts is the leash hitch."
1115-
+ " Players, bats, enderdragons, withers and certain other entities can not be held by leashes due"
1116-
+ " to minecraft limitations.";
1120+
return "void {entityUUID, holderUUID} The first argument is the entity to be held on a leash, and must be a"
1121+
+ " mob or a boat. The second is the holder of the leash and can be many types of entities,"
1122+
+ " notably a leash hitch. Certain entity types may be excluded from being leashed depending on the"
1123+
+ " Minecraft version. Boats are only supported on Paper 1.21.3+ and Spigot 1.21.10+.";
11171124
}
11181125

11191126
@Override

0 commit comments

Comments
 (0)