mirror of
https://github.com/MilkBowl/Vault.git
synced 2024-12-27 03:17:51 +01:00
Refactor: Remove redundant method names, improve usability
This commit is contained in:
parent
d2dcc8fb54
commit
764bd117a0
@ -19,7 +19,9 @@
|
||||
|
||||
package net.milkbowl.vault;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -44,12 +46,12 @@ public class Vault extends JavaPlugin {
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
// Economy
|
||||
private TreeMap<Integer, Economy> econs = new TreeMap<Integer, Economy>();
|
||||
private Economy activeEconomy = null;
|
||||
private static Map<Integer, Economy> econs = Collections.synchronizedMap(new TreeMap<Integer, Economy>());
|
||||
private static Economy activeEconomy = null;
|
||||
|
||||
// Permission
|
||||
private TreeMap<Integer,Permission> perms = new TreeMap<Integer,Permission>();
|
||||
private Permission activePermission = null;
|
||||
private static Map<Integer,Permission> perms = Collections.synchronizedMap(new TreeMap<Integer, Permission>());
|
||||
private static Permission activePermission = null;
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
@ -70,7 +72,7 @@ public class Vault extends JavaPlugin {
|
||||
* Gets current active Economy implementation
|
||||
* @return Economy class
|
||||
*/
|
||||
public Economy getEconomy() {
|
||||
public static Economy getEconomy() {
|
||||
if (activeEconomy == null) {
|
||||
Iterator<Economy> it = econs.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
@ -89,7 +91,7 @@ public class Vault extends JavaPlugin {
|
||||
* Gets current active Permission implementation
|
||||
* @return Permission class
|
||||
*/
|
||||
public Permission getPermission() {
|
||||
public static Permission getPermission() {
|
||||
if(activePermission == null) {
|
||||
Iterator<Permission> it = perms.values().iterator();
|
||||
while(it.hasNext()) {
|
||||
@ -231,7 +233,7 @@ public class Vault extends JavaPlugin {
|
||||
* @param packages String Array of package names to check
|
||||
* @return Success or Failure
|
||||
*/
|
||||
private boolean packageExists(String[] packages) {
|
||||
private static boolean packageExists(String[] packages) {
|
||||
try {
|
||||
for (String pkg : packages) {
|
||||
Class.forName(pkg);
|
||||
|
@ -35,13 +35,21 @@ public interface Permission {
|
||||
*/
|
||||
public boolean isEnabled();
|
||||
|
||||
/**
|
||||
* Checks if player has a permission node. (Short for playerHas(...)
|
||||
* @param player Player instance
|
||||
* @param permission Permission node
|
||||
* @return Success or Failure
|
||||
*/
|
||||
public boolean has(Player player, String permission);
|
||||
|
||||
/**
|
||||
* Checks if player has a permission node.
|
||||
* @param player Player instance
|
||||
* @param permission Permission node
|
||||
* @return Success or Failure
|
||||
*/
|
||||
public boolean playerHasPermission(Player player, String permission);
|
||||
public boolean playerHas(Player player, String permission);
|
||||
|
||||
/**
|
||||
* Add permission to a player.
|
||||
@ -50,7 +58,7 @@ public interface Permission {
|
||||
* @param permission Permission node
|
||||
* @return Success or Failure
|
||||
*/
|
||||
public boolean playerAddPermission(String worldName, String playerName, String permission);
|
||||
public boolean playerAdd(String worldName, String playerName, String permission);
|
||||
|
||||
/**
|
||||
* Remove permission from a player.
|
||||
@ -59,7 +67,7 @@ public interface Permission {
|
||||
* @param permission Permission node
|
||||
* @return Success or Failure
|
||||
*/
|
||||
public boolean playerRemovePermission(String worldName, String playerName, String permission);
|
||||
public boolean playerRemove(String worldName, String playerName, String permission);
|
||||
|
||||
/**
|
||||
* Checks if group has a permission node.
|
||||
@ -68,7 +76,7 @@ public interface Permission {
|
||||
* @param permission Permission node
|
||||
* @return Success or Failure
|
||||
*/
|
||||
public boolean groupHasPermission(String worldName, String groupName, String permission);
|
||||
public boolean groupHas(String worldName, String groupName, String permission);
|
||||
|
||||
/**
|
||||
* Add permission to a group.
|
||||
@ -77,7 +85,7 @@ public interface Permission {
|
||||
* @param permission Permission node
|
||||
* @return Success or Failure
|
||||
*/
|
||||
public boolean groupAddPermission(String worldName, String groupName, String permission);
|
||||
public boolean groupAdd(String worldName, String groupName, String permission);
|
||||
|
||||
/**
|
||||
* Remove permission from a group.
|
||||
@ -86,7 +94,7 @@ public interface Permission {
|
||||
* @param permission Permission node
|
||||
* @return Success or Failure
|
||||
*/
|
||||
public boolean groupRemovePermission(String worldName, String groupName, String permission);
|
||||
public boolean groupRemove(String worldName, String groupName, String permission);
|
||||
|
||||
/**
|
||||
* Check if player is member of a group.
|
||||
|
@ -32,8 +32,6 @@ import org.bukkit.event.server.ServerListener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import ru.tehkode.permissions.PermissionGroup;
|
||||
|
||||
import com.nijiko.permissions.Group;
|
||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
|
||||
@ -75,9 +73,14 @@ public class Permission_Permissions implements Permission {
|
||||
return permission.isEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(Player player, String permission) {
|
||||
return playerHas(player, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerHasPermission(Player player, String permission) {
|
||||
public boolean playerHas(Player player, String permission) {
|
||||
return this.permission.getHandler().has(player, permission);
|
||||
}
|
||||
|
||||
@ -182,25 +185,25 @@ public class Permission_Permissions implements Permission {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerAddPermission(String worldName, String playerName, String permission) {
|
||||
public boolean playerAdd(String worldName, String playerName, String permission) {
|
||||
this.permission.getHandler().addUserPermission(worldName, playerName, permission);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerRemovePermission(String worldName, String playerName, String permission) {
|
||||
public boolean playerRemove(String worldName, String playerName, String permission) {
|
||||
this.permission.getHandler().removeUserPermission(worldName, playerName, permission);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupAddPermission(String worldName, String groupName, String permission) {
|
||||
public boolean groupAdd(String worldName, String groupName, String permission) {
|
||||
this.permission.getHandler().addGroupPermission(worldName, groupName, permission);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupRemovePermission(String worldName, String groupName, String permission) {
|
||||
public boolean groupRemove(String worldName, String groupName, String permission) {
|
||||
this.permission.getHandler().removeGroupPermission(worldName, groupName, permission);
|
||||
return true;
|
||||
}
|
||||
@ -326,7 +329,7 @@ public class Permission_Permissions implements Permission {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupHasPermission(String worldName, String groupName, String permission) {
|
||||
public boolean groupHas(String worldName, String groupName, String permission) {
|
||||
try {
|
||||
Group group = this.permission.getHandler().safeGetGroup(worldName, groupName);
|
||||
return group.hasPermission(permission);
|
||||
|
@ -75,9 +75,14 @@ public class Permission_PermissionsEx implements Permission {
|
||||
return permission.isEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(Player player, String permission) {
|
||||
return playerHas(player, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerHasPermission(Player player, String permission) {
|
||||
public boolean playerHas(Player player, String permission) {
|
||||
return this.permission.has(player, permission);
|
||||
}
|
||||
|
||||
@ -178,7 +183,7 @@ public class Permission_PermissionsEx implements Permission {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerAddPermission(String worldName, String playerName, String permission) {
|
||||
public boolean playerAdd(String worldName, String playerName, String permission) {
|
||||
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
|
||||
if(user == null) {
|
||||
return false;
|
||||
@ -189,7 +194,7 @@ public class Permission_PermissionsEx implements Permission {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerRemovePermission(String worldName, String playerName, String permission) {
|
||||
public boolean playerRemove(String worldName, String playerName, String permission) {
|
||||
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
|
||||
if(user == null) {
|
||||
return false;
|
||||
@ -200,7 +205,7 @@ public class Permission_PermissionsEx implements Permission {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupAddPermission(String worldName, String groupName, String permission) {
|
||||
public boolean groupAdd(String worldName, String groupName, String permission) {
|
||||
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
|
||||
if(group == null) {
|
||||
return false;
|
||||
@ -211,7 +216,7 @@ public class Permission_PermissionsEx implements Permission {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupRemovePermission(String worldName, String groupName, String permission) {
|
||||
public boolean groupRemove(String worldName, String groupName, String permission) {
|
||||
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
|
||||
if(group == null) {
|
||||
return false;
|
||||
@ -334,7 +339,7 @@ public class Permission_PermissionsEx implements Permission {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupHasPermission(String worldName, String groupName, String permission) {
|
||||
public boolean groupHas(String worldName, String groupName, String permission) {
|
||||
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
|
||||
if(group == null) {
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user