Skip to content

Commit e55e8fa

Browse files
authored
feat: improve error handling for state property operations (#2975)
1 parent 7281fa3 commit e55e8fa

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.sk89q.worldedit.extent.Extent;
3535
import com.sk89q.worldedit.function.mask.Mask;
3636
import com.sk89q.worldedit.internal.cui.CUIEvent;
37+
import com.sk89q.worldedit.internal.util.LogManagerCompat;
3738
import com.sk89q.worldedit.math.BlockVector3;
3839
import com.sk89q.worldedit.math.Vector3;
3940
import com.sk89q.worldedit.regions.ConvexPolyhedralRegion;
@@ -62,6 +63,7 @@
6263
import com.sk89q.worldedit.world.gamemode.GameModes;
6364
import com.sk89q.worldedit.world.item.ItemType;
6465
import com.sk89q.worldedit.world.item.ItemTypes;
66+
import org.apache.logging.log4j.Logger;
6567

6668
import javax.annotation.Nullable;
6769
import java.io.File;
@@ -76,6 +78,8 @@
7678
*/
7779
public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
7880

81+
private static final Logger LOGGER = LogManagerCompat.getLogger();
82+
7983
//FAWE start
8084
private final Map<String, Object> meta;
8185

@@ -93,7 +97,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
9397
if (fe != null) {
9498
printError(fe.getComponent());
9599
} else {
96-
throwable.printStackTrace();
100+
LOGGER.error("Error occurred executing player action", throwable);
97101
}
98102
}
99103
}, this::getUniqueId);

worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,7 @@ public World getWorldForEditing(World base) {
273273
public <T extends Actor> T createProxyActor(T base) {
274274
checkNotNull(base);
275275

276-
if (base instanceof Player) {
277-
Player player = (Player) base;
278-
276+
if (base instanceof Player player) {
279277
Player permActor = queryCapability(Capability.PERMISSIONS).matchPlayer(player);
280278
if (permActor == null) {
281279
permActor = player;
@@ -389,10 +387,9 @@ public void handleBlockInteract(BlockInteractEvent event) {
389387
Location location = event.getLocation();
390388

391389
// At this time, only handle interaction from players
392-
if (!(actor instanceof Player)) {
390+
if (!(actor instanceof Player player)) {
393391
return;
394392
}
395-
Player player = (Player) actor;
396393
LocalSession session = worldEdit.getSessionManager().get(actor);
397394

398395
Request.reset();
@@ -463,7 +460,7 @@ public void handleThrowable(Throwable e, Actor actor) {
463460
} else {
464461
actor.print(Caption.of("worldedit.command.error.report"));
465462
actor.print(TextComponent.of(e.getClass().getName()+ ": " + e.getMessage()));
466-
e.printStackTrace();
463+
LOGGER.error("Error occurred executing player action", e);
467464
}
468465
}
469466
//FAWE end
@@ -511,14 +508,7 @@ public void handlePlayerInput(PlayerInputEvent event) {
511508
}
512509
//FAWE start - add own message
513510
} catch (Throwable e) {
514-
FaweException faweException = FaweException.get(e);
515-
if (faweException != null) {
516-
player.print(Caption.of("fawe.cancel.reason", faweException.getComponent()));
517-
} else {
518-
player.print(Caption.of("worldedit.command.error.report"));
519-
player.print(TextComponent.of(e.getClass().getName() + ": " + e.getMessage()));
520-
e.printStackTrace();
521-
}
511+
handleThrowable(e, player);
522512
//FAWE end
523513
} finally {
524514
Request.reset();

worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ public <V> BlockState with(final Property<V> property, final V value) {
312312
return newState != this.getInternalId() ? type.withStateId(newState) : this;
313313
} catch (ClassCastException e) {
314314
throw new IllegalArgumentException("Property not found: " + property);
315+
} catch (Exception e) {
316+
throw new UnsupportedOperationException(
317+
"Error resolving property " + property.getName() + " for block type " + getBlockType().id() + "(nullable) value " + value,
318+
e
319+
);
315320
}
316321
}
317322

@@ -322,6 +327,11 @@ public <V> V getState(final Property<V> property) {
322327
return (V) ap.getValue(this.getInternalId());
323328
} catch (ClassCastException e) {
324329
throw new IllegalArgumentException("Property not found: " + property);
330+
} catch (Exception e) {
331+
throw new UnsupportedOperationException(
332+
"Error resolving property " + property.getName() + " for blocktype " + getBlockType().id(),
333+
e
334+
);
325335
}
326336
}
327337

@@ -337,6 +347,11 @@ public <V> BlockState with(final PropertyKey property, final V value) {
337347
return newState != this.getInternalId() ? type.withStateId(newState) : this;
338348
} catch (ClassCastException e) {
339349
throw new IllegalArgumentException("Property not found: " + property);
350+
} catch (Exception e) {
351+
throw new UnsupportedOperationException(
352+
"Error resolving property " + property.getName() + " for block type " + getBlockType().id() + "(nullable) value " + value,
353+
e
354+
);
340355
}
341356
}
342357

0 commit comments

Comments
 (0)