MCNSA / MCNSANotes-Bukkit

MCNSA Notes plugin for Spigot/Bukkit servers. Write notes on players and track statistics
0 stars 0 forks source link

Quote RedHulk: NOTES?!?!?! #6

Open k0nker opened 6 years ago

k0nker commented 6 years ago

https://pastebin.com/KR9BJKzz

Wheeee~

Here, I give my tabcompletion for kGizmo. Maybe if you have MCNSANotes parse through all players in the database that have a note and add it to the arraylist then return that?

package com.k0nker.kgizmo.tabcomplete;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.bukkit.entity.Player;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;

public class GiveWandTabComplete implements TabCompleter {
    public List<String> onTabComplete(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        List<String> options = new ArrayList<String>();
        List<String> newoptions = new ArrayList<String>();

        if (sender instanceof Player) {
            if (args.length == 1) {
                options.add("crafting");
                options.add("ender");
                options.add("trading");

                // Check text typed so far against available options and output any that may match
                for (String entered : options) {
                    if (entered.toLowerCase().startsWith(args[0].toLowerCase())){
                        newoptions.add(entered);
                    }
                }
                Collections.sort(newoptions);
                return newoptions;

                }

        }
        // Returns full list of options when nothing is entered.
        return options;
    }
}
maboughey commented 6 years ago

I wrote is specifically so that it preferred using the offline data of players over the database to reduce the amount of calls to the database while typing.. As it's designed for multiple server use, I thought that it would be a benefit to only show usernames that have joined that sever during command completion