forked from EngineHub/WorldEdit
-
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
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/main/java/com/sk89q/bukkit/migration/JPermsPermissionsResolver.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,83 @@ | ||
package com.sk89q.bukkit.migration; | ||
|
||
import com.johnymuffin.jperms.beta.JohnyPerms; | ||
import com.johnymuffin.jperms.beta.JohnyPermsAPI; | ||
import com.johnymuffin.jperms.core.models.PermissionsGroup; | ||
import com.projectposeidon.api.PoseidonUUID; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Server; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.UUID; | ||
|
||
public class JPermsPermissionsResolver implements PermissionsResolver { | ||
private Server server; | ||
private JohnyPermsAPI api; | ||
|
||
public JPermsPermissionsResolver(final Server server) throws MissingPluginException, PluginAccessException { | ||
this.server = server; | ||
if (Bukkit.getServer().getPluginManager().getPlugin("JPerms") == null) { | ||
throw new MissingPluginException(); | ||
} | ||
try { | ||
this.api = JohnyPerms.getJPermsAPI(); | ||
} catch (Exception e) { | ||
throw new PluginAccessException(); | ||
} | ||
|
||
} | ||
|
||
public void load() { | ||
|
||
} | ||
|
||
private UUID getPlayerUUID(final String name) { | ||
for(Player player : Bukkit.getOnlinePlayers()) { | ||
if(player.getName().equalsIgnoreCase(name)) { | ||
return player.getUniqueId(); | ||
} | ||
} | ||
return PoseidonUUID.getPlayerGracefulUUID(name); | ||
} | ||
|
||
public boolean hasPermission(final String name, final String permission) { | ||
UUID playerUUID = getPlayerUUID(name); | ||
|
||
return api.getUser(playerUUID).hasPermissionSomehow(permission, true) || api.getUser(playerUUID).getGroup().hasPermission(permission, true); | ||
} | ||
|
||
@Override | ||
public boolean hasPermission(String worldName, String name, String permission) { | ||
//JPerms 1.0.0 does not support world permissions | ||
return hasPermission(name, permission); | ||
} | ||
|
||
public boolean inGroup(final String name, final String group) { | ||
String[] groups = getGroups(name); | ||
for(String g : groups) { | ||
if(g.equalsIgnoreCase(group)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public String[] getGroups(final String name) { | ||
UUID playerUUID = getPlayerUUID(name); | ||
PermissionsGroup group = api.getUser(playerUUID).getGroup(); | ||
String[] groups = new String[group.getInheritanceGroups().length + 1]; | ||
groups[0] = group.getName(); | ||
for(int i = 0; i < group.getInheritanceGroups().length; i++) { | ||
groups[i + 1] = group.getInheritanceGroups()[i].getName(); | ||
} | ||
return groups; | ||
} | ||
|
||
public static class PluginAccessException extends Exception { | ||
private static final long serialVersionUID = 7044832912491608706L; | ||
} | ||
|
||
public static class MissingPluginException extends Exception { | ||
private static final long serialVersionUID = 7044832912491608706L; | ||
} | ||
} |
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