Skip to content

Commit

Permalink
remove redundant party injection & fix error when using party channel…
Browse files Browse the repository at this point in the history
… and not in a party
  • Loading branch information
jpenilla committed Sep 30, 2023
1 parent 9188db4 commit dd9c609
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package net.draycia.carbon.common.channels;

import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand All @@ -34,6 +35,7 @@
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -78,7 +80,10 @@ public List<Audience> recipients(final CarbonPlayer sender) {
final WrappedCarbonPlayer wrapped = (WrappedCarbonPlayer) sender;
final @Nullable UUID party = wrapped.partyId();
if (party == null) {
throw new IllegalStateException();
if (sender.online()) {
sender.sendMessage(Component.text("You must join a party to use this channel.", NamedTextColor.RED));
}
return new ArrayList<>();
}
final List<Audience> recipients = super.recipients(sender);
recipients.removeIf(r -> r instanceof WrappedCarbonPlayer p && !Objects.equals(p.partyId(), party));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public DatabaseUserManager create(final String migrationsLocation, final Consume
.registerArgument(new ComponentArgumentFactory())
.registerArgument(new KeyArgumentFactory())
.registerRowMapper(CarbonPlayerCommon.class, new PlayerRowMapper())
.registerRowMapper(PartyImpl.class, new PartyRowMapper(this.injector))
.registerRowMapper(PartyImpl.class, new PartyRowMapper())
.registerColumnMapper(Key.class, new KeyColumnMapper())
.registerColumnMapper(Component.class, new ComponentColumnMapper())
.installPlugin(new SqlObjectPlugin());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package net.draycia.carbon.common.users.db.mapper;

import com.google.inject.Injector;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
Expand All @@ -33,21 +32,13 @@
@DefaultQualifier(NonNull.class)
public final class PartyRowMapper implements RowMapper<PartyImpl> {

private final Injector injector;

public PartyRowMapper(final Injector injector) {
this.injector = injector;
}

@Override
public PartyImpl map(final ResultSet rs, final StatementContext ctx) throws SQLException {
final ColumnMapper<UUID> uuid = ctx.findColumnMapperFor(UUID.class).orElseThrow();
final PartyImpl party = PartyImpl.create(
return PartyImpl.create(
rs.getString("name"),
uuid.map(rs, "partyid", ctx)
);
this.injector.injectMembers(party);
return party;
}

}

0 comments on commit dd9c609

Please sign in to comment.