Skip to content

Commit

Permalink
allow console to run commands
Browse files Browse the repository at this point in the history
  • Loading branch information
steve4744 committed Feb 17, 2019
1 parent 69589bf commit 04823c6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 67 deletions.
4 changes: 2 additions & 2 deletions src/io/steve4744/LaunchPlate/LaunchPlate.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ of this software and associated documentation files (the "Software"), to deal
import io.steve4744.LaunchPlate.Metrics.Metrics;

public class LaunchPlate extends JavaPlugin implements Listener {

private String version;
private Settings settings;
private static LaunchPlate instance;

@Override
public void onEnable() {

Expand Down
120 changes: 55 additions & 65 deletions src/io/steve4744/LaunchPlate/LaunchPlateCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,92 +33,94 @@ of this software and associated documentation files (the "Software"), to deal
import org.bukkit.entity.Player;

public class LaunchPlateCommands implements CommandExecutor {

private final LaunchPlate plugin;
private final String version;

public LaunchPlateCommands(LaunchPlate plugin, String version) {
this.plugin = plugin;
this.version = version;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("launchplate")) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (sender instanceof Player || sender instanceof ConsoleCommandSender) {

if (args.length == 0) {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Version " + version + " : plugin by "+ ChatColor.AQUA + "steve4744");
if (args.length == 0 || args[0].equalsIgnoreCase("info")) {
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Version " + version + " : plugin by "+ ChatColor.AQUA + "steve4744");
return false;

} else if(args[0].equalsIgnoreCase("list")) {
player.sendMessage(ChatColor.YELLOW + "===============" + ChatColor.GREEN + " LaunchPlate " + ChatColor.YELLOW + "===============");
player.sendMessage(ChatColor.GREEN + "\nBase block material : " + ChatColor.WHITE + plugin.getSettings().getLaunchBlock());
player.sendMessage(ChatColor.GREEN + "Pressure plate type : " + ChatColor.WHITE + plugin.getSettings().getPlate());
player.sendMessage(ChatColor.GREEN + "Launch sound effect : " + ChatColor.WHITE + plugin.getSettings().getSound());
player.sendMessage(ChatColor.GREEN + "Launch particle effect : " + ChatColor.WHITE + plugin.getSettings().getParticle());
player.sendMessage(ChatColor.GREEN + "Upward force applied : " + ChatColor.WHITE + plugin.getSettings().getForce());
player.sendMessage(ChatColor.YELLOW + "\n===============" + ChatColor.GREEN + " LaunchPlate " + ChatColor.YELLOW + "===============");
sender.sendMessage(ChatColor.YELLOW + "===============" + ChatColor.GREEN + " LaunchPlate " + ChatColor.YELLOW + "===============");
sender.sendMessage(ChatColor.GREEN + "Base block material : " + ChatColor.WHITE + plugin.getSettings().getLaunchBlock());
sender.sendMessage(ChatColor.GREEN + "Pressure plate type : " + ChatColor.WHITE + plugin.getSettings().getPlate());
sender.sendMessage(ChatColor.GREEN + "Launch sound effect : " + ChatColor.WHITE + plugin.getSettings().getSound());
sender.sendMessage(ChatColor.GREEN + "Launch particle effect : " + ChatColor.WHITE + plugin.getSettings().getParticle());
sender.sendMessage(ChatColor.GREEN + "Upward force applied : " + ChatColor.WHITE + plugin.getSettings().getForce());
sender.sendMessage(ChatColor.YELLOW + "===============" + ChatColor.GREEN + " LaunchPlate " + ChatColor.YELLOW + "===============");
return false;

} else if(args[0].equalsIgnoreCase("help")) {
player.sendMessage(ChatColor.YELLOW + "===============" + ChatColor.GREEN + " LaunchPlate " + ChatColor.YELLOW + "===============");
player.sendMessage(ChatColor.GREEN + "\n/lp setblock" + ChatColor.YELLOW + " (Material) " + ChatColor.WHITE + "- set the Material for the base block");
player.sendMessage(ChatColor.GREEN + "/lp setplate" + ChatColor.YELLOW + " (Material) " + ChatColor.WHITE + "- set the pressure plate Material");
player.sendMessage(ChatColor.GREEN + "/lp setsound" + ChatColor.YELLOW + " (Sound) " + ChatColor.WHITE + "- set a launch sound effect");
player.sendMessage(ChatColor.GREEN + "/lp settrail" + ChatColor.YELLOW + " (Particle) " + ChatColor.WHITE + "- set a launch particle effect");
player.sendMessage(ChatColor.GREEN + "/lp setforce" + ChatColor.YELLOW + " (Force) " + ChatColor.WHITE + "- force determines height of bounce");
player.sendMessage(ChatColor.GREEN + "/lp list " + ChatColor.WHITE + "- list the current LaunchPlate setttings");
player.sendMessage(ChatColor.GREEN + "/lp reload " + ChatColor.WHITE + "- reload the LaunchPlate config");
player.sendMessage(ChatColor.GREEN + "/lp help " + ChatColor.WHITE + "- display this command help screen");
//player.sendMessage(ChatColor.YELLOW + "\n===============" + ChatColor.GREEN + " LaunchPlate " + ChatColor.YELLOW + "===============");
String cmd = "/lp";
if (sender instanceof ConsoleCommandSender) {
cmd = "lp";
}
sender.sendMessage(ChatColor.YELLOW + "===============" + ChatColor.GREEN + " LaunchPlate " + ChatColor.YELLOW + "===============");
sender.sendMessage(ChatColor.GREEN + cmd + " setblock" + ChatColor.YELLOW + " (Material) " + ChatColor.WHITE + "- set the Material for the base block");
sender.sendMessage(ChatColor.GREEN + cmd + " setplate" + ChatColor.YELLOW + " (Material) " + ChatColor.WHITE + "- set the pressure plate Material");
sender.sendMessage(ChatColor.GREEN + cmd + " setsound" + ChatColor.YELLOW + " (Sound) " + ChatColor.WHITE + "- set a launch sound effect");
sender.sendMessage(ChatColor.GREEN + cmd + " settrail" + ChatColor.YELLOW + " (Particle) " + ChatColor.WHITE + "- set a launch particle effect");
sender.sendMessage(ChatColor.GREEN + cmd + " setforce" + ChatColor.YELLOW + " (Force) " + ChatColor.WHITE + "- force determines height of bounce");
sender.sendMessage(ChatColor.GREEN + cmd + " list " + ChatColor.WHITE + "- list the current LaunchPlate setttings");
sender.sendMessage(ChatColor.GREEN + cmd + " reload " + ChatColor.WHITE + "- reload the LaunchPlate config");
sender.sendMessage(ChatColor.GREEN + cmd + " help " + ChatColor.WHITE + "- display this command help screen");
return false;
}
if (!player.hasPermission("launchplate.admin")) {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Permission required to run commands: " + ChatColor.AQUA + "launchplate.admin");
if (!sender.hasPermission("launchplate.admin")) {
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Permission required to run commands: " + ChatColor.AQUA + "launchplate.admin");
return false;
}

if (args[0].equalsIgnoreCase("reload")) {
plugin.reloadConfig();
plugin.refreshSettings();
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Config Reloaded");
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Config Reloaded");

} else if (args[0].equalsIgnoreCase("setsound")) {
if (args.length >= 2) {
if (plugin.getSettings().setSound(args[1].toUpperCase())) {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Sound effect added");
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Sound effect added");
} else {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Invalid sound: " + ChatColor.RED + args[1]);
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Invalid sound: " + ChatColor.RED + args[1]);
}
} else {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "No sound specified");
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "No sound specified");
}

} else if (args[0].equalsIgnoreCase("settrail")) {
if (args.length >= 2) {
if (plugin.getSettings().setParticle(args[1].toUpperCase())) {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Particle effect added");
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Particle effect added");
} else {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Invalid particle effect: " + ChatColor.RED + args[1]);
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Invalid particle effect: " + ChatColor.RED + args[1]);
}
} else {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "No particle effect specified");
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "No particle effect specified");
}

} else if (args[0].equalsIgnoreCase("setBlock")) {
if (args.length >= 2) {
if (Material.getMaterial(args[1].toUpperCase()) != null) {
plugin.getSettings().setMaterial(args[1].toUpperCase());
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Block material set to " + ChatColor.AQUA + args[1].toUpperCase());
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Block material set to " + ChatColor.AQUA + args[1].toUpperCase());
} else {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Invalid block material: " + ChatColor.RED + args[1]);
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Invalid block material: " + ChatColor.RED + args[1]);
}
} else {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "No block material specified");
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "No block material specified");
}

} else if (args[0].equalsIgnoreCase("setPlate")) {
if (args.length >= 2) {
String plateMaterial;
Expand All @@ -132,44 +134,32 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
Material plate = Material.getMaterial(plateMaterial.toUpperCase());
if (plugin.getSettings().isValid(plate)) {
plugin.getSettings().setPlate(plateMaterial.toUpperCase());
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Plate material set to " + ChatColor.AQUA + args[1].toUpperCase());
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Plate material set to " + ChatColor.AQUA + args[1].toUpperCase());
} else {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Invalid plate material: " + ChatColor.RED + args[1]);
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Invalid plate material: " + ChatColor.RED + args[1]);
}
} else {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "No plate material specified");
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "No plate material specified");
}

} else if (args[0].equalsIgnoreCase("setForce")) {
if (args.length >= 2) {
if (plugin.getSettings().isDouble(args[1])) {
plugin.getSettings().setForce(Double.valueOf(args[1]));
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Force set to " + ChatColor.AQUA + args[1]);
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Force set to " + ChatColor.AQUA + args[1]);
} else {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Invalid force: " + ChatColor.RED + args[1]);
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Invalid force: " + ChatColor.RED + args[1]);
}
} else {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "No value specified for force");
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "No value specified for force");
}

} else {
player.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Invalid argument - run " + ChatColor.GREEN + "/lp help " + ChatColor.WHITE + "for more information");
sender.sendMessage(ChatColor.GREEN + "[LaunchPlate] " + ChatColor.WHITE + "Invalid argument - run " + ChatColor.GREEN + "/lp help " + ChatColor.WHITE + "for more information");
}

} else {
if (sender instanceof ConsoleCommandSender) {
if (args.length >= 1) {
if (args[0].equalsIgnoreCase("reload")) {
plugin.reloadConfig();
plugin.refreshSettings();
plugin.getLogger().info("Config Reloaded");
} else {
plugin.getLogger().info("Invalid argument - only 'reload' is supported at this time");
}
} else {
plugin.getLogger().info("Version " + version + " : plugin by steve4744");
}
}
plugin.getLogger().info("Version " + version + " : plugin by steve4744");
}
}
return false;
Expand Down

0 comments on commit 04823c6

Please sign in to comment.