mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-21 01:01:35 +08:00
Add IPermissionsHandler#addToGroup & IPermissionsHandler#removeFromGroup
This commit is contained in:
parent
52c500ee6d
commit
bfae6c5c69
@ -3,6 +3,7 @@ package com.earth2me.essentials.perm;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.TriState;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
@ -10,9 +11,13 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface IPermissionsHandler {
|
||||
String getGroup(Player base);
|
||||
boolean addToGroup(OfflinePlayer base, String group);
|
||||
|
||||
List<String> getGroups(Player base);
|
||||
boolean removeFromGroup(OfflinePlayer base, String group);
|
||||
|
||||
String getGroup(OfflinePlayer base);
|
||||
|
||||
List<String> getGroups(OfflinePlayer base);
|
||||
|
||||
List<String> getGroups();
|
||||
|
||||
|
@ -10,6 +10,7 @@ import com.earth2me.essentials.perm.impl.ModernVaultHandler;
|
||||
import com.earth2me.essentials.perm.impl.SuperpermsHandler;
|
||||
import com.earth2me.essentials.utils.TriState;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -34,7 +35,7 @@ public class PermissionsHandler implements IPermissionsHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup(final Player base) {
|
||||
public String getGroup(final OfflinePlayer base) {
|
||||
final long start = System.nanoTime();
|
||||
String group = handler.getGroup(base);
|
||||
if (group == null) {
|
||||
@ -45,7 +46,7 @@ public class PermissionsHandler implements IPermissionsHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups(final Player base) {
|
||||
public List<String> getGroups(final OfflinePlayer base) {
|
||||
final long start = System.nanoTime();
|
||||
List<String> groups = handler.getGroups(base);
|
||||
if (groups == null || groups.isEmpty()) {
|
||||
@ -66,6 +67,22 @@ public class PermissionsHandler implements IPermissionsHandler {
|
||||
return Collections.unmodifiableList(groups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToGroup(OfflinePlayer base, String group) {
|
||||
final long start = System.nanoTime();
|
||||
final boolean result = handler.addToGroup(base, group);
|
||||
checkPermLag(start, String.format("Adding group to %s", base.getName()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGroup(OfflinePlayer base, String group) {
|
||||
final long start = System.nanoTime();
|
||||
final boolean result = handler.removeFromGroup(base, group);
|
||||
checkPermLag(start, String.format("Removing group from %s", base.getName()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(final Player base, final String group) {
|
||||
return handler.canBuild(base, group);
|
||||
|
@ -3,6 +3,7 @@ package com.earth2me.essentials.perm.impl;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -32,13 +33,19 @@ public abstract class AbstractVaultHandler extends SuperpermsHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup(final Player base) {
|
||||
return perms.getPrimaryGroup(base);
|
||||
public String getGroup(final OfflinePlayer base) {
|
||||
if (base.isOnline()) {
|
||||
return perms.getPrimaryGroup(base.getPlayer());
|
||||
}
|
||||
return perms.getPrimaryGroup(null, base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups(final Player base) {
|
||||
return Arrays.asList(perms.getPlayerGroups(base));
|
||||
public List<String> getGroups(final OfflinePlayer base) {
|
||||
if (base.isOnline()) {
|
||||
return Arrays.asList(perms.getPlayerGroups(base.getPlayer()));
|
||||
}
|
||||
return Arrays.asList(perms.getPlayerGroups(null, base));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,6 +53,16 @@ public abstract class AbstractVaultHandler extends SuperpermsHandler {
|
||||
return Arrays.asList(perms.getGroups());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToGroup(OfflinePlayer base, String group) {
|
||||
return perms.playerAddGroup(null, base, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGroup(OfflinePlayer base, String group) {
|
||||
return perms.playerRemoveGroup(null, base, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inGroup(final Player base, final String group) {
|
||||
return perms.playerInGroup(base, group);
|
||||
|
@ -5,6 +5,7 @@ import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.perm.IPermissionsHandler;
|
||||
import com.earth2me.essentials.utils.TriState;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
@ -21,12 +22,22 @@ public class SuperpermsHandler implements IPermissionsHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup(final Player base) {
|
||||
public boolean addToGroup(OfflinePlayer base, String group) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGroup(OfflinePlayer base, String group) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup(final OfflinePlayer base) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups(final Player base) {
|
||||
public List<String> getGroups(final OfflinePlayer base) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user