docs: Add javadocs to new api class and methods

This commit is contained in:
Ben Woo 2023-02-10 23:36:06 +08:00
parent b84ed07371
commit 0e52316930
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
13 changed files with 527 additions and 19 deletions

View File

@ -280,11 +280,17 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
return economist;
}
/**
* {@inheritDoc}
*/
@Override
public PermissionsTool getPermissionsTool() {
return permissionsTool;
}
/**
* {@inheritDoc}
*/
@Override
public PlayerActionChecker getPlayerActionChecker() {
return playerActionChecker;

View File

@ -14,9 +14,10 @@ import com.onarandombox.MultiverseCore.economy.MVEconomist;
import com.onarandombox.MultiverseCore.teleportation.SimpleBlockSafety;
import com.onarandombox.MultiverseCore.teleportation.SimpleLocationManipulation;
import com.onarandombox.MultiverseCore.teleportation.SimpleSafeTTeleporter;
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
import com.onarandombox.MultiverseCore.utils.PermissionsTool;
import com.onarandombox.MultiverseCore.utils.actioncheck.PlayerActionChecker;
import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper;
import com.onarandombox.MultiverseCore.utils.actioncheck.PlayerActionChecker;
/**
* Multiverse 2 Core API
@ -106,8 +107,18 @@ public interface MVCore extends MVPlugin {
*/
int getPluginCount();
/**
* Gets the {@link PermissionsTool} instance.
*
* @return The {@link PermissionsTool} instance.
*/
PermissionsTool getPermissionsTool();
/**
* Gets the {@link PlayerActionChecker} instance.
*
* @return The {@link PlayerActionChecker} instance.
*/
PlayerActionChecker getPlayerActionChecker();
/**

View File

@ -5,6 +5,11 @@ import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
/**
* A response that have multiple results.
*/
public class ActionResponse implements ActionResult {
private final Set<ActionResult> results;
private final boolean continueIfFail;
@ -15,19 +20,34 @@ public class ActionResponse implements ActionResult {
this(false);
}
/**
* @param continueIfFail If true, the response will continue to add results even if one of the results is not successful.
*/
public ActionResponse(boolean continueIfFail) {
this.results = new HashSet<>();
this.continueIfFail = continueIfFail;
}
public ActionResponse then(Supplier<ActionResult> resultSupplier) {
/**
* Add a result to the response.
*
* @param resultSupplier The supplier of the result.
* @return self
*/
public @NotNull ActionResponse then(Supplier<ActionResult> resultSupplier) {
if (!continueIfFail && !isSuccessful) {
return this;
}
return addResult(resultSupplier.get());
}
public ActionResponse addResult(ActionResult result) {
/**
* Add a result to the response.
*
* @param result The result.
* @return self
*/
public @NotNull ActionResponse addResult(ActionResult result) {
if (!continueIfFail && !isSuccessful) {
return this;
}
@ -39,15 +59,25 @@ public class ActionResponse implements ActionResult {
return this;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return results.stream().map(ActionResult::getName).collect(Collectors.joining(", "));
}
/**
* {@inheritDoc}
*/
@Override
public boolean isSuccessful() {
return isSuccessful;
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasResult(ActionResult result) {
return results.contains(result);

View File

@ -1,9 +1,28 @@
package com.onarandombox.MultiverseCore.api.action;
/**
* Represents one or more action result.
*/
public interface ActionResult {
/**
* Get the name of the result.
*
* @return The name of the result.
*/
String getName();
/**
* Check if the result is successful.
*
* @return true if the result is successful.
*/
boolean isSuccessful();
/**
* Check if the result is in the response.
*
* @param result The result to check.
* @return true if the result is in the response.
*/
boolean hasResult(ActionResult result);
}

View File

@ -0,0 +1,4 @@
/**
* This package contains the Action API.
*/
package com.onarandombox.MultiverseCore.api.action;

View File

@ -1,6 +1,7 @@
package com.onarandombox.MultiverseCore.destination;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
@ -109,7 +110,7 @@ public class DestinationsProvider {
}
public @NotNull Collection<Destination<?>> getRegisteredDestinations() {
return this.destinationMap.values();
return Collections.unmodifiableCollection(this.destinationMap.values());
}
/**

View File

@ -31,6 +31,12 @@ public class MVEconomist {
return getVaultHandler().hasEconomy();
}
/**
* Formats the amount to a human readable currency string.
*
* @param world the world to get the price and currency from.
* @return the human readable currency string.
*/
public String formatPrice(MVWorld world) {
return formatPrice(world.getPrice(), world.getCurrency());
}
@ -81,6 +87,12 @@ public class MVEconomist {
}
}
/**
* Pays for a given amount of currency either from the player's economy account or inventory if the currency.
*
* @param player the player to deposit currency into.
* @param world the world to take entry fee from.
*/
public void payEntryFee(Player player, MVWorld world) {
payEntryFee(player, world.getPrice(), world.getCurrency());
}

View File

@ -277,7 +277,7 @@ public class MVPlayerListener implements Listener {
* @param player The {@link Player}.
* @param world The world the player is in.
*/
public void handleGameModeAndFlight(@NotNull Player player, @NotNull MVWorld world) {
private void handleGameModeAndFlight(@NotNull Player player, @NotNull MVWorld world) {
// We perform this task one tick later to MAKE SURE that the player actually reaches the
// destination world, otherwise we'd be changing the player mode if they havent moved anywhere.
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(
@ -286,7 +286,13 @@ public class MVPlayerListener implements Listener {
1L);
}
private void applyGameModeAndFlight(@NotNull Player player, @NotNull MVWorld world) {
/**
* Applies the gamemode and flight for the specified {@link Player}.
*
* @param player The {@link Player}.
* @param world The world the player is in.
*/
public void applyGameModeAndFlight(@NotNull Player player, @NotNull MVWorld world) {
if (MVPlayerListener.this.actionChecker.canKeepGameMode(player, world).isSuccessful()) {
Logging.fine("Player: " + player.getName() + " is IMMUNE to gamemode changes!");
return;
@ -317,6 +323,15 @@ public class MVPlayerListener implements Listener {
}
}
/**
* Sends the reason for the teleportation failure to the sender.
*
* @param sender The sender of the command.
* @param teleportee The player being teleported.
* @param fromWorld The world the player is teleporting from.
* @param toWorld The world the player is teleporting to.
* @param result The result of the teleportation.
*/
private void tellReason(@NotNull CommandSender sender,
@NotNull Player teleportee,
@Nullable MVWorld fromWorld,

View File

@ -12,6 +12,9 @@ import org.bukkit.plugin.PluginManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* A utility class for registering and checking permissions.
*/
public class PermissionsTool {
private static final String TELEPORT_PERM_PREFIX = "multiverse.teleport.";
@ -26,11 +29,17 @@ public class PermissionsTool {
this.plugin = plugin;
}
/**
* Sets up the permissions for Multiverse.
*/
public void setUpPermissions() {
this.pluginManager = this.plugin.getServer().getPluginManager();
setUpWorldPermissionWildcards();
}
/**
* Set up the world permissions wildcards.
*/
private void setUpWorldPermissionWildcards() {
this.worldAccessPermission = new Permission("multiverse.access.*",
"Allows access to all worlds",
@ -57,6 +66,11 @@ public class PermissionsTool {
Logging.finer("Registered world permissions wildcard.");
}
/**
* Registers the permissions for a world.
*
* @param world The world to register permissions for.
*/
public void registerMVWorldPermissions(MVWorld world) {
Permission accessPermission = new Permission("multiverse.access." + world.getName(),
"Allows access to " + world.getName(),
@ -89,6 +103,11 @@ public class PermissionsTool {
Logging.finer("Registered permissions for '" + world.getName() + "'");
}
/**
* Unregisters the permissions for a world.
*
* @param world The world to remove permissions for.
*/
public void removeMVWorldPermissions(MVWorld world) {
Permission accessPermission = pluginManager.getPermission("multiverse.access." + world.getName());
if (accessPermission != null) {
@ -112,6 +131,9 @@ public class PermissionsTool {
}
}
/**
* Removes all Multiverse World related permissions.
*/
public void removeAllMVWorldPermissions() {
this.worldAccessPermission.getChildren().keySet().forEach(pluginManager::removePermission);
this.bypassGameModePermission.getChildren().keySet().forEach(pluginManager::removePermission);
@ -126,6 +148,11 @@ public class PermissionsTool {
setUpWorldPermissionWildcards();
}
/**
* Registers the permissions for a destination.
*
* @param destination The destination to register permissions for.
*/
public void registerDestinationTeleportPermissions(Destination<?> destination) {
try {
pluginManager.addPermission(new Permission(TELEPORT_PERM_PREFIX + "self." + destination.getIdentifier(), PermissionDefault.OP));
@ -138,6 +165,12 @@ public class PermissionsTool {
Logging.finer("Registered permissions for '" + destination.getIdentifier() + "'");
}
/**
* Registers the finer permissions for a destination.
*
* @param destination The destination to register permissions for.
* @param finerSuffix The finer suffix to register.
*/
public void registerFinerDestinationTeleportPermissions(Destination<?> destination, String finerSuffix) {
String finerPermissionName = TELEPORT_PERM_PREFIX + "self." + destination.getIdentifier() + "." + finerSuffix;
if (pluginManager.getPermission(finerPermissionName) != null) {
@ -160,26 +193,69 @@ public class PermissionsTool {
Logging.finer("Registered finer permissions '" + finerPermissionName + "' for '" + destination.getIdentifier() + "'");
}
/**
* Checks if a player has the permission to bypass the player limit.
*
* @param sender The player to check.
* @param toWorld The world to check.
* @return True if the player has the permission, false otherwise.
*/
public boolean hasBypassPlayerLimit(@NotNull CommandSender sender, @NotNull MVWorld toWorld) {
return hasPermission(sender, "mv.bypass.playerlimit." + toWorld.getName());
}
/**
* Checks if a player has the permission to bypass the entry fee.
*
* @param sender The player to check.
* @param toWorld The world to check.
* @return True if the player has the permission, false otherwise.
*/
public boolean hasBypassEntryFee(@NotNull CommandSender sender, @NotNull MVWorld toWorld) {
return hasPermission(sender, "multiverse.exempt." + toWorld.getName());
}
/**
* Checks if a player has the permission to bypass the game mode enforcement.
*
* @param sender The player to check.
* @param toWorld The world to check.
* @return True if the player has the permission, false otherwise.
*/
public boolean hasBypassGameModeEnforcement(@NotNull CommandSender sender, @NotNull MVWorld toWorld) {
return hasPermission(sender, "mv.bypass.gamemode." + toWorld.getName());
}
/**
* Checks if a player has the permission to access the world.
*
* @param sender The player to check.
* @param toWorld The world to check.
* @return True if the player has the permission, false otherwise.
*/
public boolean hasWorldAccess(@NotNull CommandSender sender, @NotNull MVWorld toWorld) {
return hasPermission(sender, "multiverse.access." + toWorld.getName());
}
/**
* Checks if a player has the permission to teleport to a destination.
*
* @param teleportee The player to check.
* @param destination The destination to check.
* @return True if the player has the permission, false otherwise.
*/
public boolean hasDestinationTeleportPermission(@NotNull CommandSender teleportee, @NotNull Destination<?> destination) {
return hasDestinationTeleportPermission(null, teleportee, destination);
}
/**
* Checks if a player has the permission to teleport to a destination.
*
* @param teleporter The player who is teleporting the other player.
* @param teleportee The player to check.
* @param destination The destination to check.
* @return True if the player has the permission, false otherwise.
*/
public boolean hasDestinationTeleportPermission(@Nullable CommandSender teleporter,
@NotNull CommandSender teleportee,
@NotNull Destination<?> destination
@ -190,10 +266,25 @@ public class PermissionsTool {
return hasPermission(teleporter, TELEPORT_PERM_PREFIX + "other." + destination.getIdentifier());
}
/**
* Checks if a player has the permission to teleport to a destination.
*
* @param teleportee The player to check.
* @param destination The destination to check.
* @return True if the player has the permission, false otherwise.
*/
public boolean hasFinerDestinationTeleportPermission(@NotNull CommandSender teleportee, @NotNull ParsedDestination<?> destination) {
return hasFinerDestinationTeleportPermission(null, teleportee, destination);
}
/**
* Checks if a player has the permission to teleport to a destination.
*
* @param teleporter The player who is teleporting the other player.
* @param teleportee The player to check.
* @param destination The destination to check.
* @return True if the player has the permission, false otherwise.
*/
public boolean hasFinerDestinationTeleportPermission(@Nullable CommandSender teleporter,
@NotNull CommandSender teleportee,
@NotNull ParsedDestination<?> destination
@ -208,12 +299,25 @@ public class PermissionsTool {
+ destination.getDestinationInstance().getFinerPermissionSuffix());
}
/**
* Checks if a player has the permission to teleport to at least 1 destination type.
*
* @param sender The player to check.
* @return True if the player has the permission, false otherwise.
*/
public boolean hasAnyDestinationTeleportPermissions(@NotNull CommandSender sender) {
return this.plugin.getDestinationsProvider().getRegisteredDestinations().stream()
.anyMatch(destination -> hasDestinationTeleportPermission(sender, this.plugin.getServer().getConsoleSender(), destination)
|| hasDestinationTeleportPermission(sender, destination));
}
/**
* Internal method to check if a player has a permission and does logging.
*
* @param sender The sender to check.
* @param permission The permission to check.
* @return True if the player has the permission, false otherwise.
*/
private boolean hasPermission(@NotNull CommandSender sender, @NotNull String permission) {
if (sender.hasPermission(permission)) {
Logging.finer("Checking to see if sender [" + sender.getName() + "] has permission [" + permission + "]... YES");

View File

@ -2,6 +2,9 @@ package com.onarandombox.MultiverseCore.utils.actioncheck;
import com.onarandombox.MultiverseCore.api.action.ActionResult;
/**
* The result of an player action check for {@link PlayerActionChecker}
*/
public enum ActionCheckResult implements ActionResult {
NULL_WORLD(false),
NULL_LOCATION(false),
@ -10,7 +13,7 @@ public enum ActionCheckResult implements ActionResult {
CAN_USE_DESTINATION(true),
NO_DESTINATION_PERMISSION(false),
NOT_MV_WORLD(true),
NOT_FROM_MVWORLD(true),
SAME_WORLD(true),
HAS_WORLD_ACCESS(true),
@ -41,15 +44,25 @@ public enum ActionCheckResult implements ActionResult {
this.isSuccessful = isSuccessful;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return this.name();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isSuccessful() {
return isSuccessful;
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasResult(ActionResult result) {
return result == this;

View File

@ -16,21 +16,52 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Checks if a player can perform an action.
*/
public class PlayerActionChecker {
private final MultiverseCore plugin;
private final MVWorldManager worldManager;
private final PermissionsTool permissionsTool;
/**
* Creates a new PlayerActionChecker.
*
* @param plugin The MultiverseCore plugin.
*/
public PlayerActionChecker(MultiverseCore plugin) {
this.plugin = plugin;
this.worldManager = plugin.getMVWorldManager();
this.permissionsTool = plugin.getPermissionsTool();
}
/**
* Checks if a player have permissions to teleport to a destination.
* <p>
* {@link ActionCheckResult#NULL_DESTINATION} if the destination is null.
* {@link ActionCheckResult#NO_DESTINATION_PERMISSION} if the player does not have permission to teleport to the destination.
* {@link ActionCheckResult#CAN_USE_DESTINATION} if the player can teleport to the destination.
*
* @param teleportee The player to teleport.
* @param destination The destination to teleport to.
* @return The result of the check.
*/
public ActionCheckResult canUseDestinationToTeleport(@NotNull Player teleportee, @Nullable ParsedDestination<?> destination){
return canUseDestinationToTeleport(null, teleportee, destination);
}
/**
* Checks if a player have permissions to teleport to a destination by another teleporter
* <p>
* {@link ActionCheckResult#NULL_DESTINATION} if the destination is null.
* {@link ActionCheckResult#NO_DESTINATION_PERMISSION} if the player does not have permission to teleport to the destination.
* {@link ActionCheckResult#CAN_USE_DESTINATION} if the player can teleport to the destination.
*
* @param teleporter The player who is teleporting the teleportee.
* @param teleportee The player to teleport.
* @param destination The destination to teleport to.
* @return The result of the check.
*/
public ActionCheckResult canUseDestinationToTeleport(@Nullable CommandSender teleporter,
@NotNull CommandSender teleportee,
@Nullable ParsedDestination<?> destination
@ -50,10 +81,61 @@ public class PlayerActionChecker {
? ActionCheckResult.CAN_USE_DESTINATION : ActionCheckResult.NO_DESTINATION_PERMISSION;
}
/**
* Checks if a player can teleport to a destination.
* <p>
* {@link ActionCheckResult#NULL_DESTINATION} if the destination is null.
* {@link ActionCheckResult#NULL_LOCATION} if the destination does not have a location.
* {@link ActionCheckResult#NOT_FROM_MVWORLD} if the destination is not a Multiverse world.
* {@link ActionCheckResult#SAME_WORLD} if the destination is in the same world as the player.
* {@link ActionCheckResult#NO_ENFORCE_WORLD_ACCESS} if multiverse enforceaccess is disabled.
* {@link ActionCheckResult#HAS_WORLD_ACCESS} if the player has access to the world.
* {@link ActionCheckResult#NO_WORLD_ACCESS} if the player does not have access to the world.
* {@link ActionCheckResult#EXEMPTED_FROM_ENTRY_FEE} if the player is exempted from entry fees.
* {@link ActionCheckResult#ENOUGH_MONEY} if the player has to pay an entry fee.
* {@link ActionCheckResult#NOT_ENOUGH_MONEY} if the player does not have enough money to pay the entry fee.
* {@link ActionCheckResult#FREE_ENTRY} if the player can enter the world for free.
* {@link ActionCheckResult#NO_PLAYERLIMIT} if the player limit is not enabled for the world.
* {@link ActionCheckResult#WITHIN_PLAYERLIMIT} if the player limit is not reached for the world.
* {@link ActionCheckResult#EXCEED_PLAYERLIMIT} if the player limit is reached for the world.
* {@link ActionCheckResult#BYPASS_PLAYERLIMIT} if the player can bypass the player limit for the world.
* {@link ActionCheckResult#NOT_BLACKLISTED} if the player's world is not blacklisted by the target to world.
* {@link ActionCheckResult#BLACKLISTED} if the player's world is blacklisted by the target to world.
*
* @param teleportee The player to teleport.
* @param destination The destination to teleport to.
* @return One or more of the above action results.
*/
public ActionResponse canGoToDestination(@NotNull Player teleportee, @Nullable ParsedDestination<?> destination){
return canGoToDestination(null, teleportee, destination);
}
/**
* Checks if a player can teleport to a destination.
* <p>
* {@link ActionCheckResult#NULL_DESTINATION} if the destination is null.
* {@link ActionCheckResult#NULL_LOCATION} if the destination does not have a location.
* {@link ActionCheckResult#NOT_FROM_MVWORLD} if the destination is not a Multiverse world.
* {@link ActionCheckResult#SAME_WORLD} if the destination is in the same world as the player.
* {@link ActionCheckResult#NO_ENFORCE_WORLD_ACCESS} if multiverse enforceaccess is disabled.
* {@link ActionCheckResult#HAS_WORLD_ACCESS} if the player has access to the world.
* {@link ActionCheckResult#NO_WORLD_ACCESS} if the player does not have access to the world.
* {@link ActionCheckResult#EXEMPTED_FROM_ENTRY_FEE} if the player is exempted from entry fees.
* {@link ActionCheckResult#ENOUGH_MONEY} if the player has to pay an entry fee.
* {@link ActionCheckResult#NOT_ENOUGH_MONEY} if the player does not have enough money to pay the entry fee.
* {@link ActionCheckResult#FREE_ENTRY} if the player can enter the world for free.
* {@link ActionCheckResult#NO_PLAYERLIMIT} if the player limit is not enabled for the world.
* {@link ActionCheckResult#WITHIN_PLAYERLIMIT} if the player limit is not reached for the world.
* {@link ActionCheckResult#EXCEED_PLAYERLIMIT} if the player limit is reached for the world.
* {@link ActionCheckResult#BYPASS_PLAYERLIMIT} if the player can bypass the player limit for the world.
* {@link ActionCheckResult#NOT_BLACKLISTED} if the player's world is not blacklisted by the target to world.
* {@link ActionCheckResult#BLACKLISTED} if the player's world is blacklisted by the target to world.
*
* @param teleporter The player who is teleporting the teleportee.
* @param teleportee The player to teleport.
* @param destination The destination to teleport to.
* @return One or more of the above action results.
*/
public ActionResponse canGoToDestination(@Nullable CommandSender teleporter,
@NotNull Player teleportee,
@Nullable ParsedDestination<?> destination
@ -68,10 +150,59 @@ public class PlayerActionChecker {
return canGoToLocation(teleporter, teleportee, location);
}
/**
* Checks if a player can teleport to a destination.
* <p>
* {@link ActionCheckResult#NULL_LOCATION} if the destination does not have a location.
* {@link ActionCheckResult#NOT_FROM_MVWORLD} if the destination is not a Multiverse world.
* {@link ActionCheckResult#SAME_WORLD} if the destination is in the same world as the player.
* {@link ActionCheckResult#NO_ENFORCE_WORLD_ACCESS} if multiverse enforceaccess is disabled.
* {@link ActionCheckResult#HAS_WORLD_ACCESS} if the player has access to the world.
* {@link ActionCheckResult#NO_WORLD_ACCESS} if the player does not have access to the world.
* {@link ActionCheckResult#EXEMPTED_FROM_ENTRY_FEE} if the player is exempted from entry fees.
* {@link ActionCheckResult#ENOUGH_MONEY} if the player has to pay an entry fee.
* {@link ActionCheckResult#NOT_ENOUGH_MONEY} if the player does not have enough money to pay the entry fee.
* {@link ActionCheckResult#FREE_ENTRY} if the player can enter the world for free.
* {@link ActionCheckResult#NO_PLAYERLIMIT} if the player limit is not enabled for the world.
* {@link ActionCheckResult#WITHIN_PLAYERLIMIT} if the player limit is not reached for the world.
* {@link ActionCheckResult#EXCEED_PLAYERLIMIT} if the player limit is reached for the world.
* {@link ActionCheckResult#BYPASS_PLAYERLIMIT} if the player can bypass the player limit for the world.
* {@link ActionCheckResult#NOT_BLACKLISTED} if the player's world is not blacklisted by the target to world.
* {@link ActionCheckResult#BLACKLISTED} if the player's world is blacklisted by the target to world.
*
* @param teleportee The player to teleport.
* @param location The location to teleport to.
* @return One or more of the above action results.
*/
public ActionResponse canGoToLocation(@NotNull Player teleportee, @Nullable Location location){
return canGoToLocation(null, teleportee, location);
}
/**
* Checks if a player can teleport to a location.
* <p>
* {@link ActionCheckResult#NULL_LOCATION} if the destination does not have a location.
* {@link ActionCheckResult#NOT_FROM_MVWORLD} if the destination is not a Multiverse world.
* {@link ActionCheckResult#SAME_WORLD} if the destination is in the same world as the player.
* {@link ActionCheckResult#NO_ENFORCE_WORLD_ACCESS} if multiverse enforceaccess is disabled.
* {@link ActionCheckResult#HAS_WORLD_ACCESS} if the player has access to the world.
* {@link ActionCheckResult#NO_WORLD_ACCESS} if the player does not have access to the world.
* {@link ActionCheckResult#EXEMPTED_FROM_ENTRY_FEE} if the player is exempted from entry fees.
* {@link ActionCheckResult#ENOUGH_MONEY} if the player has to pay an entry fee.
* {@link ActionCheckResult#NOT_ENOUGH_MONEY} if the player does not have enough money to pay the entry fee.
* {@link ActionCheckResult#FREE_ENTRY} if the player can enter the world for free.
* {@link ActionCheckResult#NO_PLAYERLIMIT} if the player limit is not enabled for the world.
* {@link ActionCheckResult#WITHIN_PLAYERLIMIT} if the player limit is not reached for the world.
* {@link ActionCheckResult#EXCEED_PLAYERLIMIT} if the player limit is reached for the world.
* {@link ActionCheckResult#BYPASS_PLAYERLIMIT} if the player can bypass the player limit for the world.
* {@link ActionCheckResult#NOT_BLACKLISTED} if the player's world is not blacklisted by the target to world.
* {@link ActionCheckResult#BLACKLISTED} if the player's world is blacklisted by the target to world.
*
* @param teleporter The player who is teleporting the teleportee.
* @param teleportee The player to teleport.
* @param location The location to teleport to.
* @return One or more of the above action results.
*/
public ActionResponse canGoToLocation(@Nullable CommandSender teleporter,
@NotNull Player teleportee,
@Nullable Location location
@ -83,22 +214,116 @@ public class PlayerActionChecker {
return canEnterWorld(teleporter, teleportee, toWorld);
}
public ActionResponse canEnterWorld(@NotNull Player player, @NotNull MVWorld toWorld) {
return canEnterWorld(null, player, toWorld);
/**
* Checks if a player can teleport to a world.
* <p>
* {@link ActionCheckResult#NOT_FROM_MVWORLD} if the destination is not a Multiverse world.
* {@link ActionCheckResult#SAME_WORLD} if the destination is in the same world as the player.
* {@link ActionCheckResult#NO_ENFORCE_WORLD_ACCESS} if multiverse enforceaccess is disabled.
* {@link ActionCheckResult#HAS_WORLD_ACCESS} if the player has access to the world.
* {@link ActionCheckResult#NO_WORLD_ACCESS} if the player does not have access to the world.
* {@link ActionCheckResult#EXEMPTED_FROM_ENTRY_FEE} if the player is exempted from entry fees.
* {@link ActionCheckResult#ENOUGH_MONEY} if the player has to pay an entry fee.
* {@link ActionCheckResult#NOT_ENOUGH_MONEY} if the player does not have enough money to pay the entry fee.
* {@link ActionCheckResult#FREE_ENTRY} if the player can enter the world for free.
* {@link ActionCheckResult#NO_PLAYERLIMIT} if the player limit is not enabled for the world.
* {@link ActionCheckResult#WITHIN_PLAYERLIMIT} if the player limit is not reached for the world.
* {@link ActionCheckResult#EXCEED_PLAYERLIMIT} if the player limit is reached for the world.
* {@link ActionCheckResult#BYPASS_PLAYERLIMIT} if the player can bypass the player limit for the world.
* {@link ActionCheckResult#NOT_BLACKLISTED} if the player's world is not blacklisted by the target to world.
* {@link ActionCheckResult#BLACKLISTED} if the player's world is blacklisted by the target to world.
*
* @param teleportee The player to teleport.
* @param toWorld The world to teleport to.
* @return One or more of the above action results.
*/
public ActionResponse canEnterWorld(@NotNull Player teleportee, @NotNull MVWorld toWorld) {
return canEnterWorld(null, teleportee, toWorld);
}
/**
* Checks if a player can teleport to a world.
* <p>
* {@link ActionCheckResult#NOT_FROM_MVWORLD} if the destination is not a Multiverse world.
* {@link ActionCheckResult#SAME_WORLD} if the destination is in the same world as the player.
* {@link ActionCheckResult#NO_ENFORCE_WORLD_ACCESS} if multiverse enforceaccess is disabled.
* {@link ActionCheckResult#HAS_WORLD_ACCESS} if the player has access to the world.
* {@link ActionCheckResult#NO_WORLD_ACCESS} if the player does not have access to the world.
* {@link ActionCheckResult#EXEMPTED_FROM_ENTRY_FEE} if the player is exempted from entry fees.
* {@link ActionCheckResult#ENOUGH_MONEY} if the player has to pay an entry fee.
* {@link ActionCheckResult#NOT_ENOUGH_MONEY} if the player does not have enough money to pay the entry fee.
* {@link ActionCheckResult#FREE_ENTRY} if the player can enter the world for free.
* {@link ActionCheckResult#NO_PLAYERLIMIT} if the player limit is not enabled for the world.
* {@link ActionCheckResult#WITHIN_PLAYERLIMIT} if the player limit is not reached for the world.
* {@link ActionCheckResult#EXCEED_PLAYERLIMIT} if the player limit is reached for the world.
* {@link ActionCheckResult#BYPASS_PLAYERLIMIT} if the player can bypass the player limit for the world.
* {@link ActionCheckResult#NOT_BLACKLISTED} if the player's world is not blacklisted by the target to world.
* {@link ActionCheckResult#BLACKLISTED} if the player's world is blacklisted by the target to world.
*
* @param teleporter The player who is teleporting the teleportee.
* @param teleportee The player to teleport.
* @param toWorld The world to teleport to.
* @return One or more of the above action results.
*/
public ActionResponse canEnterWorld(@Nullable CommandSender teleporter,
@NotNull Player player,
@NotNull Player teleportee,
@NotNull MVWorld toWorld
) {
MVWorld fromWorld = this.worldManager.getMVWorld(player.getWorld());
return canGoFromToWorld(teleporter, player, fromWorld, toWorld);
MVWorld fromWorld = this.worldManager.getMVWorld(teleportee.getWorld());
return canGoFromToWorld(teleporter, teleportee, fromWorld, toWorld);
}
/**
* Checks if a player can teleport from a world to another world.
* <p>
* {@link ActionCheckResult#NOT_FROM_MVWORLD} if the destination is not a Multiverse world.
* {@link ActionCheckResult#SAME_WORLD} if the destination is in the same world as the player.
* {@link ActionCheckResult#NO_ENFORCE_WORLD_ACCESS} if multiverse enforceaccess is disabled.
* {@link ActionCheckResult#HAS_WORLD_ACCESS} if the player has access to the world.
* {@link ActionCheckResult#NO_WORLD_ACCESS} if the player does not have access to the world.
* {@link ActionCheckResult#EXEMPTED_FROM_ENTRY_FEE} if the player is exempted from entry fees.
* {@link ActionCheckResult#ENOUGH_MONEY} if the player has to pay an entry fee.
* {@link ActionCheckResult#NOT_ENOUGH_MONEY} if the player does not have enough money to pay the entry fee.
* {@link ActionCheckResult#FREE_ENTRY} if the player can enter the world for free.
* {@link ActionCheckResult#NO_PLAYERLIMIT} if the player limit is not enabled for the world.
* {@link ActionCheckResult#WITHIN_PLAYERLIMIT} if the player limit is not reached for the world.
* {@link ActionCheckResult#EXCEED_PLAYERLIMIT} if the player limit is reached for the world.
* {@link ActionCheckResult#BYPASS_PLAYERLIMIT} if the player can bypass the player limit for the world.
* {@link ActionCheckResult#NOT_BLACKLISTED} if the player's world is not blacklisted by the target to world.
* {@link ActionCheckResult#BLACKLISTED} if the player's world is blacklisted by the target to world.
*
* @param teleportee The player to teleport.
* @param toWorld The world to teleport to.
* @return One or more of the above action results.
*/
public ActionResponse canGoFromToWorld(@NotNull CommandSender teleportee, @Nullable MVWorld fromWorld, @NotNull MVWorld toWorld) {
return canGoFromToWorld(null, teleportee, fromWorld, toWorld);
}
/**
* Checks if a player can teleport from a world to another world.
* <p>
* {@link ActionCheckResult#NOT_FROM_MVWORLD} if the destination is not a Multiverse world.
* {@link ActionCheckResult#SAME_WORLD} if the destination is in the same world as the player.
* {@link ActionCheckResult#NO_ENFORCE_WORLD_ACCESS} if multiverse enforceaccess is disabled.
* {@link ActionCheckResult#HAS_WORLD_ACCESS} if the player has access to the world.
* {@link ActionCheckResult#NO_WORLD_ACCESS} if the player does not have access to the world.
* {@link ActionCheckResult#EXEMPTED_FROM_ENTRY_FEE} if the player is exempted from entry fees.
* {@link ActionCheckResult#ENOUGH_MONEY} if the player has to pay an entry fee.
* {@link ActionCheckResult#NOT_ENOUGH_MONEY} if the player does not have enough money to pay the entry fee.
* {@link ActionCheckResult#FREE_ENTRY} if the player can enter the world for free.
* {@link ActionCheckResult#NO_PLAYERLIMIT} if the player limit is not enabled for the world.
* {@link ActionCheckResult#WITHIN_PLAYERLIMIT} if the player limit is not reached for the world.
* {@link ActionCheckResult#EXCEED_PLAYERLIMIT} if the player limit is reached for the world.
* {@link ActionCheckResult#BYPASS_PLAYERLIMIT} if the player can bypass the player limit for the world.
* {@link ActionCheckResult#NOT_BLACKLISTED} if the player's world is not blacklisted by the target to world.
* {@link ActionCheckResult#BLACKLISTED} if the player's world is blacklisted by the target to world.
*
* @param teleporter The player who is teleporting the teleportee.
* @param teleportee The player to teleport.
* @param toWorld The world to teleport to.
* @return One or more of the above action results.
*/
public ActionResponse canGoFromToWorld(@Nullable CommandSender teleporter,
@NotNull CommandSender teleportee,
@Nullable MVWorld fromWorld,
@ -106,7 +331,7 @@ public class PlayerActionChecker {
) {
ActionResponse response = new ActionResponse();
if (toWorld == null) {
return new ActionResponse().addResult(ActionCheckResult.NOT_MV_WORLD);
return new ActionResponse().addResult(ActionCheckResult.NOT_FROM_MVWORLD);
}
if (toWorld.equals(fromWorld)) {
return response.addResult(ActionCheckResult.SAME_WORLD)
@ -121,6 +346,17 @@ public class PlayerActionChecker {
.then(() -> hasMoneyToEnterWorld(targetSender, toWorld));
}
/**
* Checks if a player has access to a world.
* <p>
* {@link ActionCheckResult#NO_ENFORCE_WORLD_ACCESS} if multiverse enforceaccess is disabled.
* {@link ActionCheckResult#HAS_WORLD_ACCESS} if the player has access to the world.
* {@link ActionCheckResult#NO_WORLD_ACCESS} if the player does not have access to the world.
*
* @param sender The sender to check.
* @param toWorld The world to teleport to.
* @return The action check result.
*/
public ActionCheckResult hasAccessToWorld(@NotNull CommandSender sender, @NotNull MVWorld toWorld) {
if (!this.plugin.getMVConfig().getEnforceAccess()) {
return ActionCheckResult.NO_ENFORCE_WORLD_ACCESS;
@ -129,6 +365,18 @@ public class PlayerActionChecker {
? ActionCheckResult.HAS_WORLD_ACCESS : ActionCheckResult.NO_WORLD_ACCESS;
}
/**
* Checks if a player has access to a world.
* <p>
* {@link ActionCheckResult#EXEMPTED_FROM_ENTRY_FEE} if the player is exempted from entry fees.
* {@link ActionCheckResult#ENOUGH_MONEY} if the player has to pay an entry fee.
* {@link ActionCheckResult#NOT_ENOUGH_MONEY} if the player does not have enough money to pay the entry fee.
* {@link ActionCheckResult#FREE_ENTRY} if the player can enter the world for free.
*
* @param sender The sender to check.
* @param toWorld The world to teleport to.
* @return The action check result.
*/
public ActionCheckResult hasMoneyToEnterWorld(@NotNull CommandSender sender, @NotNull MVWorld toWorld) {
if (sender instanceof ConsoleCommandSender || sender instanceof BlockCommandSender) {
return ActionCheckResult.EXEMPTED_FROM_ENTRY_FEE;
@ -152,6 +400,17 @@ public class PlayerActionChecker {
? ActionCheckResult.ENOUGH_MONEY : ActionCheckResult.NOT_ENOUGH_MONEY;
}
/**
* Checks if a player is within the player limit of a world.
* <p>
* {@link ActionCheckResult#NO_PLAYERLIMIT} if the player limit is not enabled for the world.
* {@link ActionCheckResult#WITHIN_PLAYERLIMIT} if the player limit is not reached for the world.
* {@link ActionCheckResult#EXCEED_PLAYERLIMIT} if the player limit is reached for the world.
*
* @param sender The sender to check.
* @param toWorld The world to teleport to.
* @return The action check result.
*/
public ActionCheckResult isWithinPlayerLimit(@NotNull CommandSender sender, @NotNull MVWorld toWorld) {
if (toWorld.getPlayerLimit() <= -1) {
return ActionCheckResult.NO_PLAYERLIMIT;
@ -163,11 +422,31 @@ public class PlayerActionChecker {
? ActionCheckResult.BYPASS_PLAYERLIMIT : ActionCheckResult.EXCEED_PLAYERLIMIT;
}
public ActionCheckResult isNotBlacklisted(@NotNull Player player, @NotNull MVWorld toWorld) {
MVWorld fromWorld = this.worldManager.getMVWorld(player.getWorld());
/**
* Checks if a player is not blacklisted from a world.
* <p>
* {@link ActionCheckResult#NOT_BLACKLISTED} if the player's world is not blacklisted by the target to world.
* {@link ActionCheckResult#BLACKLISTED} if the player's world is blacklisted by the target to world.
*
* @param teleportee The player to check.
* @param toWorld The world to teleport to.
* @return The action check result.
*/
public ActionCheckResult isNotBlacklisted(@NotNull Player teleportee, @NotNull MVWorld toWorld) {
MVWorld fromWorld = this.worldManager.getMVWorld(teleportee.getWorld());
return isNotBlacklisted(fromWorld, toWorld);
}
/**
* Checks if a world is not blacklisted by another world.
* <p>
* {@link ActionCheckResult#NOT_BLACKLISTED} if the player's world is not blacklisted by the target to world.
* {@link ActionCheckResult#BLACKLISTED} if the player's world is blacklisted by the target to world.
*
* @param fromWorld The from world that is checked for blacklisting.
* @param toWorld The to world that has the blacklist.
* @return The action check result.
*/
public ActionCheckResult isNotBlacklisted(@Nullable MVWorld fromWorld, @NotNull MVWorld toWorld) {
if (fromWorld == null) {
// No blacklisting if the player is not in a MV world
@ -177,9 +456,19 @@ public class PlayerActionChecker {
? ActionCheckResult.BLACKLISTED : ActionCheckResult.NOT_BLACKLISTED;
}
public ActionCheckResult canKeepGameMode(@NotNull CommandSender sender, @NotNull MVWorld toWorld) {
/**
* Checks if a player can keep their game mode on world change.
* <p>
* {@link ActionCheckResult#KEEP_GAME_MODE} if the player is exempted from game mode enforcement.
* {@link ActionCheckResult#ENFORCE_GAME_MODE} if the player is not exempted from game mode enforcement.
*
* @param player The sender to check.
* @param toWorld The world to teleport to.
* @return The action check result.
*/
public ActionCheckResult canKeepGameMode(@NotNull Player player, @NotNull MVWorld toWorld) {
//TODO: Add config option disable game mode enforcement
return permissionsTool.hasBypassGameModeEnforcement(sender, toWorld)
return permissionsTool.hasBypassGameModeEnforcement(player, toWorld)
? ActionCheckResult.KEEP_GAME_MODE : ActionCheckResult.ENFORCE_GAME_MODE;
}
}

View File

@ -0,0 +1,4 @@
/**
* This package contains the ActionCheck class, which is used to check if a player is allowed to
*/
package com.onarandombox.MultiverseCore.utils.actioncheck;

View File

@ -297,7 +297,7 @@ public class SimpleMVWorld implements MVWorld {
for (Player p : plugin.getServer().getWorld(getName()).getPlayers()) {
Logging.finer(String.format("Setting %s's GameMode to %s",
p.getName(), newValue.toString()));
plugin.getPlayerListener().handleGameModeAndFlight(p, SimpleMVWorld.this);
plugin.getPlayerListener().applyGameModeAndFlight(p, SimpleMVWorld.this);
}
return super.validateChange(property, newValue, oldValue, object);
}