forked from PalaceInteractiveArchive/Show
-
Notifications
You must be signed in to change notification settings - Fork 3
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
KyGuy2002
wants to merge
6
commits into
CubitsDev:staging
Choose a base branch
from
KyGuy2002:feature/tab-complete
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1dbf377
Added tab complete
KyGuy2002 c51aa55
Finished tab completions, added default help messages
KyGuy2002 bd84c95
changed return value so usage isnt sent to player every time.
KyGuy2002 0901073
Revert "changed return value so usage isnt sent to player every time."
KyGuy2002 6400888
Removed duplicate filename check
KyGuy2002 1d5b6f1
Only loads show names for tab completion on startup.
KyGuy2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/network/palace/show/commands/show/ShowTabComplete.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
KyGuy2002 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
File f = new File("plugins/Show/shows/" + world.getName()); | ||
String[] fileNames = f.list(); | ||
KyGuy2002 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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]); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.