-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
190 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
paper-plugin/src/main/java/net/thenextlvl/commander/implementation/CraftCommandManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package net.thenextlvl.commander.implementation; | ||
|
||
import core.annotation.MethodsReturnNotNullByDefault; | ||
import core.annotation.ParametersAreNotNullByDefault; | ||
import core.annotation.TypesAreNotNullByDefault; | ||
import net.thenextlvl.commander.api.CommandInfo; | ||
import net.thenextlvl.commander.api.platform.CommandManager; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
@TypesAreNotNullByDefault | ||
@MethodsReturnNotNullByDefault | ||
@ParametersAreNotNullByDefault | ||
public record CraftCommandManager(CraftCommander commander) implements CommandManager<Command> { | ||
|
||
@Override | ||
public Stream<String> getCommandNames() { | ||
return Stream.concat( | ||
Bukkit.getCommandMap().getKnownCommands().keySet().stream(), | ||
getCommands().stream().map(Command::getLabel) | ||
); | ||
} | ||
|
||
@Override | ||
public Collection<Command> getCommands() { | ||
return Bukkit.getCommandMap().getKnownCommands().values(); | ||
} | ||
|
||
@Override | ||
public Stream<Command> getCommands(String query) { | ||
return Bukkit.getCommandMap().getKnownCommands().keySet().stream() | ||
.filter(command -> CommandInfo.nameMatches(command, query)) | ||
.map(s -> getCommand(s).orElse(null)) | ||
.filter(Objects::nonNull); | ||
} | ||
|
||
@Override | ||
public Optional<Command> getCommand(String literal) { | ||
return Optional.ofNullable(Bukkit.getCommandMap().getCommand(literal)); | ||
} | ||
|
||
@Override | ||
public void updateCommands() { | ||
Bukkit.getOnlinePlayers().forEach(Player::updateCommands); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...-plugin/src/main/java/net/thenextlvl/commander/implementation/CraftPermissionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package net.thenextlvl.commander.implementation; | ||
|
||
import core.annotation.MethodsReturnNotNullByDefault; | ||
import core.annotation.ParametersAreNotNullByDefault; | ||
import core.annotation.TypesAreNotNullByDefault; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.Accessors; | ||
import net.thenextlvl.commander.api.platform.PermissionManager; | ||
import org.bukkit.command.Command; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
@Accessors(fluent = true) | ||
@TypesAreNotNullByDefault | ||
@MethodsReturnNotNullByDefault | ||
@ParametersAreNotNullByDefault | ||
public class CraftPermissionManager implements PermissionManager<Command> { | ||
private final CraftCommander commander; | ||
private final Map<String, @Nullable String> originalPermissions = new HashMap<>(); | ||
|
||
@Override | ||
public boolean overridePermissions(String query, @Nullable String permission) { | ||
var success = new AtomicBoolean(); | ||
commander().commandManager().getCommands(query).forEach(command -> { | ||
if (overridePermission(command, permission)) success.set(true); | ||
}); | ||
return success.get(); | ||
} | ||
|
||
@Override | ||
public boolean resetPermissions(String query) { | ||
var success = new AtomicBoolean(); | ||
commander().commandManager().getCommands(query).forEach(command -> { | ||
if (resetPermission(command)) success.set(true); | ||
}); | ||
return success.get(); | ||
} | ||
|
||
@Override | ||
public boolean resetPermission(Command command) { | ||
if (!originalPermissions().containsKey(command.getLabel())) return false; | ||
var permission = originalPermissions().remove(command.getLabel()); | ||
if (Objects.equals(command.getPermission(), permission)) return false; | ||
command.setPermission(permission); | ||
return Objects.equals(command.getPermission(), permission); | ||
} | ||
|
||
@Override | ||
public boolean overridePermission(Command command, @Nullable String permission) { | ||
originalPermissions().putIfAbsent(command.getLabel(), command.getPermission()); | ||
if (Objects.equals(command.getPermission(), permission)) return false; | ||
command.setPermission(permission); | ||
return Objects.equals(command.getPermission(), permission); | ||
} | ||
|
||
@Override | ||
public @Nullable String getOriginalPermission(String literal) { | ||
return originalPermissions().get(literal); | ||
} | ||
|
||
@Override | ||
public boolean hasOriginalPermission(String literal) { | ||
return !originalPermissions().containsKey(literal); | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
...n/src/main/java/net/thenextlvl/commander/implementation/command/CraftCommandRegistry.java
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
...in/java/net/thenextlvl/commander/implementation/command/CraftPlatformCommandRegistry.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...main/java/net/thenextlvl/commander/implementation/permission/CraftPermissionRegistry.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.