Adds Admin switch command to bypass protections.
Re-adds the global mod bypassprotect permission. Adds removePerm and addPerm to user class.
This commit is contained in:
parent
fc082558d5
commit
e1c8bb9f1c
|
@ -0,0 +1,71 @@
|
|||
package world.bentobox.bentobox.api.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class AdminSwitchCommand extends ConfirmableCommand {
|
||||
|
||||
private final String bypassPerm;
|
||||
|
||||
|
||||
/**
|
||||
* Switches bypass on and off
|
||||
* @param parent - admin command
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public AdminSwitchCommand(CompositeCommand parent) {
|
||||
super(parent, "switch");
|
||||
bypassPerm = getPermissionPrefix() + "mod.bypassprotect";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("mod.switch");
|
||||
setOnlyPlayer(true);
|
||||
setParametersHelp("commands.admin.switch.parameters");
|
||||
setDescription("commands.admin.switch.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute(User user, String label, List<String> args) {
|
||||
if (!args.isEmpty()) {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
if (user.isOp()) {
|
||||
user.sendMessage("commands.admin.switch.op");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (user.hasPermission(getPermissionPrefix() + "mod.switch")) {
|
||||
if (user.hasPermission(bypassPerm)) {
|
||||
user.sendMessage("commands.admin.switch.removing");
|
||||
// Remove positive perm
|
||||
if (user.removePerm(bypassPerm)) {
|
||||
user.sendMessage("general.success");
|
||||
}
|
||||
} else {
|
||||
user.sendMessage("commands.admin.switch.adding");
|
||||
// Add positive permission
|
||||
user.addPerm(bypassPerm);
|
||||
if (user.hasPermission(bypassPerm)) {
|
||||
user.sendMessage("general.success");
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -153,7 +153,8 @@ public abstract class FlagListener implements Listener {
|
|||
// Protection flag
|
||||
|
||||
// Ops or "bypass everywhere" moderators can do anything
|
||||
if (user.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + ".mod.bypass." + flag.getID() + ".everywhere")) {
|
||||
if (user.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + ".mod.bypassprotect")
|
||||
|| user.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + ".mod.bypass." + flag.getID() + ".everywhere")) {
|
||||
if (user.isOp()) {
|
||||
report(user, e, loc, flag, Why.OP);
|
||||
} else {
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.bukkit.World;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
@ -236,6 +237,33 @@ public class User {
|
|||
return permission.isEmpty() || isOp() || sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes permission from user
|
||||
* @param name - Name of the permission to remove
|
||||
* @return true if successful
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public boolean removePerm(String name) {
|
||||
for (PermissionAttachmentInfo p : player.getEffectivePermissions()) {
|
||||
if (p.getPermission().equals(name)) {
|
||||
player.removeAttachment(p.getAttachment());
|
||||
break;
|
||||
}
|
||||
}
|
||||
player.recalculatePermissions();
|
||||
return !player.hasPermission(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a permission to user
|
||||
* @param name - Name of the permission to attach
|
||||
* @return The PermissionAttachment that was just created
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public PermissionAttachment addPerm(String name) {
|
||||
return player.addAttachment(plugin, name, true);
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return player != null && player.isOnline();
|
||||
}
|
||||
|
|
|
@ -142,6 +142,10 @@ commands:
|
|||
banned-players: "Banned players:"
|
||||
banned-format: "&c[name]"
|
||||
unowned: "&cUnowned"
|
||||
switch:
|
||||
op: "&cOps can always bypass protection. Deop to use command."
|
||||
removing: "Removing protection bypass..."
|
||||
adding: "Adding protection bypass..."
|
||||
switchto:
|
||||
parameters: "<player> <number>"
|
||||
description: "switch player's island to the numbered one in trash"
|
||||
|
|
Loading…
Reference in New Issue