2011-06-23 12:14:24 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.User;
|
2019-08-05 15:12:22 +00:00
|
|
|
import com.earth2me.essentials.utils.FloatUtil;
|
2020-02-22 10:03:43 +00:00
|
|
|
import com.earth2me.essentials.utils.VersionUtil;
|
2019-08-05 15:12:22 +00:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
2017-06-11 00:17:43 +00:00
|
|
|
import com.google.common.collect.Lists;
|
2011-06-23 12:14:24 +00:00
|
|
|
import org.bukkit.Server;
|
2013-01-09 00:58:29 +00:00
|
|
|
import org.bukkit.entity.*;
|
2020-04-10 19:44:45 +00:00
|
|
|
import org.bukkit.metadata.FixedMetadataValue;
|
2011-06-23 12:14:24 +00:00
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
2017-06-11 00:17:43 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2019-08-05 15:12:22 +00:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
2011-06-23 12:14:24 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
public class Commandfireball extends EssentialsCommand {
|
2020-04-10 19:44:45 +00:00
|
|
|
|
|
|
|
public static final String FIREBALL_META_KEY = "ess_fireball_proj";
|
|
|
|
|
2020-02-22 10:03:43 +00:00
|
|
|
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)
|
2020-03-01 11:12:55 +00:00
|
|
|
.put("expbottle", ThrownExpBottle.class);
|
2020-02-22 10:03:43 +00:00
|
|
|
|
|
|
|
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_9_R01)) {
|
2020-03-01 11:12:55 +00:00
|
|
|
builder.put("dragon", DragonFireball.class)
|
|
|
|
.put("splashpotion", SplashPotion.class)
|
|
|
|
.put("lingeringpotion", LingeringPotion.class);
|
2020-02-22 10:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_13_0_R01)) {
|
|
|
|
builder.put("trident", Trident.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
types = builder.build();
|
|
|
|
}
|
2019-08-05 15:12:22 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
public Commandfireball() {
|
|
|
|
super("fireball");
|
|
|
|
}
|
2011-06-23 12:14:24 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
@Override
|
|
|
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
2019-08-05 15:12:22 +00:00
|
|
|
String type = "fireball";
|
|
|
|
double speed = 2;
|
|
|
|
boolean ride = false;
|
|
|
|
|
|
|
|
if (args.length > 0 && types.containsKey(args[0])) {
|
|
|
|
type = args[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length > 1) {
|
|
|
|
try {
|
|
|
|
speed = FloatUtil.parseDouble(args[1]);
|
2019-08-05 18:56:25 +00:00
|
|
|
speed = Double.max(0, Double.min(speed, ess.getSettings().getMaxProjectileSpeed()));
|
2020-02-22 10:03:43 +00:00
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
2019-08-05 15:12:22 +00:00
|
|
|
}
|
|
|
|
|
2019-08-05 18:56:25 +00:00
|
|
|
if (args.length > 2 && args[2].equalsIgnoreCase("ride") && user.isAuthorized("essentials.fireball.ride")) {
|
2019-08-05 15:12:22 +00:00
|
|
|
ride = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!user.isAuthorized("essentials.fireball." + type)) {
|
|
|
|
throw new Exception(tl("noPerm", "essentials.fireball." + type));
|
2015-04-15 04:06:16 +00:00
|
|
|
}
|
2019-08-05 15:12:22 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
final Vector direction = user.getBase().getEyeLocation().getDirection().multiply(speed);
|
2020-02-22 10:03:43 +00:00
|
|
|
Projectile projectile = user.getWorld().spawn(user.getBase().getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), types.get(type));
|
2015-04-15 04:06:16 +00:00
|
|
|
projectile.setShooter(user.getBase());
|
|
|
|
projectile.setVelocity(direction);
|
2020-04-10 19:44:45 +00:00
|
|
|
projectile.setMetadata(FIREBALL_META_KEY, new FixedMetadataValue(ess, true));
|
2019-08-05 15:12:22 +00:00
|
|
|
|
|
|
|
if (ride) {
|
|
|
|
projectile.addPassenger(user.getBase());
|
|
|
|
}
|
2015-04-15 04:06:16 +00:00
|
|
|
}
|
2017-06-11 00:17:43 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
|
|
|
|
if (args.length == 1) {
|
2019-08-05 15:12:22 +00:00
|
|
|
return types.keySet().stream()
|
2020-02-22 10:03:43 +00:00
|
|
|
.filter(type -> user.isAuthorized("essentials.fireball." + type))
|
|
|
|
.collect(Collectors.toList());
|
2019-08-05 15:12:22 +00:00
|
|
|
} else if (args.length == 2) {
|
|
|
|
return Lists.newArrayList("1", "2", "3", "4", "5");
|
2017-06-11 00:17:43 +00:00
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
2011-06-23 12:14:24 +00:00
|
|
|
}
|