9
0
mirror of https://gitlab.com/SamB440/rpgregions-2.git synced 2025-12-29 03:39:08 +00:00

Make /rpgregions add <region> show integration-specific command completions

This commit is contained in:
SamB440
2020-09-26 18:28:38 +01:00
parent edf35ae742
commit 6f4b35bb0b
8 changed files with 52 additions and 1 deletions

View File

@@ -94,4 +94,12 @@ public class WorldGuardLegacyIntegration implements IntegrationManager {
.getApplicableRegions(location)
.getRegions();
}
@Override
public Set<String> getAllRegionNames(org.bukkit.World world) {
return WorldGuardPlugin.inst()
.getRegionContainer()
.get(world)
.getRegions().keySet();
}
}

View File

@@ -16,7 +16,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class GriefPreventionIntegration implements IntegrationManager {
@@ -83,4 +85,13 @@ public class GriefPreventionIntegration implements IntegrationManager {
Claim claim = GriefPrevention.instance.dataStore.getClaim(Long.parseLong(region));
return claim != null;
}
@Override
public Set<String> getAllRegionNames(World world) {
Set<String> claims = new HashSet<>();
for (Claim claim : GriefPrevention.instance.dataStore.getClaims()) {
claims.add("" + claim.getID());
}
return claims;
}
}

View File

@@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class ResidenceIntegration implements IntegrationManager {
@@ -83,4 +84,9 @@ public class ResidenceIntegration implements IntegrationManager {
ClaimedResidence res = Residence.getInstance().getResidenceManager().getByName(region);
return res != null;
}
@Override
public Set<String> getAllRegionNames(World world) {
return Residence.getInstance().getResidenceManager().getResidences().keySet();
}
}

View File

@@ -19,7 +19,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class UltraRegionsIntegration implements IntegrationManager {
@@ -98,6 +100,16 @@ public class UltraRegionsIntegration implements IntegrationManager {
return !regions.isEmpty();
}
@Override
public Set<String> getAllRegionNames(World world) {
ManagedWorld managedWorld = UltraRegions.getAPI().getWorlds().find(world);
Set<String> regions = new HashSet<>();
for (Region region : UltraRegions.getAPI().newRegionQuery(managedWorld).getRegions()) {
regions.add(region.getName());
}
return regions;
}
private List<Region> getProtectedRegions(Location location) {
ManagedWorld world = UltraRegions.getAPI().getWorlds().find(location.getWorld());
RegionQuery query = UltraRegions.getAPI().newRegionQuery(world).location(new XYZ(location.getX(), location.getY(), location.getZ()));

View File

@@ -109,6 +109,15 @@ public class WorldGuardIntegration implements IntegrationManager {
.getRegions().containsKey(region);
}
@Override
public Set<String> getAllRegionNames(World world) {
return WorldGuard.getInstance()
.getPlatform()
.getRegionContainer()
.get(BukkitAdapter.adapt(world))
.getRegions().keySet();
}
private Set<ProtectedRegion> getProtectedRegions(Location location) {
return WorldGuard.getInstance()
.getPlatform()

View File

@@ -192,6 +192,7 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu
private void registerCommands() {
PaperCommandManager manager = new PaperCommandManager(this);
manager.getCommandCompletions().registerAsyncCompletion("regions", context -> ImmutableList.copyOf(getManagers().getRegionsCache().getConfiguredRegions().keySet()));
manager.getCommandCompletions().registerAsyncCompletion("integration-regions", context -> ImmutableList.copyOf(this.getManagers().getIntegrationManager().getAllRegionNames(context.getPlayer().getWorld())));
manager.getCommandCompletions().registerAsyncCompletion("schematics", context -> {
File schematicFolder = new File("plugins/WorldEdit/schematics/");
List<String> files = new ArrayList<>();

View File

@@ -5,6 +5,8 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.Set;
public interface IntegrationManager {
/**
@@ -29,4 +31,6 @@ public interface IntegrationManager {
boolean exists(World location, String region);
Set<String> getAllRegionNames(World world);
}

View File

@@ -66,7 +66,7 @@ public class RPGRegionsCommand extends BaseCommand {
@Subcommand("add")
@CommandPermission("rpgregions.add")
@CommandCompletion("@regions")
@CommandCompletion("@integration-regions")
public void onAdd(Player player, String region) {
if (!plugin.getManagers().getIntegrationManager().exists(player.getLocation().getWorld(), region)) {
player.sendMessage(StringUtils.colour("&cThat region does not exist in your protection plugin."));