feat: improve error handling for state property operations (#2975)

Dieser Commit ist enthalten in:
Jordan 2024-11-06 17:13:56 +00:00 committet von GitHub
Ursprung 7281fa360f
Commit e55e8fabe8
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
3 geänderte Dateien mit 24 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -34,6 +34,7 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.ConvexPolyhedralRegion;
@ -62,6 +63,7 @@ import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.io.File;
@ -76,6 +78,8 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
private static final Logger LOGGER = LogManagerCompat.getLogger();
//FAWE start
private final Map<String, Object> meta;
@ -93,7 +97,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
if (fe != null) {
printError(fe.getComponent());
} else {
throwable.printStackTrace();
LOGGER.error("Error occurred executing player action", throwable);
}
}
}, this::getUniqueId);

Datei anzeigen

@ -273,9 +273,7 @@ public class PlatformManager {
public <T extends Actor> T createProxyActor(T base) {
checkNotNull(base);
if (base instanceof Player) {
Player player = (Player) base;
if (base instanceof Player player) {
Player permActor = queryCapability(Capability.PERMISSIONS).matchPlayer(player);
if (permActor == null) {
permActor = player;
@ -389,10 +387,9 @@ public class PlatformManager {
Location location = event.getLocation();
// At this time, only handle interaction from players
if (!(actor instanceof Player)) {
if (!(actor instanceof Player player)) {
return;
}
Player player = (Player) actor;
LocalSession session = worldEdit.getSessionManager().get(actor);
Request.reset();
@ -463,7 +460,7 @@ public class PlatformManager {
} else {
actor.print(Caption.of("worldedit.command.error.report"));
actor.print(TextComponent.of(e.getClass().getName()+ ": " + e.getMessage()));
e.printStackTrace();
LOGGER.error("Error occurred executing player action", e);
}
}
//FAWE end
@ -511,14 +508,7 @@ public class PlatformManager {
}
//FAWE start - add own message
} catch (Throwable e) {
FaweException faweException = FaweException.get(e);
if (faweException != null) {
player.print(Caption.of("fawe.cancel.reason", faweException.getComponent()));
} else {
player.print(Caption.of("worldedit.command.error.report"));
player.print(TextComponent.of(e.getClass().getName() + ": " + e.getMessage()));
e.printStackTrace();
}
handleThrowable(e, player);
//FAWE end
} finally {
Request.reset();

Datei anzeigen

@ -312,6 +312,11 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
return newState != this.getInternalId() ? type.withStateId(newState) : this;
} catch (ClassCastException e) {
throw new IllegalArgumentException("Property not found: " + property);
} catch (Exception e) {
throw new UnsupportedOperationException(
"Error resolving property " + property.getName() + " for block type " + getBlockType().id() + "(nullable) value " + value,
e
);
}
}
@ -322,6 +327,11 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
return (V) ap.getValue(this.getInternalId());
} catch (ClassCastException e) {
throw new IllegalArgumentException("Property not found: " + property);
} catch (Exception e) {
throw new UnsupportedOperationException(
"Error resolving property " + property.getName() + " for blocktype " + getBlockType().id(),
e
);
}
}
@ -337,6 +347,11 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
return newState != this.getInternalId() ? type.withStateId(newState) : this;
} catch (ClassCastException e) {
throw new IllegalArgumentException("Property not found: " + property);
} catch (Exception e) {
throw new UnsupportedOperationException(
"Error resolving property " + property.getName() + " for block type " + getBlockType().id() + "(nullable) value " + value,
e
);
}
}