TownyAdvanced / Towny

Towny Advanced Minecraft plugin for Bukkit/Spigot.
https://townyadvanced.github.io
Other
526 stars 352 forks source link

Suggestion: Removal of seemingly redundant lists #2169

Closed LlmDl closed 9 years ago

LlmDl commented 9 years ago

Originally reported on Google Code with ID 2146

Describe in detail what your suggestion is, *make sure you search ALL
issues,* do not submit something that has already been suggested:

This is in regards to towny safe mode, and the Method Two instructions on how to fix
it posted at http://code.google.com/a/eclipselabs.org/p/towny/wiki/Troubleshooting#Towny_locked_in_safe_mode

Towny Safemode reason: Worlds file getting messed up (seems to be most common on our
servers)

Step 1: compare all the towns in towns.txt with the towns in the messed up world file.

Step 2: for any town missing from towns.txt, if a townname.txt file exists, add the
world to towns.txt, else, remove the town from worldname.txt

Basically, if there IS a townname.txt file, it should be in BOTH worldfile.txt and
towns.txt. if there ISN'T a townname.txt file, it should be in NEITHER worldfile.txt
or towns.txt

So if the list of townname.txt files controls what should or shouldn't be in the towns.txt
list and the worldname.txt list, why not simply use the list of files?

Getting this list can easily be done by doing:

File dir = new File("Directory containing townname.txt files");
File[] files = dir.listFiles();
List<String> towns = new ArrayList<String>();

for(File f: files){
  String name = f.getName();
  towns.add(name.substring(0, name.length-4); //minus 4 to get rid of ".txt"
}

That code will get you the list of all towns that have a townname.txt file. I'm not
sure what the list in worldname.txt or the list in towns.txt actually do, but they
seem to break the server more often than they should.

Reported by xf57212@umbc.edu on 2014-08-26 17:17:19

LlmDl commented 9 years ago
at the very least, this can be used to auto check and correct the towns.txt and worldname.txt
files

Reported by xf57212@umbc.edu on 2014-08-26 17:19:23

LlmDl commented 9 years ago
This is more or less how Towny sql works. It isn't as safe to do in flatfile, Towny
should have a list of what it considers the towns to be. This is in case an admin puts
a townname.txt file into the towns folder which shouldn't be there. Or, a backup somehow
gets merged, adding files. 

If you're having underlying problems with data corruption on flatfile, it wouldn't
be very difficult to track down the cause. Join the Towny IRC if you want to go over
it.

http://webchat.esper.net/?channels=towny

Reported by LlmDlio on 2014-08-26 20:32:37