Added name to UUID conversion
This commit is contained in:
parent
362d1d823c
commit
ecaecd4136
1 changed files with 23 additions and 10 deletions
|
@ -43,7 +43,7 @@ public class InvYamlStorage extends InvConfStorage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(Inventory pinv, Target target) {
|
public void load(Inventory pinv, Target target) {
|
||||||
load(pinv, YamlConfiguration.loadConfiguration(getFile(pinv, target)));
|
load(pinv, YamlConfiguration.loadConfiguration(getFile(pinv, target, false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,7 +52,11 @@ public class InvYamlStorage extends InvConfStorage {
|
||||||
yml.options().header("DO NOT MODIFY THIS FILE");
|
yml.options().header("DO NOT MODIFY THIS FILE");
|
||||||
store(pinv, yml);
|
store(pinv, yml);
|
||||||
try {
|
try {
|
||||||
yml.save(getFile(pinv, target));
|
File nameFile=getFile(pinv, target, false);
|
||||||
|
File uuidFile=getFile(pinv, target, true);
|
||||||
|
if(!nameFile.equals(uuidFile)) //It'd be recreated right after, still, don't remove if the same
|
||||||
|
nameFile.delete(); //Delete file with name so it doesn't get loaded again
|
||||||
|
yml.save(uuidFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
mod.getLog().warn("Failed to save Inventory for Player " + pinv.getPlayer().getName());
|
mod.getLog().warn("Failed to save Inventory for Player " + pinv.getPlayer().getName());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -61,19 +65,28 @@ public class InvYamlStorage extends InvConfStorage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(Inventory pinv, Target target) {
|
public void remove(Inventory pinv, Target target) {
|
||||||
getFile(pinv, target).delete();
|
getFile(pinv, target, true).delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Inventory pinv, Target target) {
|
public boolean contains(Inventory pinv, Target target) {
|
||||||
return getFile(pinv, target).exists();
|
return getFile(pinv, target, false).exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected File getFile(Inventory pinv, Target target) {
|
protected File getFile(Inventory pinv, Target target, boolean uuidonly) {
|
||||||
if (target != default_target) {
|
File file;
|
||||||
return new File(dir, pinv.getPlayer().getUniqueId() + "_" + target.toString().toLowerCase() + SUFFIX);
|
String player;
|
||||||
} else {
|
do {
|
||||||
return new File(dir, pinv.getPlayer().getUniqueId() + SUFFIX);
|
player = uuidonly ? pinv.getPlayer().getUniqueId().toString() : pinv.getPlayer().getName();
|
||||||
}
|
if (target != default_target) {
|
||||||
|
file = new File(dir, player + "_" + target.toString().toLowerCase() + SUFFIX);
|
||||||
|
} else {
|
||||||
|
file = new File(dir, player + SUFFIX);
|
||||||
|
}
|
||||||
|
if(uuidonly)
|
||||||
|
return file; //Use file with UUID, even if doesn't exist
|
||||||
|
uuidonly = true; //Run again with UUID, then return...
|
||||||
|
} while(!file.exists()); //...if the file with name is not found
|
||||||
|
return file; //Found file with player name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue