Skip to content

Commit

Permalink
Add option to work without permissions plugin, hide adminunclaim in help
Browse files Browse the repository at this point in the history
Admin unclaim is only shown in help for admins. Previously, anyone with
the the claimchunk.access permission could see it.
  • Loading branch information
cjburkey01 committed Jun 5, 2019
1 parent 33e6c64 commit 507eceb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/main/java/com/cjburkey/claimchunk/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public static String getMsg(String key) {
}

public static int clamp(int val, int min, int max) {
if (val > max) return max;
if (val < min) return min;
return val;
return Math.max(Math.min(val, max), min);
}

public static void msg(CommandSender to, String msg) {
Expand Down Expand Up @@ -68,16 +66,26 @@ public static void toPlayer(Player ply, ChatColor color, String msg) {
}
}

// Methods like these make me wish we had macros in Java
public static boolean hasPerm(@Nullable CommandSender sender, boolean basic, String perm) {
if (sender == null) return false;
boolean hasPerm = sender.hasPermission("claimchunk." + perm);
return (basic ? (hasPerm || sender.hasPermission("claimchunk.player")) : hasPerm);
return (basic
? (Config.getBool("basic", "disablePermissions")
|| hasPerm
|| sender.hasPermission("claimchunk.player"))
: hasPerm);
}

// Methods like these make me wish we had macros in Java
public static boolean hasPerm(CommandSender sender, boolean basic, Permission perm) {
if (sender == null) return false;
boolean hasPerm = sender.hasPermission(perm);
return (basic ? (hasPerm || sender.hasPermission("claimchunk.player")) : hasPerm);
return (basic
? (Config.getBool("basic", "disablePermissions")
|| hasPerm
|| sender.hasPermission("claimchunk.player"))
: hasPerm);
}

private static String prepMsg(String msg, Object... data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public String getDescription() {

@Override
public boolean getShouldDisplayInHelp(CommandSender sender) {
return Utils.hasPerm(sender, false, "access");
return Utils.hasPerm(sender, false, "admin");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ public static void showSubTitle(Player player, String text, ChatColor color, int
*/
public static void showActionbarTitle(Player player, String text, ChatColor color, int fadeInTicks, int stayTicks,
int fadeOutTicks) throws Exception {
// This may fail if the server is running a version that doesn't support action bars (like 1.10)
// This may fail if the server is running a version that doesn't support action bars
// In such a case, unless the action was to clear the action bar, the message will be displyed in the subtitle slot
// and a message logged in the console.
// This may not be necessary but I'm doing it anyway so deal with it
try {
showTitle(player, text, color, fadeInTicks, stayTicks, fadeOutTicks, "ACTIONBAR");
} catch (Exception ignored) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
basic:
disablePermissions: false

log:
debugSpam: true
anonymousMetrics: true
Expand Down

0 comments on commit 507eceb

Please sign in to comment.