-
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
1 parent
bf190ce
commit fdd1be7
Showing
12 changed files
with
149 additions
and
11 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
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
25 changes: 25 additions & 0 deletions
25
src/main/java/dev/emortal/minestom/core/module/core/playerprovider/EmortalCombatPlayer.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,25 @@ | ||
package dev.emortal.minestom.core.module.core.playerprovider; | ||
|
||
import dev.emortal.minestom.core.module.permissions.Permission; | ||
import io.github.togar2.pvp.player.CombatPlayerImpl; | ||
import net.minestom.server.network.player.PlayerConnection; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.concurrent.CopyOnWriteArraySet; | ||
|
||
// This class should be instantiated instead of CombatPlayerImpl by any games that use the Emortal API | ||
@SuppressWarnings("unused") | ||
public class EmortalCombatPlayer extends CombatPlayerImpl implements EmortalPlayer { | ||
private final @NotNull Set<Permission> permissions = new CopyOnWriteArraySet<>(); | ||
|
||
public EmortalCombatPlayer(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) { | ||
super(uuid, username, playerConnection); | ||
} | ||
|
||
@Override | ||
public @NotNull Set<Permission> getPermissions() { | ||
return this.permissions; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/dev/emortal/minestom/core/module/core/playerprovider/EmortalPlayer.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,8 @@ | ||
package dev.emortal.minestom.core.module.core.playerprovider; | ||
|
||
import dev.emortal.minestom.core.module.permissions.PermissionHolder; | ||
|
||
public interface EmortalPlayer extends PermissionHolder { | ||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/dev/emortal/minestom/core/module/core/playerprovider/EmortalPlayerImpl.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,24 @@ | ||
package dev.emortal.minestom.core.module.core.playerprovider; | ||
|
||
import dev.emortal.minestom.core.module.permissions.Permission; | ||
import dev.emortal.minestom.core.module.permissions.PermissionHolder; | ||
import net.minestom.server.entity.Player; | ||
import net.minestom.server.network.player.GameProfile; | ||
import net.minestom.server.network.player.PlayerConnection; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Set; | ||
import java.util.concurrent.CopyOnWriteArraySet; | ||
|
||
public class EmortalPlayerImpl extends Player implements EmortalPlayer { | ||
private final @NotNull Set<Permission> permissions = new CopyOnWriteArraySet<>(); | ||
|
||
public EmortalPlayerImpl(@NotNull PlayerConnection playerConnection, @NotNull GameProfile gameProfile) { | ||
super(playerConnection, gameProfile); | ||
} | ||
|
||
@Override | ||
public @NotNull Set<Permission> getPermissions() { | ||
return this.permissions; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/dev/emortal/minestom/core/module/permissions/Permission.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,11 @@ | ||
package dev.emortal.minestom.core.module.permissions; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record Permission(@NotNull String permission, boolean state) { | ||
|
||
public Permission(@NotNull String permission) { | ||
this(permission, true); | ||
} | ||
|
||
} |
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
55 changes: 55 additions & 0 deletions
55
src/main/java/dev/emortal/minestom/core/module/permissions/PermissionHolder.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,55 @@ | ||
package dev.emortal.minestom.core.module.permissions; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
|
||
public interface PermissionHolder { | ||
|
||
@NotNull Set<Permission> getPermissions(); | ||
|
||
default void addPermission(@NotNull Permission permission) { | ||
this.getPermissions().add(permission); | ||
} | ||
|
||
default void removePermission(@NotNull Permission permission) { | ||
this.getPermissions().remove(permission); | ||
} | ||
|
||
default void removePermission(@NotNull String permission) { | ||
this.getPermissions().removeIf(p -> p.permission().equals(permission)); | ||
} | ||
|
||
default boolean hasPermission(@NotNull Permission permission) { | ||
for (Permission permissionLoop : this.getPermissions()) { | ||
if (permissionLoop.equals(permission)) { | ||
return true; | ||
} | ||
String permissionLoopName = permissionLoop.permission(); | ||
if (permissionLoopName.contains("*")) { | ||
// Sanitize permissionLoopName | ||
String regexSanitized = Pattern.quote(permissionLoopName).replace("*", "\\E(.*)\\Q"); // Replace * with regex | ||
// pattern matching for wildcards, where foo.b*r.baz matches foo.baaaar.baz or foo.bar.baz | ||
if (permission.permission().matches(regexSanitized)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
default boolean hasPermission(@NotNull String permission) { | ||
return this.hasPermission(new Permission(permission, true)); | ||
} | ||
|
||
default Permission getPermission(@NotNull String permission) { | ||
for (Permission permissionLoop : this.getPermissions()) { | ||
if (permissionLoop.permission().equals(permission)) { | ||
return permissionLoop; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
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
6 changes: 5 additions & 1 deletion
6
src/main/java/dev/emortal/minestom/core/utils/command/ExtraConditions.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