protected HashMap<String, Boolean> getDisguisePermission( CommandSender sender, DisguiseType type) { switch (type) { case PLAYER: case FALLING_BLOCK: case PAINTING: case SPLASH_POTION: case FISHING_HOOK: case DROPPED_ITEM: HashMap<String, Boolean> returns = new HashMap<String, Boolean>(); String beginning = "libsdisguises.options." + getClass().getSimpleName().toLowerCase().replace("command", "") + "."; for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) { String lowerPerm = permission.getPermission().toLowerCase(); if (lowerPerm.startsWith(beginning)) { String[] split = lowerPerm.substring(beginning.length()).split("\\."); if (split.length > 1) { if (split[0].replace("_", "").equals(type.name().toLowerCase().replace("_", ""))) { for (int i = 1; i < split.length; i++) { returns.put(split[i], permission.getValue()); } } } } } return returns; default: return new HashMap<String, Boolean>(); } }
/** * 対象のプレイヤーの、チームメンバー用の権限を全て剥奪する。 * * @param player プレイヤー */ public void removeAllMemberPermission(Player player) { for (PermissionAttachmentInfo info : player.getEffectivePermissions()) { if (info.getPermission().startsWith(TEAM_PERMISSION_PREFIX)) { player.removeAttachment(info.getAttachment()); } } }
/** Get perms for the node. Returns a hashmap of allowed disguisetypes and their options */ protected HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> getPermissions( CommandSender sender, String permissionNode) { HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> singleDisguises = new HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>>(); HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> rangeDisguises = new HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>>(); HashMap<String, Boolean> perms = new HashMap<String, Boolean>(); for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) { String perm = permission.getPermission().toLowerCase(); if (perm.startsWith(permissionNode) && (!perms.containsKey(perm) || !permission.getValue())) { perms.put(perm, permission.getValue()); } } if (!perms.containsKey(permissionNode + "*") && sender.hasPermission(permissionNode + "*")) { perms.put(permissionNode + "*", true); } if (!perms.containsKey(permissionNode + "*.*") && sender.hasPermission(permissionNode + "*.*")) { perms.put(permissionNode + "*.*", true); } for (String perm : perms.keySet()) { if (perms.get(perm)) { perm = perm.substring(permissionNode.length()); String disguiseType = perm.split("\\.")[0]; DisguiseType dType = null; for (DisguiseType t : DisguiseType.values()) { if (t.name().replace("_", "").equalsIgnoreCase(disguiseType.replace("_", ""))) { dType = t; break; } } if (dType != null) { HashMap<ArrayList<String>, Boolean> list; if (singleDisguises.containsKey(dType)) { list = singleDisguises.get(dType); } else { list = new HashMap<ArrayList<String>, Boolean>(); singleDisguises.put(dType, list); } HashMap<ArrayList<String>, Boolean> map1 = getOptions(perm); list.put(map1.keySet().iterator().next(), map1.values().iterator().next()); } else { for (DisguiseType type : DisguiseType.values()) { HashMap<ArrayList<String>, Boolean> options = null; Class entityClass = type.getEntityType() == null ? Entity.class : type.getEntityType().getEntityClass(); if (disguiseType.equals("mob")) { if (type.isMob()) { options = getOptions(perm); } } else if (disguiseType.equals("animal") || disguiseType.equals("animals")) { if (Animals.class.isAssignableFrom(entityClass)) { options = getOptions(perm); } } else if (disguiseType.equals("monster") || disguiseType.equals("monsters")) { if (Monster.class.isAssignableFrom(entityClass)) { options = getOptions(perm); } } else if (disguiseType.equals("misc")) { if (type.isMisc()) { options = getOptions(perm); } } else if (disguiseType.equals("ageable")) { if (Ageable.class.isAssignableFrom(entityClass)) { options = getOptions(perm); } } else if (disguiseType.equals("*")) { options = getOptions(perm); } if (options != null) { HashMap<ArrayList<String>, Boolean> list; if (rangeDisguises.containsKey(type)) { list = rangeDisguises.get(type); } else { list = new HashMap<ArrayList<String>, Boolean>(); rangeDisguises.put(type, list); } HashMap<ArrayList<String>, Boolean> map1 = getOptions(perm); list.put(map1.keySet().iterator().next(), map1.values().iterator().next()); } } } } } for (String perm : perms.keySet()) { if (!perms.get(perm)) { perm = perm.substring(permissionNode.length()); String disguiseType = perm.split("\\.")[0]; DisguiseType dType = null; for (DisguiseType t : DisguiseType.values()) { if (t.name().replace("_", "").equalsIgnoreCase(disguiseType.replace("_", ""))) { dType = t; break; } } if (dType != null) { singleDisguises.remove(dType); rangeDisguises.remove(dType); } else { for (DisguiseType type : DisguiseType.values()) { boolean foundHim = false; Class entityClass = type.getEntityType() == null ? Entity.class : type.getEntityType().getEntityClass(); if (disguiseType.equals("mob")) { if (type.isMob()) { foundHim = true; } } else if (disguiseType.equals("animal") || disguiseType.equals("animals")) { if (Animals.class.isAssignableFrom(entityClass)) { foundHim = true; } } else if (disguiseType.equals("monster") || disguiseType.equals("monsters")) { if (Monster.class.isAssignableFrom(entityClass)) { foundHim = true; } } else if (disguiseType.equals("misc")) { if (type.isMisc()) { foundHim = true; } } else if (disguiseType.equals("ageable")) { if (Ageable.class.isAssignableFrom(entityClass)) { foundHim = true; } } else if (disguiseType.equals("*")) { foundHim = true; } if (foundHim) { rangeDisguises.remove(type); } } } } } HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map = new HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>>(); for (DisguiseType type : DisguiseType.values()) { HashMap<ArrayList<String>, Boolean> temp = new HashMap<ArrayList<String>, Boolean>(); if (singleDisguises.containsKey(type)) { temp.putAll(singleDisguises.get(type)); } if (rangeDisguises.containsKey(type)) { temp.putAll(rangeDisguises.get(type)); } if (!temp.isEmpty()) { map.put(type, temp); } } return map; }