Skip to content

Commit

Permalink
Move EditSession closure into exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal committed Sep 12, 2024
1 parent 4e7abf5 commit e07633c
Showing 1 changed file with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,33 @@ public void handleCommand(CommandEvent event) {
// exceptions without writing a hook into every dispatcher, we need to unwrap these
// exceptions and rethrow their converted form, if their is one.
try {
commandManager.execute(context, ImmutableList.copyOf(split));
try {
commandManager.execute(context, ImmutableList.copyOf(split));
} finally {
Optional<EditSession> editSessionOpt =
context.snapshotMemory().injectedValue(Key.of(EditSession.class));

if (editSessionOpt.isPresent()) {
EditSession editSession = editSessionOpt.get();
session.remember(editSession);
editSession.close();

if (config.profile) {
long time = System.currentTimeMillis() - start;
double timeS = (time / 1000.0);
int changed = editSession.getBlockChangeCount();
double throughput = timeS == 0 ? changed : changed / timeS;
actor.printDebug(TranslatableComponent.of(
"worldedit.command.time-elapsed",
TextComponent.of(timeS),
TextComponent.of(changed),
TextComponent.of(Math.round(throughput))
));
}

worldEdit.flushBlockBag(actor, editSession);
}
}
} catch (Throwable t) {
// Use the exception converter to convert the exception if any of its causes
// can be converted, otherwise throw the original exception
Expand Down Expand Up @@ -540,29 +566,6 @@ public void handleCommand(CommandEvent event) {
} catch (Throwable t) {
handleUnknownException(actor, t);
} finally {
Optional<EditSession> editSessionOpt =
context.snapshotMemory().injectedValue(Key.of(EditSession.class));

if (editSessionOpt.isPresent()) {
EditSession editSession = editSessionOpt.get();
session.remember(editSession);
editSession.close();

if (config.profile) {
long time = System.currentTimeMillis() - start;
double timeS = (time / 1000.0);
int changed = editSession.getBlockChangeCount();
double throughput = timeS == 0 ? changed : changed / timeS;
actor.printDebug(TranslatableComponent.of(
"worldedit.command.time-elapsed",
TextComponent.of(timeS),
TextComponent.of(changed),
TextComponent.of(Math.round(throughput))
));
}

worldEdit.flushBlockBag(actor, editSession);
}
Request.reset();
}

Expand Down

0 comments on commit e07633c

Please sign in to comment.