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

View File

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