diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java b/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java index 7715e0821..de1368009 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java @@ -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> types = ImmutableMap.>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> types; + + static { + ImmutableMap.Builder> builder = ImmutableMap.>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 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 {