Solved Print filenames in plugin directory/make them clickable

Discussion in 'Plugin Development' started by Alias_Me, Jan 18, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    Alias_Me

    So I currently have a waypoint plugin in production, and when a player right-clicks a sign the chat is supposed to print the name of every waypoint currently build.
    Every waypoint has its own file in the plugin folder, so how would I go about printing the file names?
    Also how do I make them clickable? (the waypoint file contains a location the player is then supposed to be teleported to)
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Alias_Me Find the files, trim the path away from it.
     
  3. Offline

    KarimAKL

    Last edited by a moderator: Jan 18, 2019
  4. Offline

    Alias_Me

    @KarimAKL Ok but what I dont get is how to print all waypoints, like there are theoretically an indefinite amount of waypoints/files, so how would i print the correct amount of file names?
     
  5. Offline

    KarimAKL

    @Alias_Me Get the folder with all the waypoints and then loop all the files in there.
    Example:
    Code:Java
    1. List<String> waypoints = new ArrayList<String>();
    2. File folderWithWaypoints = new File("Path/To/Folder");
    3. for (File waypoint : folderWithWaypoints.listFiles()) {
    4. if (waypoint.isFile()) {
    5. //Remember this also has the file extension, you can remove that with
    6. //waypoint.getName().substring(0, waypoint.getName().length - fileExtension.length)
    7. //You can know the file extension length by knowing the file type you are looking for
    8. waypoints.add(waypoint.getName());
    9. }
    10. }
    11. //Now you have the 'waypoints' list with all the names
    12. //You can then do something like this
    13. for (String waypoint : waypoints) {
    14. player.sendMessage(waypoint);
    15. }
    16. //That should send the player all waypoints
     
Thread Status:
Not open for further replies.

Share This Page