Skip to content

Commit 849bd6a

Browse files
committed
1.10 support (polar bears and strays)
1 parent 4c74b25 commit 849bd6a

File tree

4 files changed

+71
-25
lines changed

4 files changed

+71
-25
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>org.spigotmc</groupId>
3333
<artifactId>spigot-api</artifactId>
34-
<version>1.9.4-R0.1-SNAPSHOT</version>
34+
<version>1.10-R0.1-SNAPSHOT</version>
3535
<scope>provided</scope>
3636
</dependency>
3737

src/main/java/ch/njol/skript/entity/SimpleEntityData.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.bukkit.entity.MushroomCow;
5757
import org.bukkit.entity.Painting;
5858
import org.bukkit.entity.PigZombie;
59+
import org.bukkit.entity.PolarBear;
5960
import org.bukkit.entity.Projectile;
6061
import org.bukkit.entity.Shulker;
6162
import org.bukkit.entity.ShulkerBullet;
@@ -150,7 +151,7 @@ public boolean equals(final @Nullable Object obj) {
150151
types.add(new SimpleEntityDataInfo("squid", Squid.class));
151152
types.add(new SimpleEntityDataInfo("bottle of enchanting", ThrownExpBottle.class));
152153
types.add(new SimpleEntityDataInfo("tnt", TNTPrimed.class));
153-
types.add(new SimpleEntityDataInfo("zombie", Zombie.class));
154+
types.add(new SimpleEntityDataInfo("zombie", Zombie.class)); // TODO husks and zombie villagers (and test that)
154155
types.add(new SimpleEntityDataInfo("golem", Golem.class));
155156

156157
if (Skript.classExists("org.bukkit.entity.ItemFrame")) {
@@ -165,10 +166,13 @@ public boolean equals(final @Nullable Object obj) {
165166
if(Skript.classExists("org.bukkit.entity.ArmorStand")){
166167
types.add(new SimpleEntityDataInfo("endermite", Endermite.class));
167168
types.add(new SimpleEntityDataInfo("armor stand", ArmorStand.class));
168-
} if (Skript.classExists("org.bukkit.entity.Shulker")) {
169+
}
170+
if (Skript.classExists("org.bukkit.entity.Shulker")) {
169171
types.add(new SimpleEntityDataInfo("shulker", Shulker.class));
170172
types.add(new SimpleEntityDataInfo("shulker bullet", ShulkerBullet.class));
171173
}
174+
if (Skript.classExists("org.bukkit.entity.PolarBear"))
175+
types.add(new SimpleEntityDataInfo("polar bear", PolarBear.class));
172176
// TODO !Update with every version [entities]
173177

174178
// supertypes

src/main/java/ch/njol/skript/entity/SkeletonData.java

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,67 +26,103 @@
2626
import org.eclipse.jdt.annotation.Nullable;
2727

2828
import ch.njol.skript.Skript;
29+
import ch.njol.skript.SkriptAPIException;
2930
import ch.njol.skript.lang.Literal;
3031
import ch.njol.skript.lang.SkriptParser.ParseResult;
3132

3233
/**
3334
* @author Peter Güttinger
3435
*/
3536
public class SkeletonData extends EntityData<Skeleton> {
37+
3638
private final static boolean hasWither = Skript.methodExists(Skeleton.class, "getSkeletonType");
39+
private final static boolean hasStray = Skript.isRunningMinecraft(1, 10);
40+
3741
static {
38-
if (hasWither)
42+
if (hasStray)
43+
register(SkeletonData.class, "skeleton", Skeleton.class, 0, "skeleton", "wither skeleton", "stray");
44+
else if (hasWither)
3945
register(SkeletonData.class, "skeleton", Skeleton.class, 0, "skeleton", "wither skeleton");
4046
else
4147
register(SkeletonData.class, "skeleton", Skeleton.class, "skeleton");
4248

4349
}
4450

45-
private boolean wither;
51+
private int type;
52+
public static final int NORMAL = 0, WITHER = 1, STRAY = 2, LAST_INDEX = STRAY;
4653

4754
public SkeletonData() {}
4855

49-
public SkeletonData(final boolean wither) {
50-
this.wither = wither;
56+
public SkeletonData(final int type) {
57+
if (type > LAST_INDEX)
58+
throw new SkriptAPIException("Unsupported skeleton type " + type);
59+
this.type = type;
5160
}
5261

5362
public boolean isWither() {
54-
return wither;
63+
return type == WITHER;
64+
}
65+
66+
public boolean isStray() {
67+
return type == STRAY;
5568
}
5669

5770
@Override
5871
protected boolean init(final Literal<?>[] exprs, final int matchedPattern, final ParseResult parseResult) {
59-
wither = matchedPattern == 1;
72+
type = matchedPattern;
6073
return true;
6174
}
6275

6376
@Override
6477
protected boolean init(final @Nullable Class<? extends Skeleton> c, final @Nullable Skeleton e) {
65-
wither = (e == null || !hasWither) ? false : e.getSkeletonType() == SkeletonType.WITHER;
78+
if (e == null)
79+
return true;
80+
81+
if (hasWither && e.getSkeletonType() == SkeletonType.WITHER)
82+
type = WITHER;
83+
if (hasStray && e.getSkeletonType() == SkeletonType.STRAY)
84+
type = STRAY;
6685
return true;
6786
}
6887

6988
// return wither ? "1" : "0";
7089
@Override
7190
protected boolean deserialize(final String s) {
72-
if (s.equals("1"))
73-
wither = true;
74-
else if (s.equals("0"))
75-
wither = false;
76-
else
77-
return false;
91+
try {
92+
int typeOffer = Integer.parseInt(s);
93+
if (typeOffer > LAST_INDEX)
94+
throw new SkriptAPIException("Unsupported skeleton type " + s);
95+
} catch (NumberFormatException e) {
96+
throw new SkriptAPIException("Cannot parse skeleton type " + s);
97+
}
98+
7899
return true;
79100
}
80101

81102
@Override
82-
public void set(final Skeleton entity) {
83-
if (hasWither)
84-
entity.setSkeletonType(wither ? SkeletonType.WITHER : SkeletonType.NORMAL);
103+
public void set(final Skeleton e) {
104+
switch (type) {
105+
case WITHER:
106+
e.setSkeletonType(SkeletonType.WITHER);
107+
break;
108+
case STRAY:
109+
e.setSkeletonType(SkeletonType.STRAY);
110+
break;
111+
default:
112+
e.setSkeletonType(SkeletonType.NORMAL);
113+
}
85114
}
86115

87116
@Override
88-
protected boolean match(final Skeleton entity) {
89-
return hasWither ? (entity.getSkeletonType() == SkeletonType.WITHER) == wither : true;
117+
protected boolean match(final Skeleton e) {
118+
switch (type) {
119+
case WITHER:
120+
return e.getSkeletonType() == SkeletonType.WITHER;
121+
case STRAY:
122+
return e.getSkeletonType() == SkeletonType.STRAY;
123+
default:
124+
return e.getSkeletonType() == SkeletonType.NORMAL;
125+
}
90126
}
91127

92128
@Override
@@ -99,24 +135,24 @@ protected boolean equals_i(final EntityData<?> obj) {
99135
if (!(obj instanceof SkeletonData))
100136
return false;
101137
final SkeletonData other = (SkeletonData) obj;
102-
return other.wither == wither;
138+
return other.type == type;
103139
}
104140

105141
@Override
106142
protected int hashCode_i() {
107-
return wither ? 1 : 0;
143+
return type;
108144
}
109145

110146
@Override
111147
public boolean isSupertypeOf(final EntityData<?> e) {
112148
if (e instanceof SkeletonData)
113-
return ((SkeletonData) e).wither == wither;
149+
return ((SkeletonData) e).type == type;
114150
return false;
115151
}
116152

117153
@Override
118154
public EntityData getSuperType() {
119-
return new SkeletonData(wither);
155+
return new SkeletonData(type);
120156
}
121157

122158
}

src/main/resources/lang/english.lang

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,12 @@ entities:
793793
endermite:
794794
name: endermite¦s
795795
pattern: endermite(|1¦s)
796+
stray:
797+
name: stray¦s
798+
pattern: stray(|1¦s)
799+
polar bear:
800+
name: polar bear¦s
801+
pattern: polar bears(|1¦s)
796802

797803
# -- Damage Causes --
798804
damage causes:

0 commit comments

Comments
 (0)