Search in sources :

Example 1 with LegacyComponentSerializer

use of net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer in project SpongeCommon by SpongePowered.

the class SpongeBanBuilder method build.

@Override
public Ban build() {
    if (this.banType == null) {
        throw new IllegalStateException("BanType cannot be null!");
    }
    final LegacyComponentSerializer lcs = LegacyComponentSerializer.legacySection();
    final String sourceName = this.source != null ? lcs.serialize(this.source) : null;
    final String reason = this.reason != null ? lcs.serialize(this.reason) : null;
    if (this.banType == BanTypes.PROFILE.get()) {
        if (this.profile == null) {
            throw new IllegalStateException("User cannot be null");
        }
        return (Ban) new UserBanListEntry(SpongeGameProfile.toMcProfile(this.profile.withoutProperties()), Date.from(this.start), sourceName, this.toDate(this.end), reason);
    }
    if (this.address == null) {
        throw new IllegalStateException("Address cannot be null!");
    }
    return (Ban) new IpBanListEntry(BanUtil.addressToBanCompatibleString(this.address), Date.from(this.start), sourceName, this.toDate(this.end), reason);
}
Also used : IpBanListEntry(net.minecraft.server.players.IpBanListEntry) UserBanListEntry(net.minecraft.server.players.UserBanListEntry) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) Ban(org.spongepowered.api.service.ban.Ban)

Example 2 with LegacyComponentSerializer

use of net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer in project SpongeCommon by SpongePowered.

the class ServerScoreboardMixin method resetPlayerScore.

@Override
public void resetPlayerScore(final String name, final net.minecraft.world.scores.Objective objective) {
    final LegacyComponentSerializer lcs = LegacyComponentSerializer.legacySection();
    if (objective != null) {
        final SpongeObjective spongeObjective = ((ObjectiveBridge) objective).bridge$getSpongeObjective();
        final Optional<org.spongepowered.api.scoreboard.Score> score = spongeObjective.findScore(lcs.deserialize(name));
        if (score.isPresent()) {
            spongeObjective.removeScore(score.get());
        } else {
            SpongeCommon.logger().warn("Objective {} did have have the score", name);
        }
    } else {
        final Component textName = lcs.deserialize(name);
        for (final net.minecraft.world.scores.Objective scoreObjective : this.getObjectives()) {
            ((ObjectiveBridge) scoreObjective).bridge$getSpongeObjective().removeScore(textName);
        }
    }
}
Also used : Score(net.minecraft.world.scores.Score) SpongeScore(org.spongepowered.common.scoreboard.SpongeScore) ObjectiveBridge(org.spongepowered.common.bridge.world.scores.ObjectiveBridge) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective) Component(net.kyori.adventure.text.Component) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer)

Example 3 with LegacyComponentSerializer

use of net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer in project SpongeCommon by SpongePowered.

the class BanListEntryMixin method bridge$initializeFields.

@Inject(method = "<init>*", at = @At("RETURN"))
private void bridge$initializeFields(final CallbackInfo ci) {
    // Prevent this from being overriden in UserListIPBansEntryMixin
    final LegacyComponentSerializer lcs = LegacyComponentSerializer.legacySection();
    this.impl$reason = this.reason == null ? null : lcs.deserialize(this.reason);
    this.impl$source = lcs.deserialize(this.source);
}
Also used : LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

LegacyComponentSerializer (net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer)3 Component (net.kyori.adventure.text.Component)1 IpBanListEntry (net.minecraft.server.players.IpBanListEntry)1 UserBanListEntry (net.minecraft.server.players.UserBanListEntry)1 Score (net.minecraft.world.scores.Score)1 Ban (org.spongepowered.api.service.ban.Ban)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 ObjectiveBridge (org.spongepowered.common.bridge.world.scores.ObjectiveBridge)1 SpongeObjective (org.spongepowered.common.scoreboard.SpongeObjective)1 SpongeScore (org.spongepowered.common.scoreboard.SpongeScore)1