3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-26 02:50:06 +01:00

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

Datei anzeigen

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

Datei anzeigen

@ -312,6 +312,11 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
return newState != this.getInternalId() ? type.withStateId(newState) : this; return newState != this.getInternalId() ? type.withStateId(newState) : this;
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new IllegalArgumentException("Property not found: " + property); 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()); return (V) ap.getValue(this.getInternalId());
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new IllegalArgumentException("Property not found: " + property); 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; return newState != this.getInternalId() ? type.withStateId(newState) : this;
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new IllegalArgumentException("Property not found: " + property); 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
);
} }
} }