mirror of
https://github.com/TotalFreedomMC/TF-Marriage.git
synced 2024-09-28 12:43:03 +00:00
change permissions
This commit is contained in:
parent
020e312a92
commit
57786c609b
10
pom.xml
10
pom.xml
|
@ -19,6 +19,10 @@
|
|||
<id>md5-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<!--<repository>-->
|
||||
<!--<id>vault-repo</id>-->
|
||||
<!--<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>-->
|
||||
<!--</repository>-->
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
@ -47,6 +51,12 @@
|
|||
<version>1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>net.milkbowl.vault</groupId>-->
|
||||
<!--<artifactId>VaultAPI</artifactId>-->
|
||||
<!--<version>1.5</version>-->
|
||||
<!--<scope>provided</scope>-->
|
||||
<!--</dependency>-->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.lenis0012.bukkit.marriage2.commands;
|
||||
|
||||
import com.lenis0012.bukkit.marriage2.config.Permissions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -14,7 +15,7 @@ public abstract class Command {
|
|||
private String description = "No description available";
|
||||
private String usage = "";
|
||||
private int minArgs = 0;
|
||||
private String permission = null;
|
||||
private Permissions permission = null;
|
||||
private boolean allowConsole = false;
|
||||
private boolean hidden = false;
|
||||
|
||||
|
@ -26,7 +27,7 @@ public abstract class Command {
|
|||
this.marriage = marriage;
|
||||
this.aliases = aliases;
|
||||
if(aliases.length > 0) {
|
||||
this.permission = "marry." + aliases[0];
|
||||
this.permission = Permissions.getByNode("marry." + aliases[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,11 +112,11 @@ public abstract class Command {
|
|||
Bukkit.broadcastMessage(message);
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
public Permissions getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public void setPermission(String permission) {
|
||||
public void setPermission(Permissions permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ public class CommandHelp extends Command {
|
|||
super(marriage, "help");
|
||||
setMinArgs(-1);
|
||||
setHidden(true);
|
||||
setPermission(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.lenis0012.bukkit.marriage2.commands;
|
|||
import com.lenis0012.bukkit.marriage2.MPlayer;
|
||||
import com.lenis0012.bukkit.marriage2.Marriage;
|
||||
import com.lenis0012.bukkit.marriage2.config.Message;
|
||||
import com.lenis0012.bukkit.marriage2.config.Permissions;
|
||||
import com.lenis0012.bukkit.marriage2.config.Settings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -16,7 +17,7 @@ public class CommandPriest extends Command {
|
|||
setDescription("Set whether or not a player should be priest.");
|
||||
setUsage("add/remove <player>");
|
||||
setMinArgs(2);
|
||||
setPermission("marry.admin");
|
||||
setPermission(Permissions.ADMIN);
|
||||
|
||||
if(!Settings.ENABLE_PRIEST.value()) {
|
||||
setHidden(true);
|
||||
|
|
|
@ -13,7 +13,6 @@ public class CommandUpdate extends Command {
|
|||
public CommandUpdate(Marriage marriage) {
|
||||
super(marriage, "update");
|
||||
setHidden(true);
|
||||
setPermission("marry.update");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
package com.lenis0012.bukkit.marriage2.config;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
public enum Permissions {
|
||||
/**
|
||||
* Kitds
|
||||
*/
|
||||
ALL("marry.*", PermissionDefault.FALSE, -1),
|
||||
ADMIN("marry.admin", PermissionDefault.OP, 0),
|
||||
DEFAULT("marry.default", PermissionDefault.TRUE, 0),
|
||||
/**
|
||||
* Admin commands
|
||||
*/
|
||||
UPDATE("marry.update", PermissionDefault.OP, 1),
|
||||
/**
|
||||
* Player commands
|
||||
*/
|
||||
MARRY("marry.marry", PermissionDefault.TRUE),
|
||||
LIST("marry.list", PermissionDefault.TRUE),
|
||||
TELEPORT("marry.tp", PermissionDefault.TRUE),
|
||||
HOME("marry.home", PermissionDefault.TRUE),
|
||||
SET_HOME("marry.sethome", PermissionDefault.TRUE),
|
||||
GIFT("marry.gift", PermissionDefault.TRUE),
|
||||
CHAT("marry.chat", PermissionDefault.TRUE),
|
||||
SEEN("marry.seen", PermissionDefault.TRUE);
|
||||
|
||||
// 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 final String node;
|
||||
private final PermissionDefault defaultSetting;
|
||||
private final int parent;
|
||||
|
||||
Permissions(String node, PermissionDefault defaultSetting) {
|
||||
this(node, defaultSetting, 2);
|
||||
}
|
||||
|
||||
Permissions(String node, PermissionDefault defaultSetting, int parent) {
|
||||
this.node = node;
|
||||
this.defaultSetting = defaultSetting;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public boolean has(CommandSender sender) {
|
||||
if(parent >= 0 && values()[parent].has(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return sender.hasPermission(node);
|
||||
|
||||
// if(permissionService != null) {
|
||||
// return permissionService.has(player, node);
|
||||
// }
|
||||
//
|
||||
// return defaultSetting.getValue(player.isOp());
|
||||
}
|
||||
|
||||
public static Permissions getByNode(String node) {
|
||||
for(Permissions permission : values()) {
|
||||
if(permission.node.equalsIgnoreCase(node)) {
|
||||
return permission;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ public class MarriageCommandExecutor implements CommandExecutor {
|
|||
|
||||
// Assuming that the command is not null now, if it is, then that is a mistake on my side.
|
||||
if(args.length > command.getMinArgs()) {
|
||||
if(command.getPermission() == null || sender.hasPermission(command.getPermission())) {
|
||||
if(command.getPermission() == null || command.getPermission().has(sender)) {
|
||||
if(command.isAllowConsole() || sender instanceof Player) {
|
||||
command.prepare(sender, args);
|
||||
command.execute();
|
||||
|
|
|
@ -95,12 +95,12 @@ public class MarriagePlayer implements MPlayer {
|
|||
@Override
|
||||
public MPlayer getPartner() {
|
||||
Marriage core = MarriagePlugin.getInstance();
|
||||
UUID id = null;
|
||||
if(marriage != null) {
|
||||
id = uuid.equals(marriage.getPlayer1Id()) ? marriage.getPllayer2Id() : marriage.getPlayer1Id();
|
||||
UUID id = uuid.equals(marriage.getPlayer1Id()) ? marriage.getPllayer2Id() : marriage.getPlayer1Id();
|
||||
return core.getMPlayer(id);
|
||||
}
|
||||
|
||||
return core.getMPlayer(id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.lenis0012.bukkit.marriage2.listeners;
|
||||
|
||||
import com.lenis0012.bukkit.marriage2.config.Message;
|
||||
import com.lenis0012.bukkit.marriage2.config.Permissions;
|
||||
import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
|
||||
import com.lenis0012.updater.api.Updater;
|
||||
import com.lenis0012.updater.api.Version;
|
||||
|
@ -21,7 +22,7 @@ public class UpdateListener implements Listener {
|
|||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if(player.hasPermission("marry.update")) {
|
||||
if(Permissions.UPDATE.has(player)) {
|
||||
final Updater updater = core.getUpdater();
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(core.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -6,7 +6,25 @@
|
|||
"---[ Changelog ]---",
|
||||
"When restarted, check config",
|
||||
"",
|
||||
"- Updated chat format"
|
||||
"- Updated chat format",
|
||||
"",
|
||||
"- Updated permission support",
|
||||
"",
|
||||
"- Fixed error on divorce"
|
||||
],
|
||||
[
|
||||
"====[ DONATE ]====",
|
||||
"",
|
||||
"Make minecraft great again",
|
||||
"$1 = 1 TRUMP VOTE",
|
||||
"",
|
||||
"paypal.me/lenis0012",
|
||||
"=====[ SOCIAL ]=====",
|
||||
"IGN: lenis",
|
||||
"Twitter: @lenis0012",
|
||||
"",
|
||||
"Report bugs!",
|
||||
"-lenis"
|
||||
]
|
||||
]
|
||||
}
|
|
@ -8,41 +8,4 @@ softdepend: [Vault]
|
|||
commands:
|
||||
marry:
|
||||
description: Marriage main command.
|
||||
usage: /marry <args>
|
||||
permissions:
|
||||
marry.*:
|
||||
description: Allows all Marriage Commands
|
||||
default: false
|
||||
children:
|
||||
marry.admin:
|
||||
description: Allows all admin commands
|
||||
default: false
|
||||
children:
|
||||
marry.update:
|
||||
description: Allows user to update plugin if updater is enabled.
|
||||
default: op
|
||||
marry.default:
|
||||
description: Allows default player commands
|
||||
default: true
|
||||
children:
|
||||
marry.marry:
|
||||
description: Allows to marry with players
|
||||
default: true
|
||||
marry.tp:
|
||||
description: Allows to tp to your partner
|
||||
default: true
|
||||
marry.home:
|
||||
description: Allows to tp to your home if set
|
||||
default: true
|
||||
marry.sethome:
|
||||
description: Allows to set your Marriage home
|
||||
default: true
|
||||
marry.gift:
|
||||
description: Allows to gift items to your partner
|
||||
default: true
|
||||
marry.chat:
|
||||
description: Allows to chat with your partner
|
||||
default: true
|
||||
marry.seen:
|
||||
description: Allows to see your last login from your partner
|
||||
default: true
|
||||
usage: /marry <args>
|
Loading…
Reference in a new issue