Skip to content
Open
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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</repository>
<repository>
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>sk89q-repo</id>
Expand All @@ -31,13 +31,13 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.2-R0.1-SNAPSHOT</version>
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>LATEST</version>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@

import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.codemc.worldguardwrapper.WorldGuardWrapper;
import org.codemc.worldguardwrapper.region.IWrappedRegion;
import org.codemc.worldguardwrapper.selection.ICuboidSelection;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toMap;

public class WorldGuardExpansion extends PlaceholderExpansion {
Expand All @@ -55,7 +57,7 @@ public boolean canRegister() {
}

@Override
public String getName() {
public @NotNull String getName() {
return NAME;
}

Expand All @@ -65,7 +67,7 @@ public String getName() {
* @return The name of the author as a String.
*/
@Override
public String getAuthor() {
public @NotNull String getAuthor() {
return "clip";
}

Expand All @@ -75,7 +77,7 @@ public String getAuthor() {
* @return The version as a String.
*/
@Override
public String getVersion() {
public @NotNull String getVersion() {
return VERSION;
}

Expand All @@ -85,14 +87,22 @@ public String getVersion() {
* @return "worldguard".
*/
@Override
public String getIdentifier() {
public @NotNull String getIdentifier() {
return IDENTIFIER;
}


@Override
public String onRequest(OfflinePlayer offlinePlayer, String params) {

if (params.equalsIgnoreCase("regions")) {
return String.join(", ",getRegions(offlinePlayer.getLocation()));
}
if (params.startsWith("is_in_region_")) {
List<String> regions = getRegions(offlinePlayer.getLocation());
return regions.contains(params.substring(13)) ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse();
}

// Get the wrapper from input location
IWrappedRegion region;
ICuboidSelection selection;
Expand Down Expand Up @@ -134,15 +144,29 @@ public String onRequest(OfflinePlayer offlinePlayer, String params) {
return region.getFlags().keySet().stream().anyMatch(f ->
f.getName().equalsIgnoreCase(rg[1])) ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse();
}
if (params.startsWith("region_flag_")) {
final String[] rg = params.split("region_flag_");
if (rg.length < 1) return null;

Optional<?> flag = region.getFlags().keySet().stream().filter(f ->
f.getName().equalsIgnoreCase(rg[1])).map(region::getFlag).findAny().orElse(null);
if (flag == null || !flag.isPresent()) return "";
return flag.get() instanceof Optional && ((Optional<?>) flag.get()).isPresent()
? String.valueOf(((Optional<?>) flag.get()).get())
: "";
}

// Defined as a switch statement to keep thinks clean
switch (params) {
// Check the name of the region the player is in
case "region_name":
return region.getId();
// Because some people are stubborn, let's have it also provide capitalization
// lul, that's fair
case "region_name_capitalized":
return Character.isLetter(region.getId().charAt(0)) ? StringUtils.capitalize(region.getId()) : region.getId();
return Character.isLetter(region.getId().charAt(0))
? String.valueOf(region.getId().charAt(0)).toUpperCase() + region.getId().substring(1)
: region.getId();
case "region_owner": {
// Create a set of owners
Set<String> owners = new HashSet<>();
Expand Down Expand Up @@ -220,6 +244,12 @@ private IWrappedRegion getRegion(Location location, int priority) {
return null;
}
}
private List<String> getRegions(Location location) {
return worldguard.getRegions(location)
.stream()
.map(IWrappedRegion::getId)
.collect(Collectors.toList());
}

/**
* Convert a string to a location
Expand Down