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

Fix falling block spawning with sections #4717

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 11 additions & 18 deletions src/main/java/ch/njol/skript/entity/EntityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,35 +413,28 @@ public static EntityData<?> parseWithoutIndefiniteArticle(String s) {
}

@Nullable
public E spawn(final Location loc) {
assert loc != null;
try {
final E e = loc.getWorld().spawn(loc, getType());
if (baby.isTrue())
EntityUtils.setBaby(e);
else if (baby.isFalse())
EntityUtils.setAdult(e);
set(e);
return e;
} catch (final IllegalArgumentException e) {
if (Skript.testing())
Skript.error("Can't spawn " + getType().getName());
return null;
}
public final E spawn(Location loc) {
return spawn(loc, null);
}

@SuppressWarnings("unchecked")
@Nullable
public E spawn(Location loc, Consumer<E> consumer) {
public E spawn(Location loc, @Nullable Consumer<E> consumer) {
assert loc != null;
try {
E e = loc.getWorld().spawn(loc, (Class<E>) getType(), consumer);
E e;
if (consumer != null)
e = loc.getWorld().spawn(loc, (Class<E>) getType(), consumer);
else
e = loc.getWorld().spawn(loc, getType());

if (baby.isTrue())
EntityUtils.setBaby(e);
else if (baby.isFalse())
EntityUtils.setAdult(e);
set(e);
return e;
} catch (final IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
if (Skript.testing())
Skript.error("Can't spawn " + getType().getName());
return null;
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/ch/njol/skript/entity/FallingBlockData.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.bukkit.Material;
import org.bukkit.entity.FallingBlock;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Consumer;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
Expand Down Expand Up @@ -110,21 +111,21 @@ protected boolean match(final FallingBlock entity) {
}
return true;
}

@SuppressWarnings("deprecation")
@Override
@Nullable
public FallingBlock spawn(final Location loc) {
final ItemType t = CollectionUtils.getRandom(types);
public FallingBlock spawn(Location loc, @Nullable Consumer<FallingBlock> consumer) {
ItemType t = CollectionUtils.getRandom(types);
assert t != null;
final ItemStack i = t.getRandom();
ItemStack i = t.getRandom();
if (i == null || i.getType() == Material.AIR || !i.getType().isBlock()) {
assert false : i;
return null;
}
return loc.getWorld().spawnFallingBlock(loc, i.getType(), (byte) i.getDurability());
}

@Override
public void set(final FallingBlock entity) {
assert false;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/ch/njol/skript/entity/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Consumer;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.lang.Literal;
Expand Down Expand Up @@ -63,13 +64,13 @@ protected boolean match(final Player p) {
public Class<? extends Player> getType() {
return Player.class;
}

@Override
@Nullable
public Player spawn(final Location loc) {
public Player spawn(Location loc, @Nullable Consumer<Player> consumer) {
return null;
}

@Override
protected int hashCode_i() {
return op;
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/ch/njol/skript/entity/ThrownPotionData.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.bukkit.entity.ThrownPotion;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Consumer;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
Expand Down Expand Up @@ -97,21 +98,25 @@ protected boolean match(final ThrownPotion entity) {
}
return true;
}

@Nullable

@Override
public ThrownPotion spawn(Location loc) {
public @Nullable ThrownPotion spawn(Location loc, @Nullable Consumer<ThrownPotion> consumer) {
ItemType t = CollectionUtils.getRandom(types);
assert t != null;
final ItemStack i = t.getRandom();
if (i == null) {
ItemStack i = t.getRandom();
if (i == null)
return null;
}
ThrownPotion potion = loc.getWorld().spawn(loc, ThrownPotion.class);

ThrownPotion potion;
if (consumer != null)
potion = loc.getWorld().spawn(loc, ThrownPotion.class, consumer);
else
potion = loc.getWorld().spawn(loc, ThrownPotion.class);

potion.setItem(i);
return potion;
}

@Override
public void set(final ThrownPotion entity) {
if (types != null) {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/ch/njol/skript/entity/XpOrbData.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.bukkit.Location;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.util.Consumer;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.lang.Literal;
Expand Down Expand Up @@ -68,18 +69,18 @@ public void set(final ExperienceOrb entity) {
if (xp != -1)
entity.setExperience(xp);
}

@Override
@Nullable
public ExperienceOrb spawn(final Location loc) {
final ExperienceOrb orb = super.spawn(loc);
public ExperienceOrb spawn(Location loc, @Nullable Consumer<ExperienceOrb> consumer) {
ExperienceOrb orb = super.spawn(loc, consumer);
if (orb == null)
return null;
if (xp == -1)
orb.setExperience(1);
return orb;
}

private final static ArgsMessage format = new ArgsMessage("entities.xp-orb.format");

@Override
Expand Down