Skip to content

Commit

Permalink
feat: implement TeamMember as a subinterface of OnlineUser (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
Snabeldier authored Jan 15, 2025
1 parent fe6a2d6 commit 20c65e9
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 4 deletions.
44 changes: 40 additions & 4 deletions src/main/java/minevalley/core/api/users/OnlineUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import minevalley.core.api.users.enums.McVersion;
import minevalley.core.api.users.enums.TabListView;
import minevalley.core.api.users.enums.TeamRank;
import minevalley.core.api.users.exceptions.UserNotPermittedException;
import minevalley.core.api.utils.ChatHandler;
import minevalley.core.api.utils.ClickableMessage;
import minevalley.core.api.vehicles.LoadedVehicle;
Expand Down Expand Up @@ -386,12 +387,34 @@ default void closeInventory() {
@Contract(pure = true)
Fraction getFractionService();

void enterFractionService(@Nonnull Fraction service) throws IllegalArgumentException;
/**
* Sets the user's current fraction service.
*
* @param service fraction to enter service
* @throws IllegalArgumentException if the service is null
* @throws UserNotPermittedException if the user is not allowed to enter the service
* @throws IllegalStateException if the user is already in a service
*/
void enterFractionService(@Nonnull Fraction service) throws IllegalArgumentException, UserNotPermittedException, IllegalStateException;

void leaveFractionService();
/**
* Lets the user leave the fraction-service.
*
* @throws IllegalStateException if the user is not in a service
*/
void leaveFractionService() throws IllegalStateException;

// TeamRank

/**
* Gets the team-member object of this user.
*
* @return team-member object
* @throws UserNotPermittedException if the user is no team-member
*/
@Nonnull
TeamMember team() throws UserNotPermittedException;

/**
* Gets if the player has any type of team-rank.
*
Expand All @@ -405,6 +428,7 @@ default void closeInventory() {
*
* @return true, if the user is team-plus-member
*/
@Deprecated(forRemoval = true)
@Contract(pure = true)
boolean isTeamPlus();

Expand All @@ -413,7 +437,8 @@ default void closeInventory() {
*
* @return users team-rank
*/
@Nullable
@Deprecated(forRemoval = true)
@Nonnull
@Contract(pure = true)
TeamRank getTeamRank();

Expand All @@ -423,6 +448,7 @@ default void closeInventory() {
*
* @return [custom] team rank name
*/
@Deprecated(forRemoval = true)
@Nullable
@Contract(pure = true)
String getCustomTeamRankName();
Expand All @@ -435,6 +461,7 @@ default void closeInventory() {
*
* @return true, if this user is displayed as team member in chat, tab list, etc.
*/
@Deprecated(forRemoval = true)
@Contract(pure = true)
boolean isDisplayedAsTeamler();

Expand All @@ -444,6 +471,7 @@ default void closeInventory() {
* @param ranks list of team-ranks to be checked for
* @return true, if the user has one of the ranks
*/
@Deprecated(forRemoval = true)
@Contract(pure = true)
boolean hasTeamRank(@Nonnull TeamRank... ranks);

Expand All @@ -452,6 +480,7 @@ default void closeInventory() {
*
* @return true, if the player is allowed to use a general-key
*/
@Deprecated(forRemoval = true)
@Contract(pure = true)
boolean isAllowedToUseGeneralKey();

Expand All @@ -460,6 +489,7 @@ default void closeInventory() {
*
* @return true, if the player is using a general-key
*/
@Deprecated(forRemoval = true)
@Contract(pure = true)
boolean isUsingGeneralKey();

Expand All @@ -471,31 +501,36 @@ default void closeInventory() {
/**
* Lets the user leave the team-service.
*/
@Deprecated(forRemoval = true)
void leaveTeamService() throws IllegalStateException;

/**
* Gets whether the user is allowed to enter the support-service.
*
* @return true, if the user is allowed to enter the support-service
*/
@Deprecated(forRemoval = true)
@Contract(pure = true)
boolean canEnterSupportService();

/**
* Lets the user enter the support-service. If the user isn't allowed to, nothing happens.
*/
@Deprecated(forRemoval = true)
void joinSupportService() throws UnsupportedOperationException, IllegalStateException;

/**
* Lets the user leave the support-service.
*/
@Deprecated(forRemoval = true)
void leaveSupportService() throws IllegalStateException;

/**
* Gets whether the user is marked as server-operator (!= OP-permission)
*
* @return true, if the user is marked as server-operator
*/
@Deprecated(forRemoval = true)
@Contract(pure = true)
boolean isOperator();

Expand All @@ -504,6 +539,7 @@ default void closeInventory() {
*
* @return true, if the user is in support-service
*/
@Deprecated(forRemoval = true)
@Contract(pure = true)
boolean isInSupportService();

Expand Down Expand Up @@ -564,7 +600,7 @@ default void closeInventory() {
@Contract(pure = true)
boolean isAllowedToUse(Block block);

void changeSign(@Nonnull Block block, @Nonnull String line1, @Nonnull String line2, @Nonnull String line3, @Nonnull String line4) throws IllegalArgumentException;
void changeSign(@Nonnull Block block, @Nullable String line1, @Nullable String line2, @Nullable String line3, @Nullable String line4) throws IllegalArgumentException;

void resetSign(@Nonnull Block block) throws IllegalArgumentException;

Expand Down
125 changes: 125 additions & 0 deletions src/main/java/minevalley/core/api/users/TeamMember.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package minevalley.core.api.users;

import minevalley.core.api.users.enums.TeamRank;
import org.jetbrains.annotations.Contract;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public interface TeamMember extends OnlineUser {

/**
* Gets whether the player is team-member with the plus-rank.
*
* @return true, if the user is team-plus-member
*/
@Contract(pure = true)
@SuppressWarnings("removal")
boolean isTeamPlus();

/**
* Gets the team-rank of this user.
*
* @return users team-rank
*/
@Nonnull
@Contract(pure = true)
@SuppressWarnings("removal")
TeamRank getTeamRank();

/**
* Gets the custom team rank name.
* If no custom name is defined, this returns the name of the users team rank.
*
* @return [custom] team rank name
*/
@Nullable
@Contract(pure = true)
@SuppressWarnings("removal")
String getCustomTeamRankName();

/**
* Sometimes a player is assigned a team rank to grant them permission or access.
* Because team members are highlighted in the chat and tab list,
* they appear representative of the project and players may assume they have the permission and knowledge
* to guide other players. Therefore, the rank assigned to the player can be hidden.
*
* @return true, if this user is displayed as team member in chat, tab list, etc.
*/
@Contract(pure = true)
@SuppressWarnings("removal")
boolean isDisplayedAsTeamler();

/**
* Gets whether the user has any of the listed team-ranks.
*
* @param ranks list of team-ranks to be checked for
* @return true, if the user has one of the ranks
*/
@Contract(pure = true)
@SuppressWarnings("removal")
boolean hasTeamRank(@Nonnull TeamRank... ranks);

/**
* Gets whether the user is allowed to use a general-key
*
* @return true, if the player is allowed to use a general-key
*/
@Contract(pure = true)
@SuppressWarnings("removal")
boolean isAllowedToUseGeneralKey();

/**
* Gets whether the user is using a general-key at the moment, by checking the item in his hand. If he is using a general-key without the permission to do, his key gets removed automatically.
*
* @return true, if the player is using a general-key
*/
@Contract(pure = true)
@SuppressWarnings("removal")
boolean isUsingGeneralKey();

/**
* Lets the user leave the team-service.
*/
@SuppressWarnings("removal")
void leaveTeamService() throws IllegalStateException;

/**
* Gets whether the user is allowed to enter the support-service.
*
* @return true, if the user is allowed to enter the support-service
*/
@Contract(pure = true)
@SuppressWarnings("removal")
boolean canEnterSupportService();

/**
* Lets the user enter the support-service. If the user isn't allowed to, nothing happens.
*/
@SuppressWarnings("removal")
void joinSupportService() throws UnsupportedOperationException, IllegalStateException;

/**
* Lets the user leave the support-service.
*/
@SuppressWarnings("removal")
void leaveSupportService() throws IllegalStateException;

/**
* Gets whether the user is marked as server-operator (!= OP-permission)
*
* @return true, if the user is marked as server-operator
*/
@Contract(pure = true)
@SuppressWarnings("removal")
boolean isOperator();

/**
* Gets whether the user is in support-service
*
* @return true, if the user is in support-service
*/
@Contract(pure = true)
@SuppressWarnings("removal")
boolean isInSupportService();
}
12 changes: 12 additions & 0 deletions src/main/java/minevalley/core/api/users/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@
import minevalley.core.api.corporations.Member;
import minevalley.core.api.enums.DebugType;
import minevalley.core.api.phone.Telephone;
import minevalley.core.api.users.exceptions.UserNotOnlineException;
import minevalley.core.api.users.friends.FriendRequest;
import minevalley.core.api.users.friends.Friendship;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public interface User extends Registrant {

/**
* Gets the online user-object of this user.
*
* @return online user-object
* @throws UserNotOnlineException if the user is not online
*/
@Nonnull
OnlineUser online() throws UserNotOnlineException;

@Deprecated(forRemoval = true)
OnlineUser getOnlineUser();

boolean isOnline();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@SuppressWarnings("unused")
public enum Fraction {

POLICE("Polizei"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package minevalley.core.api.users.exceptions;

import lombok.Getter;
import minevalley.core.api.users.User;

import javax.annotation.Nonnull;

@Getter
public class UserNotOnlineException extends RuntimeException {

private final User user;

public UserNotOnlineException(@Nonnull User user) {
super("User " + user.getName() + " is not online.");
this.user = user;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package minevalley.core.api.users.exceptions;

import lombok.Getter;
import minevalley.core.api.users.User;

import javax.annotation.Nonnull;

@Getter
public class UserNotPermittedException extends RuntimeException {

private final User user;

public UserNotPermittedException(@Nonnull User user) {
super("User " + user.getName() + " is not permitted to perform this action.");
this.user = user;
}

public UserNotPermittedException(@Nonnull User user, @Nonnull String message) {
super(message);
this.user = user;
}
}

0 comments on commit 20c65e9

Please sign in to comment.