-
-
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.
Merge pull request #1 from TheNextLvl-net/2.0.0
2.0.0
- Loading branch information
Showing
23 changed files
with
459 additions
and
295 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
41 changes: 0 additions & 41 deletions
41
api/src/main/java/net/thenextlvl/commander/api/CommandManager.java
This file was deleted.
Oops, something went wrong.
32 changes: 24 additions & 8 deletions
32
api/src/main/java/net/thenextlvl/commander/api/Commander.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 |
---|---|---|
@@ -1,19 +1,35 @@ | ||
package net.thenextlvl.commander.api; | ||
|
||
import net.thenextlvl.commander.i18n.Placeholders; | ||
import net.thenextlvl.commander.api.command.CommandRegistry; | ||
import net.thenextlvl.commander.api.command.PlatformCommandRegistry; | ||
import net.thenextlvl.commander.api.permission.PermissionRegistry; | ||
import net.thenextlvl.commander.api.permission.PlatformPermissionRegistry; | ||
|
||
public abstract class Commander { | ||
public interface Commander { | ||
/** | ||
* @return The command manager | ||
* @return the command registry | ||
*/ | ||
public abstract CommandManager commandManager(); | ||
CommandRegistry commandRegistry(); | ||
|
||
/** | ||
* @return The permission manager | ||
* @return the permission registry | ||
*/ | ||
public abstract PermissionManager permissionManager(); | ||
PermissionRegistry permissionRegistry(); | ||
|
||
static { | ||
Placeholders.init(); | ||
/** | ||
* @return the platform registries | ||
*/ | ||
PlatformRegistry platform(); | ||
|
||
interface PlatformRegistry { | ||
/** | ||
* @return the platform command registry | ||
*/ | ||
PlatformCommandRegistry<?> commandRegistry(); | ||
|
||
/** | ||
* @return the platform permission registry | ||
*/ | ||
PlatformPermissionRegistry permissionRegistry(); | ||
} | ||
} |
46 changes: 0 additions & 46 deletions
46
api/src/main/java/net/thenextlvl/commander/api/PermissionManager.java
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
api/src/main/java/net/thenextlvl/commander/api/command/CommandRegistry.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,71 @@ | ||
package net.thenextlvl.commander.api.command; | ||
|
||
import com.google.gson.reflect.TypeToken; | ||
import core.api.file.format.GsonFile; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import net.thenextlvl.commander.api.Commander; | ||
|
||
import java.io.File; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class CommandRegistry { | ||
private final GsonFile<HashSet<String>> removedCommandsFile; | ||
private final @Getter Commander commander; | ||
|
||
protected CommandRegistry(Commander commander, File dataFolder) { | ||
this(new GsonFile<>( | ||
new File(dataFolder, "removed-commands.json"), | ||
new HashSet<String>(), | ||
new TypeToken<>() { | ||
} | ||
).saveIfAbsent(), commander); | ||
} | ||
|
||
/** | ||
* Register a removed command query again | ||
* | ||
* @param query the command query | ||
* @return whether the command query was registered | ||
*/ | ||
public boolean registerCommand(String query) { | ||
var remove = getRemovedCommands().remove(query); | ||
if (remove) removedCommandsFile.save(); | ||
return remove; | ||
} | ||
|
||
/** | ||
* Unregister a command query | ||
* | ||
* @param query the command query | ||
* @return whether the pattern was not registered before | ||
*/ | ||
public boolean unregisterCommands(String query) { | ||
var added = getRemovedCommands().add(query); | ||
if (added) removedCommandsFile.save(); | ||
return added; | ||
} | ||
|
||
/** | ||
* Get whether a command query is removed | ||
* | ||
* @param query the command query | ||
* @return whether a command is removed | ||
*/ | ||
public boolean isCommandRemoved(String query) { | ||
return getRemovedCommands().stream().anyMatch(s -> query.equals(s) | ||
|| (s.contains("*") && query.matches(s.replaceAll("\\*", ".+")))); | ||
} | ||
|
||
/** | ||
* Get all removed command patterns | ||
* | ||
* @return all removed command patterns | ||
*/ | ||
public Set<String> getRemovedCommands() { | ||
return removedCommandsFile.getRoot(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
api/src/main/java/net/thenextlvl/commander/api/command/PlatformCommandRegistry.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,58 @@ | ||
package net.thenextlvl.commander.api.command; | ||
|
||
import net.thenextlvl.commander.api.Commander; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
public interface PlatformCommandRegistry<C> { | ||
|
||
/** | ||
* Get the namespaces of all registered commands | ||
* | ||
* @return a stream of command namespaces | ||
*/ | ||
Stream<String> getCommandNamespaces(); | ||
|
||
/** | ||
* Get all registered command instanced | ||
* | ||
* @return a set of command instances | ||
*/ | ||
Collection<C> getCommands(); | ||
|
||
/** | ||
* Get a registered command instance by its literal | ||
* | ||
* @param literal the command literal | ||
* @return the command instance | ||
*/ | ||
Optional<C> getCommand(String literal); | ||
|
||
/** | ||
* Check whether a command is registered | ||
* | ||
* @param literal the command literal | ||
* @return whether the command is registered | ||
*/ | ||
default boolean isCommandRegistered(String literal) { | ||
return getCommand(literal).isPresent(); | ||
} | ||
|
||
/** | ||
* Check whether both commands match | ||
* | ||
* @param first the first command | ||
* @param second the second command | ||
* @return whether the commands match | ||
*/ | ||
boolean matches(C first, C second); | ||
|
||
/** | ||
* Update all commands | ||
*/ | ||
void updateCommands(); | ||
|
||
Commander commander(); | ||
} |
8 changes: 0 additions & 8 deletions
8
api/src/main/java/net/thenextlvl/commander/api/package-info.java
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
api/src/main/java/net/thenextlvl/commander/api/permission/PermissionRegistry.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,57 @@ | ||
package net.thenextlvl.commander.api.permission; | ||
|
||
import com.google.gson.reflect.TypeToken; | ||
import core.api.file.format.GsonFile; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import net.thenextlvl.commander.api.Commander; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.File; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public abstract class PermissionRegistry { | ||
private final GsonFile<HashMap<String, String>> file; | ||
private final @Getter Map<String, String> originalPermissions = new HashMap<>(); | ||
private final @Getter Commander commander; | ||
|
||
protected PermissionRegistry(Commander commander, File dataFolder) { | ||
this(new GsonFile<>( | ||
new File(dataFolder, "permission-override.json"), | ||
new HashMap<String, String>(), | ||
new TypeToken<>() { | ||
} | ||
).saveIfAbsent(), commander); | ||
} | ||
|
||
/** | ||
* Reset the permission of a certain command | ||
* | ||
* @param literal the command literal | ||
* @return whether the permission was overridden in the first place | ||
*/ | ||
public boolean resetPermission(String literal) { | ||
if (!getPermissionOverride().containsKey(literal)) return false; | ||
getPermissionOverride().remove(literal); | ||
file.save(); | ||
return true; | ||
} | ||
|
||
public void overridePermission(String literal, @Nullable String permission) { | ||
getPermissionOverride().put(literal, permission); | ||
file.save(); | ||
} | ||
|
||
/** | ||
* Get a map of all overridden permissions<br/> | ||
* The key being the command pattern and the value being the new permission | ||
* | ||
* @return all overridden permissions | ||
*/ | ||
public Map<String, String> getPermissionOverride() { | ||
return file.getRoot(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
api/src/main/java/net/thenextlvl/commander/api/permission/PlatformPermissionRegistry.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,18 @@ | ||
package net.thenextlvl.commander.api.permission; | ||
|
||
import net.thenextlvl.commander.api.Commander; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface PlatformPermissionRegistry { | ||
Commander commander(); | ||
|
||
default void overridePermissions() { | ||
commander().permissionRegistry().getPermissionOverride().forEach(this::overridePermission); | ||
} | ||
|
||
boolean overridePermission(String literal, @Nullable String permission); | ||
|
||
@Nullable String getOriginalPermission(String literal); | ||
|
||
boolean hasOriginalPermission(String literal); | ||
} |
Oops, something went wrong.