Skip to content

Commit

Permalink
Add option to exclude deprecated voice regions
Browse files Browse the repository at this point in the history
Default behaviour is still retrieving deprecated regions, must pass
false to retrieveRegions(boolean) in order to exclude them.
  • Loading branch information
MinnDevelopment committed May 16, 2018
1 parent 81cfe00 commit b001158
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/main/java/net/dv8tion/jda/core/entities/Guild.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,27 @@ public interface Guild extends ISnowflake
{
/**
* Retrieves the available regions for this Guild
* <br>Shortcut for {@link #retrieveRegions(boolean) retrieveRegions(true)}
* <br>This will include deprecated voice regions by default.
*
* @return {@link net.dv8tion.jda.core.requests.RestAction RestAction} - Type {@link java.util.EnumSet EnumSet}
*/
@CheckReturnValue
RestAction<EnumSet<Region>> retrieveRegions();
default RestAction<EnumSet<Region>> retrieveRegions()
{
return retrieveRegions(true);
}

/**
* Retrieves the available regions for this Guild
*
* @param includeDeprecated
* Whether to include deprecated regions
*
* @return {@link net.dv8tion.jda.core.requests.RestAction RestAction} - Type {@link java.util.EnumSet EnumSet}
*/
@CheckReturnValue
RestAction<EnumSet<Region>> retrieveRegions(boolean includeDeprecated);

/**
* Adds the user represented by the provided id to this guild.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.dv8tion.jda.core.requests.restaction.MemberAction;
import net.dv8tion.jda.core.requests.restaction.pagination.AuditLogPaginationAction;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.core.utils.Helpers;
import net.dv8tion.jda.core.utils.MiscUtil;
import net.dv8tion.jda.core.utils.cache.MemberCacheView;
import net.dv8tion.jda.core.utils.cache.SnowflakeCacheView;
Expand Down Expand Up @@ -99,7 +100,7 @@ public GuildImpl(JDAImpl api, long id)
}

@Override
public RestAction<EnumSet<Region>> retrieveRegions()
public RestAction<EnumSet<Region>> retrieveRegions(boolean includeDeprecated)
{
Route.CompiledRoute route = Route.Guilds.GET_VOICE_REGIONS.compile(getId());
return new RestAction<EnumSet<Region>>(api, route)
Expand All @@ -117,6 +118,8 @@ protected void handleResponse(Response response, Request<EnumSet<Region>> reques
for (int i = 0; arr != null && i < arr.length(); i++)
{
JSONObject obj = arr.getJSONObject(i);
if (!includeDeprecated && Helpers.optBoolean(obj, "deprecated"))
continue;
String id = obj.optString("id");
Region region = Region.fromKey(id);
if (region != Region.UNKNOWN)
Expand Down

0 comments on commit b001158

Please sign in to comment.