Solved Creating a list of players in a File

Discussion in 'Spigot Plugin Development' started by bengalman211, Jun 8, 2017.

  1. So far, I have created my file (Escaped.yml), and in a seperate method I'd like to add players to this list. How would I go about doing that. And also checking if a player is in the list, for loop?

    Creating file:
    Code (Text):
    private void createConfig() {
            try {
                if (!getDataFolder().exists()) {
                File file = new File(getDataFolder(), "escaped.yml");
                if (!file.exists()) {
                    getLogger().info("escaped.yml not found, creating!");
                } else {
                    getLogger().info("escaped.yml found, loading!");
            } catch (Exception e) {

  2. Assuming you mean an arraylist, you can
    Code (Text):
    YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
    and change it just as you would change the default config. So,
    Code (Text):
    List<UUID> list = new List<UUID>();
    yml.set("List", list);
  3. Do you have to do YAML? MySQL could be much more efficient depending on what you are making.
  4. The idea is to, when a "prisoner" leaves the worldguard region labeled "prison" it changes their nametag color to red. In theory could this work? Am I close?
  5. At a quick glare, it does look to be correct. Try it out! Trial and error!
  6. That wouldn't work. You would need to use event.getTo(), instead of p.getLocation(), and if the player is in any region (even if they are also in the prison region), the code would fire. Use the .contains() method on getApplicableRegions().
  7. I've updated this line
    Code (Text):
    for(ProtectedRegion r : WGBukkit.getRegionManager(p.getWorld()).getApplicableRegions(e.getTo()).contains("prison")) {
    However on contains I get the following:
    Code (Text):
    The method contains(String) is undefined for the type ApplicableRegionSet
    -- I think this is because I need to use a region variable instead of a String, but how would I define the region and set its name?

    I've also been getting another error on the entire part of the worldguard code and i'm not too sure what to do about it:
    Code (Text):
    The type com.sk89q.worldedit.Vector cannot be resolved. It is indirectly referenced from required .class files
    I have referenced worldguard.

    I have fixed the dependency error by making worldedit a dependency, but can someone explain why that line of code calls for worldedit? Is getRegionManager only a worldedit thing? Thanks.

    Solved by checking if a region contains player vector.
    #7 bengalman211, Jun 8, 2017
    Last edited: Jun 8, 2017