Skip to content

Commit

Permalink
chore: javax annotations, streams instead of for loops, entity builde…
Browse files Browse the repository at this point in the history
…r for entitlement, primitive types, deferrable interface impl for premium required reply callback
  • Loading branch information
Giuliopime committed Nov 14, 2023
1 parent 020f464 commit 4751083
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 93 deletions.
73 changes: 48 additions & 25 deletions src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,88 @@

package net.dv8tion.jda.api.entities;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.time.OffsetDateTime;

/**
* Represents a Discord Entitlement for premium App subscriptions.
* <br>This should contain all information provided from Discord about an {@link Entitlement Entitlement}.
*/
public interface Entitlement
public interface Entitlement extends ISnowflake
{
/**
* The id of the entitlement
*
* @return The id of the {@link Entitlement Entitlement}
*/
String getId();

@Override
long getIdLong();

/**
* The id of the sku related to this {@link Entitlement Entitlement}
*
* @return The id of the SKU related to this {@link Entitlement Entitlement}
*/
long getSkuIdLong();

/**
* The id of the sku related to this {@link Entitlement Entitlement}
*
* @return The id of the SKU related to this {@link Entitlement Entitlement}
*/
@Nonnull
String getSkuId();

/**
* The id of the parent application of this {@link Entitlement Entitlement}
*
* @return The id of the parent application of this {@link Entitlement Entitlement}
*/
long getApplicationIdLong();

/**
* The id of the parent application of this {@link Entitlement Entitlement}
*
* @return The id of the parent application of this {@link Entitlement Entitlement}
*/
@Nonnull
String getApplicationId();

/**
* The id of the user that purchased the {@link Entitlement Entitlement}
*
* @return The id of the user that purchased the {@link Entitlement Entitlement}
*/
@Nullable
Long getUserIdLong();

/**
* The id of the user that purchased the {@link Entitlement Entitlement}
*
* @return The id of the user that purchased the {@link Entitlement Entitlement}
*/
@Nullable
String getUserId();

/**
* The guild id that is granted access to the {@link Entitlement Entitlement}'s sku
*
* @return The id of the guild that is granted access to the {@link Entitlement Entitlement}'s sku,
* or Null if this entitlement is related to a subscription of type "User Subscription"
*/
@Nullable
String getGuildId();
Long getGuildIdLong();

/*
Mentioned by Discord in the example but not included in the api specification
@Nullable
String getPromotionId();
/**
* The guild id that is granted access to the {@link Entitlement Entitlement}'s sku
*
* @return The id of the guild that is granted access to the {@link Entitlement Entitlement}'s sku,
* or Null if this entitlement is related to a subscription of type "User Subscription"
*/
@Nullable
String getGuildId();

/**
* The type of the Entitlement
Expand All @@ -71,42 +106,30 @@ public interface Entitlement
*
* @return the {@link Entitlement Entitlement} type, 8 is the only possible value
*/
Integer getType();
int getType();

/**
* Whether the {@link Entitlement Entitlement} has been deleted or not.
*
* @return True if the {@link Entitlement Entitlement} was deleted, False otherwise
*
* @see net.dv8tion.jda.api.events.entitlement.EntitlementDeleteEvent
*/
Boolean getDeleted();

/*
Mentioned by Discord in the example but not included in the api specification
Long getGiftCodeFlags();
*/

/*
Mentioned by Discord in the example but not included in the api specification
Boolean getConsumed();
*/
boolean getDeleted();

/**
* The start date at which the {@link Entitlement Entitlement} is valid.
*
* @return Start date at which the {@link Entitlement Entitlement} is valid. Not present when using test entitlements.
*/
@Nullable
OffsetDateTime getStartsAt();

/**
* Date at which the {@link Entitlement Entitlement} is no longer valid.
*
* @return Date at which the {@link Entitlement Entitlement} is no longer valid. Not present when using test entitlements.
*/
@Nullable
OffsetDateTime getEndsAt();

/*
Mentioned by Discord in the example but not included in the api specification
@Nullable
String getSubscriptionId();
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Entitlement;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;

/**
* Indicates that a user subscribed to a SKU.
Expand All @@ -27,7 +28,7 @@
*/
public class EntitlementCreateEvent extends GenericEntitlementEvent
{
public EntitlementCreateEvent(@NotNull JDA api, long responseNumber, @NotNull Entitlement entitlement)
public EntitlementCreateEvent(@Nonnull JDA api, long responseNumber, @Nonnull Entitlement entitlement)
{
super(api, responseNumber, entitlement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Entitlement;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;

/**
* Indicates a user's entitlement is deleted. Entitlement deletions are infrequent, and occur when:
Expand All @@ -37,7 +38,7 @@
*/
public class EntitlementDeleteEvent extends GenericEntitlementEvent
{
public EntitlementDeleteEvent(@NotNull JDA api, long responseNumber, @NotNull Entitlement entitlement)
public EntitlementDeleteEvent(@Nonnull JDA api, long responseNumber, @Nonnull Entitlement entitlement)
{
super(api, responseNumber, entitlement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Entitlement;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;

/**
* Indicates a user's subscription has renewed for the next billing period.
Expand All @@ -32,7 +33,7 @@
*/
public class EntitlementUpdateEvent extends GenericEntitlementEvent
{
public EntitlementUpdateEvent(@NotNull JDA api, long responseNumber, @NotNull Entitlement entitlement)
public EntitlementUpdateEvent(@Nonnull JDA api, long responseNumber, @Nonnull Entitlement entitlement)
{
super(api, responseNumber, entitlement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import net.dv8tion.jda.api.events.Event;
import net.dv8tion.jda.api.interactions.DiscordLocale;
import net.dv8tion.jda.api.interactions.Interaction;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -124,7 +123,7 @@ public User getUser()
return interaction.getUser();
}

@NotNull
@Nonnull
@Override
public List<Entitlement> getEntitlements()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import net.dv8tion.jda.api.requests.restaction.interactions.ModalCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.PremiumRequiredCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -121,7 +120,7 @@ public ModalCallbackAction replyModal(@Nonnull Modal modal)
return getInteraction().replyModal(modal);
}

@NotNull
@Nonnull
@Override
public PremiumRequiredCallbackAction replyWithPremiumRequired()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import net.dv8tion.jda.api.requests.restaction.interactions.ModalCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.PremiumRequiredCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -127,7 +126,7 @@ public ModalCallbackAction replyModal(@Nonnull Modal modal)
return interaction.replyModal(modal);
}

@NotNull
@Nonnull
@Override
public PremiumRequiredCallbackAction replyWithPremiumRequired()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package net.dv8tion.jda.api.interactions.callbacks;

import net.dv8tion.jda.api.interactions.Interaction;
import net.dv8tion.jda.api.requests.restaction.interactions.PremiumRequiredCallbackAction;

import javax.annotation.CheckReturnValue;
Expand All @@ -27,7 +26,7 @@
*
* <p>Replying with {@link #replyWithPremiumRequired()} will automatically acknowledge this interaction.
*/
public interface IPremiumRequiredReplyCallback extends Interaction
public interface IPremiumRequiredReplyCallback extends IDeferrableCallback
{
@Nonnull
@CheckReturnValue
Expand Down
Loading

0 comments on commit 4751083

Please sign in to comment.