3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-25 18:40:05 +01:00

Implement getNameUnsafe method to allow an unloaded world's name to be accessed (#1712)

* Implement getNameUnsafe method to allow an unloaded world's name to be accessed
 - Fixes #1671 and #504

* Add javadoc since tag

Co-authored-by: Alexander Brandes <mc.cache@web.de>

Co-authored-by: Alexander Brandes <mc.cache@web.de>
Dieser Commit ist enthalten in:
Jordan 2022-05-05 20:39:45 +01:00 committet von GitHub
Ursprung c1b5f8c84a
Commit 210ee9f2ef
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
8 geänderte Dateien mit 63 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -15,4 +15,11 @@ public class WorldUnloadedException extends WorldEditException {
super(Caption.of("worldedit.error.world-unloaded")); super(Caption.of("worldedit.error.world-unloaded"));
} }
/**
* Create a new instance.
*/
public WorldUnloadedException(String name) {
super(Caption.of("worldedit.error.named-world-unloaded", name));
}
} }

Datei anzeigen

@ -193,19 +193,34 @@ public class BukkitWorld extends AbstractWorld {
* @return the world * @return the world
*/ */
protected World getWorldChecked() throws WorldEditException { protected World getWorldChecked() throws WorldEditException {
World world = worldRef.get(); World tmp = worldRef.get();
if (world == null) { if (tmp == null) {
throw new WorldUnloadedException(); tmp = Bukkit.getWorld(worldNameRef);
if (tmp != null) {
worldRef = new WeakReference<>(tmp);
} }
return world; }
if (tmp == null) {
throw new WorldUnloadedException(worldNameRef);
}
return tmp;
} }
//FAWE end //FAWE end
@Override @Override
public String getName() { public String getName() {
return getWorld().getName(); //FAWE start - Throw WorldUnloadedException rather than NPE when world unloaded and attempted to be accessed
return getWorldChecked().getName();
//FAWE end
} }
//FAWE start - allow history to read an unloaded world's name
@Override
public String getNameUnsafe() {
return worldNameRef;
}
//FAWE end
@Override @Override
public String getId() { public String getId() {
return getWorld().getName().replace(" ", "_").toLowerCase(Locale.ROOT); return getWorld().getName().replace(" ", "_").toLowerCase(Locale.ROOT);

Datei anzeigen

@ -76,6 +76,13 @@ public class ClipboardWorld extends AbstractWorld implements Clipboard, CLIWorld
return this.name; return this.name;
} }
//FAWE start - allow history to read an unloaded world's name
@Override
public String getNameUnsafe() {
return this.name;
}
//FAWE end
@Override @Override
public String getId() { public String getId() {
return getName().replace(" ", "_").toLowerCase(Locale.ROOT); return getName().replace(" ", "_").toLowerCase(Locale.ROOT);

Datei anzeigen

@ -198,6 +198,13 @@ public class WorldWrapper extends AbstractWorld {
return parent.getName(); return parent.getName();
} }
//FAWE start - allow history to read an unloaded world's name
@Override
public String getNameUnsafe() {
return parent.getNameUnsafe();
}
//FAWE end
@Override @Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws
WorldEditException { WorldEditException {

Datei anzeigen

@ -306,7 +306,8 @@ public class LocalSession implements TextureHolder {
} }
File file = MainUtil.getFile( File file = MainUtil.getFile(
Fawe.platform().getDirectory(), Fawe.platform().getDirectory(),
Settings.settings().PATHS.HISTORY + File.separator + world.getName() + File.separator + uuid + File.separator + "index" // Use "unsafe" method here as world does not need to be loaded to save this information.
Settings.settings().PATHS.HISTORY + File.separator + world.getNameUnsafe() + File.separator + uuid + File.separator + "index"
); );
if (getHistoryNegativeIndex() != 0) { if (getHistoryNegativeIndex() != 0) {
try { try {

Datei anzeigen

@ -69,6 +69,13 @@ public class NullWorld extends AbstractWorld {
return "null"; return "null";
} }
//FAWE start - allow history to read an unloaded world's name
@Override
public String getNameUnsafe() {
return "null";
}
//FAWE end
@Override @Override
public String getId() { public String getId() {
return "null"; return "null";

Datei anzeigen

@ -63,12 +63,23 @@ public interface World extends Extent, Keyed, IChunkCache<IChunkGet> {
//FAWE end //FAWE end
/** /**
* Get the name of the world. * Get the name of the world. This will error if world has been unloaded by the server.
* *
* @return a name for the world * @return a name for the world
*/ */
String getName(); String getName();
//FAWE start - allow history to read an unloaded world's name
/**
* Get the name of the world. If the world referenced has been unloaded, this will still return the name.
*
* @return a name for the world
* @since TODO
*/
String getNameUnsafe();
//FAWE end
/** /**
* Get the folder in which this world is stored. May return null if unknown * Get the folder in which this world is stored. May return null if unknown
* or if this world is not serialized to disk. * or if this world is not serialized to disk.

Datei anzeigen

@ -248,6 +248,7 @@
"worldedit.tool.error.cannot-bind": "Can't bind tool to {0}: {1}", "worldedit.tool.error.cannot-bind": "Can't bind tool to {0}: {1}",
"worldedit.error.file-aborted": "File selection aborted.", "worldedit.error.file-aborted": "File selection aborted.",
"worldedit.error.world-unloaded": "The world was unloaded already.", "worldedit.error.world-unloaded": "The world was unloaded already.",
"worldedit.error.named-world-unloaded": "The world '{0}' was unloaded already.",
"worldedit.error.blocks-cant-be-used": "Blocks can't be used", "worldedit.error.blocks-cant-be-used": "Blocks can't be used",
"worldedit.error.unknown-tag": "Tag name '{0}' was not recognized.", "worldedit.error.unknown-tag": "Tag name '{0}' was not recognized.",
"worldedit.error.empty-tag": "Tag name '{0}' has no contents.", "worldedit.error.empty-tag": "Tag name '{0}' has no contents.",