Fix /fireball on 1.8.8 (#3027)

Dragon fireballs were added in 1.9 and so this previously caused an
error. This PR fixes that (and adds tridents as throwables). Fixes #3016.
This commit is contained in:
md678685 2020-02-22 10:03:43 +00:00 committed by GitHub
parent 0bafbc3184
commit a747eccaa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 17 deletions

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FloatUtil;
import com.earth2me.essentials.utils.VersionUtil;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.bukkit.Server;
@ -16,19 +17,31 @@ import java.util.stream.Collectors;
import static com.earth2me.essentials.I18n.tl;
public class Commandfireball extends EssentialsCommand {
private static final Map<String, Class<? extends Entity>> types = ImmutableMap.<String, Class<? extends Entity>>builder()
.put("fireball", Fireball.class)
.put("small", SmallFireball.class)
.put("large", LargeFireball.class)
.put("dragon", DragonFireball.class)
.put("arrow", Arrow.class)
.put("skull", WitherSkull.class)
.put("egg", Egg.class)
.put("snowball", Snowball.class)
.put("expbottle", ThrownExpBottle.class)
.put("splashpotion", SplashPotion.class)
.put("lingeringpotion", LingeringPotion.class)
.build();
private static final Map<String, Class<? extends Projectile>> types;
static {
ImmutableMap.Builder<String, Class<? extends Projectile>> builder = ImmutableMap.<String, Class<? extends Projectile>>builder()
.put("fireball", Fireball.class)
.put("small", SmallFireball.class)
.put("large", LargeFireball.class)
.put("arrow", Arrow.class)
.put("skull", WitherSkull.class)
.put("egg", Egg.class)
.put("snowball", Snowball.class)
.put("expbottle", ThrownExpBottle.class)
.put("splashpotion", SplashPotion.class)
.put("lingeringpotion", LingeringPotion.class);
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_9_R01)) {
builder.put("dragon", DragonFireball.class);
}
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_13_0_R01)) {
builder.put("trident", Trident.class);
}
types = builder.build();
}
public Commandfireball() {
super("fireball");
@ -48,7 +61,8 @@ public class Commandfireball extends EssentialsCommand {
try {
speed = FloatUtil.parseDouble(args[1]);
speed = Double.max(0, Double.min(speed, ess.getSettings().getMaxProjectileSpeed()));
} catch (Exception ignored) {}
} catch (Exception ignored) {
}
}
if (args.length > 2 && args[2].equalsIgnoreCase("ride") && user.isAuthorized("essentials.fireball.ride")) {
@ -60,7 +74,7 @@ public class Commandfireball extends EssentialsCommand {
}
final Vector direction = user.getBase().getEyeLocation().getDirection().multiply(speed);
Projectile projectile = (Projectile) user.getWorld().spawn(user.getBase().getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), types.get(type));
Projectile projectile = user.getWorld().spawn(user.getBase().getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), types.get(type));
projectile.setShooter(user.getBase());
projectile.setVelocity(direction);
@ -73,8 +87,8 @@ public class Commandfireball extends EssentialsCommand {
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (args.length == 1) {
return types.keySet().stream()
.filter(type -> user.isAuthorized("essentials.fireball." + type))
.collect(Collectors.toList());
.filter(type -> user.isAuthorized("essentials.fireball." + type))
.collect(Collectors.toList());
} else if (args.length == 2) {
return Lists.newArrayList("1", "2", "3", "4", "5");
} else {