Skip to content

Added tab complete. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/network/palace/show/ShowPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.craftmend.openaudiomc.spigot.OpenAudioMcSpigot;
import lombok.Getter;
import network.palace.show.commands.*;
import network.palace.show.commands.show.ShowTabComplete;
import network.palace.show.commands.showgen.ShowGenTabComplete;
import network.palace.show.generator.ShowGenerator;
import network.palace.show.listeners.ChunkListener;
import network.palace.show.listeners.PlayerInteract;
Expand Down Expand Up @@ -83,13 +85,16 @@ public void onEnable() {
openAudioMcSpigot = OpenAudioMcSpigot.getInstance();
FileUtil.setupFiles();
this.getCommand("show").setExecutor(new ShowCommand());
this.getCommand("show").setTabCompleter(new ShowTabComplete());

this.getCommand("showdebug").setExecutor(new ShowDebugCommand());

FileConfiguration config = this.getConfig();
this.saveDefaultConfig();
if (config.getString("github.token") != null) {
githubToken = config.getString("github.token");
this.getCommand("showgen").setExecutor(new ShowgenCommand());
this.getCommand("showgen").setTabCompleter(new ShowGenTabComplete());
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "[Show] Showgen has been enabled in show!");
} else {
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Show] Showgen will not be running in Show! To enable it, add a github token to the config!");
Expand Down
34 changes: 30 additions & 4 deletions src/main/java/network/palace/show/commands/ShowCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,64 @@ public class ShowCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) {
sender.sendMessage(ChatColor.GREEN + "Show Commands:");
sender.sendMessage(ChatColor.AQUA + "/show list " + ChatColor.GREEN + "- List all running shows");
sender.sendMessage(ChatColor.AQUA + "/show start [Show Name] " + ChatColor.GREEN + "- Start a show");
sender.sendMessage(ChatColor.AQUA + "/show stop [Show Name] " + ChatColor.GREEN + "- Stop a show");
sendHelpMsg(sender);
return true;
} else {
switch (args[0]) {
case "list":
new ListCommand().runList(sender);
break;
case "start":
if (sender instanceof Player) {
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "/show start <name>");
return true;
}
new StartCommand().handle(sender, args[1], ((Player) sender).getWorld());
} else if (sender instanceof BlockCommandSender) {
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "/show start <name>");
return true;
}
new StartCommand().handle(sender, args[1], ((BlockCommandSender) sender).getBlock().getWorld());
} else {
sender.sendMessage(ChatColor.RED + "You cannot run this from the console!");
}
break;
case "stop":
if (sender instanceof Player) {
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "/show stop <name>");
return true;
}
new StopCommand().handle(sender, args[1]);
} else if (sender instanceof CommandBlock) {
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "/show stop <name>");
return true;
}
new StopCommand().handle(sender, args[1]);
} else {
sender.sendMessage(ChatColor.RED + "You cannot run this from the console!");
}
break;
default:
sendHelpMsg(sender);
break;
}
}

return true;
}

/**
* Sends a help message to the player.
* @param sender Who to send it to.
*/
private void sendHelpMsg(CommandSender sender) {
sender.sendMessage(ChatColor.GREEN + "Show Commands:");
sender.sendMessage(ChatColor.AQUA + "/show list " + ChatColor.GREEN + "- List all running shows");
sender.sendMessage(ChatColor.AQUA + "/show start [Show Name] " + ChatColor.GREEN + "- Start a show");
sender.sendMessage(ChatColor.AQUA + "/show stop [Show Name] " + ChatColor.GREEN + "- Stop a show");
}
}
23 changes: 13 additions & 10 deletions src/main/java/network/palace/show/commands/ShowDebugCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ public class ShowDebugCommand implements CommandExecutor {

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Debug is always enabled for console!");
return true;
}

Player player = (Player) sender;

if (!ShowPlugin.debugMap.containsKey(player.getDisplayName())) {
ShowPlugin.debugMap.put(player.getDisplayName(), true);
player.sendMessage(ChatColor.AQUA + "[ShowDebug] - " + ChatColor.GREEN + "Enabled");
} else {
ShowPlugin.debugMap.remove(player.getDisplayName());
player.sendMessage(ChatColor.AQUA + "[ShowDebug] - " + ChatColor.RED + "Disabled");
}
if (!ShowPlugin.debugMap.containsKey(player.getDisplayName())) {
ShowPlugin.debugMap.put(player.getDisplayName(), true);
player.sendMessage(ChatColor.AQUA + "[ShowDebug] - " + ChatColor.GREEN + "Enabled");
} else {
ShowPlugin.debugMap.remove(player.getDisplayName());
player.sendMessage(ChatColor.AQUA + "[ShowDebug] - " + ChatColor.RED + "Disabled");
}
return false;
return true;
}
}
21 changes: 13 additions & 8 deletions src/main/java/network/palace/show/commands/ShowgenCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public class ShowgenCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 0) {
sender.sendMessage(ChatColor.GREEN + "ShowGen Commands:");
sender.sendMessage(ChatColor.AQUA + "/showgen generate [action] [bottom/top] [delay per layer] [timestamp]" + ChatColor.GREEN + "- Generate blocks of show actions with one command");
sender.sendMessage(ChatColor.AQUA + "/showgen setcorner x,y,z" + ChatColor.GREEN + "- Set the location of the final north-west-bottom corner to help give real coordinate values");
sender.sendMessage(ChatColor.AQUA + "/showgen setinitialscene " + ChatColor.GREEN + "- Set the initial scene for a generator session");
sendHelpMsg(sender);
return true;
}

Expand All @@ -40,12 +37,20 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
new SetInitialCommand().handle(sender);
break;
default:
sender.sendMessage(ChatColor.GREEN + "ShowGen Commands:");
sender.sendMessage(ChatColor.AQUA + "/showgen generate [action] [bottom/top] [delay per layer] [timestamp]" + ChatColor.GREEN + "- Generate blocks of show actions with one command");
sender.sendMessage(ChatColor.AQUA + "/showgen setcorner x,y,z" + ChatColor.GREEN + "- Set the location of the final north-west-bottom corner to help give real coordinate values");
sender.sendMessage(ChatColor.AQUA + "/showgen setinitialscene " + ChatColor.GREEN + "- Set the initial scene for a generator session");
sendHelpMsg(sender);
break;
}
return true;
}

/**
* Sends a help message to the player.
* @param sender Who to send it to.
*/
private void sendHelpMsg(CommandSender sender) {
sender.sendMessage(ChatColor.GREEN + "ShowGen Commands:");
sender.sendMessage(ChatColor.AQUA + "/showgen generate [action] [bottom/top] [delay per layer] [timestamp]" + ChatColor.GREEN + "- Generate blocks of show actions with one command");
sender.sendMessage(ChatColor.AQUA + "/showgen setcorner x,y,z" + ChatColor.GREEN + "- Set the location of the final north-west-bottom corner to help give real coordinate values");
sender.sendMessage(ChatColor.AQUA + "/showgen setinitialscene " + ChatColor.GREEN + "- Set the initial scene for a generator session");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package network.palace.show.commands.show;

import network.palace.show.ShowPlugin;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ShowTabComplete implements TabCompleter {

/*
Commands:

/show start <name>
/show stop <name>
/show list

/showgen generate <type> <time>
/showgen setinitialscene
/showgen setcorner <x,y,z>

/showdebug
*/

private static final String[] baseShowCmds = { "start", "stop", "list" };

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
final List<String> completions = new ArrayList<>();

// Return all subcommands if nothing has been typed
if (args.length == 0) {
completions.addAll(Arrays.asList(baseShowCmds));
return completions;
}

// Return applicable commands if started typing
if (args.length == 1) {
StringUtil.copyPartialMatches(args[0], Arrays.asList(baseShowCmds), completions);
return completions;
}

// Handle subcommand args
switch (args[0]) {
case "start": {
StringUtil.copyPartialMatches(args[1], Arrays.asList(getStoppedShows(((Player)sender).getWorld())), completions);
return completions;
}
case "stop": {
StringUtil.copyPartialMatches(args[1], ShowPlugin.getShows().keySet(), completions);
return completions;
}
}

// Everything else without args
return completions;
}

/**
* Gets all shows that arent currently running in the world.
* @param world What world
* @return The show names (minus .show)
*/
private String[] getStoppedShows(World world) {
File f = new File("plugins/Show/shows/" + world.getName());
String[] fileNames = f.list();
if (fileNames == null) return new String[]{};

ArrayList<String> names = new ArrayList<>(List.of(fileNames));

// Strip ".show"
ArrayList<String> tempNames = new ArrayList<>();
for (String name : names) {
tempNames.add(name.replaceAll(".show", ""));
}
names = tempNames;

// Remove running shows
for (String name : ShowPlugin.getShows().keySet()) names.remove(name);

return names.toArray(new String[0]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void handle(CommandSender sender, String filename, World world) {
return;
}
if (filename == null | filename.equals("")) {
sender.sendMessage(ChatColor.RED + "/show start [Show Name]");
sender.sendMessage(ChatColor.RED + "/show start <name>");
return;
}
if (ShowPlugin.getShows().containsKey(filename)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
public class StopCommand {

public void handle(CommandSender sender, String filename) {
if (filename == null | filename.equals("")) {
sender.sendMessage(ChatColor.RED + "/show stop [Show Name]");
return;
}
if (!ShowPlugin.getShows().containsKey(filename)) {
sender.sendMessage(ChatColor.RED + "----------------------------------------------");
sender.sendMessage(ChatColor.GOLD + filename + ChatColor.AQUA + " is not running!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,36 @@ public class SetCornerCommand {
public void handle(CommandSender sender, String[] args) {
Player player = (Player) sender;
if (args.length < 2) {
player.sendMessage(ChatColor.RED + "/showgen setcorner x,y,z");
player.sendMessage(ChatColor.RED + "/showgen setcorner <x> <y> <z>");
return;
}
String[] locData = args[1].split(",");
if (locData.length < 3) {
player.sendMessage(ChatColor.RED + "/showgen setcorner x,y,z");
return;

String[] locData;

if (args[1].contains(",")) { // Legacy coordinate format - showgen setcorner x,y,z
locData = args[1].split(",");
if (locData.length < 3) {
player.sendMessage(ChatColor.RED + "/showgen setcorner <x> <y> <z>");
return;
}

} else { // New format - showgen setcorner x y z
if (args.length != 4) {
player.sendMessage(ChatColor.RED + "/showgen setcorner <x> <y> <z>");
return;
}

locData = new String[]{args[1], args[2], args[3]};
}

try {
int x = Integer.parseInt(locData[0]);
int y = Integer.parseInt(locData[1]);
int z = Integer.parseInt(locData[2]);
int x = (int) Double.parseDouble(locData[0]);
int y = (int) Double.parseDouble(locData[1]);
int z = (int) Double.parseDouble(locData[2]);
World w = player.getWorld();
GeneratorSession session = ShowPlugin.getShowGenerator().getOrCreateSession(player.getUniqueId());
session.setCorner(new Location(w, x, y, z));
player.sendMessage(ChatColor.GREEN + "Set north-west-bottom corner to " + x + "," + y + "," + z + "!");
player.sendMessage(ChatColor.GREEN + "Set north-west-bottom corner to " + x + ", " + y + ", " + z + "!");
} catch (NumberFormatException e) {
player.sendMessage(ChatColor.RED + "Are you sure those are all numbers?");
}
Expand Down
Loading