You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
4.8 KiB
99 lines
4.8 KiB
package net.mcbat.LightningEvent.Commands;
|
|
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.command.ConsoleCommandSender;
|
|
|
|
import net.mcbat.LightningEvent.LightningEvent;
|
|
|
|
public class CommandCast {
|
|
private final LightningEvent _plugin;
|
|
|
|
private final SubcommandFake _fake;
|
|
private final SubcommandReal _real;
|
|
|
|
public CommandCast(LightningEvent plugin) {
|
|
_plugin = plugin;
|
|
_fake = new SubcommandFake(plugin, this);
|
|
_real = new SubcommandReal(plugin, this);
|
|
}
|
|
|
|
public boolean checkPlayer(String p) {
|
|
return (_plugin.getServer().getPlayer(p) != null);
|
|
}
|
|
|
|
public boolean checkWorld(String w) {
|
|
return (_plugin.getServer().getWorld(w) != null);
|
|
}
|
|
|
|
public boolean checkLocation(String x, String y, String z) {
|
|
return (x.matches("[-]?[0-9]+") && y.matches("[-]?[0-9]+") && z.matches("[-]?[0-9]+"));
|
|
}
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
if (sender instanceof ConsoleCommandSender) {
|
|
if (args.length >= 1 && args[0].equalsIgnoreCase("fake"))
|
|
return _fake.onConsoleCommand(sender, command, label, args);
|
|
else if (args.length >= 1 && args[0].equalsIgnoreCase("real"))
|
|
return _real.onConsoleCommand(sender, command, label, args);
|
|
else
|
|
return commandUsage(sender, label, false);
|
|
}
|
|
else {
|
|
if (args.length >= 1 && args[0].equalsIgnoreCase("fake")) {
|
|
if (!sender.hasPermission("lightningevent.commands.cast.fake"))
|
|
return noAccess(sender);
|
|
|
|
return _fake.onPlayerCommand(sender, command, label, args);
|
|
}
|
|
else if (args.length >= 1 && args[0].equalsIgnoreCase("real")) {
|
|
if (!sender.hasPermission("lightningevent.commands.cast.real"))
|
|
return noAccess(sender);
|
|
|
|
return _real.onPlayerCommand(sender, command, label, args);
|
|
}
|
|
else
|
|
return commandUsage(sender, label, true);
|
|
}
|
|
}
|
|
|
|
private boolean noAccess(CommandSender sender) {
|
|
sender.sendMessage(ChatColor.DARK_RED+"You do not have access to that command.");
|
|
return true;
|
|
}
|
|
|
|
private boolean commandUsage(CommandSender sender, String label, boolean isPlayer) {
|
|
if (!isPlayer) {
|
|
sender.sendMessage(ChatColor.RED+"[==== "+ChatColor.GREEN+"/"+label+ChatColor.RED+" ====]");
|
|
sender.sendMessage(ChatColor.GREEN+"/"+label+" fake "+ChatColor.LIGHT_PURPLE+"<world> <x> <y> <z>"+ChatColor.GREEN+" - "+ChatColor.WHITE+"Casts a fake lightning bolt.");
|
|
sender.sendMessage(ChatColor.GREEN+"/"+label+" fake "+ChatColor.LIGHT_PURPLE+"<player>"+ChatColor.GREEN+" - "+ChatColor.WHITE+"Casts a lightning bolt on a player.");
|
|
sender.sendMessage(ChatColor.GREEN+"/"+label+" real "+ChatColor.LIGHT_PURPLE+"<world> <x> <y> <z>"+ChatColor.GREEN+" - "+ChatColor.WHITE+"Casts a lightning bolt.");
|
|
sender.sendMessage(ChatColor.GREEN+"/"+label+" real "+ChatColor.LIGHT_PURPLE+"<player>"+ChatColor.GREEN+" - "+ChatColor.WHITE+"Casts a lightning bolt on a player.");
|
|
return true;
|
|
}
|
|
else {
|
|
if (sender.hasPermission("lightningevent.commands.cast.fake") || sender.hasPermission("lightningevent.commands.cast.real")) {
|
|
sender.sendMessage(ChatColor.RED+"[==== "+ChatColor.GREEN+"/"+label+ChatColor.RED+" ====]");
|
|
|
|
if (sender.hasPermission("lightningevent.commmands.cast.fake")) {
|
|
sender.sendMessage(ChatColor.GREEN+"/"+label+" fake "+ChatColor.LIGHT_PURPLE+"<world> <x> <y> <z>"+ChatColor.GREEN+" - "+ChatColor.WHITE+"Casts a fake lightning bolt in the specified world and location.");
|
|
sender.sendMessage(ChatColor.GREEN+"/"+label+" fake "+ChatColor.LIGHT_PURPLE+"<x> <y> <z>"+ChatColor.GREEN+" - "+ChatColor.WHITE+"Casts a fake lightning bolt in the current world at the specified location.");
|
|
sender.sendMessage(ChatColor.GREEN+"/"+label+" fake "+ChatColor.LIGHT_PURPLE+"<player>"+ChatColor.GREEN+" - "+ChatColor.WHITE+"Casts a fake lightning bolt on a player.");
|
|
sender.sendMessage(ChatColor.GREEN+"/"+label+" fake "+ChatColor.GREEN+" - "+ChatColor.WHITE+"Casts a fake lightning bolt where you are looking.");
|
|
}
|
|
|
|
if (sender.hasPermission("lightningevent.commands.cast.real")) {
|
|
sender.sendMessage(ChatColor.GREEN+"/"+label+" real "+ChatColor.LIGHT_PURPLE+"<world> <x> <y> <z>"+ChatColor.GREEN+" - "+ChatColor.WHITE+"Casts a lightning bolt in the specified world and location.");
|
|
sender.sendMessage(ChatColor.GREEN+"/"+label+" real "+ChatColor.LIGHT_PURPLE+"<x> <y> <z>"+ChatColor.GREEN+" - "+ChatColor.WHITE+"Casts a lightning bolt in the current world at the specified location.");
|
|
sender.sendMessage(ChatColor.GREEN+"/"+label+" real "+ChatColor.LIGHT_PURPLE+"<player>"+ChatColor.GREEN+" - "+ChatColor.WHITE+"Casts a lightning bolt on a player.");
|
|
sender.sendMessage(ChatColor.GREEN+"/"+label+" real "+ChatColor.GREEN+" - "+ChatColor.WHITE+"Casts a lightning bolt where you are looking.");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
else
|
|
return noAccess(sender);
|
|
}
|
|
}
|
|
}
|
|
|