Skip to content

Commit

Permalink
Finally fix claimchunk.player permission!
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed May 1, 2024
1 parent 0e4dbdf commit 741c19b
Show file tree
Hide file tree
Showing 29 changed files with 148 additions and 171 deletions.
7 changes: 4 additions & 3 deletions PRE_PUSH_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ Things to make sure I do before I push a new release version:
- [ ] Update [wiki](https://claimchunk.cjburkey.com/) with new information.
- [ ] Create changelog
- Building
- [ ] Run `./gradlew clean`, `./gradlew googleFormat`, and `./gradlew build`
- These must be run separately for compatibility reasons (might be fixed in the future).
- Upload `OUT/claimchunk-VERSION-plugin.jar` as Github release with changelog
- [ ] Run `./gradlew clean googleFormat`
- [ ] Run `./gradlew build`
- Run separate from others because of stupid error
- Upload `OUT/claimchunk-VERSION-plugin.jar` as GitHub release with changelog
- Add new release on [Spigot](https://www.spigotmc.org/resources/claimchunk.44458/) with changelog.
- Done!

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ tasks {
}

build {
mustRunAfter("googleFormat")
mustRunAfter("googleFormat", "clean")
// When the build task is run, copy the version into the testServerDir and output
// (Also rebuild the README file)
finalizedBy("updateReadme",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ public CCBukkitCommand(
this.register();
}

@SuppressWarnings("UnstableApiUsage")
@Override
public @NotNull List<String> tabComplete(
@NotNull CommandSender sender, @NotNull String alias, String[] args) {
// Is this ok?
return Objects.requireNonNull(baseCommand.onTabComplete(sender, this, alias, args));
}

@SuppressWarnings("UnstableApiUsage")
@Override
public boolean execute(
@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
Expand Down Expand Up @@ -95,6 +93,7 @@ public void removeFromMap() {
"Failed to unregister command! If you are reloading, updates to permissions"
+ " won't appear until a server reboot.");
if (Utils.getDebugEnableOverride()) {
//noinspection CallToPrintStackTrace
e.printStackTrace();
}
}
Expand All @@ -117,6 +116,7 @@ private void register() {
} catch (IllegalAccessException | NoSuchFieldException e) {
Utils.err("ERROR FINDING BUKKIT COMMAND MAP USING REFLECTION!!");
Utils.err("This is a slightly very big problem!!");
//noinspection CallToPrintStackTrace
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,33 @@ public abstract class CCSubCommand extends SmartSubCommand implements TabComplet

protected final ClaimChunk claimChunk;

// allow multiple permissions here too
public CCSubCommand(
@NotNull ClaimChunk claimChunk,
@NotNull Executor executorLevel,
@Nullable String permissionChild,
boolean isDefault) {
boolean isDefault,
String... permissionChildren) {
super(
executorLevel,
(claimChunk.getConfigHandler().getDisablePermissions() && isDefault)
? ""
: (permissionChild != null ? ("claimchunk." + permissionChild) : ""));
? new String[0]
: Arrays.stream(permissionChildren)
.map(perm -> "claimchunk." + perm)
.toArray(String[]::new));

this.claimChunk = claimChunk;
}

/**
* Get the description for this subcommand.
*
* @return The description for this subcommand.
*/
public abstract @NotNull Optional<String> getDescription();

/**
* Get whether this command should be displayed in the help subcommand list for the provided
* executor.
*
* @return Whether this command will be displayed within the help list.
*/
// maybe make a method to just check sender permission against permission array, so we don't
// have to check everywhere everytime
public boolean getShouldDisplayInHelp(@NotNull CommandSender sender) {
String perm = getPermission().orElse(null);
return (getExecutor() == Executor.CONSOLE_PLAYER
|| Executor.fromSender(sender) == getExecutor())
&& (perm == null || sender.hasPermission(perm));
return rightExecutorAndPermission(sender);
}

/**
Expand Down Expand Up @@ -145,6 +140,7 @@ public final boolean onCommand(
@NotNull String label,
@NotNull String[] args) {
// TODO: WAITING ON UPDATE TO COMMAND DISPATCHER
// Maybe I should do that instead?
// Make sure the player provided the correct number of arguments
if (args.length < getRequiredArguments() || args.length > getMaxArguments()) {
displayUsage(label, sender);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.stream.Collectors;

/**
* Special thank you to Goldmensch for the new command API! Github link: <a
* Special thank you to Goldmensch for the new command API! GitHub link: <a
* href="https://github.com/Goldmensch/SmartCommandDispatcher">github.com/Goldmensch/SmartCommandDispatcher</a>.
* <br>
* I have included the JavaDoc comments for methods that I wasn't 100% certain on and/or were
Expand Down Expand Up @@ -99,6 +99,7 @@ private void registerCmds(CommandStr... commands) {
// Hopefully won't occur, but compile-time safety isn't one of
// Java's strong-suits
Utils.err("Failed to initialize subcommand: /chunk %s", String.join(" ", cmd.args));
//noinspection CallToPrintStackTrace
e.printStackTrace();
}
}
Expand Down Expand Up @@ -133,6 +134,7 @@ public boolean noSubFound(
* @param cmd The command executed, along with the arguments passed.
* @param sender The command sender.
*/
@SuppressWarnings("GrazieInspection")
@Override
public void wrongExecutor(
@NotNull SubCommandEntity cmd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import org.jetbrains.annotations.Nullable;

/**
* @since 0.0.23
*/
public class AdminOverrideCmd extends CCSubCommand {

public AdminOverrideCmd(ClaimChunk claimChunk) {
super(claimChunk, Executor.PLAYER, "admin", false);
super(claimChunk, Executor.PLAYER, false, "admin");
}

@Override
public @NotNull Optional<String> getDescription() {
return Optional.ofNullable(claimChunk.getMessages().cmdAdminOverride);
public @Nullable String getDescription() {
return claimChunk.getMessages().cmdAdminOverride;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@

import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import org.jetbrains.annotations.Nullable;

public class AdminReloadCmd extends CCSubCommand {

public AdminReloadCmd(ClaimChunk claimChunk) {
super(claimChunk, Executor.CONSOLE_PLAYER, "admin", false);
super(claimChunk, Executor.CONSOLE_PLAYER, false, "admin");
}

@Override
public @NotNull Optional<String> getDescription() {
return Optional.ofNullable(claimChunk.getMessages().cmdReload);
public @Nullable String getDescription() {
return claimChunk.getMessages().cmdReload;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import org.jetbrains.annotations.Nullable;

public class AdminUnclaimAllCmd extends CCSubCommand {

public AdminUnclaimAllCmd(ClaimChunk claimChunk) {
super(claimChunk, Executor.PLAYER, "admin", false);
super(claimChunk, Executor.PLAYER, false, "admin");
}

@Override
public @NotNull Optional<String> getDescription() {
return Optional.ofNullable(claimChunk.getMessages().cmdAdminUnclaimAll);
public @Nullable String getDescription() {
return claimChunk.getMessages().cmdAdminUnclaimAll;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import org.jetbrains.annotations.Nullable;

public class AdminUnclaimCmd extends CCSubCommand {

public AdminUnclaimCmd(ClaimChunk claimChunk) {
super(claimChunk, Executor.PLAYER, "admin", false);
super(claimChunk, Executor.PLAYER, false, "admin");
}

@Override
public @NotNull Optional<String> getDescription() {
return Optional.ofNullable(claimChunk.getMessages().cmdAdminUnclaim);
public @Nullable String getDescription() {
return claimChunk.getMessages().cmdAdminUnclaim;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* @since 0.0.24
Expand All @@ -35,12 +35,12 @@ public class AccessCmd extends CCSubCommand {
public AccessCmd(ClaimChunk claimChunk) {
// TODO: CREATE `/chunk admin access <PLY>` to allow listing from
// console as well
super(claimChunk, Executor.PLAYER, "access", true);
super(claimChunk, Executor.PLAYER, true, "player", "access");
}

@Override
public @NotNull Optional<String> getDescription() {
return Optional.ofNullable(claimChunk.getMessages().cmdAccess);
public @Nullable String getDescription() {
return claimChunk.getMessages().cmdAccess;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import org.jetbrains.annotations.Nullable;

/**
* @since 0.0.23
*/
public class AlertCmd extends CCSubCommand {

public AlertCmd(ClaimChunk claimChunk) {
super(claimChunk, Executor.PLAYER, "alert", true);
super(claimChunk, Executor.PLAYER, true, "player", "alert");
}

@Override
public @NotNull Optional<String> getDescription() {
return Optional.ofNullable(claimChunk.getMessages().cmdAlert);
public @Nullable String getDescription() {
return claimChunk.getMessages().cmdAlert;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import org.jetbrains.annotations.Nullable;

/**
* @since 0.0.23
*/
public class AutoCmd extends CCSubCommand {

public AutoCmd(ClaimChunk claimChunk) {
super(claimChunk, Executor.PLAYER, "auto", true);
super(claimChunk, Executor.PLAYER, true, "player", "auto");
}

@Override
public @NotNull Optional<String> getDescription() {
return Optional.ofNullable(claimChunk.getMessages().cmdAuto);
public @Nullable String getDescription() {
return claimChunk.getMessages().cmdAuto;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import org.jetbrains.annotations.Nullable;

/**
* @since 0.0.24
*/
public class CheckAccessCmd extends CCSubCommand {

public CheckAccessCmd(ClaimChunk claimChunk) {
super(claimChunk, Executor.PLAYER, "access", true);
super(claimChunk, Executor.PLAYER, true, "player", "access");
}

@Override
public @NotNull Optional<String> getDescription() {
return Optional.ofNullable(claimChunk.getMessages().cmdCheckAccess);
public @Nullable String getDescription() {
return claimChunk.getMessages().cmdCheckAccess;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import org.jetbrains.annotations.Nullable;

/**
* @since 0.0.23
Expand All @@ -22,12 +21,12 @@ public ClaimCmd(ClaimChunk claimChunk) {
// ADD `/chunk admin claim <PLY> <X> <Y>` to allow claiming the
// chunk containing the world coordinates X and Y for the given
// player.
super(claimChunk, Executor.PLAYER, "claim", true);
super(claimChunk, Executor.PLAYER, true, "player", "claim");
}

@Override
public @NotNull Optional<String> getDescription() {
return Optional.ofNullable(claimChunk.getMessages().cmdClaim);
public @Nullable String getDescription() {
return claimChunk.getMessages().cmdClaim;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import org.jetbrains.annotations.Nullable;

/**
* @since 0.0.23
*/
public class GiveCmd extends CCSubCommand {

public GiveCmd(ClaimChunk claimChunk) {
super(claimChunk, Executor.PLAYER, "give", true);
super(claimChunk, Executor.PLAYER, true, "player", "give");
}

@Override
public @NotNull Optional<String> getDescription() {
return Optional.ofNullable(claimChunk.getMessages().cmdGive);
public @Nullable String getDescription() {
return claimChunk.getMessages().cmdGive;
}

@Override
Expand Down
Loading

0 comments on commit 741c19b

Please sign in to comment.