Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespaces Draft #423

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import io.papermc.lib.PaperLib;
import org.bukkit.BanList.Type;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -54,6 +55,16 @@ public String getName() {
return name;
}

@Override
public String getDefaultNamespace() {
// TODO: Add a per player override
boolean useNamespaces = WorldGuard.getInstance().getPlatform().getGlobalStateManager().useNamespaces;
if (useNamespaces) {
return getUniqueId().toString();
}
return null;
}

@Override
public boolean hasGroup(String group) {
return plugin.inGroup(getPlayer(), group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@

public interface LocalPlayer extends Player, RegionAssociable {

/**
* Returns the default namespace for this player.
*
* @return the default namespace.
*/
String getDefaultNamespace();

default boolean isDefaultNamespace(String otherNamespace) {
String namespace = getDefaultNamespace();
// If both are null, they're the same (the global)
if (namespace == null && otherNamespace == null) {
return true;
}

// If only one is null, they're a mismatch
if (namespace == null || otherNamespace == null) {
return false;
}

// Compare string equality
return namespace.equalsIgnoreCase(otherNamespace);
}

/**
* Returns true if this player is inside a group.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionIdentifier;
import com.sk89q.worldguard.protection.util.DomainInputResolver;
import com.sk89q.worldguard.protection.util.DomainInputResolver.UserLocatorPolicy;

Expand All @@ -50,13 +51,13 @@ public MemberCommands(WorldGuard worldGuard) {
flags = "nw:",
desc = "Add a member to a region",
min = 2)
public void addMember(CommandContext args, Actor sender) throws CommandException {
public void addMember(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
warnAboutSaveFailures(sender);

World world = checkWorld(args, sender, 'w'); // Get the world
String id = args.getString(0);
RegionManager manager = checkRegionManager(world);
ProtectedRegion region = checkExistingRegion(manager, id, true);
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
ProtectedRegion region = checkExistingRegion(sender, manager, id);

// Check permissions
if (!getPermissionModel(sender).mayAddMembers(region)) {
Expand All @@ -69,10 +70,11 @@ public void addMember(CommandContext args, Actor sender) throws CommandException
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);


final String description = String.format("Adding members to the region '%s' on '%s'", region.getId(), world.getName());
String friendlyName = id.getDisplayName(sender);
final String description = String.format("Adding members to the region '%s' on '%s'", friendlyName, world.getName());
AsyncCommandBuilder.wrap(resolver, sender)
.registerWithSupervisor(worldGuard.getSupervisor(), description)
.onSuccess(String.format("Region '%s' updated with new members.", region.getId()), region.getMembers()::addAll)
.onSuccess(String.format("Region '%s' updated with new members.", friendlyName), region.getMembers()::addAll)
.onFailure("Failed to add new members", worldGuard.getExceptionConverter())
.buildAndExec(worldGuard.getExecutorService());
}
Expand All @@ -82,15 +84,14 @@ public void addMember(CommandContext args, Actor sender) throws CommandException
flags = "nw:",
desc = "Add an owner to a region",
min = 2)
public void addOwner(CommandContext args, Actor sender) throws CommandException {
public void addOwner(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
warnAboutSaveFailures(sender);

World world = checkWorld(args, sender, 'w'); // Get the world

String id = args.getString(0);

RegionManager manager = checkRegionManager(world);
ProtectedRegion region = checkExistingRegion(manager, id, true);
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
ProtectedRegion region = checkExistingRegion(sender, manager, id);

// Check permissions
if (!getPermissionModel(sender).mayAddOwners(region)) {
Expand All @@ -103,10 +104,11 @@ public void addOwner(CommandContext args, Actor sender) throws CommandException
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);


final String description = String.format("Adding owners to the region '%s' on '%s'", region.getId(), world.getName());
String friendlyName = id.getDisplayName(sender);
final String description = String.format("Adding owners to the region '%s' on '%s'", friendlyName, world.getName());
AsyncCommandBuilder.wrap(checkedAddOwners(sender, manager, region, world, resolver), sender)
.registerWithSupervisor(worldGuard.getSupervisor(), description)
.onSuccess(String.format("Region '%s' updated with new owners.", region.getId()), region.getOwners()::addAll)
.onSuccess(String.format("Region '%s' updated with new owners.", friendlyName), region.getOwners()::addAll)
.onFailure("Failed to add new owners", worldGuard.getExceptionConverter())
.buildAndExec(worldGuard.getExecutorService());
}
Expand Down Expand Up @@ -149,13 +151,13 @@ private static Callable<DefaultDomain> checkedAddOwners(Actor sender, RegionMana
flags = "naw:",
desc = "Remove an owner to a region",
min = 1)
public void removeMember(CommandContext args, Actor sender) throws CommandException {
public void removeMember(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
warnAboutSaveFailures(sender);

World world = checkWorld(args, sender, 'w'); // Get the world
String id = args.getString(0);
RegionManager manager = checkRegionManager(world);
ProtectedRegion region = checkExistingRegion(manager, id, true);
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
ProtectedRegion region = checkExistingRegion(sender, manager, id);

// Check permissions
if (!getPermissionModel(sender).mayRemoveMembers(region)) {
Expand All @@ -178,11 +180,12 @@ public void removeMember(CommandContext args, Actor sender) throws CommandExcept
callable = resolver;
}

final String description = String.format("Removing members from the region '%s' on '%s'", region.getId(), world.getName());
String friendlyName = id.getDisplayName(sender);
final String description = String.format("Removing members from the region '%s' on '%s'", friendlyName, world.getName());
AsyncCommandBuilder.wrap(callable, sender)
.registerWithSupervisor(worldGuard.getSupervisor(), description)
.sendMessageAfterDelay("(Please wait... querying player names...)")
.onSuccess(String.format("Region '%s' updated with members removed.", region.getId()), region.getMembers()::removeAll)
.onSuccess(String.format("Region '%s' updated with members removed.", friendlyName), region.getMembers()::removeAll)
.onFailure("Failed to remove members", worldGuard.getExceptionConverter())
.buildAndExec(worldGuard.getExecutorService());
}
Expand All @@ -192,13 +195,13 @@ public void removeMember(CommandContext args, Actor sender) throws CommandExcept
flags = "naw:",
desc = "Remove an owner to a region",
min = 1)
public void removeOwner(CommandContext args, Actor sender) throws CommandException {
public void removeOwner(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
warnAboutSaveFailures(sender);

World world = checkWorld(args, sender, 'w'); // Get the world
String id = args.getString(0);
RegionManager manager = checkRegionManager(world);
ProtectedRegion region = checkExistingRegion(manager, id, true);
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
ProtectedRegion region = checkExistingRegion(sender, manager, id);

// Check permissions
if (!getPermissionModel(sender).mayRemoveOwners(region)) {
Expand All @@ -221,11 +224,12 @@ public void removeOwner(CommandContext args, Actor sender) throws CommandExcepti
callable = resolver;
}

final String description = String.format("Removing owners from the region '%s' on '%s'", region.getId(), world.getName());
String friendlyName = id.getDisplayName(sender);
final String description = String.format("Removing owners from the region '%s' on '%s'", friendlyName, world.getName());
AsyncCommandBuilder.wrap(callable, sender)
.registerWithSupervisor(worldGuard.getSupervisor(), description)
.sendMessageAfterDelay("(Please wait... querying player names...)")
.onSuccess(String.format("Region '%s' updated with owners removed.", region.getId()), region.getOwners()::removeAll)
.onSuccess(String.format("Region '%s' updated with owners removed.", friendlyName), region.getOwners()::removeAll)
.onFailure("Failed to remove owners", worldGuard.getExceptionConverter())
.buildAndExec(worldGuard.getExecutorService());
}
Expand Down
Loading