mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 09:08:01 +01:00
Add per-projectile permissions and speed argument to /fireball
This commit is contained in:
parent
60c4e75a1c
commit
ff9f712d65
@ -1,6 +1,8 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.FloatUtil;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.*;
|
||||
@ -8,50 +10,72 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
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();
|
||||
|
||||
public Commandfireball() {
|
||||
super("fireball");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
Class<? extends Entity> type = Fireball.class;
|
||||
Projectile projectile;
|
||||
int speed = 2;
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("small")) {
|
||||
type = SmallFireball.class;
|
||||
} else if (args[0].equalsIgnoreCase("arrow")) {
|
||||
type = Arrow.class;
|
||||
} else if (args[0].equalsIgnoreCase("skull")) {
|
||||
type = WitherSkull.class;
|
||||
} else if (args[0].equalsIgnoreCase("egg")) {
|
||||
type = Egg.class;
|
||||
} else if (args[0].equalsIgnoreCase("snowball")) {
|
||||
type = Snowball.class;
|
||||
} else if (args[0].equalsIgnoreCase("expbottle")) {
|
||||
type = ThrownExpBottle.class;
|
||||
} else if (args[0].equalsIgnoreCase("large")) {
|
||||
type = LargeFireball.class;
|
||||
} else if (args[0].equalsIgnoreCase("splashpotion")) {
|
||||
type = SplashPotion.class;
|
||||
} else if (args[0].equalsIgnoreCase("lingeringpotion")) {
|
||||
type = LingeringPotion.class;
|
||||
} else if (args[0].equalsIgnoreCase("dragon")) {
|
||||
type = DragonFireball.class;
|
||||
}
|
||||
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]);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
if (args.length > 2 && args[2].equalsIgnoreCase("ride")) {
|
||||
ride = true;
|
||||
}
|
||||
|
||||
if (!user.isAuthorized("essentials.fireball." + type)) {
|
||||
throw new Exception(tl("noPerm", "essentials.fireball." + type));
|
||||
}
|
||||
|
||||
final Vector direction = user.getBase().getEyeLocation().getDirection().multiply(speed);
|
||||
projectile = (Projectile) user.getWorld().spawn(user.getBase().getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), type);
|
||||
Projectile 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);
|
||||
|
||||
if (ride) {
|
||||
projectile.addPassenger(user.getBase());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
|
||||
if (args.length == 1) {
|
||||
return Lists.newArrayList("small", "arrow", "skull", "egg", "snowball", "expbottle", "large", "splashpotion", "lingeringpotion", "dragon");
|
||||
return types.keySet().stream()
|
||||
.filter(type -> user.isAuthorized("essentials.fireball." + type))
|
||||
.collect(Collectors.toList());
|
||||
} else if (args.length == 2) {
|
||||
return Lists.newArrayList("1", "2", "3", "4", "5");
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ commands:
|
||||
aliases: [efly]
|
||||
fireball:
|
||||
description: Throw a fireball.
|
||||
usage: /<command> [small|skull]
|
||||
usage: /<command> [small|large|dragon|arrow|skull|egg|snowball|expbottle|splashpotion|lingeringpotion] [speed]
|
||||
aliases: [efireball,fireentity,efireentity,fireskull,efireskull]
|
||||
firework:
|
||||
description: Allows you to modify a stack of fireworks.
|
||||
|
Loading…
Reference in New Issue
Block a user