Added coop and trust limits (with permissions) (#1267)

Implements #1065.

Added two new permissions:
* [gamemode].trust.maxsize.[NUMBER]
* [gamemode].coop.maxsize.[NUMBER]

Added two new WorldSettings and related methods in IWM:
* getMaxCoopSize() (defaults to 4)
* getMaxTrustSize() (defaults to 4)

* Add limit for coop players #1065

* Edit comparison sign

* Add limit for trust players #1065

* Add default value and add since javadoc tags

* improved messages

* readded missing "

Co-authored-by: Florian CUNY <poslovitch@bentobox.world>
This commit is contained in:
Clément P 2020-04-05 14:28:59 +02:00 committed by GitHub
parent e0d5c7b8bd
commit 0f2ba0e202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 0 deletions

View File

@ -93,6 +93,11 @@ public class IslandTeamCoopCommand extends CompositeCommand {
target.sendMessage("commands.island.team.coop.name-has-invited-you", TextVariables.NAME, user.getName());
target.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
} else {
if (getMaxCoopSize(user) <= island.getMemberSet(RanksManager.COOP_RANK, false).size()) {
user.sendMessage("commands.island.team.coop.is-full");
return false;
}
island.setRank(target, RanksManager.COOP_RANK);
user.sendMessage("commands.island.team.coop.success", TextVariables.NAME, target.getName());
target.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, user.getName());
@ -114,4 +119,14 @@ public class IslandTeamCoopCommand extends CompositeCommand {
String lastArg = args.get(args.size()-1);
return Optional.of(Util.tabLimit(Util.getOnlinePlayerList(user), lastArg));
}
/**
* Gets the maximum coop size for this player in this game based on the permission or the world's setting
* @param user user
* @return max coop size of user
* @since 1.13.0
*/
public int getMaxCoopSize(User user) {
return user.getPermissionValue(getPermissionPrefix() + "coop.maxsize", getIWM().getMaxCoopSize(getWorld()));
}
}

View File

@ -95,6 +95,11 @@ public class IslandTeamTrustCommand extends CompositeCommand {
target.sendMessage("commands.island.team.trust.name-has-invited-you", TextVariables.NAME, user.getName());
target.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
} else {
if (getMaxTrustSize(user) <= island.getMemberSet(RanksManager.TRUSTED_RANK, false).size()) {
user.sendMessage("commands.island.team.trust.is-full");
return false;
}
island.setRank(target, RanksManager.TRUSTED_RANK);
user.sendMessage("commands.island.team.trust.success", TextVariables.NAME, target.getName());
target.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, user.getName());
@ -116,4 +121,14 @@ public class IslandTeamTrustCommand extends CompositeCommand {
String lastArg = args.get(args.size()-1);
return Optional.of(Util.tabLimit(Util.getOnlinePlayerList(user), lastArg));
}
/**
* Gets the maximum trust size for this player in this game based on the permission or the world's setting
* @param user user
* @return max trust size of user
* @since 1.13.0
*/
public int getMaxTrustSize(User user) {
return user.getPermissionValue(getPermissionPrefix() + "trust.maxsize", getIWM().getMaxTrustSize(getWorld()));
}
}

View File

@ -107,6 +107,22 @@ public interface WorldSettings extends ConfigObject {
*/
int getMaxTeamSize();
/**
* @return the max coop size for this world
* @since 1.13.0
*/
default int getMaxCoopSize() {
return 4;
}
/**
* @return the max trust size for this world
* @since 1.13.0
*/
default int getMaxTrustSize() {
return 4;
}
/**
* @return the netherSpawnRadius
*/

View File

@ -437,6 +437,26 @@ public class IslandWorldManager {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getMaxTeamSize() : 0;
}
/**
* Get max coop size for this world
* @param world - world
* @return max coop size or zero if world is not a game world
* @since 1.13.0
*/
public int getMaxCoopSize(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getMaxCoopSize() : 0;
}
/**
* Get max trust size for this world
* @param world - world
* @return max trust size or zero if world is not a game world
* @since 1.13.0
*/
public int getMaxTrustSize(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getMaxTrustSize() : 0;
}
/**
* Get max homes for world
*
@ -871,4 +891,5 @@ public class IslandWorldManager {
public boolean isTeleportPlayerToIslandUponIslandCreation(@NonNull World world) {
return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isTeleportPlayerToIslandUponIslandCreation();
}
}

View File

@ -540,6 +540,7 @@ commands:
you-are-no-longer-a-coop-member: "&c You are no longer a coop member of [name]'s island"
all-members-logged-off: "&c All island members logged off so you are no longer a coop member of [name]'s island"
success: "&b [name] &a is no longer a coop member of your island."
is-full: "&c You cannot coop anyone else."
trust:
description: "give a player trusted rank on your island"
parameters: "<player>"
@ -548,6 +549,7 @@ commands:
player-already-trusted: "&c Player is already trusted!"
you-are-trusted: "&2 You are trusted by &b [name]&a !"
success: "&a You trusted &b [name]&a ."
is-full: "&c You cannot trust anyone else."
untrust:
description: "remove trusted player rank from player"
parameters: "<player>"