mirror of
https://github.com/TotalFreedomMC/TF-Marriage.git
synced 2024-12-28 11:04:24 +00:00
fix permissions
This commit is contained in:
parent
1ae1611405
commit
a5e4da2a76
4 changed files with 37 additions and 56 deletions
14
pom.xml
14
pom.xml
|
@ -42,13 +42,13 @@
|
|||
<version>1.9-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.9-R0.1-SNAPSHOT</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/spigot.jar</systemPath>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.spigotmc</groupId>-->
|
||||
<!--<artifactId>spigot</artifactId>-->
|
||||
<!--<version>1.9-R0.1-SNAPSHOT</version>-->
|
||||
<!--<scope>system</scope>-->
|
||||
<!--<systemPath>${project.basedir}/lib/spigot.jar</systemPath>-->
|
||||
<!--</dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.lenis0012.bukkit</groupId>
|
||||
<artifactId>lenisutils</artifactId>
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.lenis0012.bukkit.marriage2;
|
|||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface MData {
|
||||
|
@ -24,7 +23,6 @@ public interface MData {
|
|||
*
|
||||
* @return Marriage home, NULL if not set.
|
||||
*/
|
||||
@Nullable
|
||||
Location getHome();
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.lenis0012.bukkit.marriage2;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface MPlayer {
|
||||
|
@ -46,7 +45,6 @@ public interface MPlayer {
|
|||
*
|
||||
* @return Player's marriage, NULL if not married.
|
||||
*/
|
||||
@Nullable
|
||||
MData getMarriage();
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,22 +1,25 @@
|
|||
package com.lenis0012.bukkit.marriage2.config;
|
||||
|
||||
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public enum Permissions {
|
||||
/**
|
||||
* Kitds
|
||||
* Kits
|
||||
*/
|
||||
ALL("marry.*", PermissionDefault.FALSE, -1),
|
||||
ADMIN("marry.admin", PermissionDefault.OP, 0),
|
||||
DEFAULT("marry.default", PermissionDefault.OP, 0),
|
||||
ALL("marry.*", -1),
|
||||
ADMIN("marry.admin", 0),
|
||||
DEFAULT("marry.default", 0),
|
||||
/**
|
||||
* Admin commands
|
||||
*/
|
||||
UPDATE("marry.update", PermissionDefault.FALSE, 1),
|
||||
CHAT_SPY("marry.chatspy", PermissionDefault.FALSE, 1),
|
||||
UPDATE("marry.update", 1),
|
||||
CHAT_SPY("marry.chatspy", 1),
|
||||
/**
|
||||
* Player commands
|
||||
*/
|
||||
|
@ -29,35 +32,29 @@ public enum Permissions {
|
|||
CHAT("marry.chat"),
|
||||
SEEN("marry.seen");
|
||||
|
||||
// public static Permission permissionService;
|
||||
//
|
||||
// public boolean setupPermissions() {
|
||||
// RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServicesManager().getRegistration(Permission.class);
|
||||
// if(permissionProvider != null) {
|
||||
// permissionService = permissionProvider.getProvider();
|
||||
// }
|
||||
// return permissionService != null;
|
||||
// }
|
||||
private static boolean vaultEnabled = false;
|
||||
private static Permission permissionService;
|
||||
|
||||
public boolean setupPermissions() {
|
||||
RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServicesManager().getRegistration(Permission.class);
|
||||
if(permissionProvider != null) {
|
||||
permissionService = permissionProvider.getProvider();
|
||||
vaultEnabled = true;
|
||||
MarriagePlugin.getCore().getLogger().log(Level.INFO, "Hooked with " + permissionService.getName() + " using Vault!");
|
||||
}
|
||||
return permissionService != null;
|
||||
}
|
||||
|
||||
private final String node;
|
||||
private final PermissionDefault defaultSetting;
|
||||
private final int parent;
|
||||
private Permission permission;
|
||||
|
||||
Permissions(String node) {
|
||||
this(node, PermissionDefault.FALSE);
|
||||
this(node, 2);
|
||||
}
|
||||
|
||||
Permissions(String node, PermissionDefault defaultSetting) {
|
||||
this(node, defaultSetting, 2);
|
||||
}
|
||||
|
||||
Permissions(String node, PermissionDefault defaultSetting, int parent) {
|
||||
Permissions(String node, int parent) {
|
||||
this.node = node;
|
||||
this.defaultSetting = defaultSetting;
|
||||
this.parent = parent;
|
||||
this.permission = new Permission(node, null, defaultSetting);
|
||||
Bukkit.getPluginManager().addPermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,7 +64,11 @@ public enum Permissions {
|
|||
* @return True if has permission, False otherwise
|
||||
*/
|
||||
public boolean has(CommandSender sender) {
|
||||
return sender.hasPermission(permission);
|
||||
if(parent >= 0 && values()[parent].has(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return vaultEnabled ? permissionService.has(sender, node) : sender.hasPermission(node);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,20 +86,4 @@ public enum Permissions {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set child relations
|
||||
*/
|
||||
public static void setupChildRelations() {
|
||||
for(Permissions perm : values()) {
|
||||
if(perm.parent < 0) continue;
|
||||
perm.permission.addParent(values()[perm.parent].permission, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void unloadAll() {
|
||||
for(Permissions perm : values()) {
|
||||
Bukkit.getPluginManager().removePermission(perm.permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue