use of org.spongepowered.common.data.value.ImmutableSpongeListValue in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin method impl$callChangeSignEvent.
@Redirect(method = "updateSignText", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/List;size()I"))
private int impl$callChangeSignEvent(final List<String> list, ServerboundSignUpdatePacket p_244542_1_, List<String> p_244542_2_) {
final SignBlockEntity blockEntity = (SignBlockEntity) this.player.level.getBlockEntity(p_244542_1_.getPos());
final ListValue<Component> originalLinesValue = ((Sign) blockEntity).getValue(Keys.SIGN_LINES).orElseGet(() -> new ImmutableSpongeListValue<>(Keys.SIGN_LINES, ImmutableList.of()));
final List<Component> newLines = new ArrayList<>();
for (final String line : list) {
// Sponge Start - While Vanilla does some strip formatting, it doesn't catch everything. This patches an exploit that allows color
// signs to be created.
newLines.add(Component.text(SharedConstants.filterText(line)));
}
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(this.player);
final ListValue.Mutable<Component> newLinesValue = ListValue.mutableOf(Keys.SIGN_LINES, newLines);
final ChangeSignEvent event = SpongeEventFactory.createChangeSignEvent(PhaseTracker.getCauseStackManager().currentCause(), originalLinesValue.asImmutable(), newLinesValue, (Sign) blockEntity);
final ListValue<Component> toApply = SpongeCommon.post(event) ? originalLinesValue : newLinesValue;
((Sign) blockEntity).offer(toApply);
}
return 0;
}
Aggregations