├── .gitignore ├── LICENSE.txt ├── README.md ├── pom.xml └── src └── main ├── java └── me │ └── lucko │ └── extracontexts │ ├── ExtraContextsPlugin.java │ └── calculators │ ├── HasPlayedBeforeCalculator.java │ ├── PlaceholderApiCalculator.java │ ├── TeamCalculator.java │ ├── WhitelistedCalculator.java │ ├── WorldGuardFlagCalculator.java │ └── WorldGuardRegionCalculator.java └── resources ├── config.yml └── plugin.yml /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/ 2 | 3 | ### Intellij ### 4 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 5 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 6 | 7 | # User-specific stuff: 8 | .idea/ 9 | *.iws 10 | /out/ 11 | *.iml 12 | .idea_modules/ 13 | 14 | # JIRA plugin 15 | atlassian-ide-plugin.xml 16 | 17 | # Crashlytics plugin (for Android Studio and IntelliJ) 18 | com_crashlytics_export_strings.xml 19 | crashlytics.properties 20 | crashlytics-build.properties 21 | fabric.properties 22 | 23 | 24 | ### Maven ### 25 | target/ 26 | pom.xml.tag 27 | pom.xml.releaseBackup 28 | pom.xml.versionsBackup 29 | pom.xml.next 30 | release.properties 31 | dependency-reduced-pom.xml 32 | buildNumber.properties 33 | .mvn/timing.properties 34 | 35 | 36 | ### Eclipse ### 37 | 38 | .metadata 39 | bin/ 40 | tmp/ 41 | *.tmp 42 | *.bak 43 | *.swp 44 | *~.nib 45 | local.properties 46 | .settings/ 47 | .loadpath 48 | .recommenders 49 | 50 | # Eclipse Core 51 | .project 52 | 53 | # External tool builders 54 | .externalToolBuilders/ 55 | 56 | # Locally stored "Eclipse launch configurations" 57 | *.launch 58 | 59 | # PyDev specific (Python IDE for Eclipse) 60 | *.pydevproject 61 | 62 | # CDT-specific (C/C++ Development Tooling) 63 | .cproject 64 | 65 | # JDT-specific (Eclipse Java Development Tools) 66 | .classpath 67 | 68 | # Java annotation processor (APT) 69 | .factorypath 70 | 71 | # PDT-specific (PHP Development Tools) 72 | .buildpath 73 | 74 | # sbteclipse plugin 75 | .target 76 | 77 | # Tern plugin 78 | .tern-project 79 | 80 | # TeXlipse plugin 81 | .texlipse 82 | 83 | # STS (Spring Tool Suite) 84 | .springBeans 85 | 86 | # Code Recommenders 87 | .recommenders/ 88 | 89 | 90 | ### Linux ### 91 | *~ 92 | 93 | # temporary files which can be created if a process still has a handle open of a deleted file 94 | .fuse_hidden* 95 | 96 | # KDE directory preferences 97 | .directory 98 | 99 | # Linux trash folder which might appear on any partition or disk 100 | .Trash-* 101 | 102 | # .nfs files are created when an open file is removed but is still being accessed 103 | .nfs* 104 | 105 | 106 | ### macOS ### 107 | *.DS_Store 108 | .AppleDouble 109 | .LSOverride 110 | 111 | # Icon must end with two \r 112 | Icon 113 | # Thumbnails 114 | ._* 115 | # Files that might appear in the root of a volume 116 | .DocumentRevisions-V100 117 | .fseventsd 118 | .Spotlight-V100 119 | .TemporaryItems 120 | .Trashes 121 | .VolumeIcon.icns 122 | .com.apple.timemachine.donotpresent 123 | # Directories potentially created on remote AFP share 124 | .AppleDB 125 | .AppleDesktop 126 | Network Trash Folder 127 | Temporary Items 128 | .apdisk 129 | 130 | 131 | ### Windows ### 132 | # Windows image file caches 133 | Thumbs.db 134 | ehthumbs.db 135 | 136 | # Folder config file 137 | Desktop.ini 138 | 139 | # Recycle Bin used on file shares 140 | $RECYCLE.BIN/ 141 | 142 | # Windows Installer files 143 | *.cab 144 | *.msi 145 | *.msm 146 | *.msp 147 | 148 | # Windows shortcuts 149 | *.lnk 150 | 151 | 152 | ### Java ### 153 | *.class 154 | 155 | # Mobile Tools for Java (J2ME) 156 | .mtj.tmp/ 157 | 158 | # Package Files # 159 | *.jar 160 | *.war 161 | *.ear 162 | 163 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 164 | hs_err_pid* -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License. 2 | 3 | Copyright (c) lucko (Luck) 4 | Copyright (c) contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ExtraContexts 2 | Provides a number of extra "contexts" for [LuckPerms](https://github.com/lucko/LuckPerms). 3 | 4 | 5 | ## About 6 | Contexts are a concept in LuckPerms that allows permissions to be set to apply only in certain circumstances. See [here](https://github.com/lucko/LuckPerms/wiki/Context) for more info. 7 | 8 | This plugin (ExtraContexts) provides a number of contexts for Bukkit servers. The supported contexts are listed below. 9 | 10 | 11 | ## Downloads and Usage 12 | 13 | * The plugin can be downloaded from [Jenkins](https://ci.lucko.me/job/ExtraContexts/). [[direct link](https://ci.lucko.me/job/ExtraContexts/lastSuccessfulBuild/artifact/target/ExtraContexts.jar)] 14 | * To use it, just add it to your plugins folder and enable the contexts you want to use. You have to enable each placeholder in `config.yml` 15 | 16 | ##### How do I check if it's working? 17 | A player's "current contexts" are listed when you run `/lp user info`. 18 | 19 | 20 | ## Contexts 21 | ___ 22 | #### `worldguard:region` 23 | Returns the name of each WorldGuard region the player is currently in 24 | 25 | e.g. 26 | 27 | > worldguard:region=spawn 28 | 29 | ___ 30 | #### `worldguard:in-region` 31 | Returns true or false if the player is in a WorldGuard region 32 | 33 | e.g. 34 | 35 | > worldguard:in-region=true 36 | 37 | ___ 38 | #### `worldguard:flag-xxx` 39 | Returns the value of each flag set by WorldGuard in the region the player is currently in 40 | 41 | e.g. 42 | 43 | > worldguard:flag-build=allow 44 | 45 | ___ 46 | #### `whitelisted` 47 | Returns if the player is whitelisted on the server or not 48 | 49 | e.g. 50 | 51 | > whitelisted=true 52 | 53 | ___ 54 | #### `team` 55 | Returns the name of the team the players is in 56 | 57 | e.g. 58 | 59 | > team=pvp-blue 60 | 61 | ___ 62 | #### `has-played-before` 63 | Returns if the player has connected to the server before, or if this is their first time 64 | 65 | e.g. 66 | 67 | > has-played-before=false 68 | 69 | ___ 70 | #### PlaceholderAPI 71 | Returns the result for a defined set of placeholders. 72 | 73 | e.g. 74 | 75 | **config:** 76 | ```yml 77 | placeholderapi-placeholders: 78 | allowflight: "%player_allow_flight%" 79 | ``` 80 | 81 | > allowflight=true 82 | 83 | ___ -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | me.lucko 8 | extracontexts 9 | 2.0-SNAPSHOT 10 | jar 11 | 12 | ExtraContexts 13 | Provides a number of extra contexts for LuckPerms. 14 | 15 | 16 | 17 | MIT 18 | https://opensource.org/licenses/MIT 19 | 20 | 21 | 22 | 23 | scm:git:https://github.com/lucko/ExtraContexts.git 24 | scm:git:git@github.com:lucko/ExtraContexts.git 25 | https://github.com/lucko/ExtraContexts 26 | 27 | 28 | 29 | UTF-8 30 | 31 | 32 | 33 | clean package 34 | ExtraContexts 35 | 36 | 37 | ${project.basedir}/src/main/resources 38 | true 39 | 40 | 41 | ${project.basedir} 42 | false 43 | 44 | LICENSE.txt 45 | 46 | 47 | 48 | 49 | 50 | org.apache.maven.plugins 51 | maven-compiler-plugin 52 | 3.8.0 53 | 54 | 1.8 55 | 1.8 56 | 57 | 58 | 59 | org.apache.maven.plugins 60 | maven-shade-plugin 61 | 3.2.1 62 | 63 | 64 | package 65 | 66 | shade 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.codemc.worldguardwrapper 74 | me.lucko.extracontexts.libs.worldguardwrapper 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | net.luckperms 86 | api 87 | 5.3 88 | provided 89 | 90 | 91 | 92 | org.bukkit 93 | bukkit 94 | 1.12-R0.1-SNAPSHOT 95 | provided 96 | 97 | 98 | 99 | 100 | org.codemc.worldguardwrapper 101 | worldguardwrapper 102 | 1.2.0-SNAPSHOT 103 | compile 104 | 105 | 106 | me.clip 107 | placeholderapi 108 | 2.9.2 109 | provided 110 | 111 | 112 | 113 | 114 | 115 | spigotmc-repo 116 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/ 117 | 118 | 119 | luck-repo 120 | https://repo.lucko.me/ 121 | 122 | 123 | codemc-repo 124 | https://repo.codemc.org/repository/maven-public/ 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /src/main/java/me/lucko/extracontexts/ExtraContextsPlugin.java: -------------------------------------------------------------------------------- 1 | package me.lucko.extracontexts; 2 | 3 | import me.lucko.extracontexts.calculators.HasPlayedBeforeCalculator; 4 | import me.lucko.extracontexts.calculators.PlaceholderApiCalculator; 5 | import me.lucko.extracontexts.calculators.TeamCalculator; 6 | import me.lucko.extracontexts.calculators.WhitelistedCalculator; 7 | import me.lucko.extracontexts.calculators.WorldGuardFlagCalculator; 8 | import me.lucko.extracontexts.calculators.WorldGuardRegionCalculator; 9 | 10 | import net.luckperms.api.LuckPerms; 11 | import net.luckperms.api.context.ContextCalculator; 12 | import net.luckperms.api.context.ContextManager; 13 | 14 | import org.bukkit.ChatColor; 15 | import org.bukkit.command.Command; 16 | import org.bukkit.command.CommandExecutor; 17 | import org.bukkit.command.CommandSender; 18 | import org.bukkit.entity.Player; 19 | import org.bukkit.plugin.java.JavaPlugin; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import java.util.function.Supplier; 24 | 25 | public class ExtraContextsPlugin extends JavaPlugin implements CommandExecutor { 26 | private ContextManager contextManager; 27 | private final List> registeredCalculators = new ArrayList<>(); 28 | 29 | @Override 30 | public void onEnable() { 31 | LuckPerms luckPerms = getServer().getServicesManager().load(LuckPerms.class); 32 | if (luckPerms == null) { 33 | throw new IllegalStateException("LuckPerms API not loaded."); 34 | } 35 | this.contextManager = luckPerms.getContextManager(); 36 | 37 | saveDefaultConfig(); 38 | setup(); 39 | } 40 | 41 | @Override 42 | public void onDisable() { 43 | unregisterAll(); 44 | } 45 | 46 | @Override 47 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 48 | unregisterAll(); 49 | reloadConfig(); 50 | setup(); 51 | sender.sendMessage(ChatColor.GREEN + "ExtraContexts configuration reloaded."); 52 | return true; 53 | } 54 | 55 | private void setup() { 56 | register("worldguard-region", "WorldGuard", WorldGuardRegionCalculator::new); 57 | register("worldguard-flag", "WorldGuard", WorldGuardFlagCalculator::new); 58 | register("whitelisted", null, WhitelistedCalculator::new); 59 | register("team", null, TeamCalculator::new); 60 | register("has-played-before", null, HasPlayedBeforeCalculator::new); 61 | register("placeholderapi", "PlaceholderAPI", () -> new PlaceholderApiCalculator(getConfig().getConfigurationSection("placeholderapi-placeholders"))); 62 | } 63 | 64 | private void register(String option, String requiredPlugin, Supplier> calculatorSupplier) { 65 | if (getConfig().getBoolean(option, false)) { 66 | if (requiredPlugin != null && getServer().getPluginManager().getPlugin(requiredPlugin) == null) { 67 | getLogger().info(requiredPlugin + " not present. Skipping registration of '" + option + "'..."); 68 | } else { 69 | getLogger().info("Registering '" + option + "' calculator."); 70 | ContextCalculator calculator = calculatorSupplier.get(); 71 | this.contextManager.registerCalculator(calculator); 72 | this.registeredCalculators.add(calculator); 73 | } 74 | } 75 | } 76 | 77 | private void unregisterAll() { 78 | this.registeredCalculators.forEach(c -> this.contextManager.unregisterCalculator(c)); 79 | this.registeredCalculators.clear(); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/me/lucko/extracontexts/calculators/HasPlayedBeforeCalculator.java: -------------------------------------------------------------------------------- 1 | package me.lucko.extracontexts.calculators; 2 | 3 | import net.luckperms.api.context.ContextCalculator; 4 | import net.luckperms.api.context.ContextConsumer; 5 | import net.luckperms.api.context.ContextSet; 6 | import net.luckperms.api.context.ImmutableContextSet; 7 | 8 | import org.bukkit.entity.Player; 9 | 10 | public class HasPlayedBeforeCalculator implements ContextCalculator { 11 | private static final String KEY = "has-played-before"; 12 | 13 | @Override 14 | public void calculate(Player target, ContextConsumer consumer) { 15 | consumer.accept(KEY, String.valueOf(target.hasPlayedBefore())); 16 | } 17 | 18 | @Override 19 | public ContextSet estimatePotentialContexts() { 20 | return ImmutableContextSet.builder() 21 | .add(KEY, "true") 22 | .add(KEY, "false") 23 | .build(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/me/lucko/extracontexts/calculators/PlaceholderApiCalculator.java: -------------------------------------------------------------------------------- 1 | package me.lucko.extracontexts.calculators; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | import me.clip.placeholderapi.PlaceholderAPI; 5 | import net.luckperms.api.context.ContextCalculator; 6 | import net.luckperms.api.context.ContextConsumer; 7 | import org.bukkit.configuration.ConfigurationSection; 8 | import org.bukkit.entity.Player; 9 | 10 | import java.util.Map; 11 | 12 | public class PlaceholderApiCalculator implements ContextCalculator { 13 | 14 | private final Map placeholders; 15 | 16 | public PlaceholderApiCalculator(ConfigurationSection placeholders) { 17 | ImmutableMap.Builder map = ImmutableMap.builder(); 18 | for (String key : placeholders.getKeys(false)) { 19 | map.put(key, placeholders.getString(key)); 20 | } 21 | this.placeholders = map.build(); 22 | } 23 | 24 | @Override 25 | public void calculate(Player target, ContextConsumer consumer) { 26 | for (Map.Entry placeholder : this.placeholders.entrySet()) { 27 | String result = PlaceholderAPI.setPlaceholders(target, placeholder.getValue()); 28 | if (result == null || result.trim().isEmpty()) { 29 | continue; 30 | } 31 | consumer.accept(placeholder.getKey(), result); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/me/lucko/extracontexts/calculators/TeamCalculator.java: -------------------------------------------------------------------------------- 1 | package me.lucko.extracontexts.calculators; 2 | 3 | import net.luckperms.api.context.ContextCalculator; 4 | import net.luckperms.api.context.ContextConsumer; 5 | import net.luckperms.api.context.ContextSet; 6 | import net.luckperms.api.context.ImmutableContextSet; 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.scoreboard.Team; 10 | 11 | public class TeamCalculator implements ContextCalculator { 12 | private static final String KEY = "team"; 13 | 14 | @Override 15 | public void calculate(Player target, ContextConsumer consumer) { 16 | Team team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam(target.getName()); 17 | if (team != null) { 18 | consumer.accept(KEY, team.getName()); 19 | } 20 | } 21 | 22 | @Override 23 | public ContextSet estimatePotentialContexts() { 24 | ImmutableContextSet.Builder builder = ImmutableContextSet.builder(); 25 | for (Team team : Bukkit.getScoreboardManager().getMainScoreboard().getTeams()) { 26 | builder.add(KEY, team.getName()); 27 | } 28 | return builder.build(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/me/lucko/extracontexts/calculators/WhitelistedCalculator.java: -------------------------------------------------------------------------------- 1 | package me.lucko.extracontexts.calculators; 2 | 3 | import net.luckperms.api.context.ContextCalculator; 4 | import net.luckperms.api.context.ContextConsumer; 5 | import net.luckperms.api.context.ContextSet; 6 | import net.luckperms.api.context.ImmutableContextSet; 7 | 8 | import org.bukkit.entity.Player; 9 | 10 | public class WhitelistedCalculator implements ContextCalculator { 11 | private static final String KEY = "whitelisted"; 12 | 13 | @Override 14 | public void calculate(Player target, ContextConsumer consumer) { 15 | consumer.accept(KEY, String.valueOf(target.isWhitelisted())); 16 | } 17 | 18 | @Override 19 | public ContextSet estimatePotentialContexts() { 20 | return ImmutableContextSet.builder() 21 | .add(KEY, "true") 22 | .add(KEY, "false") 23 | .build(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/me/lucko/extracontexts/calculators/WorldGuardFlagCalculator.java: -------------------------------------------------------------------------------- 1 | package me.lucko.extracontexts.calculators; 2 | 3 | import net.luckperms.api.context.Context; 4 | import net.luckperms.api.context.ContextCalculator; 5 | import net.luckperms.api.context.ContextConsumer; 6 | import net.luckperms.api.context.ContextSet; 7 | import net.luckperms.api.context.ImmutableContextSet; 8 | 9 | import org.bukkit.Bukkit; 10 | import org.bukkit.Location; 11 | import org.bukkit.World; 12 | import org.bukkit.entity.Player; 13 | import org.bukkit.util.Vector; 14 | import org.codemc.worldguardwrapper.WorldGuardWrapper; 15 | import org.codemc.worldguardwrapper.flag.IWrappedFlag; 16 | import org.codemc.worldguardwrapper.flag.IWrappedStatusFlag; 17 | import org.codemc.worldguardwrapper.flag.WrappedState; 18 | import org.codemc.worldguardwrapper.region.IWrappedRegion; 19 | 20 | import java.util.Map; 21 | 22 | // @Deprecated 23 | public class WorldGuardFlagCalculator implements ContextCalculator { 24 | 25 | // calling worldGuard.queryApplicableFlags can sometimes cause Vault lookups, which 26 | // would make a recursive call to this calculator. this breaks the 3rd rule that 27 | // ContextCalculators should follow. 28 | // 29 | // see for more info: https://github.com/LuckPerms/ExtraContexts/issues/27 30 | // 31 | // the safest/best solution would be to remove this calculator entirely, but this 32 | // ThreadLocal hack is a good enough work around for users who already 33 | // depend on it. 34 | private static final ThreadLocal IN_PROGRESS = ThreadLocal.withInitial(() -> false); 35 | 36 | private static final String KEY = "worldguard:flag-"; 37 | 38 | private final WorldGuardWrapper worldGuard = WorldGuardWrapper.getInstance(); 39 | 40 | @Override 41 | public void calculate(Player target, ContextConsumer consumer) { 42 | if (IN_PROGRESS.get()) { 43 | return; 44 | } 45 | 46 | IN_PROGRESS.set(true); 47 | try { 48 | Map, Object> flags = this.worldGuard.queryApplicableFlags(target, target.getLocation()); 49 | flags.forEach((flag, value) -> { 50 | if (invalidValue(value)) { 51 | return; 52 | } 53 | consumer.accept(KEY + flag.getName(), value.toString()); 54 | }); 55 | } finally { 56 | IN_PROGRESS.set(false); 57 | } 58 | } 59 | 60 | @Override 61 | public ContextSet estimatePotentialContexts() { 62 | ImmutableContextSet.Builder builder = ImmutableContextSet.builder(); 63 | for (World world : Bukkit.getWorlds()) { 64 | for (IWrappedRegion region : this.worldGuard.getRegions(world).values()) { 65 | Map, Object> flags = region.getFlags(); 66 | flags.forEach((flag, value) -> { 67 | if (flag instanceof IWrappedStatusFlag) { 68 | for (WrappedState state : WrappedState.values()) { 69 | builder.add(KEY + flag.getName(), state.toString()); 70 | } 71 | } else { 72 | if (!invalidValue(value)) { 73 | builder.add(KEY + flag.getName(), value.toString()); 74 | } 75 | 76 | Object defaultValue = flag.getDefaultValue().orElse(null); 77 | if (!invalidValue(defaultValue)) { 78 | builder.add(KEY + flag.getName(), defaultValue.toString()); 79 | } 80 | } 81 | }); 82 | } 83 | } 84 | return builder.build(); 85 | } 86 | 87 | private static boolean invalidValue(Object value) { 88 | return value == null || value instanceof Location || value instanceof Vector || (value instanceof String && !Context.isValidValue(((String) value))); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/me/lucko/extracontexts/calculators/WorldGuardRegionCalculator.java: -------------------------------------------------------------------------------- 1 | package me.lucko.extracontexts.calculators; 2 | 3 | import net.luckperms.api.context.ContextCalculator; 4 | import net.luckperms.api.context.ContextConsumer; 5 | import net.luckperms.api.context.ContextSet; 6 | import net.luckperms.api.context.ImmutableContextSet; 7 | 8 | import org.bukkit.Bukkit; 9 | import org.bukkit.World; 10 | import org.bukkit.entity.Player; 11 | import org.codemc.worldguardwrapper.WorldGuardWrapper; 12 | import org.codemc.worldguardwrapper.region.IWrappedRegion; 13 | 14 | import java.util.Set; 15 | 16 | public class WorldGuardRegionCalculator implements ContextCalculator { 17 | private static final String KEY = "worldguard:region"; 18 | private static final String IN_REGION_KEY = "worldguard:in-region"; 19 | 20 | private final WorldGuardWrapper worldGuard = WorldGuardWrapper.getInstance(); 21 | 22 | @Override 23 | public void calculate(Player target, ContextConsumer consumer) { 24 | Set regions = this.worldGuard.getRegions(target.getLocation()); 25 | 26 | if (regions.isEmpty()) { 27 | consumer.accept(IN_REGION_KEY, "false"); 28 | } else { 29 | consumer.accept(IN_REGION_KEY, "true"); 30 | for (IWrappedRegion region : regions) { 31 | consumer.accept(KEY, region.getId()); 32 | } 33 | } 34 | } 35 | 36 | @Override 37 | public ContextSet estimatePotentialContexts() { 38 | ImmutableContextSet.Builder builder = ImmutableContextSet.builder(); 39 | for (World world : Bukkit.getWorlds()) { 40 | for (IWrappedRegion region : this.worldGuard.getRegions(world).values()) { 41 | builder.add(KEY, region.getId()); 42 | } 43 | } 44 | builder.add(IN_REGION_KEY, "true"); 45 | builder.add(IN_REGION_KEY, "false"); 46 | return builder.build(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/resources/config.yml: -------------------------------------------------------------------------------- 1 | # ExtraContexts 2 | # made with <3 by Luck 3 | 4 | 5 | # Set a provider to true to enable it. 6 | # Contexts are explained in more detail here: 7 | # https://github.com/lucko/LuckPerms/wiki/Context 8 | 9 | 10 | # Provides the 'worldguard:region' and 'worldguard:in-region' contexts. 11 | # Returns the name of each WorldGuard region the player is currently in. 12 | # 13 | # e.g. worldguard:in-region=true and worldguard:region=spawn 14 | worldguard-region: false 15 | 16 | # Provides the 'worldguard:flag-xxx' contexts. 17 | # Returns the value of each flag set by WorldGuard in the region the player is currently in. 18 | # 19 | # WARNING: WorldGuard flags can sometimes depend on permission/group status, which 20 | # really makes them unsuitable for use as a permission context. 21 | # With that in mind: use this calculator with caution, and if possible, find a different 22 | # context/approach to use. :) 23 | # 24 | # e.g. worldguard:flag-build=allow 25 | worldguard-flag: false 26 | 27 | # Provides the 'whitelisted' context. 28 | # Returns if the player is whitelisted on the server or not. 29 | # 30 | # e.g. whitelisted=true 31 | whitelisted: false 32 | 33 | # Provides the 'team' context. 34 | # Returns the name of the team the players is in. 35 | # 36 | # e.g. team=pvp-blue 37 | team: false 38 | 39 | # Provides the 'has-played-before' context. 40 | # Returns if the player has connected to the server before, or if this is their first time. 41 | # 42 | # e.g. has-played-before=false 43 | has-played-before: false 44 | 45 | placeholderapi: false 46 | placeholderapi-placeholders: 47 | allowflight: "%player_allow_flight%" 48 | -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: ${project.name} 2 | version: ${project.version} 3 | author: Luck 4 | main: me.lucko.extracontexts.ExtraContextsPlugin 5 | depend: [LuckPerms] 6 | softdepend: [WorldGuard, PlaceholderAPI] 7 | api-version: 1.13 8 | 9 | commands: 10 | extracontexts-reload: 11 | description: Reloads the configuration 12 | permission: extracontexts.reload 13 | usage: /extracontexts-reload --------------------------------------------------------------------------------