mirror of
https://e.coding.net/circlecloud/Residence.git
synced 2025-11-26 22:06:07 +00:00
File diff suppressed because it is too large
Load Diff
@@ -5,9 +5,6 @@
|
||||
|
||||
package com.bekvon.bukkit.residence.protection;
|
||||
|
||||
import com.bekvon.bukkit.residence.Residence;
|
||||
import com.bekvon.bukkit.residence.protection.ResidenceManager.ChunkRef;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -16,199 +13,202 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.bekvon.bukkit.residence.protection.ResidenceManager.ChunkRef;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
public class CuboidArea {
|
||||
protected Location highPoints;
|
||||
protected Location lowPoints;
|
||||
protected Location highPoints;
|
||||
protected Location lowPoints;
|
||||
|
||||
protected CuboidArea() {
|
||||
}
|
||||
public CuboidArea(final Location startLoc, final Location endLoc) {
|
||||
int highx, highy, highz, lowx, lowy, lowz;
|
||||
if (startLoc.getBlockX() > endLoc.getBlockX()) {
|
||||
highx = startLoc.getBlockX();
|
||||
lowx = endLoc.getBlockX();
|
||||
} else {
|
||||
highx = endLoc.getBlockX();
|
||||
lowx = startLoc.getBlockX();
|
||||
}
|
||||
if (startLoc.getBlockY() > endLoc.getBlockY()) {
|
||||
highy = startLoc.getBlockY();
|
||||
lowy = endLoc.getBlockY();
|
||||
} else {
|
||||
highy = endLoc.getBlockY();
|
||||
lowy = startLoc.getBlockY();
|
||||
}
|
||||
if (startLoc.getBlockZ() > endLoc.getBlockZ()) {
|
||||
highz = startLoc.getBlockZ();
|
||||
lowz = endLoc.getBlockZ();
|
||||
} else {
|
||||
highz = endLoc.getBlockZ();
|
||||
lowz = startLoc.getBlockZ();
|
||||
}
|
||||
highPoints = new Location(startLoc.getWorld(), highx, highy, highz);
|
||||
lowPoints = new Location(startLoc.getWorld(), lowx, lowy, lowz);
|
||||
}
|
||||
|
||||
public CuboidArea(Location startLoc, Location endLoc) {
|
||||
int highx, highy, highz, lowx, lowy, lowz;
|
||||
if (startLoc.getBlockX() > endLoc.getBlockX()) {
|
||||
highx = startLoc.getBlockX();
|
||||
lowx = endLoc.getBlockX();
|
||||
} else {
|
||||
highx = endLoc.getBlockX();
|
||||
lowx = startLoc.getBlockX();
|
||||
}
|
||||
if (startLoc.getBlockY() > endLoc.getBlockY()) {
|
||||
highy = startLoc.getBlockY();
|
||||
lowy = endLoc.getBlockY();
|
||||
} else {
|
||||
highy = endLoc.getBlockY();
|
||||
lowy = startLoc.getBlockY();
|
||||
}
|
||||
if (startLoc.getBlockZ() > endLoc.getBlockZ()) {
|
||||
highz = startLoc.getBlockZ();
|
||||
lowz = endLoc.getBlockZ();
|
||||
} else {
|
||||
highz = endLoc.getBlockZ();
|
||||
lowz = startLoc.getBlockZ();
|
||||
}
|
||||
highPoints = new Location(startLoc.getWorld(), highx, highy, highz);
|
||||
lowPoints = new Location(startLoc.getWorld(), lowx, lowy, lowz);
|
||||
}
|
||||
protected CuboidArea() {
|
||||
}
|
||||
|
||||
public boolean isAreaWithinArea(CuboidArea area) {
|
||||
return (this.containsLoc(area.highPoints) && this.containsLoc(area.lowPoints));
|
||||
}
|
||||
public static CuboidArea load(final DataInputStream in, final int version) throws IOException {
|
||||
final CuboidArea newArea = new CuboidArea();
|
||||
final Server server = Bukkit.getServer();
|
||||
final World world = server.getWorld(in.readUTF());
|
||||
final int highx = in.readInt();
|
||||
final int highy = in.readInt();
|
||||
final int highz = in.readInt();
|
||||
final int lowx = in.readInt();
|
||||
final int lowy = in.readInt();
|
||||
final int lowz = in.readInt();
|
||||
newArea.highPoints = new Location(world, highx, highy, highz);
|
||||
newArea.lowPoints = new Location(world, lowx, lowy, lowz);
|
||||
return newArea;
|
||||
}
|
||||
|
||||
public boolean containsLoc(Location loc) {
|
||||
if (loc == null) {
|
||||
return false;
|
||||
}
|
||||
if (!loc.getWorld().equals(highPoints.getWorld())) {
|
||||
return false;
|
||||
}
|
||||
if (lowPoints.getBlockX() <= loc.getBlockX() && highPoints.getBlockX() >= loc.getBlockX()) {
|
||||
if (lowPoints.getBlockZ() <= loc.getBlockZ() && highPoints.getBlockZ() >= loc.getBlockZ()) {
|
||||
if (lowPoints.getBlockY() <= loc.getBlockY() && highPoints.getBlockY() >= loc.getBlockY()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static CuboidArea load(final Map<String, Object> root, final World world) throws Exception {
|
||||
if (root == null) {
|
||||
throw new Exception("Invalid residence physical location...");
|
||||
}
|
||||
final CuboidArea newArea = new CuboidArea();
|
||||
final int x1 = (Integer) root.get("X1");
|
||||
final int y1 = (Integer) root.get("Y1");
|
||||
final int z1 = (Integer) root.get("Z1");
|
||||
final int x2 = (Integer) root.get("X2");
|
||||
final int y2 = (Integer) root.get("Y2");
|
||||
final int z2 = (Integer) root.get("Z2");
|
||||
newArea.highPoints = new Location(world, x1, y1, z1);
|
||||
newArea.lowPoints = new Location(world, x2, y2, z2);
|
||||
return newArea;
|
||||
}
|
||||
|
||||
public boolean checkCollision(CuboidArea area) {
|
||||
if (!area.getWorld().equals(this.getWorld())) {
|
||||
return false;
|
||||
}
|
||||
if (area.containsLoc(lowPoints) || area.containsLoc(highPoints) || this.containsLoc(area.highPoints) || this.containsLoc(area.lowPoints)) {
|
||||
return true;
|
||||
}
|
||||
return advCuboidCheckCollision(highPoints, lowPoints, area.highPoints, area.lowPoints);
|
||||
}
|
||||
public boolean checkCollision(final CuboidArea area) {
|
||||
if (!area.getWorld().equals(this.getWorld())) {
|
||||
return false;
|
||||
}
|
||||
if (area.containsLoc(lowPoints) || area.containsLoc(highPoints) || this.containsLoc(area.highPoints) || this.containsLoc(area.lowPoints)) {
|
||||
return true;
|
||||
}
|
||||
return advCuboidCheckCollision(highPoints, lowPoints, area.highPoints, area.lowPoints);
|
||||
}
|
||||
|
||||
private boolean advCuboidCheckCollision(Location A1High, Location A1Low, Location A2High, Location A2Low) {
|
||||
int A1HX = A1High.getBlockX();
|
||||
int A1LX = A1Low.getBlockX();
|
||||
int A1HY = A1High.getBlockY();
|
||||
int A1LY = A1Low.getBlockY();
|
||||
int A1HZ = A1High.getBlockZ();
|
||||
int A1LZ = A1Low.getBlockZ();
|
||||
int A2HX = A2High.getBlockX();
|
||||
int A2LX = A2Low.getBlockX();
|
||||
int A2HY = A2High.getBlockY();
|
||||
int A2LY = A2Low.getBlockY();
|
||||
int A2HZ = A2High.getBlockZ();
|
||||
int A2LZ = A2Low.getBlockZ();
|
||||
if ((A1HX >= A2LX && A1HX <= A2HX) || (A1LX >= A2LX && A1LX <= A2HX) || (A2HX >= A1LX && A2HX <= A1HX) || (A2LX >= A1LX && A2LX <= A1HX)) {
|
||||
if ((A1HY >= A2LY && A1HY <= A2HY) || (A1LY >= A2LY && A1LY <= A2HY) || (A2HY >= A1LY && A2HY <= A1HY) || (A2LY >= A1LY && A2LY <= A1HY)) {
|
||||
if ((A1HZ >= A2LZ && A1HZ <= A2HZ) || (A1LZ >= A2LZ && A1LZ <= A2HZ) || (A2HZ >= A1LZ && A2HZ <= A1HZ) || (A2LZ >= A1LZ && A2LZ <= A1HZ)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean containsLoc(final Location loc) {
|
||||
if (loc == null) {
|
||||
return false;
|
||||
}
|
||||
if (!loc.getWorld().equals(highPoints.getWorld())) {
|
||||
return false;
|
||||
}
|
||||
if (lowPoints.getBlockX() <= loc.getBlockX() && highPoints.getBlockX() >= loc.getBlockX()) {
|
||||
if (lowPoints.getBlockZ() <= loc.getBlockZ() && highPoints.getBlockZ() >= loc.getBlockZ()) {
|
||||
if (lowPoints.getBlockY() <= loc.getBlockY() && highPoints.getBlockY() >= loc.getBlockY()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
int xsize = (highPoints.getBlockX() - lowPoints.getBlockX()) + 1;
|
||||
int ysize = (highPoints.getBlockY() - lowPoints.getBlockY()) + 1;
|
||||
int zsize = (highPoints.getBlockZ() - lowPoints.getBlockZ()) + 1;
|
||||
return xsize * ysize * zsize;
|
||||
}
|
||||
public List<ChunkRef> getChunks() {
|
||||
final List<ChunkRef> chunks = new ArrayList<ChunkRef>();
|
||||
final Location high = this.highPoints;
|
||||
final Location low = this.lowPoints;
|
||||
final int lowX = ChunkRef.getChunkCoord(low.getBlockX());
|
||||
final int lowZ = ChunkRef.getChunkCoord(low.getBlockZ());
|
||||
final int highX = ChunkRef.getChunkCoord(high.getBlockX());
|
||||
final int highZ = ChunkRef.getChunkCoord(high.getBlockZ());
|
||||
|
||||
public int getXSize() {
|
||||
return (highPoints.getBlockX() - lowPoints.getBlockX()) + 1;
|
||||
}
|
||||
for (int x = lowX; x <= highX; x++) {
|
||||
for (int z = lowZ; z <= highZ; z++) {
|
||||
chunks.add(new ChunkRef(x, z));
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public int getYSize() {
|
||||
return (highPoints.getBlockY() - lowPoints.getBlockY()) + 1;
|
||||
}
|
||||
public Location getHighLoc() {
|
||||
return highPoints;
|
||||
}
|
||||
|
||||
public int getZSize() {
|
||||
return (highPoints.getBlockZ() - lowPoints.getBlockZ()) + 1;
|
||||
}
|
||||
public Location getLowLoc() {
|
||||
return lowPoints;
|
||||
}
|
||||
|
||||
public Location getHighLoc() {
|
||||
return highPoints;
|
||||
}
|
||||
public long getSize() {
|
||||
final int xsize = (highPoints.getBlockX() - lowPoints.getBlockX()) + 1;
|
||||
final int ysize = (highPoints.getBlockY() - lowPoints.getBlockY()) + 1;
|
||||
final int zsize = (highPoints.getBlockZ() - lowPoints.getBlockZ()) + 1;
|
||||
return xsize * ysize * zsize;
|
||||
}
|
||||
|
||||
public Location getLowLoc() {
|
||||
return lowPoints;
|
||||
}
|
||||
public World getWorld() {
|
||||
return highPoints.getWorld();
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return highPoints.getWorld();
|
||||
}
|
||||
public int getXSize() {
|
||||
return (highPoints.getBlockX() - lowPoints.getBlockX()) + 1;
|
||||
}
|
||||
|
||||
public void save(DataOutputStream out, int version) throws IOException {
|
||||
out.writeUTF(highPoints.getWorld().getName());
|
||||
out.writeInt(highPoints.getBlockX());
|
||||
out.writeInt(highPoints.getBlockY());
|
||||
out.writeInt(highPoints.getBlockZ());
|
||||
out.writeInt(lowPoints.getBlockX());
|
||||
out.writeInt(lowPoints.getBlockY());
|
||||
out.writeInt(lowPoints.getBlockZ());
|
||||
}
|
||||
public int getYSize() {
|
||||
return (highPoints.getBlockY() - lowPoints.getBlockY()) + 1;
|
||||
}
|
||||
|
||||
public static CuboidArea load(DataInputStream in, int version) throws IOException {
|
||||
CuboidArea newArea = new CuboidArea();
|
||||
Server server = Residence.getServ();
|
||||
World world = server.getWorld(in.readUTF());
|
||||
int highx = in.readInt();
|
||||
int highy = in.readInt();
|
||||
int highz = in.readInt();
|
||||
int lowx = in.readInt();
|
||||
int lowy = in.readInt();
|
||||
int lowz = in.readInt();
|
||||
newArea.highPoints = new Location(world, highx, highy, highz);
|
||||
newArea.lowPoints = new Location(world, lowx, lowy, lowz);
|
||||
return newArea;
|
||||
}
|
||||
public int getZSize() {
|
||||
return (highPoints.getBlockZ() - lowPoints.getBlockZ()) + 1;
|
||||
}
|
||||
|
||||
public Map<String, Object> save() {
|
||||
Map<String, Object> root = new LinkedHashMap<String, Object>();
|
||||
root.put("X1", this.highPoints.getBlockX());
|
||||
root.put("Y1", this.highPoints.getBlockY());
|
||||
root.put("Z1", this.highPoints.getBlockZ());
|
||||
root.put("X2", this.lowPoints.getBlockX());
|
||||
root.put("Y2", this.lowPoints.getBlockY());
|
||||
root.put("Z2", this.lowPoints.getBlockZ());
|
||||
return root;
|
||||
}
|
||||
public boolean isAreaWithinArea(final CuboidArea area) {
|
||||
return (this.containsLoc(area.highPoints) && this.containsLoc(area.lowPoints));
|
||||
}
|
||||
|
||||
public static CuboidArea load(Map<String, Object> root, World world) throws Exception {
|
||||
if (root == null) {
|
||||
throw new Exception("Invalid residence physical location...");
|
||||
}
|
||||
CuboidArea newArea = new CuboidArea();
|
||||
int x1 = (Integer) root.get("X1");
|
||||
int y1 = (Integer) root.get("Y1");
|
||||
int z1 = (Integer) root.get("Z1");
|
||||
int x2 = (Integer) root.get("X2");
|
||||
int y2 = (Integer) root.get("Y2");
|
||||
int z2 = (Integer) root.get("Z2");
|
||||
newArea.highPoints = new Location(world, x1, y1, z1);
|
||||
newArea.lowPoints = new Location(world, x2, y2, z2);
|
||||
return newArea;
|
||||
}
|
||||
public Map<String, Object> save() {
|
||||
final Map<String, Object> root = new LinkedHashMap<String, Object>();
|
||||
root.put("X1", this.highPoints.getBlockX());
|
||||
root.put("Y1", this.highPoints.getBlockY());
|
||||
root.put("Z1", this.highPoints.getBlockZ());
|
||||
root.put("X2", this.lowPoints.getBlockX());
|
||||
root.put("Y2", this.lowPoints.getBlockY());
|
||||
root.put("Z2", this.lowPoints.getBlockZ());
|
||||
return root;
|
||||
}
|
||||
|
||||
public List<ChunkRef> getChunks() {
|
||||
List<ChunkRef> chunks = new ArrayList<ChunkRef>();
|
||||
Location high = this.highPoints;
|
||||
Location low = this.lowPoints;
|
||||
int lowX = ChunkRef.getChunkCoord(low.getBlockX());
|
||||
int lowZ = ChunkRef.getChunkCoord(low.getBlockZ());
|
||||
int highX = ChunkRef.getChunkCoord(high.getBlockX());
|
||||
int highZ = ChunkRef.getChunkCoord(high.getBlockZ());
|
||||
public void save(final DataOutputStream out, final int version) throws IOException {
|
||||
out.writeUTF(highPoints.getWorld().getName());
|
||||
out.writeInt(highPoints.getBlockX());
|
||||
out.writeInt(highPoints.getBlockY());
|
||||
out.writeInt(highPoints.getBlockZ());
|
||||
out.writeInt(lowPoints.getBlockX());
|
||||
out.writeInt(lowPoints.getBlockY());
|
||||
out.writeInt(lowPoints.getBlockZ());
|
||||
}
|
||||
|
||||
for (int x = lowX; x <= highX; x++) {
|
||||
for (int z = lowZ; z <= highZ; z++) {
|
||||
chunks.add(new ChunkRef(x, z));
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
private boolean advCuboidCheckCollision(final Location A1High, final Location A1Low, final Location A2High, final Location A2Low) {
|
||||
final int A1HX = A1High.getBlockX();
|
||||
final int A1LX = A1Low.getBlockX();
|
||||
final int A1HY = A1High.getBlockY();
|
||||
final int A1LY = A1Low.getBlockY();
|
||||
final int A1HZ = A1High.getBlockZ();
|
||||
final int A1LZ = A1Low.getBlockZ();
|
||||
final int A2HX = A2High.getBlockX();
|
||||
final int A2LX = A2Low.getBlockX();
|
||||
final int A2HY = A2High.getBlockY();
|
||||
final int A2LY = A2Low.getBlockY();
|
||||
final int A2HZ = A2High.getBlockZ();
|
||||
final int A2LZ = A2Low.getBlockZ();
|
||||
if ((A1HX >= A2LX && A1HX <= A2HX) || (A1LX >= A2LX && A1LX <= A2HX) || (A2HX >= A1LX && A2HX <= A1HX) || (A2LX >= A1LX && A2LX <= A1HX)) {
|
||||
if ((A1HY >= A2LY && A1HY <= A2HY) || (A1LY >= A2LY && A1LY <= A2HY) || (A2HY >= A1LY && A2HY <= A1HY) || (A2LY >= A1LY && A2LY <= A1HY)) {
|
||||
if ((A1HZ >= A2LZ && A1HZ <= A2HZ) || (A1LZ >= A2LZ && A1LZ <= A2HZ) || (A2HZ >= A1LZ && A2HZ <= A1HZ) || (A2LZ >= A1LZ && A2LZ <= A1HZ)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,18 +27,19 @@ import com.bekvon.bukkit.residence.Residence;
|
||||
*/
|
||||
public class FlagPermissions {
|
||||
|
||||
protected static ArrayList<String> validAreaFlags = new ArrayList<String>();
|
||||
protected static HashMap<String, ArrayList<String>> validFlagGroups = new HashMap<String, ArrayList<String>>();
|
||||
protected static ArrayList<String> validFlags = new ArrayList<String>();
|
||||
protected static ArrayList<String> validPlayerFlags = new ArrayList<String>();
|
||||
protected static ArrayList<String> validAreaFlags = new ArrayList<String>();
|
||||
final static Map<Material, String> matUseFlagList = new EnumMap<Material, String>(Material.class);
|
||||
protected static HashMap<String, ArrayList<String>> validFlagGroups = new HashMap<String, ArrayList<String>>();
|
||||
protected Map<String, Map<String, Boolean>> playerFlags;
|
||||
protected Map<String, Map<String, Boolean>> groupFlags;
|
||||
static Residence plugin;
|
||||
protected Map<String, Boolean> cuboidFlags;
|
||||
|
||||
protected Map<String, Map<String, Boolean>> groupFlags;
|
||||
protected FlagPermissions parent;
|
||||
protected Map<String, Map<String, Boolean>> playerFlags;
|
||||
|
||||
public FlagPermissions() {
|
||||
public FlagPermissions(final Residence plugin) {
|
||||
FlagPermissions.plugin = plugin;
|
||||
cuboidFlags = Collections.synchronizedMap(new HashMap<String, Boolean>());
|
||||
playerFlags = Collections.synchronizedMap(new HashMap<String, Map<String, Boolean>>());
|
||||
groupFlags = Collections.synchronizedMap(new HashMap<String, Map<String, Boolean>>());
|
||||
@@ -46,42 +47,49 @@ public class FlagPermissions {
|
||||
|
||||
public static void addFlag(String flag) {
|
||||
flag = flag.toLowerCase();
|
||||
if (!validFlags.contains(flag))
|
||||
if (!validFlags.contains(flag)) {
|
||||
validFlags.add(flag);
|
||||
if (validFlagGroups.containsKey(flag))
|
||||
}
|
||||
if (validFlagGroups.containsKey(flag)) {
|
||||
validFlagGroups.remove(flag);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addFlagToFlagGroup(String group, String flag) {
|
||||
public static void addFlagToFlagGroup(final String group, final String flag) {
|
||||
if (!FlagPermissions.validFlags.contains(group) && !FlagPermissions.validAreaFlags.contains(group) && !FlagPermissions.validPlayerFlags.contains(group)) {
|
||||
if (!validFlagGroups.containsKey(group))
|
||||
if (!validFlagGroups.containsKey(group)) {
|
||||
validFlagGroups.put(group, new ArrayList<String>());
|
||||
ArrayList<String> flags = validFlagGroups.get(group);
|
||||
}
|
||||
final ArrayList<String> flags = validFlagGroups.get(group);
|
||||
flags.add(flag);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addMaterialToUseFlag(Material mat, String flag) {
|
||||
public static void addMaterialToUseFlag(final Material mat, final String flag) {
|
||||
matUseFlagList.put(mat, flag);
|
||||
}
|
||||
|
||||
public static void addPlayerOrGroupOnlyFlag(String flag) {
|
||||
flag = flag.toLowerCase();
|
||||
if (!validPlayerFlags.contains(flag))
|
||||
if (!validPlayerFlags.contains(flag)) {
|
||||
validPlayerFlags.add(flag);
|
||||
if (validFlagGroups.containsKey(flag))
|
||||
}
|
||||
if (validFlagGroups.containsKey(flag)) {
|
||||
validFlagGroups.remove(flag);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addResidenceOnlyFlag(String flag) {
|
||||
flag = flag.toLowerCase();
|
||||
if (!validAreaFlags.contains(flag))
|
||||
if (!validAreaFlags.contains(flag)) {
|
||||
validAreaFlags.add(flag);
|
||||
if (validFlagGroups.containsKey(flag))
|
||||
}
|
||||
if (validFlagGroups.containsKey(flag)) {
|
||||
validFlagGroups.remove(flag);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean flagGroupExists(String group) {
|
||||
public static boolean flagGroupExists(final String group) {
|
||||
return validFlagGroups.containsKey(group);
|
||||
}
|
||||
|
||||
@@ -173,7 +181,7 @@ public class FlagPermissions {
|
||||
addMaterialToUseFlag(Material.WORKBENCH, "table");
|
||||
addMaterialToUseFlag(Material.WOODEN_DOOR, "door");
|
||||
|
||||
if (Residence.is1_8()) {
|
||||
if (plugin.is1_8()) {
|
||||
/* 1.8 Doors */
|
||||
addMaterialToUseFlag(Material.SPRUCE_DOOR, "door");
|
||||
addMaterialToUseFlag(Material.BIRCH_DOOR, "door");
|
||||
@@ -216,66 +224,73 @@ public class FlagPermissions {
|
||||
addMaterialToUseFlag(Material.CAKE_BLOCK, "cake");
|
||||
}
|
||||
|
||||
public static FlagPermissions load(Map<String, Object> root) throws Exception {
|
||||
FlagPermissions newperms = new FlagPermissions();
|
||||
public static FlagPermissions load(final Map<String, Object> root) throws Exception {
|
||||
final FlagPermissions newperms = new FlagPermissions(plugin);
|
||||
return FlagPermissions.load(root, newperms);
|
||||
}
|
||||
|
||||
public static FlagPermissions parseFromConfigNode(String name, ConfigurationSection node) {
|
||||
FlagPermissions list = new FlagPermissions();
|
||||
Set<String> keys = node.getConfigurationSection(name).getKeys(false);
|
||||
if (keys != null)
|
||||
public static FlagPermissions parseFromConfigNode(final String name, final ConfigurationSection node) {
|
||||
final FlagPermissions list = new FlagPermissions(plugin);
|
||||
final Set<String> keys = node.getConfigurationSection(name).getKeys(false);
|
||||
if (keys != null) {
|
||||
for (String key : keys) {
|
||||
boolean state = node.getBoolean(name + "." + key, false);
|
||||
final boolean state = node.getBoolean(name + "." + key, false);
|
||||
key = key.toLowerCase();
|
||||
if (state)
|
||||
if (state) {
|
||||
list.setFlag(key, FlagState.TRUE);
|
||||
else
|
||||
} else {
|
||||
list.setFlag(key, FlagState.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void removeFlagFromFlagGroup(String group, String flag) {
|
||||
public static void removeFlagFromFlagGroup(final String group, final String flag) {
|
||||
if (validFlagGroups.containsKey(group)) {
|
||||
ArrayList<String> flags = validFlagGroups.get(group);
|
||||
final ArrayList<String> flags = validFlagGroups.get(group);
|
||||
flags.remove(flag);
|
||||
if (flags.isEmpty())
|
||||
if (flags.isEmpty()) {
|
||||
validFlagGroups.remove(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeMaterialFromUseFlag(Material mat) {
|
||||
public static void removeMaterialFromUseFlag(final Material mat) {
|
||||
matUseFlagList.remove(mat);
|
||||
}
|
||||
|
||||
public static FlagState stringToFlagState(String flagstate) {
|
||||
if (flagstate.equalsIgnoreCase("true") || flagstate.equalsIgnoreCase("t"))
|
||||
public static FlagState stringToFlagState(final String flagstate) {
|
||||
if (flagstate.equalsIgnoreCase("true") || flagstate.equalsIgnoreCase("t")) {
|
||||
return FlagState.TRUE;
|
||||
else if (flagstate.equalsIgnoreCase("false") || flagstate.equalsIgnoreCase("f"))
|
||||
} else if (flagstate.equalsIgnoreCase("false") || flagstate.equalsIgnoreCase("f")) {
|
||||
return FlagState.FALSE;
|
||||
else if (flagstate.equalsIgnoreCase("remove") || flagstate.equalsIgnoreCase("r"))
|
||||
} else if (flagstate.equalsIgnoreCase("remove") || flagstate.equalsIgnoreCase("r")) {
|
||||
return FlagState.NEITHER;
|
||||
else
|
||||
} else {
|
||||
return FlagState.INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static FlagPermissions load(Map<String, Object> root, FlagPermissions newperms) throws Exception {
|
||||
protected static FlagPermissions load(final Map<String, Object> root, final FlagPermissions newperms) throws Exception {
|
||||
newperms.playerFlags = (Map<String, Map<String, Boolean>>) root.get("PlayerFlags");
|
||||
newperms.groupFlags = (Map<String, Map<String, Boolean>>) root.get("GroupFlags");
|
||||
newperms.cuboidFlags = (Map<String, Boolean>) root.get("AreaFlags");
|
||||
return newperms;
|
||||
}
|
||||
|
||||
public boolean checkValidFlag(String flag, boolean globalflag) {
|
||||
if (validFlags.contains(flag))
|
||||
public boolean checkValidFlag(final String flag, final boolean globalflag) {
|
||||
if (validFlags.contains(flag)) {
|
||||
return true;
|
||||
}
|
||||
if (globalflag) {
|
||||
if (validAreaFlags.contains(flag))
|
||||
if (validAreaFlags.contains(flag)) {
|
||||
return true;
|
||||
} else if (validPlayerFlags.contains(flag))
|
||||
}
|
||||
} else if (validPlayerFlags.contains(flag)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -285,23 +300,25 @@ public class FlagPermissions {
|
||||
cuboidFlags.clear();
|
||||
}
|
||||
|
||||
public void clearPlayersFlags(String user) {
|
||||
if (playerFlags.containsKey(user))
|
||||
public void clearPlayersFlags(final String user) {
|
||||
if (playerFlags.containsKey(user)) {
|
||||
playerFlags.remove(user);
|
||||
}
|
||||
}
|
||||
|
||||
public void copyUserPermissions(String fromUser, String toUser) {
|
||||
fromUser = fromUser.toLowerCase();
|
||||
toUser = toUser.toLowerCase();
|
||||
Map<String, Boolean> get = playerFlags.get(fromUser);
|
||||
final Map<String, Boolean> get = playerFlags.get(fromUser);
|
||||
if (get != null) {
|
||||
Map<String, Boolean> targ = playerFlags.get(toUser);
|
||||
if (targ == null) {
|
||||
targ = new HashMap<String, Boolean>();
|
||||
playerFlags.put(toUser, targ);
|
||||
}
|
||||
for (Entry<String, Boolean> entry : get.entrySet())
|
||||
for (final Entry<String, Boolean> entry : get.entrySet()) {
|
||||
targ.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,91 +326,101 @@ public class FlagPermissions {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public boolean groupHas(String group, String flag, boolean def) {
|
||||
public boolean groupHas(final String group, final String flag, final boolean def) {
|
||||
return this.groupCheck(group, flag, this.has(flag, def));
|
||||
}
|
||||
|
||||
public boolean has(String flag, boolean def) {
|
||||
if (cuboidFlags.containsKey(flag))
|
||||
public boolean has(final String flag, final boolean def) {
|
||||
if (cuboidFlags.containsKey(flag)) {
|
||||
return cuboidFlags.get(flag);
|
||||
if (parent != null)
|
||||
}
|
||||
if (parent != null) {
|
||||
return parent.has(flag, def);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
public boolean inheritanceIsGroupSet(String group, String flag) {
|
||||
public boolean inheritanceIsGroupSet(String group, final String flag) {
|
||||
group = group.toLowerCase();
|
||||
Map<String, Boolean> flags = groupFlags.get(group);
|
||||
if (flags == null)
|
||||
final Map<String, Boolean> flags = groupFlags.get(group);
|
||||
if (flags == null) {
|
||||
return parent == null ? false : parent.inheritanceIsGroupSet(group, flag);
|
||||
}
|
||||
return flags.containsKey(flag) ? true : parent == null ? false : parent.inheritanceIsGroupSet(group, flag);
|
||||
}
|
||||
|
||||
public boolean inheritanceIsPlayerSet(String player, String flag) {
|
||||
public boolean inheritanceIsPlayerSet(String player, final String flag) {
|
||||
player = player.toLowerCase();
|
||||
Map<String, Boolean> flags = playerFlags.get(player);
|
||||
if (flags == null)
|
||||
final Map<String, Boolean> flags = playerFlags.get(player);
|
||||
if (flags == null) {
|
||||
return parent == null ? false : parent.inheritanceIsPlayerSet(player, flag);
|
||||
}
|
||||
return flags.containsKey(flag) ? true : parent == null ? false : parent.inheritanceIsPlayerSet(player, flag);
|
||||
}
|
||||
|
||||
public boolean inheritanceIsSet(String flag) {
|
||||
public boolean inheritanceIsSet(final String flag) {
|
||||
return cuboidFlags.containsKey(flag) ? true : parent == null ? false : parent.inheritanceIsSet(flag);
|
||||
}
|
||||
|
||||
public boolean isGroupSet(String group, String flag) {
|
||||
public boolean isGroupSet(String group, final String flag) {
|
||||
group = group.toLowerCase();
|
||||
Map<String, Boolean> flags = groupFlags.get(group);
|
||||
if (flags == null)
|
||||
final Map<String, Boolean> flags = groupFlags.get(group);
|
||||
if (flags == null) {
|
||||
return false;
|
||||
}
|
||||
return flags.containsKey(flag);
|
||||
}
|
||||
|
||||
public boolean isPlayerSet(String player, String flag) {
|
||||
public boolean isPlayerSet(String player, final String flag) {
|
||||
player = player.toLowerCase();
|
||||
Map<String, Boolean> flags = playerFlags.get(player);
|
||||
if (flags == null)
|
||||
final Map<String, Boolean> flags = playerFlags.get(player);
|
||||
if (flags == null) {
|
||||
return false;
|
||||
}
|
||||
return flags.containsKey(flag);
|
||||
}
|
||||
|
||||
public boolean isSet(String flag) {
|
||||
public boolean isSet(final String flag) {
|
||||
return cuboidFlags.containsKey(flag);
|
||||
}
|
||||
|
||||
public String listFlags() {
|
||||
StringBuilder sbuild = new StringBuilder();
|
||||
Set<Entry<String, Boolean>> set = cuboidFlags.entrySet();
|
||||
final StringBuilder sbuild = new StringBuilder();
|
||||
final Set<Entry<String, Boolean>> set = cuboidFlags.entrySet();
|
||||
synchronized (cuboidFlags) {
|
||||
Iterator<Entry<String, Boolean>> it = set.iterator();
|
||||
final Iterator<Entry<String, Boolean>> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, Boolean> next = it.next();
|
||||
final Entry<String, Boolean> next = it.next();
|
||||
if (next.getValue()) {
|
||||
sbuild.append("+").append(next.getKey());
|
||||
if (it.hasNext())
|
||||
if (it.hasNext()) {
|
||||
sbuild.append(" ");
|
||||
}
|
||||
} else {
|
||||
sbuild.append("-").append(next.getKey());
|
||||
if (it.hasNext())
|
||||
if (it.hasNext()) {
|
||||
sbuild.append(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sbuild.length() == 0)
|
||||
if (sbuild.length() == 0) {
|
||||
sbuild.append("none");
|
||||
}
|
||||
return sbuild.toString();
|
||||
}
|
||||
|
||||
public String listGroupFlags() {
|
||||
StringBuilder sbuild = new StringBuilder();
|
||||
Set<String> set = groupFlags.keySet();
|
||||
final StringBuilder sbuild = new StringBuilder();
|
||||
final Set<String> set = groupFlags.keySet();
|
||||
synchronized (groupFlags) {
|
||||
Iterator<String> it = set.iterator();
|
||||
final Iterator<String> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
String next = it.next();
|
||||
String perms = listGroupFlags(next);
|
||||
if (!perms.equals("none"))
|
||||
final String next = it.next();
|
||||
final String perms = listGroupFlags(next);
|
||||
if (!perms.equals("none")) {
|
||||
sbuild.append(next).append("[" + ChatColor.DARK_AQUA).append(perms).append(ChatColor.RED + "] ");
|
||||
}
|
||||
}
|
||||
}
|
||||
return sbuild.toString();
|
||||
@@ -402,21 +429,23 @@ public class FlagPermissions {
|
||||
public String listGroupFlags(String group) {
|
||||
group = group.toLowerCase();
|
||||
if (groupFlags.containsKey(group)) {
|
||||
StringBuilder sbuild = new StringBuilder();
|
||||
Map<String, Boolean> get = groupFlags.get(group);
|
||||
Set<Entry<String, Boolean>> set = get.entrySet();
|
||||
final StringBuilder sbuild = new StringBuilder();
|
||||
final Map<String, Boolean> get = groupFlags.get(group);
|
||||
final Set<Entry<String, Boolean>> set = get.entrySet();
|
||||
synchronized (get) {
|
||||
Iterator<Entry<String, Boolean>> it = set.iterator();
|
||||
final Iterator<Entry<String, Boolean>> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, Boolean> next = it.next();
|
||||
final Entry<String, Boolean> next = it.next();
|
||||
if (next.getValue()) {
|
||||
sbuild.append("+").append(next.getKey());
|
||||
if (it.hasNext())
|
||||
if (it.hasNext()) {
|
||||
sbuild.append(" ");
|
||||
}
|
||||
} else {
|
||||
sbuild.append("-").append(next.getKey());
|
||||
if (it.hasNext())
|
||||
if (it.hasNext()) {
|
||||
sbuild.append(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -425,22 +454,24 @@ public class FlagPermissions {
|
||||
sbuild.append("none");
|
||||
}
|
||||
return sbuild.toString();
|
||||
} else
|
||||
} else {
|
||||
return "none";
|
||||
}
|
||||
}
|
||||
|
||||
public String listOtherPlayersFlags(String player) {
|
||||
player = player.toLowerCase();
|
||||
StringBuilder sbuild = new StringBuilder();
|
||||
Set<String> set = playerFlags.keySet();
|
||||
final StringBuilder sbuild = new StringBuilder();
|
||||
final Set<String> set = playerFlags.keySet();
|
||||
synchronized (playerFlags) {
|
||||
Iterator<String> it = set.iterator();
|
||||
final Iterator<String> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
String next = it.next();
|
||||
final String next = it.next();
|
||||
if (!next.equals(player)) {
|
||||
String perms = listPlayerFlags(next);
|
||||
if (!perms.equals("none"))
|
||||
final String perms = listPlayerFlags(next);
|
||||
if (!perms.equals("none")) {
|
||||
sbuild.append(next).append("[" + ChatColor.DARK_AQUA).append(perms).append(ChatColor.RED + "] ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -450,21 +481,23 @@ public class FlagPermissions {
|
||||
public String listPlayerFlags(String player) {
|
||||
player = player.toLowerCase();
|
||||
if (playerFlags.containsKey(player)) {
|
||||
StringBuilder sbuild = new StringBuilder();
|
||||
Map<String, Boolean> get = playerFlags.get(player);
|
||||
Set<Entry<String, Boolean>> set = get.entrySet();
|
||||
final StringBuilder sbuild = new StringBuilder();
|
||||
final Map<String, Boolean> get = playerFlags.get(player);
|
||||
final Set<Entry<String, Boolean>> set = get.entrySet();
|
||||
synchronized (get) {
|
||||
Iterator<Entry<String, Boolean>> it = set.iterator();
|
||||
final Iterator<Entry<String, Boolean>> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, Boolean> next = it.next();
|
||||
final Entry<String, Boolean> next = it.next();
|
||||
if (next.getValue()) {
|
||||
sbuild.append("+").append(next.getKey());
|
||||
if (it.hasNext())
|
||||
if (it.hasNext()) {
|
||||
sbuild.append(" ");
|
||||
}
|
||||
} else {
|
||||
sbuild.append("-").append(next.getKey());
|
||||
if (it.hasNext())
|
||||
if (it.hasNext()) {
|
||||
sbuild.append(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -473,115 +506,130 @@ public class FlagPermissions {
|
||||
sbuild.append("none");
|
||||
}
|
||||
return sbuild.toString();
|
||||
} else
|
||||
} else {
|
||||
return "none";
|
||||
}
|
||||
}
|
||||
|
||||
public boolean playerHas(String player, String world, String flag, boolean def) {
|
||||
String group = Residence.getPermissionManager().getGroupNameByPlayer(player, world);
|
||||
public boolean playerHas(final String player, final String world, final String flag, final boolean def) {
|
||||
final String group = plugin.getPermissionManager().getGroupNameByPlayer(player, world);
|
||||
return this.playerCheck(player, flag, this.groupCheck(group, flag, this.has(flag, def)));
|
||||
}
|
||||
|
||||
public void printFlags(Player player) {
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Flags") + ":" + ChatColor.BLUE + " " + listFlags());
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Your.Flags") + ":" + ChatColor.GREEN + " " + listPlayerFlags(player.getName()));
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Group.Flags") + ":" + ChatColor.RED + " " + listGroupFlags());
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Others.Flags") + ":" + ChatColor.RED + " " + listOtherPlayersFlags(player.getName()));
|
||||
public void printFlags(final Player player) {
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Flags") + ":" + ChatColor.BLUE + " " + listFlags());
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Your.Flags") + ":" + ChatColor.GREEN + " " + listPlayerFlags(player.getName()));
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Group.Flags") + ":" + ChatColor.RED + " " + listGroupFlags());
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Others.Flags") + ":" + ChatColor.RED + " " + listOtherPlayersFlags(player.getName()));
|
||||
}
|
||||
|
||||
public void removeAllGroupFlags(String group) {
|
||||
public void removeAllGroupFlags(final String group) {
|
||||
groupFlags.remove(group);
|
||||
}
|
||||
|
||||
public void removeAllPlayerFlags(String player) {
|
||||
public void removeAllPlayerFlags(final String player) {
|
||||
playerFlags.remove(player);
|
||||
}
|
||||
|
||||
public Map<String, Object> save() {
|
||||
Map<String, Object> root = new LinkedHashMap<String, Object>();
|
||||
final Map<String, Object> root = new LinkedHashMap<String, Object>();
|
||||
root.put("PlayerFlags", playerFlags);
|
||||
root.put("GroupFlags", groupFlags);
|
||||
root.put("AreaFlags", cuboidFlags);
|
||||
return root;
|
||||
}
|
||||
|
||||
public boolean setFlag(String flag, FlagState state) {
|
||||
if (state == FlagState.FALSE)
|
||||
public boolean setFlag(final String flag, final FlagState state) {
|
||||
if (state == FlagState.FALSE) {
|
||||
cuboidFlags.put(flag, false);
|
||||
else if (state == FlagState.TRUE)
|
||||
} else if (state == FlagState.TRUE) {
|
||||
cuboidFlags.put(flag, true);
|
||||
else if (state == FlagState.NEITHER)
|
||||
if (cuboidFlags.containsKey(flag))
|
||||
} else if (state == FlagState.NEITHER) {
|
||||
if (cuboidFlags.containsKey(flag)) {
|
||||
cuboidFlags.remove(flag);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setGroupFlag(String group, String flag, FlagState state) {
|
||||
public boolean setGroupFlag(String group, final String flag, final FlagState state) {
|
||||
group = group.toLowerCase();
|
||||
if (!groupFlags.containsKey(group))
|
||||
if (!groupFlags.containsKey(group)) {
|
||||
groupFlags.put(group, Collections.synchronizedMap(new HashMap<String, Boolean>()));
|
||||
Map<String, Boolean> map = groupFlags.get(group);
|
||||
if (state == FlagState.FALSE)
|
||||
}
|
||||
final Map<String, Boolean> map = groupFlags.get(group);
|
||||
if (state == FlagState.FALSE) {
|
||||
map.put(flag, false);
|
||||
else if (state == FlagState.TRUE)
|
||||
} else if (state == FlagState.TRUE) {
|
||||
map.put(flag, true);
|
||||
else if (state == FlagState.NEITHER)
|
||||
if (map.containsKey(flag))
|
||||
} else if (state == FlagState.NEITHER) {
|
||||
if (map.containsKey(flag)) {
|
||||
map.remove(flag);
|
||||
if (map.isEmpty())
|
||||
}
|
||||
}
|
||||
if (map.isEmpty()) {
|
||||
groupFlags.remove(group);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setParent(FlagPermissions p) {
|
||||
public void setParent(final FlagPermissions p) {
|
||||
parent = p;
|
||||
}
|
||||
|
||||
public boolean setPlayerFlag(String player, String flag, FlagState state) {
|
||||
public boolean setPlayerFlag(String player, final String flag, final FlagState state) {
|
||||
player = player.toLowerCase();
|
||||
if (!playerFlags.containsKey(player))
|
||||
if (!playerFlags.containsKey(player)) {
|
||||
playerFlags.put(player, Collections.synchronizedMap(new HashMap<String, Boolean>()));
|
||||
Map<String, Boolean> map = playerFlags.get(player);
|
||||
if (state == FlagState.FALSE)
|
||||
}
|
||||
final Map<String, Boolean> map = playerFlags.get(player);
|
||||
if (state == FlagState.FALSE) {
|
||||
map.put(flag, false);
|
||||
else if (state == FlagState.TRUE)
|
||||
} else if (state == FlagState.TRUE) {
|
||||
map.put(flag, true);
|
||||
else if (state == FlagState.NEITHER)
|
||||
if (map.containsKey(flag))
|
||||
} else if (state == FlagState.NEITHER) {
|
||||
if (map.containsKey(flag)) {
|
||||
map.remove(flag);
|
||||
if (map.isEmpty())
|
||||
}
|
||||
}
|
||||
if (map.isEmpty()) {
|
||||
playerFlags.remove(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean groupCheck(String group, String flag, boolean def) {
|
||||
private boolean groupCheck(final String group, final String flag, final boolean def) {
|
||||
if (groupFlags.containsKey(group)) {
|
||||
Map<String, Boolean> gmap = groupFlags.get(group);
|
||||
if (gmap.containsKey(flag))
|
||||
final Map<String, Boolean> gmap = groupFlags.get(group);
|
||||
if (gmap.containsKey(flag)) {
|
||||
return gmap.get(flag);
|
||||
}
|
||||
}
|
||||
if (parent != null)
|
||||
if (parent != null) {
|
||||
return parent.groupCheck(group, flag, def);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
private boolean playerCheck(String player, String flag, boolean def) {
|
||||
private boolean playerCheck(String player, final String flag, final boolean def) {
|
||||
player = player.toLowerCase();
|
||||
if (playerFlags.containsKey(player)) {
|
||||
Map<String, Boolean> pmap = playerFlags.get(player);
|
||||
if (pmap.containsKey(flag))
|
||||
final Map<String, Boolean> pmap = playerFlags.get(player);
|
||||
if (pmap.containsKey(flag)) {
|
||||
return pmap.get(flag);
|
||||
}
|
||||
}
|
||||
if (parent != null)
|
||||
if (parent != null) {
|
||||
return parent.playerCheck(player, flag, def);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
public static enum FlagState {
|
||||
|
||||
TRUE,
|
||||
FALSE,
|
||||
INVALID,
|
||||
NEITHER,
|
||||
INVALID
|
||||
TRUE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,6 @@
|
||||
|
||||
package com.bekvon.bukkit.residence.protection;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.bekvon.bukkit.residence.Residence;
|
||||
import com.bekvon.bukkit.residence.economy.EconomyInterface;
|
||||
import com.bekvon.bukkit.residence.event.ResidenceDeleteEvent;
|
||||
import com.bekvon.bukkit.residence.event.ResidenceDeleteEvent.DeleteCause;
|
||||
import com.bekvon.bukkit.residence.permissions.PermissionGroup;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@@ -21,8 +13,15 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bekvon.bukkit.residence.Residence;
|
||||
import com.bekvon.bukkit.residence.economy.EconomyInterface;
|
||||
import com.bekvon.bukkit.residence.event.ResidenceDeleteEvent;
|
||||
import com.bekvon.bukkit.residence.event.ResidenceDeleteEvent.DeleteCause;
|
||||
import com.bekvon.bukkit.residence.permissions.PermissionGroup;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Administrator
|
||||
@@ -32,64 +31,125 @@ public class LeaseManager {
|
||||
private Map<String, Long> leaseExpireTime;
|
||||
|
||||
ResidenceManager manager;
|
||||
Residence plugin;
|
||||
|
||||
public LeaseManager(ResidenceManager m) {
|
||||
public LeaseManager(final Residence plugin, final ResidenceManager m) {
|
||||
this.plugin = plugin;
|
||||
manager = m;
|
||||
leaseExpireTime = Collections
|
||||
.synchronizedMap(new HashMap<String, Long>());
|
||||
leaseExpireTime = Collections.synchronizedMap(new HashMap<String, Long>());
|
||||
}
|
||||
|
||||
public boolean leaseExpires(String area) {
|
||||
return leaseExpireTime.containsKey(area);
|
||||
public static LeaseManager load(final Residence plugin, final Map<String, Long> root, final ResidenceManager m) {
|
||||
final LeaseManager l = new LeaseManager(plugin, m);
|
||||
if (root != null) {
|
||||
for (final Object val : root.values()) {
|
||||
if (!(val instanceof Long)) {
|
||||
root.remove(val);
|
||||
}
|
||||
}
|
||||
l.leaseExpireTime = Collections.synchronizedMap(root);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public Date getExpireTime(String area) {
|
||||
public void doExpirations() {
|
||||
final Set<Entry<String, Long>> set = leaseExpireTime.entrySet();
|
||||
final Iterator<Entry<String, Long>> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
final Entry<String, Long> next = it.next();
|
||||
if (next.getValue() <= System.currentTimeMillis()) {
|
||||
final String resname = next.getKey();
|
||||
final ClaimedResidence res = plugin.getResidenceManager().getByName(resname);
|
||||
if (res == null) {
|
||||
it.remove();
|
||||
} else {
|
||||
boolean renewed = false;
|
||||
final String owner = res.getPermissions().getOwner();
|
||||
final PermissionGroup limits = plugin.getPermissionManager().getGroup(owner, res.getPermissions().getWorld());
|
||||
final int cost = this.getRenewCost(res);
|
||||
if (plugin.getConfigManager().enableEconomy() && plugin.getConfigManager().autoRenewLeases()) {
|
||||
if (cost == 0) {
|
||||
renewed = true;
|
||||
} else if (res.getBank().hasEnough(cost)) {
|
||||
res.getBank().subtract(cost);
|
||||
renewed = true;
|
||||
if (plugin.getConfigManager().debugEnabled()) {
|
||||
System.out.println("Lease Renewed From Residence Bank: " + resname);
|
||||
}
|
||||
} else if (plugin.getEconomyManager().canAfford(owner, cost)) {
|
||||
if (plugin.getEconomyManager().subtract(owner, cost)) {
|
||||
renewed = true;
|
||||
if (plugin.getConfigManager().debugEnabled()) {
|
||||
System.out.println("Lease Renewed From Economy: " + resname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!renewed) {
|
||||
if (!plugin.getConfigManager().enabledRentSystem() || !plugin.getRentManager().isRented(resname)) {
|
||||
final ResidenceDeleteEvent resevent = new ResidenceDeleteEvent(null, res, DeleteCause.LEASE_EXPIRE);
|
||||
plugin.getServ().getPluginManager().callEvent(resevent);
|
||||
if (!resevent.isCancelled()) {
|
||||
manager.removeResidence(next.getKey());
|
||||
it.remove();
|
||||
if (plugin.getConfigManager().debugEnabled()) {
|
||||
System.out.println("Lease NOT removed, Removing: " + resname);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (plugin.getConfigManager().enableEconomy() && plugin.getConfigManager().enableLeaseMoneyAccount()) {
|
||||
plugin.getEconomyManager().add("Lease Money", cost);
|
||||
}
|
||||
if (plugin.getConfigManager().debugEnabled()) {
|
||||
System.out.println("Lease Renew Old: " + next.getValue());
|
||||
}
|
||||
next.setValue(System.currentTimeMillis() + daysToMs(limits.getLeaseGiveTime()));
|
||||
if (plugin.getConfigManager().debugEnabled()) {
|
||||
System.out.println("Lease Renew New: " + next.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Date getExpireTime(final String area) {
|
||||
if (leaseExpireTime.containsKey(area)) {
|
||||
return new Date(leaseExpireTime.get(area));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeExpireTime(String area) {
|
||||
public int getRenewCost(final ClaimedResidence res) {
|
||||
final PermissionGroup limits = plugin.getPermissionManager().getGroup(res.getPermissions().getOwner(), res.getPermissions().getWorld());
|
||||
final double cost = limits.getLeaseRenewCost();
|
||||
final int amount = (int) Math.ceil(res.getTotalSize() * cost);
|
||||
return amount;
|
||||
}
|
||||
|
||||
public boolean leaseExpires(final String area) {
|
||||
return leaseExpireTime.containsKey(area);
|
||||
}
|
||||
|
||||
public void removeExpireTime(final String area) {
|
||||
leaseExpireTime.remove(area);
|
||||
}
|
||||
|
||||
public void setExpireTime(String area, int days) {
|
||||
this.setExpireTime(null, area, days);
|
||||
}
|
||||
|
||||
public void setExpireTime(Player player, String area, int days) {
|
||||
area = area.replace(".", "_");
|
||||
if (manager.getByName(area) != null) {
|
||||
leaseExpireTime.put(area,
|
||||
daysToMs(days) + System.currentTimeMillis());
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.GREEN
|
||||
+ Residence.getLanguage().getPhrase("LeaseRenew",
|
||||
getExpireTime(area).toString()));
|
||||
} else {
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ Residence.getLanguage().getPhrase("InvalidArea"));
|
||||
}
|
||||
}
|
||||
|
||||
public void renewArea(String area, Player player) {
|
||||
public void renewArea(final String area, final Player player) {
|
||||
if (!leaseExpires(area)) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ Residence.getLanguage().getPhrase("LeaseNotExpire"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("LeaseNotExpire"));
|
||||
return;
|
||||
}
|
||||
PermissionGroup limits = Residence.getPermissionManager().getGroup(
|
||||
player);
|
||||
int max = limits.getMaxLeaseTime();
|
||||
int add = limits.getLeaseGiveTime();
|
||||
int rem = daysRemaining(area);
|
||||
EconomyInterface econ = Residence.getEconomyManager();
|
||||
final PermissionGroup limits = plugin.getPermissionManager().getGroup(player);
|
||||
final int max = limits.getMaxLeaseTime();
|
||||
final int add = limits.getLeaseGiveTime();
|
||||
final int rem = daysRemaining(area);
|
||||
final EconomyInterface econ = plugin.getEconomyManager();
|
||||
if (econ != null) {
|
||||
double cost = limits.getLeaseRenewCost();
|
||||
ClaimedResidence res = manager.getByName(area);
|
||||
int amount = (int) Math.ceil((double) res.getTotalSize() * cost);
|
||||
final double cost = limits.getLeaseRenewCost();
|
||||
final ClaimedResidence res = manager.getByName(area);
|
||||
final int amount = (int) Math.ceil(res.getTotalSize() * cost);
|
||||
if (cost != 0D) {
|
||||
// Account account =
|
||||
// iConomy.getBank().getAccount(player.getName());
|
||||
@@ -99,156 +159,38 @@ public class LeaseManager {
|
||||
*/) {
|
||||
econ.subtract(player.getName(), amount);
|
||||
econ.add("Lease Money", amount);
|
||||
player.sendMessage(ChatColor.GREEN
|
||||
+ Residence.getLanguage().getPhrase(
|
||||
"MoneyCharged",
|
||||
ChatColor.YELLOW
|
||||
+ String.format("%d", amount)
|
||||
+ ChatColor.GREEN + "."
|
||||
+ ChatColor.YELLOW + econ.getName()
|
||||
+ ChatColor.GREEN));
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("MoneyCharged",
|
||||
ChatColor.YELLOW + String.format("%d", amount) + ChatColor.GREEN + "." + ChatColor.YELLOW + econ.getName() + ChatColor.GREEN));
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ Residence.getLanguage().getPhrase(
|
||||
"NotEnoughMoney"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NotEnoughMoney"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rem + add > max) {
|
||||
setExpireTime(player, area, max);
|
||||
player.sendMessage(ChatColor.GOLD
|
||||
+ Residence.getLanguage().getPhrase("LeaseRenewMax"));
|
||||
player.sendMessage(ChatColor.YELLOW
|
||||
+ Residence.getLanguage().getPhrase("LeaseRenew",
|
||||
ChatColor.GREEN + "" + getExpireTime(area))
|
||||
+ ChatColor.YELLOW);
|
||||
player.sendMessage(ChatColor.GOLD + plugin.getLanguage().getPhrase("LeaseRenewMax"));
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("LeaseRenew", ChatColor.GREEN + "" + getExpireTime(area)) + ChatColor.YELLOW);
|
||||
return;
|
||||
}
|
||||
Long get = leaseExpireTime.get(area);
|
||||
if (get != null) {
|
||||
get = get + daysToMs(add);
|
||||
leaseExpireTime.put(area, get);
|
||||
} else
|
||||
} else {
|
||||
leaseExpireTime.put(area, daysToMs(add));
|
||||
player.sendMessage(ChatColor.YELLOW
|
||||
+ Residence.getLanguage().getPhrase("LeaseRenew",
|
||||
ChatColor.GREEN + "" + getExpireTime(area)));
|
||||
}
|
||||
|
||||
public int getRenewCost(ClaimedResidence res) {
|
||||
PermissionGroup limits = Residence.getPermissionManager().getGroup(
|
||||
res.getPermissions().getOwner(),
|
||||
res.getPermissions().getWorld());
|
||||
double cost = limits.getLeaseRenewCost();
|
||||
int amount = (int) Math.ceil((double) res.getTotalSize() * cost);
|
||||
return amount;
|
||||
}
|
||||
|
||||
private long daysToMs(int days) {
|
||||
return (((long) days) * 24L * 60L * 60L * 1000L);
|
||||
}
|
||||
|
||||
private int msToDays(long ms) {
|
||||
return (int) Math.ceil(((((double) ms / 1000D) / 60D) / 60D) / 24D);
|
||||
}
|
||||
|
||||
private int daysRemaining(String area) {
|
||||
Long get = leaseExpireTime.get(area);
|
||||
if (get <= System.currentTimeMillis())
|
||||
return 0;
|
||||
return msToDays((int) (get - System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
public void doExpirations() {
|
||||
Set<Entry<String, Long>> set = leaseExpireTime.entrySet();
|
||||
Iterator<Entry<String, Long>> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, Long> next = it.next();
|
||||
if (next.getValue() <= System.currentTimeMillis()) {
|
||||
String resname = next.getKey();
|
||||
ClaimedResidence res = Residence.getResidenceManager()
|
||||
.getByName(resname);
|
||||
if (res == null) {
|
||||
it.remove();
|
||||
} else {
|
||||
boolean renewed = false;
|
||||
String owner = res.getPermissions().getOwner();
|
||||
PermissionGroup limits = Residence.getPermissionManager()
|
||||
.getGroup(owner, res.getPermissions().getWorld());
|
||||
int cost = this.getRenewCost(res);
|
||||
if (Residence.getConfigManager().enableEconomy()
|
||||
&& Residence.getConfigManager().autoRenewLeases()) {
|
||||
if (cost == 0) {
|
||||
renewed = true;
|
||||
} else if (res.getBank().hasEnough(cost)) {
|
||||
res.getBank().subtract(cost);
|
||||
renewed = true;
|
||||
if (Residence.getConfigManager().debugEnabled())
|
||||
System.out
|
||||
.println("Lease Renewed From Residence Bank: "
|
||||
+ resname);
|
||||
} else if (Residence.getEconomyManager().canAfford(
|
||||
owner, cost)) {
|
||||
if (Residence.getEconomyManager().subtract(owner,
|
||||
cost)) {
|
||||
renewed = true;
|
||||
if (Residence.getConfigManager().debugEnabled())
|
||||
System.out
|
||||
.println("Lease Renewed From Economy: "
|
||||
+ resname);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!renewed) {
|
||||
if (!Residence.getConfigManager().enabledRentSystem()
|
||||
|| !Residence.getRentManager()
|
||||
.isRented(resname)) {
|
||||
ResidenceDeleteEvent resevent = new ResidenceDeleteEvent(
|
||||
null, res, DeleteCause.LEASE_EXPIRE);
|
||||
Residence.getServ().getPluginManager()
|
||||
.callEvent(resevent);
|
||||
if (!resevent.isCancelled()) {
|
||||
manager.removeResidence(next.getKey());
|
||||
it.remove();
|
||||
if (Residence.getConfigManager().debugEnabled())
|
||||
System.out
|
||||
.println("Lease NOT removed, Removing: "
|
||||
+ resname);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Residence.getConfigManager().enableEconomy()
|
||||
&& Residence.getConfigManager()
|
||||
.enableLeaseMoneyAccount()) {
|
||||
Residence.getEconomyManager().add("Lease Money",
|
||||
cost);
|
||||
}
|
||||
if (Residence.getConfigManager().debugEnabled())
|
||||
System.out.println("Lease Renew Old: "
|
||||
+ next.getValue());
|
||||
next.setValue(System.currentTimeMillis()
|
||||
+ daysToMs(limits.getLeaseGiveTime()));
|
||||
if (Residence.getConfigManager().debugEnabled())
|
||||
System.out.println("Lease Renew New: "
|
||||
+ next.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("LeaseRenew", ChatColor.GREEN + "" + getExpireTime(area)));
|
||||
}
|
||||
|
||||
public void resetLeases() {
|
||||
leaseExpireTime.clear();
|
||||
String[] list = manager.getResidenceList();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i] != null) {
|
||||
ClaimedResidence res = Residence.getResidenceManager()
|
||||
.getByName(list[i]);
|
||||
PermissionGroup group = Residence.getPermissionManager()
|
||||
.getGroup(res.getPermissions().getOwner(),
|
||||
res.getPermissions().getWorld());
|
||||
this.setExpireTime(null, list[i], group.getLeaseGiveTime());
|
||||
final String[] list = manager.getResidenceList();
|
||||
for (final String element : list) {
|
||||
if (element != null) {
|
||||
final ClaimedResidence res = plugin.getResidenceManager().getByName(element);
|
||||
final PermissionGroup group = plugin.getPermissionManager().getGroup(res.getPermissions().getOwner(), res.getPermissions().getWorld());
|
||||
this.setExpireTime(null, element, group.getLeaseGiveTime());
|
||||
}
|
||||
}
|
||||
System.out.println("[Residence] - Set default leases.");
|
||||
@@ -258,23 +200,44 @@ public class LeaseManager {
|
||||
return leaseExpireTime;
|
||||
}
|
||||
|
||||
public void updateLeaseName(String oldName, String newName) {
|
||||
public void setExpireTime(final Player player, String area, final int days) {
|
||||
area = area.replace(".", "_");
|
||||
if (manager.getByName(area) != null) {
|
||||
leaseExpireTime.put(area, daysToMs(days) + System.currentTimeMillis());
|
||||
if (player != null) {
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("LeaseRenew", getExpireTime(area).toString()));
|
||||
}
|
||||
} else {
|
||||
if (player != null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidArea"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setExpireTime(final String area, final int days) {
|
||||
this.setExpireTime(null, area, days);
|
||||
}
|
||||
|
||||
public void updateLeaseName(final String oldName, final String newName) {
|
||||
if (leaseExpireTime.containsKey(oldName)) {
|
||||
leaseExpireTime.put(newName, leaseExpireTime.get(oldName));
|
||||
leaseExpireTime.remove(oldName);
|
||||
}
|
||||
}
|
||||
|
||||
public static LeaseManager load(Map<String, Long> root, ResidenceManager m) {
|
||||
LeaseManager l = new LeaseManager(m);
|
||||
if (root != null) {
|
||||
for (Object val : root.values()) {
|
||||
if (!(val instanceof Long)) {
|
||||
root.remove(val);
|
||||
}
|
||||
}
|
||||
l.leaseExpireTime = Collections.synchronizedMap(root);
|
||||
private int daysRemaining(final String area) {
|
||||
final Long get = leaseExpireTime.get(area);
|
||||
if (get <= System.currentTimeMillis()) {
|
||||
return 0;
|
||||
}
|
||||
return l;
|
||||
return msToDays((int) (get - System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
private long daysToMs(final int days) {
|
||||
return ((days) * 24L * 60L * 60L * 1000L);
|
||||
}
|
||||
|
||||
private int msToDays(final long ms) {
|
||||
return (int) Math.ceil((((ms / 1000D) / 60D) / 60D) / 24D);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,40 +5,74 @@
|
||||
|
||||
package com.bekvon.bukkit.residence.protection;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.bekvon.bukkit.residence.Residence;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bekvon.bukkit.residence.Residence;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
public class PermissionListManager {
|
||||
|
||||
private Map<String, Map<String, FlagPermissions>> lists;
|
||||
private final Map<String, Map<String, FlagPermissions>> lists;
|
||||
Residence plugin;
|
||||
|
||||
public PermissionListManager() {
|
||||
lists = Collections
|
||||
.synchronizedMap(new HashMap<String, Map<String, FlagPermissions>>());
|
||||
public PermissionListManager(final Residence plugin) {
|
||||
this.plugin = plugin;
|
||||
lists = Collections.synchronizedMap(new HashMap<String, Map<String, FlagPermissions>>());
|
||||
}
|
||||
|
||||
public FlagPermissions getList(String player, String listname) {
|
||||
Map<String, FlagPermissions> get = lists.get(player);
|
||||
@SuppressWarnings("unchecked")
|
||||
public static PermissionListManager load(final Residence plugin, final Map<String, Object> root) {
|
||||
final PermissionListManager p = new PermissionListManager(plugin);
|
||||
if (root != null) {
|
||||
for (final Entry<String, Object> players : root.entrySet()) {
|
||||
try {
|
||||
final Map<String, Object> value = (Map<String, Object>) players.getValue();
|
||||
final Map<String, FlagPermissions> loadedMap = Collections.synchronizedMap(new HashMap<String, FlagPermissions>());
|
||||
for (final Entry<String, Object> list : value.entrySet()) {
|
||||
loadedMap.put(list.getKey(), FlagPermissions.load((Map<String, Object>) list.getValue()));
|
||||
}
|
||||
p.lists.put(players.getKey(), loadedMap);
|
||||
} catch (final Exception ex) {
|
||||
plugin.getLogger().warning(" - 玩家: " + players.getKey() + " 的权限列表载入失败...");
|
||||
}
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public void applyListToResidence(final Player player, final String listname, final String areaname, final boolean resadmin) {
|
||||
final FlagPermissions list = this.getList(player.getName(), listname);
|
||||
if (list == null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidList"));
|
||||
return;
|
||||
}
|
||||
final ClaimedResidence res = plugin.getResidenceManager().getByName(areaname);
|
||||
if (res == null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidResidence"));
|
||||
return;
|
||||
}
|
||||
res.getPermissions().applyTemplate(player, list, resadmin);
|
||||
}
|
||||
|
||||
public FlagPermissions getList(final String player, final String listname) {
|
||||
final Map<String, FlagPermissions> get = lists.get(player);
|
||||
if (get == null) {
|
||||
return null;
|
||||
}
|
||||
return get.get(listname);
|
||||
}
|
||||
|
||||
public void makeList(Player player, String listname) {
|
||||
public void makeList(final Player player, final String listname) {
|
||||
Map<String, FlagPermissions> get = lists.get(player.getName());
|
||||
if (get == null) {
|
||||
get = new HashMap<String, FlagPermissions>();
|
||||
@@ -46,117 +80,62 @@ public class PermissionListManager {
|
||||
}
|
||||
FlagPermissions perms = get.get(listname);
|
||||
if (perms == null) {
|
||||
perms = new FlagPermissions();
|
||||
perms = new FlagPermissions(plugin);
|
||||
get.put(listname, perms);
|
||||
player.sendMessage(ChatColor.GREEN
|
||||
+ Residence.getLanguage().getPhrase("ListCreate", listname));
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("ListCreate", listname));
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ Residence.getLanguage().getPhrase("ListExists"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("ListExists"));
|
||||
}
|
||||
}
|
||||
|
||||
public void removeList(Player player, String listname) {
|
||||
Map<String, FlagPermissions> get = lists.get(player.getName());
|
||||
if (get == null) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ Residence.getLanguage().getPhrase("InvalidList"));
|
||||
return;
|
||||
}
|
||||
FlagPermissions list = get.get(listname);
|
||||
public void printList(final Player player, final String listname) {
|
||||
final FlagPermissions list = this.getList(player.getName(), listname);
|
||||
if (list == null) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ Residence.getLanguage().getPhrase("InvalidList"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidList"));
|
||||
return;
|
||||
}
|
||||
get.remove(listname);
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ Residence.getLanguage().getPhrase("ListRemoved"));
|
||||
}
|
||||
|
||||
public void applyListToResidence(Player player, String listname,
|
||||
String areaname, boolean resadmin) {
|
||||
FlagPermissions list = this.getList(player.getName(), listname);
|
||||
if (list == null) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ Residence.getLanguage().getPhrase("InvalidList"));
|
||||
return;
|
||||
}
|
||||
ClaimedResidence res = Residence.getResidenceManager().getByName(
|
||||
areaname);
|
||||
if (res == null) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ Residence.getLanguage().getPhrase("InvalidResidence"));
|
||||
return;
|
||||
}
|
||||
res.getPermissions().applyTemplate(player, list, resadmin);
|
||||
}
|
||||
|
||||
public void printList(Player player, String listname) {
|
||||
FlagPermissions list = this.getList(player.getName(), listname);
|
||||
if (list == null) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ Residence.getLanguage().getPhrase("InvalidList"));
|
||||
return;
|
||||
}
|
||||
player.sendMessage(ChatColor.LIGHT_PURPLE
|
||||
+ "------Permission Template------");
|
||||
player.sendMessage(Residence.getLanguage().getPhrase("Name") + ": "
|
||||
+ ChatColor.GREEN + listname);
|
||||
player.sendMessage(ChatColor.LIGHT_PURPLE + "------Permission Template------");
|
||||
player.sendMessage(plugin.getLanguage().getPhrase("Name") + ": " + ChatColor.GREEN + listname);
|
||||
list.printFlags(player);
|
||||
}
|
||||
|
||||
public void printLists(final Player player) {
|
||||
final StringBuilder sbuild = new StringBuilder();
|
||||
final Map<String, FlagPermissions> get = lists.get(player.getName());
|
||||
sbuild.append(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Lists") + ":" + ChatColor.DARK_AQUA + " ");
|
||||
if (get != null) {
|
||||
for (final Entry<String, FlagPermissions> thislist : get.entrySet()) {
|
||||
sbuild.append(thislist.getKey()).append(" ");
|
||||
}
|
||||
}
|
||||
player.sendMessage(sbuild.toString());
|
||||
}
|
||||
|
||||
public void removeList(final Player player, final String listname) {
|
||||
final Map<String, FlagPermissions> get = lists.get(player.getName());
|
||||
if (get == null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidList"));
|
||||
return;
|
||||
}
|
||||
final FlagPermissions list = get.get(listname);
|
||||
if (list == null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidList"));
|
||||
return;
|
||||
}
|
||||
get.remove(listname);
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("ListRemoved"));
|
||||
}
|
||||
|
||||
public Map<String, Object> save() {
|
||||
Map<String, Object> root = new LinkedHashMap<String, Object>();
|
||||
for (Entry<String, Map<String, FlagPermissions>> players : lists
|
||||
.entrySet()) {
|
||||
Map<String, Object> saveMap = new LinkedHashMap<String, Object>();
|
||||
Map<String, FlagPermissions> map = players.getValue();
|
||||
for (Entry<String, FlagPermissions> list : map.entrySet()) {
|
||||
final Map<String, Object> root = new LinkedHashMap<String, Object>();
|
||||
for (final Entry<String, Map<String, FlagPermissions>> players : lists.entrySet()) {
|
||||
final Map<String, Object> saveMap = new LinkedHashMap<String, Object>();
|
||||
final Map<String, FlagPermissions> map = players.getValue();
|
||||
for (final Entry<String, FlagPermissions> list : map.entrySet()) {
|
||||
saveMap.put(list.getKey(), list.getValue().save());
|
||||
}
|
||||
root.put(players.getKey(), saveMap);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static PermissionListManager load(Map<String, Object> root) {
|
||||
|
||||
PermissionListManager p = new PermissionListManager();
|
||||
if (root != null) {
|
||||
for (Entry<String, Object> players : root.entrySet()) {
|
||||
try {
|
||||
Map<String, Object> value = (Map<String, Object>) players
|
||||
.getValue();
|
||||
Map<String, FlagPermissions> loadedMap = Collections
|
||||
.synchronizedMap(new HashMap<String, FlagPermissions>());
|
||||
for (Entry<String, Object> list : value.entrySet()) {
|
||||
loadedMap.put(list.getKey(), FlagPermissions
|
||||
.load((Map<String, Object>) list.getValue()));
|
||||
}
|
||||
p.lists.put(players.getKey(), loadedMap);
|
||||
} catch (Exception ex) {
|
||||
System.out
|
||||
.println("[Residence] - Failed to load permission lists for player: "
|
||||
+ players.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public void printLists(Player player) {
|
||||
StringBuilder sbuild = new StringBuilder();
|
||||
Map<String, FlagPermissions> get = lists.get(player.getName());
|
||||
sbuild.append(ChatColor.YELLOW
|
||||
+ Residence.getLanguage().getPhrase("Lists") + ":"
|
||||
+ ChatColor.DARK_AQUA + " ");
|
||||
if (get != null) {
|
||||
for (Entry<String, FlagPermissions> thislist : get.entrySet()) {
|
||||
sbuild.append(thislist.getKey()).append(" ");
|
||||
}
|
||||
}
|
||||
player.sendMessage(sbuild.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,254 +36,299 @@ import com.bekvon.bukkit.residence.text.help.InformationPager;
|
||||
* @author Administrator
|
||||
*/
|
||||
public class ResidenceManager {
|
||||
protected Map<String, ClaimedResidence> residences;
|
||||
|
||||
protected Map<String, Map<ChunkRef, List<String>>> chunkResidences;
|
||||
|
||||
public ResidenceManager() {
|
||||
protected Map<String, ClaimedResidence> residences;
|
||||
|
||||
Residence plugin;
|
||||
|
||||
public ResidenceManager(final Residence plugin) {
|
||||
this.plugin = plugin;
|
||||
residences = new HashMap<String, ClaimedResidence>();
|
||||
chunkResidences = new HashMap<String, Map<ChunkRef, List<String>>>();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static ResidenceManager load(Map<String, Object> root) throws Exception {
|
||||
ResidenceManager resm = new ResidenceManager();
|
||||
if (root == null)
|
||||
public static ResidenceManager load(final Residence plugin, final Map<String, Object> root) throws Exception {
|
||||
final ResidenceManager resm = new ResidenceManager(plugin);
|
||||
if (root == null) {
|
||||
return resm;
|
||||
for (World world : Residence.getServ().getWorlds()) {
|
||||
Map<String, Object> reslist = (Map<String, Object>) root.get(world.getName());
|
||||
if (reslist != null)
|
||||
}
|
||||
for (final World world : plugin.getServ().getWorlds()) {
|
||||
final Map<String, Object> reslist = (Map<String, Object>) root.get(world.getName());
|
||||
if (reslist != null) {
|
||||
try {
|
||||
resm.chunkResidences.put(world.getName(), loadMap(reslist, resm));
|
||||
} catch (Exception ex) {
|
||||
Residence.getLog().warning("载入世界: " + world.getName() + "的领地数据时发生错误!");
|
||||
if (Residence.getConfigManager().stopOnSaveError())
|
||||
resm.chunkResidences.put(world.getName(), loadMap(plugin, reslist, resm));
|
||||
} catch (final Exception ex) {
|
||||
plugin.getLog().warning("载入世界: " + world.getName() + "的领地数据时发生错误!");
|
||||
if (plugin.getConfigManager().stopOnSaveError()) {
|
||||
throw (ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return resm;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<ChunkRef, List<String>> loadMap(Map<String, Object> root, ResidenceManager resm) throws Exception {
|
||||
Map<ChunkRef, List<String>> retRes = new HashMap<ChunkRef, List<String>>();
|
||||
if (root != null)
|
||||
for (Entry<String, Object> res : root.entrySet())
|
||||
public static Map<ChunkRef, List<String>> loadMap(final Residence plugin, final Map<String, Object> root, final ResidenceManager resm) throws Exception {
|
||||
final Map<ChunkRef, List<String>> retRes = new HashMap<ChunkRef, List<String>>();
|
||||
if (root != null) {
|
||||
for (final Entry<String, Object> res : root.entrySet()) {
|
||||
try {
|
||||
ClaimedResidence residence = ClaimedResidence.load((Map<String, Object>) res.getValue(), null);
|
||||
for (ChunkRef chunk : getChunks(residence)) {
|
||||
List<String> ress = new ArrayList<String>();
|
||||
if (retRes.containsKey(chunk))
|
||||
final ClaimedResidence residence = ClaimedResidence.load(plugin, (Map<String, Object>) res.getValue(), null);
|
||||
for (final ChunkRef chunk : getChunks(residence)) {
|
||||
final List<String> ress = new ArrayList<String>();
|
||||
if (retRes.containsKey(chunk)) {
|
||||
ress.addAll(retRes.get(chunk));
|
||||
}
|
||||
ress.add(res.getKey());
|
||||
retRes.put(chunk, ress);
|
||||
}
|
||||
resm.residences.put(res.getKey(), residence);
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
System.out.print("[Residence] Failed to load residence (" + res.getKey() + ")! Reason:" + ex.getMessage() + " Error Log:");
|
||||
Logger.getLogger(ResidenceManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||
if (Residence.getConfigManager().stopOnSaveError())
|
||||
if (plugin.getConfigManager().stopOnSaveError()) {
|
||||
throw (ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return retRes;
|
||||
}
|
||||
|
||||
private static List<ChunkRef> getChunks(ClaimedResidence res) {
|
||||
List<ChunkRef> chunks = new ArrayList<ChunkRef>();
|
||||
for (CuboidArea area : res.getAreaArray())
|
||||
private static List<ChunkRef> getChunks(final ClaimedResidence res) {
|
||||
final List<ChunkRef> chunks = new ArrayList<ChunkRef>();
|
||||
for (final CuboidArea area : res.getAreaArray()) {
|
||||
chunks.addAll(area.getChunks());
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public boolean addResidence(Player player, String name, Location loc1, Location loc2, boolean resadmin) {
|
||||
public boolean addResidence(final Player player, final String name, final Location loc1, final Location loc2, final boolean resadmin) {
|
||||
return this.addResidence(player, player.getName(), name, loc1, loc2, resadmin);
|
||||
}
|
||||
|
||||
public boolean addResidence(Player player, String owner, String name, Location loc1, Location loc2, boolean resadmin) {
|
||||
if (!Residence.validName(name)) {
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidNameCharacters"));
|
||||
public boolean addResidence(final Player player, final String owner, String name, final Location loc1, final Location loc2, final boolean resadmin) {
|
||||
if (!plugin.validName(name)) {
|
||||
if (player != null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidNameCharacters"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (loc1 == null || loc2 == null || !loc1.getWorld().getName().equals(loc2.getWorld().getName())) {
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("SelectPoints"));
|
||||
if (player != null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("SelectPoints"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
PermissionGroup group = Residence.getPermissionManager().getGroup(owner, loc1.getWorld().getName());
|
||||
boolean createpermission = group.canCreateResidences() || (player == null ? true : player.hasPermission("residence.create"));
|
||||
final PermissionGroup group = plugin.getPermissionManager().getGroup(owner, loc1.getWorld().getName());
|
||||
final boolean createpermission = group.canCreateResidences() || (player == null ? true : player.hasPermission("residence.create"));
|
||||
if (!createpermission && !resadmin) {
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission"));
|
||||
if (player != null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (player != null)
|
||||
if (player != null) {
|
||||
if (getOwnedZoneCount(player.getName()) >= group.getMaxZones() && !resadmin) {
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ResidenceTooMany"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("ResidenceTooMany"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
CuboidArea newArea = new CuboidArea(loc1, loc2);
|
||||
ClaimedResidence newRes = new ClaimedResidence(owner, loc1.getWorld().getName());
|
||||
final ClaimedResidence newRes = new ClaimedResidence(plugin, owner, loc1.getWorld().getName());
|
||||
newRes.getPermissions().applyDefaultFlags();
|
||||
newRes.setEnterMessage(group.getDefaultEnterMessage());
|
||||
newRes.setLeaveMessage(group.getDefaultLeaveMessage());
|
||||
|
||||
ResidenceCreationEvent resevent = new ResidenceCreationEvent(player, name, newRes, newArea);
|
||||
Residence.getServ().getPluginManager().callEvent(resevent);
|
||||
if (resevent.isCancelled())
|
||||
final ResidenceCreationEvent resevent = new ResidenceCreationEvent(player, name, newRes, newArea);
|
||||
plugin.getServ().getPluginManager().callEvent(resevent);
|
||||
if (resevent.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
newArea = resevent.getPhysicalArea();
|
||||
name = resevent.getResidenceName();
|
||||
if (residences.containsKey(name)) {
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ResidenceAlreadyExists", ChatColor.YELLOW + name + ChatColor.RED));
|
||||
if (player != null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("ResidenceAlreadyExists", ChatColor.YELLOW + name + ChatColor.RED));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (player != null)
|
||||
if (player != null) {
|
||||
newRes.addArea(player, newArea, "main", resadmin);
|
||||
else
|
||||
} else {
|
||||
newRes.addArea(newArea, "main");
|
||||
}
|
||||
if (newRes.getAreaCount() != 0) {
|
||||
residences.put(name, newRes);
|
||||
calculateChunks(name);
|
||||
Residence.getLeaseManager().removeExpireTime(name);
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("ResidenceCreate", ChatColor.YELLOW + name + ChatColor.GREEN));
|
||||
if (Residence.getConfigManager().useLeases())
|
||||
if (player != null)
|
||||
Residence.getLeaseManager().setExpireTime(player, name, group.getLeaseGiveTime());
|
||||
else
|
||||
Residence.getLeaseManager().setExpireTime(name, group.getLeaseGiveTime());
|
||||
plugin.getLeaseManager().removeExpireTime(name);
|
||||
if (player != null) {
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("ResidenceCreate", ChatColor.YELLOW + name + ChatColor.GREEN));
|
||||
}
|
||||
if (plugin.getConfigManager().useLeases()) {
|
||||
if (player != null) {
|
||||
plugin.getLeaseManager().setExpireTime(player, name, group.getLeaseGiveTime());
|
||||
} else {
|
||||
plugin.getLeaseManager().setExpireTime(name, group.getLeaseGiveTime());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addResidence(String name, Location loc1, Location loc2) {
|
||||
public boolean addResidence(final String name, final Location loc1, final Location loc2) {
|
||||
return this.addResidence(name, "Server Land", loc1, loc2);
|
||||
}
|
||||
|
||||
public boolean addResidence(String name, String owner, Location loc1, Location loc2) {
|
||||
public boolean addResidence(final String name, final String owner, final Location loc1, final Location loc2) {
|
||||
return this.addResidence(null, owner, name, loc1, loc2, true);
|
||||
}
|
||||
|
||||
public void calculateChunks(String name) {
|
||||
ClaimedResidence res = residences.get(name);
|
||||
public void calculateChunks(final String name) {
|
||||
final ClaimedResidence res = residences.get(name);
|
||||
if (res != null) {
|
||||
String world = res.getWorld();
|
||||
if (chunkResidences.get(world) == null)
|
||||
final String world = res.getWorld();
|
||||
if (chunkResidences.get(world) == null) {
|
||||
chunkResidences.put(world, new HashMap<ChunkRef, List<String>>());
|
||||
for (ChunkRef chunk : getChunks(res)) {
|
||||
List<String> ress = new ArrayList<String>();
|
||||
if (chunkResidences.get(world).containsKey(chunk))
|
||||
}
|
||||
for (final ChunkRef chunk : getChunks(res)) {
|
||||
final List<String> ress = new ArrayList<String>();
|
||||
if (chunkResidences.get(world).containsKey(chunk)) {
|
||||
ress.addAll(chunkResidences.get(world).get(chunk));
|
||||
}
|
||||
ress.add(name);
|
||||
chunkResidences.get(world).put(chunk, ress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String checkAreaCollision(CuboidArea newarea, ClaimedResidence parentResidence) {
|
||||
Set<Entry<String, ClaimedResidence>> set = residences.entrySet();
|
||||
for (Entry<String, ClaimedResidence> entry : set) {
|
||||
ClaimedResidence check = entry.getValue();
|
||||
if (check != parentResidence && check.checkCollision(newarea))
|
||||
public String checkAreaCollision(final CuboidArea newarea, final ClaimedResidence parentResidence) {
|
||||
final Set<Entry<String, ClaimedResidence>> set = residences.entrySet();
|
||||
for (final Entry<String, ClaimedResidence> entry : set) {
|
||||
final ClaimedResidence check = entry.getValue();
|
||||
if (check != parentResidence && check.checkCollision(newarea)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClaimedResidence getByLoc(Location loc) {
|
||||
if (loc == null)
|
||||
public ClaimedResidence getByLoc(final Location loc) {
|
||||
if (loc == null) {
|
||||
return null;
|
||||
}
|
||||
ClaimedResidence res = null;
|
||||
boolean found = false;
|
||||
String world = loc.getWorld().getName();
|
||||
ChunkRef chunk = new ChunkRef(loc);
|
||||
if (chunkResidences.get(world) != null)
|
||||
if (chunkResidences.get(world).get(chunk) != null)
|
||||
for (String key : chunkResidences.get(world).get(chunk)) {
|
||||
ClaimedResidence entry = residences.get(key);
|
||||
final String world = loc.getWorld().getName();
|
||||
final ChunkRef chunk = new ChunkRef(loc);
|
||||
if (chunkResidences.get(world) != null) {
|
||||
if (chunkResidences.get(world).get(chunk) != null) {
|
||||
for (final String key : chunkResidences.get(world).get(chunk)) {
|
||||
final ClaimedResidence entry = residences.get(key);
|
||||
if (entry.containsLoc(loc)) {
|
||||
res = entry;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
return null;
|
||||
if (res == null)
|
||||
}
|
||||
if (res == null) {
|
||||
return null;
|
||||
ClaimedResidence subres = res.getSubzoneByLoc(loc);
|
||||
if (subres == null)
|
||||
}
|
||||
final ClaimedResidence subres = res.getSubzoneByLoc(loc);
|
||||
if (subres == null) {
|
||||
return res;
|
||||
}
|
||||
return subres;
|
||||
}
|
||||
|
||||
public ClaimedResidence getByName(String name) {
|
||||
if (name == null)
|
||||
public ClaimedResidence getByName(final String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
String[] split = name.split("\\.");
|
||||
if (split.length == 1)
|
||||
}
|
||||
final String[] split = name.split("\\.");
|
||||
if (split.length == 1) {
|
||||
return residences.get(name);
|
||||
}
|
||||
ClaimedResidence res = residences.get(split[0]);
|
||||
for (int i = 1; i < split.length; i++)
|
||||
if (res != null)
|
||||
for (int i = 1; i < split.length; i++) {
|
||||
if (res != null) {
|
||||
res = res.getSubzone(split[i]);
|
||||
else
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public String getNameByLoc(Location loc) {
|
||||
if (loc == null)
|
||||
public String getNameByLoc(final Location loc) {
|
||||
if (loc == null) {
|
||||
return null;
|
||||
}
|
||||
ClaimedResidence res = null;
|
||||
String name = null;
|
||||
boolean found = false;
|
||||
String world = loc.getWorld().getName();
|
||||
ChunkRef chunk = new ChunkRef(loc);
|
||||
if (chunkResidences.get(world) != null)
|
||||
if (chunkResidences.get(world).get(chunk) != null)
|
||||
for (String key : chunkResidences.get(world).get(chunk)) {
|
||||
ClaimedResidence entry = residences.get(key);
|
||||
final String world = loc.getWorld().getName();
|
||||
final ChunkRef chunk = new ChunkRef(loc);
|
||||
if (chunkResidences.get(world) != null) {
|
||||
if (chunkResidences.get(world).get(chunk) != null) {
|
||||
for (final String key : chunkResidences.get(world).get(chunk)) {
|
||||
final ClaimedResidence entry = residences.get(key);
|
||||
if (entry.containsLoc(loc)) {
|
||||
res = entry;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
return null;
|
||||
if (res == null)
|
||||
}
|
||||
if (res == null) {
|
||||
return null;
|
||||
}
|
||||
name = res.getName();
|
||||
if (name == null)
|
||||
if (name == null) {
|
||||
return null;
|
||||
String szname = res.getSubzoneNameByLoc(loc);
|
||||
if (szname != null)
|
||||
}
|
||||
final String szname = res.getSubzoneNameByLoc(loc);
|
||||
if (szname != null) {
|
||||
return name + "." + szname;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getNameByRes(ClaimedResidence res) {
|
||||
Set<Entry<String, ClaimedResidence>> set = residences.entrySet();
|
||||
for (Entry<String, ClaimedResidence> check : set) {
|
||||
if (check.getValue() == res)
|
||||
public String getNameByRes(final ClaimedResidence res) {
|
||||
final Set<Entry<String, ClaimedResidence>> set = residences.entrySet();
|
||||
for (final Entry<String, ClaimedResidence> check : set) {
|
||||
if (check.getValue() == res) {
|
||||
return check.getKey();
|
||||
String n = check.getValue().getSubzoneNameByRes(res);
|
||||
if (n != null)
|
||||
}
|
||||
final String n = check.getValue().getSubzoneNameByRes(res);
|
||||
if (n != null) {
|
||||
return check.getKey() + "." + n;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getOwnedZoneCount(String player) {
|
||||
Collection<ClaimedResidence> set = residences.values();
|
||||
public int getOwnedZoneCount(final String player) {
|
||||
final Collection<ClaimedResidence> set = residences.values();
|
||||
int count = 0;
|
||||
for (ClaimedResidence res : set)
|
||||
if (res.getPermissions().getOwner().equalsIgnoreCase(player))
|
||||
for (final ClaimedResidence res : set) {
|
||||
if (res.getPermissions().getOwner().equalsIgnoreCase(player)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -295,171 +340,182 @@ public class ResidenceManager {
|
||||
return this.getResidenceList(true, true).toArray(new String[0]);
|
||||
}
|
||||
|
||||
public ArrayList<String> getResidenceList(boolean showhidden, boolean showsubzones) {
|
||||
public ArrayList<String> getResidenceList(final boolean showhidden, final boolean showsubzones) {
|
||||
return this.getResidenceList(null, showhidden, showsubzones, false);
|
||||
}
|
||||
|
||||
public ArrayList<String> getResidenceList(String targetplayer, boolean showhidden, boolean showsubzones) {
|
||||
public ArrayList<String> getResidenceList(final String targetplayer, final boolean showhidden, final boolean showsubzones) {
|
||||
return this.getResidenceList(targetplayer, showhidden, showsubzones, false);
|
||||
}
|
||||
|
||||
public ArrayList<String> getResidenceList(String targetplayer, boolean showhidden, boolean showsubzones, boolean formattedOutput) {
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
for (Entry<String, ClaimedResidence> res : residences.entrySet())
|
||||
public ArrayList<String> getResidenceList(final String targetplayer, final boolean showhidden, final boolean showsubzones, final boolean formattedOutput) {
|
||||
final ArrayList<String> list = new ArrayList<String>();
|
||||
for (final Entry<String, ClaimedResidence> res : residences.entrySet()) {
|
||||
this.getResidenceList(targetplayer, showhidden, showsubzones, "", res.getKey(), res.getValue(), list, formattedOutput);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void giveResidence(Player reqPlayer, String targPlayer, String residence, boolean resadmin) {
|
||||
ClaimedResidence res = getByName(residence);
|
||||
public void giveResidence(final Player reqPlayer, final String targPlayer, final String residence, final boolean resadmin) {
|
||||
final ClaimedResidence res = getByName(residence);
|
||||
if (res == null) {
|
||||
reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidResidence"));
|
||||
reqPlayer.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidResidence"));
|
||||
return;
|
||||
}
|
||||
if (!res.getPermissions().hasResidencePermission(reqPlayer, true) && !resadmin) {
|
||||
reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission"));
|
||||
reqPlayer.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission"));
|
||||
return;
|
||||
}
|
||||
Player giveplayer = Residence.getServ().getPlayer(targPlayer);
|
||||
final Player giveplayer = plugin.getServ().getPlayer(targPlayer);
|
||||
if (giveplayer == null || !giveplayer.isOnline()) {
|
||||
reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NotOnline"));
|
||||
reqPlayer.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NotOnline"));
|
||||
return;
|
||||
}
|
||||
CuboidArea[] areas = res.getAreaArray();
|
||||
PermissionGroup g = Residence.getPermissionManager().getGroup(giveplayer);
|
||||
final CuboidArea[] areas = res.getAreaArray();
|
||||
final PermissionGroup g = plugin.getPermissionManager().getGroup(giveplayer);
|
||||
if (areas.length > g.getMaxPhysicalPerResidence() && !resadmin) {
|
||||
reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ResidenceGiveLimits"));
|
||||
reqPlayer.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("ResidenceGiveLimits"));
|
||||
return;
|
||||
}
|
||||
if (getOwnedZoneCount(giveplayer.getName()) >= g.getMaxZones() && !resadmin) {
|
||||
reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ResidenceGiveLimits"));
|
||||
reqPlayer.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("ResidenceGiveLimits"));
|
||||
return;
|
||||
}
|
||||
if (!resadmin)
|
||||
for (CuboidArea area : areas)
|
||||
if (!resadmin) {
|
||||
for (final CuboidArea area : areas) {
|
||||
if (!g.inLimits(area)) {
|
||||
reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ResidenceGiveLimits"));
|
||||
reqPlayer.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("ResidenceGiveLimits"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
res.getPermissions().setOwner(giveplayer.getName(), true);
|
||||
// Fix phrases here
|
||||
reqPlayer.sendMessage(
|
||||
ChatColor.GREEN + Residence.getLanguage().getPhrase("ResidenceGive", ChatColor.YELLOW + residence + ChatColor.GREEN + "." + ChatColor.YELLOW + giveplayer.getName() + ChatColor.GREEN));
|
||||
giveplayer.sendMessage(Residence.getLanguage().getPhrase("ResidenceRecieve", ChatColor.GREEN + residence + ChatColor.YELLOW + "." + ChatColor.GREEN + reqPlayer.getName() + ChatColor.YELLOW));
|
||||
ChatColor.GREEN + plugin.getLanguage().getPhrase("ResidenceGive", ChatColor.YELLOW + residence + ChatColor.GREEN + "." + ChatColor.YELLOW + giveplayer.getName() + ChatColor.GREEN));
|
||||
giveplayer.sendMessage(plugin.getLanguage().getPhrase("ResidenceRecieve", ChatColor.GREEN + residence + ChatColor.YELLOW + "." + ChatColor.GREEN + reqPlayer.getName() + ChatColor.YELLOW));
|
||||
}
|
||||
|
||||
public void listAllResidences(Player player, int page) {
|
||||
public void listAllResidences(final Player player, final int page) {
|
||||
this.listAllResidences(player, page, false);
|
||||
}
|
||||
|
||||
public void listAllResidences(Player player, int page, boolean showhidden) {
|
||||
public void listAllResidences(final Player player, final int page, final boolean showhidden) {
|
||||
this.listAllResidences(player, page, showhidden, false);
|
||||
}
|
||||
|
||||
public void listAllResidences(Player player, int page, boolean showhidden, boolean showsubzones) {
|
||||
if (showhidden && !Residence.isResAdminOn(player))
|
||||
public void listAllResidences(final Player player, final int page, boolean showhidden, final boolean showsubzones) {
|
||||
if (showhidden && !plugin.isResAdminOn(player)) {
|
||||
showhidden = false;
|
||||
InformationPager.printInfo(player, Residence.getLanguage().getPhrase("Residences"), this.getResidenceList(null, showhidden, showsubzones, true), page);
|
||||
}
|
||||
InformationPager.printInfo(plugin, player, plugin.getLanguage().getPhrase("Residences"), this.getResidenceList(null, showhidden, showsubzones, true), page);
|
||||
}
|
||||
|
||||
public void listResidences(Player player) {
|
||||
public void listResidences(final Player player) {
|
||||
this.listResidences(player, player.getName(), 1);
|
||||
}
|
||||
|
||||
public void listResidences(Player player, int page) {
|
||||
public void listResidences(final Player player, final int page) {
|
||||
this.listResidences(player, player.getName(), page);
|
||||
}
|
||||
|
||||
public void listResidences(Player player, int page, boolean showhidden) {
|
||||
public void listResidences(final Player player, final int page, final boolean showhidden) {
|
||||
this.listResidences(player, player.getName(), page, showhidden);
|
||||
}
|
||||
|
||||
public void listResidences(Player player, String targetplayer) {
|
||||
public void listResidences(final Player player, final String targetplayer) {
|
||||
this.listResidences(player, targetplayer, 1);
|
||||
}
|
||||
|
||||
public void listResidences(Player player, String targetplayer, int page) {
|
||||
public void listResidences(final Player player, final String targetplayer, final int page) {
|
||||
this.listResidences(player, targetplayer, page, false);
|
||||
}
|
||||
|
||||
public void listResidences(Player player, String targetplayer, int page, boolean showhidden) {
|
||||
public void listResidences(final Player player, final String targetplayer, final int page, final boolean showhidden) {
|
||||
this.listResidences(player, targetplayer, page, showhidden, false);
|
||||
}
|
||||
|
||||
public void listResidences(Player player, String targetplayer, int page, boolean showhidden, boolean showsubzones) {
|
||||
if (showhidden && !Residence.isResAdminOn(player) && !player.getName().equals(targetplayer))
|
||||
public void listResidences(final Player player, final String targetplayer, final int page, boolean showhidden, final boolean showsubzones) {
|
||||
if (showhidden && !plugin.isResAdminOn(player) && !player.getName().equals(targetplayer)) {
|
||||
showhidden = false;
|
||||
InformationPager.printInfo(player, Residence.getLanguage().getPhrase("Residences") + " - " + targetplayer, this.getResidenceList(targetplayer, showhidden, showsubzones, true), page);
|
||||
}
|
||||
InformationPager.printInfo(plugin, player, plugin.getLanguage().getPhrase("Residences") + " - " + targetplayer, this.getResidenceList(targetplayer, showhidden, showsubzones, true), page);
|
||||
}
|
||||
|
||||
public void mirrorPerms(Player reqPlayer, String targetArea, String sourceArea, boolean resadmin) {
|
||||
ClaimedResidence reciever = this.getByName(targetArea);
|
||||
ClaimedResidence source = this.getByName(sourceArea);
|
||||
public void mirrorPerms(final Player reqPlayer, final String targetArea, final String sourceArea, final boolean resadmin) {
|
||||
final ClaimedResidence reciever = this.getByName(targetArea);
|
||||
final ClaimedResidence source = this.getByName(sourceArea);
|
||||
if (source == null || reciever == null) {
|
||||
reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidResidence"));
|
||||
reqPlayer.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidResidence"));
|
||||
return;
|
||||
}
|
||||
if (!resadmin)
|
||||
if (!resadmin) {
|
||||
if (!reciever.getPermissions().hasResidencePermission(reqPlayer, true) || !source.getPermissions().hasResidencePermission(reqPlayer, true)) {
|
||||
reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission"));
|
||||
reqPlayer.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
reciever.getPermissions().applyTemplate(reqPlayer, source.getPermissions(), resadmin);
|
||||
}
|
||||
|
||||
public void printAreaInfo(String areaname, Player player) {
|
||||
ClaimedResidence res = this.getByName(areaname);
|
||||
public void printAreaInfo(final String areaname, final Player player) {
|
||||
final ClaimedResidence res = this.getByName(areaname);
|
||||
if (res == null) {
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidResidence"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidResidence"));
|
||||
return;
|
||||
}
|
||||
ResidencePermissions perms = res.getPermissions();
|
||||
if (Residence.getConfigManager().enableEconomy())
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Residence") + ":" + ChatColor.DARK_GREEN + " " + areaname + " " + ChatColor.YELLOW + "Bank: " + ChatColor.GOLD
|
||||
final ResidencePermissions perms = res.getPermissions();
|
||||
if (plugin.getConfigManager().enableEconomy()) {
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Residence") + ":" + ChatColor.DARK_GREEN + " " + areaname + " " + ChatColor.YELLOW + "Bank: " + ChatColor.GOLD
|
||||
+ res.getBank().getStoredMoney());
|
||||
else
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Residence") + ":" + ChatColor.DARK_GREEN + " " + areaname);
|
||||
if (Residence.getConfigManager().enabledRentSystem() && Residence.getRentManager().isRented(areaname))
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Owner") + ":" + ChatColor.RED + " " + perms.getOwner() + ChatColor.YELLOW + " Rented by: " + ChatColor.RED
|
||||
+ Residence.getRentManager().getRentingPlayer(areaname));
|
||||
else
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Owner") + ":" + ChatColor.RED + " " + perms.getOwner() + ChatColor.YELLOW + " - "
|
||||
+ Residence.getLanguage().getPhrase("World") + ": " + ChatColor.RED + perms.getWorld());
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Flags") + ":" + ChatColor.BLUE + " " + perms.listFlags());
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Your.Flags") + ": " + ChatColor.GREEN + perms.listPlayerFlags(player.getName()));
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Group.Flags") + ":" + ChatColor.RED + " " + perms.listGroupFlags());
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Others.Flags") + ":" + ChatColor.RED + " " + perms.listOtherPlayersFlags(player.getName()));
|
||||
String aid = res.getAreaIDbyLoc(player.getLocation());
|
||||
if (aid != null)
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("CurrentArea") + ": " + ChatColor.GOLD + aid);
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Total.Size") + ":" + ChatColor.LIGHT_PURPLE + " " + res.getTotalSize());
|
||||
if (aid != null) {
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("CoordsT") + ": " + ChatColor.LIGHT_PURPLE
|
||||
+ Residence.getLanguage().getPhrase("CoordsTop", res.getAreaByLoc(player.getLocation()).getHighLoc().getBlockX() + "."
|
||||
+ res.getAreaByLoc(player.getLocation()).getHighLoc().getBlockY() + "." + res.getAreaByLoc(player.getLocation()).getHighLoc().getBlockZ()));
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("CoordsB") + ": " + ChatColor.LIGHT_PURPLE
|
||||
+ Residence.getLanguage().getPhrase("CoordsBottom", res.getAreaByLoc(player.getLocation()).getLowLoc().getBlockX() + "."
|
||||
+ res.getAreaByLoc(player.getLocation()).getLowLoc().getBlockY() + "." + res.getAreaByLoc(player.getLocation()).getLowLoc().getBlockZ()));
|
||||
if (Residence.isUseWorldEdit())
|
||||
WECUI.UPDATESELECT(res, player);
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Residence") + ":" + ChatColor.DARK_GREEN + " " + areaname);
|
||||
}
|
||||
if (plugin.getConfigManager().enabledRentSystem() && plugin.getRentManager().isRented(areaname)) {
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Owner") + ":" + ChatColor.RED + " " + perms.getOwner() + ChatColor.YELLOW + " Rented by: " + ChatColor.RED
|
||||
+ plugin.getRentManager().getRentingPlayer(areaname));
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Owner") + ":" + ChatColor.RED + " " + perms.getOwner() + ChatColor.YELLOW + " - "
|
||||
+ plugin.getLanguage().getPhrase("World") + ": " + ChatColor.RED + perms.getWorld());
|
||||
}
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Flags") + ":" + ChatColor.BLUE + " " + perms.listFlags());
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Your.Flags") + ": " + ChatColor.GREEN + perms.listPlayerFlags(player.getName()));
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Group.Flags") + ":" + ChatColor.RED + " " + perms.listGroupFlags());
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Others.Flags") + ":" + ChatColor.RED + " " + perms.listOtherPlayersFlags(player.getName()));
|
||||
final String aid = res.getAreaIDbyLoc(player.getLocation());
|
||||
if (aid != null) {
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("CurrentArea") + ": " + ChatColor.GOLD + aid);
|
||||
}
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("Total.Size") + ":" + ChatColor.LIGHT_PURPLE + " " + res.getTotalSize());
|
||||
if (aid != null) {
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("CoordsT") + ": " + ChatColor.LIGHT_PURPLE
|
||||
+ plugin.getLanguage().getPhrase("CoordsTop", res.getAreaByLoc(player.getLocation()).getHighLoc().getBlockX() + "."
|
||||
+ res.getAreaByLoc(player.getLocation()).getHighLoc().getBlockY() + "." + res.getAreaByLoc(player.getLocation()).getHighLoc().getBlockZ()));
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("CoordsB") + ": " + ChatColor.LIGHT_PURPLE
|
||||
+ plugin.getLanguage().getPhrase("CoordsBottom", res.getAreaByLoc(player.getLocation()).getLowLoc().getBlockX() + "."
|
||||
+ res.getAreaByLoc(player.getLocation()).getLowLoc().getBlockY() + "." + res.getAreaByLoc(player.getLocation()).getLowLoc().getBlockZ()));
|
||||
if (plugin.isUseWorldEdit()) {
|
||||
WECUI.UPDATESELECT(res, player);
|
||||
}
|
||||
}
|
||||
if (plugin.getConfigManager().useLeases() && plugin.getLeaseManager().leaseExpires(areaname)) {
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("LeaseExpire") + ":" + ChatColor.GREEN + " " + plugin.getLeaseManager().getExpireTime(areaname));
|
||||
}
|
||||
if (Residence.getConfigManager().useLeases() && Residence.getLeaseManager().leaseExpires(areaname))
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("LeaseExpire") + ":" + ChatColor.GREEN + " " + Residence.getLeaseManager().getExpireTime(areaname));
|
||||
}
|
||||
|
||||
public void removeAllByOwner(Player player, String owner) {
|
||||
public void removeAllByOwner(final Player player, final String owner) {
|
||||
this.removeAllByOwner(player, owner, residences);
|
||||
}
|
||||
|
||||
public void removeAllByOwner(String owner) {
|
||||
public void removeAllByOwner(final String owner) {
|
||||
this.removeAllByOwner(null, owner, residences);
|
||||
}
|
||||
|
||||
public void removeAllFromWorld(CommandSender sender, String world) {
|
||||
public void removeAllFromWorld(final CommandSender sender, final String world) {
|
||||
int count = 0;
|
||||
Iterator<ClaimedResidence> it = residences.values().iterator();
|
||||
final Iterator<ClaimedResidence> it = residences.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
ClaimedResidence next = it.next();
|
||||
final ClaimedResidence next = it.next();
|
||||
if (next.getWorld().equals(world)) {
|
||||
it.remove();
|
||||
count++;
|
||||
@@ -467,173 +523,195 @@ public class ResidenceManager {
|
||||
}
|
||||
chunkResidences.remove(world);
|
||||
chunkResidences.put(world, new HashMap<ChunkRef, List<String>>());
|
||||
if (count == 0)
|
||||
if (count == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "No residences found in world: " + ChatColor.YELLOW + world);
|
||||
else
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Removed " + ChatColor.YELLOW + count + ChatColor.RED + " residences in world: " + ChatColor.YELLOW + world);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeChunkList(String name) {
|
||||
ClaimedResidence res = residences.get(name);
|
||||
public void removeChunkList(final String name) {
|
||||
final ClaimedResidence res = residences.get(name);
|
||||
if (res != null) {
|
||||
String world = res.getWorld();
|
||||
if (chunkResidences.get(world) != null)
|
||||
for (ChunkRef chunk : getChunks(res)) {
|
||||
List<String> ress = new ArrayList<String>();
|
||||
if (chunkResidences.get(world).containsKey(chunk))
|
||||
final String world = res.getWorld();
|
||||
if (chunkResidences.get(world) != null) {
|
||||
for (final ChunkRef chunk : getChunks(res)) {
|
||||
final List<String> ress = new ArrayList<String>();
|
||||
if (chunkResidences.get(world).containsKey(chunk)) {
|
||||
ress.addAll(chunkResidences.get(world).get(chunk));
|
||||
}
|
||||
ress.remove(name);
|
||||
chunkResidences.get(world).put(chunk, ress);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeResidence(Player player, String name, boolean resadmin) {
|
||||
ClaimedResidence res = this.getByName(name);
|
||||
public void removeResidence(final Player player, final String name, final boolean resadmin) {
|
||||
final ClaimedResidence res = this.getByName(name);
|
||||
if (res != null) {
|
||||
if (player != null && !resadmin)
|
||||
if (player != null && !resadmin) {
|
||||
if (!res.getPermissions().hasResidencePermission(player, true) && !resadmin) {
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission"));
|
||||
return;
|
||||
}
|
||||
ResidenceDeleteEvent resevent = new ResidenceDeleteEvent(player, res, player == null ? DeleteCause.OTHER : DeleteCause.PLAYER_DELETE);
|
||||
Residence.getServ().getPluginManager().callEvent(resevent);
|
||||
if (resevent.isCancelled())
|
||||
}
|
||||
final ResidenceDeleteEvent resevent = new ResidenceDeleteEvent(player, res, player == null ? DeleteCause.OTHER : DeleteCause.PLAYER_DELETE);
|
||||
plugin.getServ().getPluginManager().callEvent(resevent);
|
||||
if (resevent.isCancelled()) {
|
||||
return;
|
||||
ClaimedResidence parent = res.getParent();
|
||||
}
|
||||
final ClaimedResidence parent = res.getParent();
|
||||
if (parent == null) {
|
||||
removeChunkList(name);
|
||||
residences.remove(name);
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("ResidenceRemove", ChatColor.YELLOW + name + ChatColor.GREEN));
|
||||
if (player != null) {
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("ResidenceRemove", ChatColor.YELLOW + name + ChatColor.GREEN));
|
||||
}
|
||||
} else {
|
||||
String[] split = name.split("\\.");
|
||||
if (player != null)
|
||||
final String[] split = name.split("\\.");
|
||||
if (player != null) {
|
||||
parent.removeSubzone(player, split[split.length - 1], true);
|
||||
else
|
||||
} else {
|
||||
parent.removeSubzone(split[split.length - 1]);
|
||||
}
|
||||
}
|
||||
// Residence.getLeaseManager().removeExpireTime(name); - causing
|
||||
// plugin.getLeaseManager().removeExpireTime(name); - causing
|
||||
// concurrent modification exception in lease manager... worked
|
||||
// around for now
|
||||
Residence.getRentManager().removeRentable(name);
|
||||
plugin.getRentManager().removeRentable(name);
|
||||
|
||||
} else if (player != null)
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidResidence"));
|
||||
} else if (player != null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidResidence"));
|
||||
}
|
||||
}
|
||||
|
||||
public void removeResidence(String name) {
|
||||
public void removeResidence(final String name) {
|
||||
this.removeResidence(null, name, true);
|
||||
}
|
||||
|
||||
public boolean renameResidence(Player player, String oldName, String newName, boolean resadmin) {
|
||||
if (!Residence.validName(newName)) {
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidNameCharacters"));
|
||||
public boolean renameResidence(final Player player, final String oldName, final String newName, final boolean resadmin) {
|
||||
if (!plugin.validName(newName)) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidNameCharacters"));
|
||||
return false;
|
||||
}
|
||||
ClaimedResidence res = this.getByName(oldName);
|
||||
final ClaimedResidence res = this.getByName(oldName);
|
||||
if (res == null) {
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidResidence"));
|
||||
if (player != null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidResidence"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (res.getPermissions().hasResidencePermission(player, true) || resadmin) {
|
||||
if (res.getParent() == null) {
|
||||
if (residences.containsKey(newName)) {
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ResidenceAlreadyExists", ChatColor.YELLOW + newName + ChatColor.RED));
|
||||
if (player != null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("ResidenceAlreadyExists", ChatColor.YELLOW + newName + ChatColor.RED));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
ResidenceRenameEvent resevent = new ResidenceRenameEvent(res, newName, oldName);
|
||||
Residence.getServ().getPluginManager().callEvent(resevent);
|
||||
final ResidenceRenameEvent resevent = new ResidenceRenameEvent(res, newName, oldName);
|
||||
plugin.getServ().getPluginManager().callEvent(resevent);
|
||||
removeChunkList(oldName);
|
||||
residences.put(newName, res);
|
||||
residences.remove(oldName);
|
||||
calculateChunks(newName);
|
||||
if (Residence.getConfigManager().useLeases())
|
||||
Residence.getLeaseManager().updateLeaseName(oldName, newName);
|
||||
if (Residence.getConfigManager().enabledRentSystem())
|
||||
Residence.getRentManager().updateRentableName(oldName, newName);
|
||||
if (player != null)
|
||||
if (plugin.getConfigManager().useLeases()) {
|
||||
plugin.getLeaseManager().updateLeaseName(oldName, newName);
|
||||
}
|
||||
if (plugin.getConfigManager().enabledRentSystem()) {
|
||||
plugin.getRentManager().updateRentableName(oldName, newName);
|
||||
}
|
||||
if (player != null) {
|
||||
player.sendMessage(
|
||||
ChatColor.GREEN + Residence.getLanguage().getPhrase("ResidenceRename", ChatColor.YELLOW + oldName + ChatColor.GREEN + "." + ChatColor.YELLOW + newName + ChatColor.GREEN));
|
||||
ChatColor.GREEN + plugin.getLanguage().getPhrase("ResidenceRename", ChatColor.YELLOW + oldName + ChatColor.GREEN + "." + ChatColor.YELLOW + newName + ChatColor.GREEN));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
String[] oldname = oldName.split("\\.");
|
||||
ClaimedResidence parent = res.getParent();
|
||||
final String[] oldname = oldName.split("\\.");
|
||||
final ClaimedResidence parent = res.getParent();
|
||||
return parent.renameSubzone(player, oldname[oldname.length - 1], newName, resadmin);
|
||||
}
|
||||
} else {
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission"));
|
||||
if (player != null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean renameResidence(String oldName, String newName) {
|
||||
public boolean renameResidence(final String oldName, final String newName) {
|
||||
return this.renameResidence(null, oldName, newName, true);
|
||||
}
|
||||
|
||||
public Map<String, Object> save() {
|
||||
Map<String, Object> worldmap = new LinkedHashMap<String, Object>();
|
||||
for (World world : Residence.getServ().getWorlds()) {
|
||||
Map<String, Object> resmap = new LinkedHashMap<String, Object>();
|
||||
for (Entry<String, ClaimedResidence> res : residences.entrySet())
|
||||
if (res.getValue().getWorld().equals(world.getName()))
|
||||
final Map<String, Object> worldmap = new LinkedHashMap<String, Object>();
|
||||
for (final World world : plugin.getServ().getWorlds()) {
|
||||
final Map<String, Object> resmap = new LinkedHashMap<String, Object>();
|
||||
for (final Entry<String, ClaimedResidence> res : residences.entrySet()) {
|
||||
if (res.getValue().getWorld().equals(world.getName())) {
|
||||
try {
|
||||
resmap.put(res.getKey(), res.getValue().save());
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
System.out.println("[Residence] Failed to save residence (" + res.getKey() + ")!");
|
||||
Logger.getLogger(ResidenceManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
worldmap.put(world.getName(), resmap);
|
||||
}
|
||||
return worldmap;
|
||||
}
|
||||
|
||||
private void getResidenceList(String targetplayer, boolean showhidden, boolean showsubzones, String parentzone, String resname, ClaimedResidence res, ArrayList<String> list,
|
||||
boolean formattedOutput) {
|
||||
boolean hidden = res.getPermissions().has("hidden", false);
|
||||
private void getResidenceList(final String targetplayer, final boolean showhidden, final boolean showsubzones, final String parentzone, final String resname, final ClaimedResidence res,
|
||||
final ArrayList<String> list, final boolean formattedOutput) {
|
||||
final boolean hidden = res.getPermissions().has("hidden", false);
|
||||
if ((showhidden) || (!showhidden && !hidden)) {
|
||||
if (targetplayer == null || res.getPermissions().getOwner().equalsIgnoreCase(targetplayer))
|
||||
if (formattedOutput)
|
||||
list.add(ChatColor.GREEN + parentzone + resname + ChatColor.YELLOW + " - " + Residence.getLanguage().getPhrase("World") + ": " + res.getWorld());
|
||||
else
|
||||
if (targetplayer == null || res.getPermissions().getOwner().equalsIgnoreCase(targetplayer)) {
|
||||
if (formattedOutput) {
|
||||
list.add(ChatColor.GREEN + parentzone + resname + ChatColor.YELLOW + " - " + plugin.getLanguage().getPhrase("World") + ": " + res.getWorld());
|
||||
} else {
|
||||
list.add(parentzone + resname);
|
||||
if (showsubzones)
|
||||
for (Entry<String, ClaimedResidence> sz : res.subzones.entrySet())
|
||||
}
|
||||
}
|
||||
if (showsubzones) {
|
||||
for (final Entry<String, ClaimedResidence> sz : res.subzones.entrySet()) {
|
||||
this.getResidenceList(targetplayer, showhidden, showsubzones, parentzone + resname + ".", sz.getKey(), sz.getValue(), list, formattedOutput);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeAllByOwner(Player player, String owner, Map<String, ClaimedResidence> resholder) {
|
||||
Iterator<ClaimedResidence> it = resholder.values().iterator();
|
||||
private void removeAllByOwner(final Player player, final String owner, final Map<String, ClaimedResidence> resholder) {
|
||||
final Iterator<ClaimedResidence> it = resholder.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
ClaimedResidence res = it.next();
|
||||
final ClaimedResidence res = it.next();
|
||||
if (res.getOwner().equalsIgnoreCase(owner)) {
|
||||
ResidenceDeleteEvent resevent = new ResidenceDeleteEvent(player, res, player == null ? DeleteCause.OTHER : DeleteCause.PLAYER_DELETE);
|
||||
Residence.getServ().getPluginManager().callEvent(resevent);
|
||||
if (resevent.isCancelled())
|
||||
final ResidenceDeleteEvent resevent = new ResidenceDeleteEvent(player, res, player == null ? DeleteCause.OTHER : DeleteCause.PLAYER_DELETE);
|
||||
plugin.getServ().getPluginManager().callEvent(resevent);
|
||||
if (resevent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
removeChunkList(res.getName());
|
||||
it.remove();
|
||||
} else
|
||||
} else {
|
||||
this.removeAllByOwner(player, owner, res.subzones);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ChunkRef {
|
||||
|
||||
private final int z;
|
||||
|
||||
private final int x;
|
||||
|
||||
public ChunkRef(int x, int z) {
|
||||
private final int z;
|
||||
|
||||
public ChunkRef(final int x, final int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public ChunkRef(Location loc) {
|
||||
public ChunkRef(final Location loc) {
|
||||
this.x = getChunkCoord(loc.getBlockX());
|
||||
this.z = getChunkCoord(loc.getBlockZ());
|
||||
}
|
||||
@@ -645,13 +723,16 @@ public class ResidenceManager {
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj)
|
||||
if (this == obj) {
|
||||
return true;
|
||||
if (obj == null)
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
ChunkRef other = (ChunkRef) obj;
|
||||
}
|
||||
final ChunkRef other = (ChunkRef) obj;
|
||||
return this.x == other.x && this.z == other.z;
|
||||
}
|
||||
|
||||
@@ -665,7 +746,7 @@ public class ResidenceManager {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("{ x: ").append(x).append(", z: ").append(z).append(" }");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -31,148 +31,186 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
|
||||
protected String owner;
|
||||
|
||||
protected String world;
|
||||
protected ClaimedResidence residence;
|
||||
protected String world;
|
||||
Residence plugin;
|
||||
|
||||
public ResidencePermissions(ClaimedResidence res, String creator, String inworld) {
|
||||
this(res);
|
||||
public ResidencePermissions(final Residence plugin, final ClaimedResidence res) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
residence = res;
|
||||
}
|
||||
|
||||
public ResidencePermissions(final Residence plugin, final ClaimedResidence res, final String creator, final String inworld) {
|
||||
this(plugin, res);
|
||||
owner = creator;
|
||||
world = inworld;
|
||||
}
|
||||
|
||||
private ResidencePermissions(ClaimedResidence res) {
|
||||
residence = res;
|
||||
}
|
||||
|
||||
public static ResidencePermissions load(ClaimedResidence res, Map<String, Object> root) throws Exception {
|
||||
ResidencePermissions newperms = new ResidencePermissions(res);
|
||||
public static ResidencePermissions load(final Residence plugin, final ClaimedResidence res, final Map<String, Object> root) throws Exception {
|
||||
final ResidencePermissions newperms = new ResidencePermissions(plugin, res);
|
||||
newperms.owner = (String) root.get("Owner");
|
||||
if (newperms.owner == null)
|
||||
newperms.owner = (String) root.get("OwnerLastKnownName");
|
||||
if (newperms.owner == null) {
|
||||
Residence.getLog().warning("发现未知所有者的领地,转换为Server Land...");
|
||||
newperms.owner = (String) root.get("OwnerLastKnownName");
|
||||
}
|
||||
if (newperms.owner == null) {
|
||||
plugin.getLog().warning("发现未知所有者的领地,转换为Server Land...");
|
||||
newperms.owner = "Server Land";
|
||||
}
|
||||
newperms.world = (String) root.get("World");
|
||||
FlagPermissions.load(root, newperms);
|
||||
if (newperms.owner == null)
|
||||
if (newperms.owner == null) {
|
||||
throw new Exception("错误的Owner数据...");
|
||||
if (newperms.world == null)
|
||||
}
|
||||
if (newperms.world == null) {
|
||||
throw new Exception("错误的World数据...");
|
||||
if (newperms.playerFlags == null)
|
||||
}
|
||||
if (newperms.playerFlags == null) {
|
||||
throw new Exception("错误的PlayerFlags数据...");
|
||||
if (newperms.groupFlags == null)
|
||||
}
|
||||
if (newperms.groupFlags == null) {
|
||||
throw new Exception("错误的GroupFlags数据...");
|
||||
if (newperms.cuboidFlags == null)
|
||||
}
|
||||
if (newperms.cuboidFlags == null) {
|
||||
throw new Exception("错误的CuboidFlags数据...");
|
||||
}
|
||||
newperms.fixNames();
|
||||
return newperms;
|
||||
}
|
||||
|
||||
public void applyDefaultFlags() {
|
||||
PermissionManager gm = Residence.getPermissionManager();
|
||||
PermissionGroup group = gm.getGroup(owner, world);
|
||||
Set<Entry<String, Boolean>> dflags = group.getDefaultResidenceFlags();
|
||||
Set<Entry<String, Boolean>> dcflags = group.getDefaultCreatorFlags();
|
||||
Set<Entry<String, Map<String, Boolean>>> dgflags = group.getDefaultGroupFlags();
|
||||
final PermissionManager gm = plugin.getPermissionManager();
|
||||
final PermissionGroup group = gm.getGroup(owner, world);
|
||||
final Set<Entry<String, Boolean>> dflags = group.getDefaultResidenceFlags();
|
||||
final Set<Entry<String, Boolean>> dcflags = group.getDefaultCreatorFlags();
|
||||
final Set<Entry<String, Map<String, Boolean>>> dgflags = group.getDefaultGroupFlags();
|
||||
this.applyGlobalDefaults();
|
||||
for (Entry<String, Boolean> next : dflags)
|
||||
if (this.checkValidFlag(next.getKey(), true))
|
||||
if (next.getValue())
|
||||
for (final Entry<String, Boolean> next : dflags) {
|
||||
if (this.checkValidFlag(next.getKey(), true)) {
|
||||
if (next.getValue()) {
|
||||
this.setFlag(next.getKey(), FlagState.TRUE);
|
||||
else
|
||||
} else {
|
||||
this.setFlag(next.getKey(), FlagState.FALSE);
|
||||
for (Entry<String, Boolean> next : dcflags)
|
||||
if (this.checkValidFlag(next.getKey(), false))
|
||||
if (next.getValue())
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Entry<String, Boolean> next : dcflags) {
|
||||
if (this.checkValidFlag(next.getKey(), false)) {
|
||||
if (next.getValue()) {
|
||||
this.setPlayerFlag(owner, next.getKey(), FlagState.TRUE);
|
||||
else
|
||||
} else {
|
||||
this.setPlayerFlag(owner, next.getKey(), FlagState.FALSE);
|
||||
for (Entry<String, Map<String, Boolean>> entry : dgflags) {
|
||||
Map<String, Boolean> value = entry.getValue();
|
||||
for (Entry<String, Boolean> flag : value.entrySet())
|
||||
if (flag.getValue())
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Entry<String, Map<String, Boolean>> entry : dgflags) {
|
||||
final Map<String, Boolean> value = entry.getValue();
|
||||
for (final Entry<String, Boolean> flag : value.entrySet()) {
|
||||
if (flag.getValue()) {
|
||||
this.setGroupFlag(entry.getKey(), flag.getKey(), FlagState.TRUE);
|
||||
else
|
||||
} else {
|
||||
this.setGroupFlag(entry.getKey(), flag.getKey(), FlagState.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void applyDefaultFlags(Player player, boolean resadmin) {
|
||||
public void applyDefaultFlags(final Player player, final boolean resadmin) {
|
||||
if (this.hasResidencePermission(player, true) || resadmin) {
|
||||
this.applyDefaultFlags();
|
||||
player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("FlagsDefault"));
|
||||
} else
|
||||
player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("NoPermission"));
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("FlagsDefault"));
|
||||
} else {
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("NoPermission"));
|
||||
}
|
||||
}
|
||||
|
||||
public void applyGlobalDefaults() {
|
||||
this.clearFlags();
|
||||
FlagPermissions gRD = Residence.getConfigManager().getGlobalResidenceDefaultFlags();
|
||||
FlagPermissions gCD = Residence.getConfigManager().getGlobalCreatorDefaultFlags();
|
||||
Map<String, FlagPermissions> gGD = Residence.getConfigManager().getGlobalGroupDefaultFlags();
|
||||
for (Entry<String, Boolean> entry : gRD.cuboidFlags.entrySet())
|
||||
if (entry.getValue())
|
||||
final FlagPermissions gRD = plugin.getConfigManager().getGlobalResidenceDefaultFlags();
|
||||
final FlagPermissions gCD = plugin.getConfigManager().getGlobalCreatorDefaultFlags();
|
||||
final Map<String, FlagPermissions> gGD = plugin.getConfigManager().getGlobalGroupDefaultFlags();
|
||||
for (final Entry<String, Boolean> entry : gRD.cuboidFlags.entrySet()) {
|
||||
if (entry.getValue()) {
|
||||
this.setFlag(entry.getKey(), FlagState.TRUE);
|
||||
else
|
||||
} else {
|
||||
this.setFlag(entry.getKey(), FlagState.FALSE);
|
||||
for (Entry<String, Boolean> entry : gCD.cuboidFlags.entrySet())
|
||||
if (entry.getValue())
|
||||
}
|
||||
}
|
||||
for (final Entry<String, Boolean> entry : gCD.cuboidFlags.entrySet()) {
|
||||
if (entry.getValue()) {
|
||||
this.setPlayerFlag(owner, entry.getKey(), FlagState.TRUE);
|
||||
else
|
||||
} else {
|
||||
this.setPlayerFlag(owner, entry.getKey(), FlagState.FALSE);
|
||||
for (Entry<String, FlagPermissions> entry : gGD.entrySet())
|
||||
for (Entry<String, Boolean> flag : entry.getValue().cuboidFlags.entrySet())
|
||||
if (flag.getValue())
|
||||
}
|
||||
}
|
||||
for (final Entry<String, FlagPermissions> entry : gGD.entrySet()) {
|
||||
for (final Entry<String, Boolean> flag : entry.getValue().cuboidFlags.entrySet()) {
|
||||
if (flag.getValue()) {
|
||||
this.setGroupFlag(entry.getKey(), flag.getKey(), FlagState.TRUE);
|
||||
else
|
||||
} else {
|
||||
this.setGroupFlag(entry.getKey(), flag.getKey(), FlagState.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void applyTemplate(Player player, FlagPermissions list, boolean resadmin) {
|
||||
public void applyTemplate(final Player player, final FlagPermissions list, boolean resadmin) {
|
||||
if (player != null) {
|
||||
if (!player.getName().equals(owner) && !resadmin) {
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission"));
|
||||
return;
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
resadmin = true;
|
||||
PermissionGroup group = Residence.getPermissionManager().getGroup(owner, world);
|
||||
for (Entry<String, Boolean> flag : list.cuboidFlags.entrySet())
|
||||
if (group.hasFlagAccess(flag.getKey()) || resadmin)
|
||||
}
|
||||
final PermissionGroup group = plugin.getPermissionManager().getGroup(owner, world);
|
||||
for (final Entry<String, Boolean> flag : list.cuboidFlags.entrySet()) {
|
||||
if (group.hasFlagAccess(flag.getKey()) || resadmin) {
|
||||
this.cuboidFlags.put(flag.getKey(), flag.getValue());
|
||||
else if (player != null)
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("FlagSetDeny", ChatColor.YELLOW + flag.getKey() + ChatColor.RED));
|
||||
for (Entry<String, Map<String, Boolean>> plists : list.playerFlags.entrySet())
|
||||
for (Entry<String, Boolean> flag : plists.getValue().entrySet())
|
||||
} else if (player != null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("FlagSetDeny", ChatColor.YELLOW + flag.getKey() + ChatColor.RED));
|
||||
}
|
||||
}
|
||||
for (final Entry<String, Map<String, Boolean>> plists : list.playerFlags.entrySet()) {
|
||||
for (final Entry<String, Boolean> flag : plists.getValue().entrySet()) {
|
||||
if (group.hasFlagAccess(flag.getKey()) || resadmin) {
|
||||
if (!this.playerFlags.containsKey(plists.getKey()))
|
||||
if (!this.playerFlags.containsKey(plists.getKey())) {
|
||||
this.playerFlags.put(plists.getKey(), Collections.synchronizedMap(new HashMap<String, Boolean>()));
|
||||
}
|
||||
this.playerFlags.get(plists.getKey()).put(flag.getKey(), flag.getValue());
|
||||
} else if (player != null)
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("FlagSetDeny", ChatColor.YELLOW + flag.getKey() + ChatColor.RED));
|
||||
for (Entry<String, Map<String, Boolean>> glists : list.groupFlags.entrySet())
|
||||
for (Entry<String, Boolean> flag : glists.getValue().entrySet())
|
||||
} else if (player != null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("FlagSetDeny", ChatColor.YELLOW + flag.getKey() + ChatColor.RED));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Entry<String, Map<String, Boolean>> glists : list.groupFlags.entrySet()) {
|
||||
for (final Entry<String, Boolean> flag : glists.getValue().entrySet()) {
|
||||
if (group.hasFlagAccess(flag.getKey()) || resadmin) {
|
||||
if (!this.groupFlags.containsKey(glists.getKey()))
|
||||
if (!this.groupFlags.containsKey(glists.getKey())) {
|
||||
this.groupFlags.put(glists.getKey(), Collections.synchronizedMap(new HashMap<String, Boolean>()));
|
||||
}
|
||||
this.groupFlags.get(glists.getKey()).put(flag.getKey(), flag.getValue());
|
||||
} else if (player != null)
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("FlagSetDeny", ChatColor.YELLOW + flag.getKey() + ChatColor.RED));
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("PermissionsApply"));
|
||||
} else if (player != null) {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("FlagSetDeny", ChatColor.YELLOW + flag.getKey() + ChatColor.RED));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (player != null) {
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("PermissionsApply"));
|
||||
}
|
||||
}
|
||||
|
||||
public void fixNames() {
|
||||
ArrayList<String> fixNames = new ArrayList<String>();
|
||||
Iterator<Entry<String, Map<String, Boolean>>> it = playerFlags.entrySet().iterator();
|
||||
final ArrayList<String> fixNames = new ArrayList<String>();
|
||||
final Iterator<Entry<String, Map<String, Boolean>>> it = playerFlags.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
String name = it.next().getKey();
|
||||
if (!name.equals(name.toLowerCase()))
|
||||
final String name = it.next().getKey();
|
||||
if (!name.equals(name.toLowerCase())) {
|
||||
fixNames.add(name);
|
||||
}
|
||||
}
|
||||
for (String name : fixNames) {
|
||||
Map<String, Boolean> get = playerFlags.get(name);
|
||||
for (final String name : fixNames) {
|
||||
final Map<String, Boolean> get = playerFlags.get(name);
|
||||
playerFlags.remove(name);
|
||||
playerFlags.put(name.toLowerCase(), get);
|
||||
}
|
||||
@@ -187,79 +225,87 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupHas(String group, String flag, boolean def) {
|
||||
ResidenceFlagCheckEvent fc = new ResidenceFlagCheckEvent(residence, flag, FlagType.GROUP, group, def);
|
||||
Residence.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isOverriden())
|
||||
public boolean groupHas(final String group, final String flag, final boolean def) {
|
||||
final ResidenceFlagCheckEvent fc = new ResidenceFlagCheckEvent(residence, flag, FlagType.GROUP, group, def);
|
||||
plugin.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isOverriden()) {
|
||||
return fc.getOverrideValue();
|
||||
}
|
||||
return super.groupHas(group, flag, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(String flag, boolean def) {
|
||||
ResidenceFlagCheckEvent fc = new ResidenceFlagCheckEvent(residence, flag, FlagType.RESIDENCE, null, def);
|
||||
Residence.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isOverriden())
|
||||
public boolean has(final String flag, final boolean def) {
|
||||
final ResidenceFlagCheckEvent fc = new ResidenceFlagCheckEvent(residence, flag, FlagType.RESIDENCE, null, def);
|
||||
plugin.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isOverriden()) {
|
||||
return fc.getOverrideValue();
|
||||
}
|
||||
return super.has(flag, def);
|
||||
}
|
||||
|
||||
public boolean hasApplicableFlag(String player, String flag) {
|
||||
return super.inheritanceIsPlayerSet(player, flag) || super.inheritanceIsGroupSet(Residence.getPermissionManager().getGroupNameByPlayer(player, world), flag) || super.inheritanceIsSet(flag);
|
||||
public boolean hasApplicableFlag(final String player, final String flag) {
|
||||
return super.inheritanceIsPlayerSet(player, flag) || super.inheritanceIsGroupSet(plugin.getPermissionManager().getGroupNameByPlayer(player, world), flag) || super.inheritanceIsSet(flag);
|
||||
}
|
||||
|
||||
public boolean hasResidencePermission(Player player, boolean requireOwner) {
|
||||
if (Residence.getConfigManager().enabledRentSystem()) {
|
||||
String resname = residence.getName();
|
||||
if (Residence.getRentManager().isRented(resname)) {
|
||||
if (requireOwner)
|
||||
public boolean hasResidencePermission(final Player player, final boolean requireOwner) {
|
||||
if (plugin.getConfigManager().enabledRentSystem()) {
|
||||
final String resname = residence.getName();
|
||||
if (plugin.getRentManager().isRented(resname)) {
|
||||
if (requireOwner) {
|
||||
return false;
|
||||
String renter = Residence.getRentManager().getRentingPlayer(resname);
|
||||
if (player.getName().equalsIgnoreCase(renter))
|
||||
}
|
||||
final String renter = plugin.getRentManager().getRentingPlayer(resname);
|
||||
if (player.getName().equalsIgnoreCase(renter)) {
|
||||
return true;
|
||||
else
|
||||
} else {
|
||||
return (playerHas(player.getName(), "admin", false));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requireOwner)
|
||||
if (requireOwner) {
|
||||
return (owner.equalsIgnoreCase(player.getName()));
|
||||
}
|
||||
return (playerHas(player.getName(), "admin", false) || owner.equalsIgnoreCase(player.getName()));
|
||||
}
|
||||
|
||||
public boolean playerHas(String player, String flag, boolean def) {
|
||||
public boolean playerHas(final String player, final String flag, final boolean def) {
|
||||
return this.playerHas(player, world, flag, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerHas(String player, String world, String flag, boolean def) {
|
||||
ResidenceFlagCheckEvent fc = new ResidenceFlagCheckEvent(residence, flag, FlagType.PLAYER, player, def);
|
||||
Residence.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isOverriden())
|
||||
public boolean playerHas(final String player, final String world, final String flag, final boolean def) {
|
||||
final ResidenceFlagCheckEvent fc = new ResidenceFlagCheckEvent(residence, flag, FlagType.PLAYER, player, def);
|
||||
plugin.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isOverriden()) {
|
||||
return fc.getOverrideValue();
|
||||
}
|
||||
return super.playerHas(player, world, flag, def);
|
||||
}
|
||||
|
||||
public boolean removeAllGroupFlags(Player player, String group, boolean resadmin) {
|
||||
public boolean removeAllGroupFlags(final Player player, final String group, final boolean resadmin) {
|
||||
if (this.hasResidencePermission(player, false) || resadmin) {
|
||||
ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, "ALL", ResidenceFlagChangeEvent.FlagType.GROUP, FlagState.NEITHER, null);
|
||||
Residence.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled())
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, "ALL", ResidenceFlagChangeEvent.FlagType.GROUP, FlagState.NEITHER, null);
|
||||
plugin.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
super.removeAllGroupFlags(group);
|
||||
player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("FlagSet"));
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("FlagSet"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeAllPlayerFlags(Player player, String targetPlayer, boolean resadmin) {
|
||||
public boolean removeAllPlayerFlags(final Player player, final String targetPlayer, final boolean resadmin) {
|
||||
if (this.hasResidencePermission(player, false) || resadmin) {
|
||||
ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, "ALL", ResidenceFlagChangeEvent.FlagType.RESIDENCE, FlagState.NEITHER, null);
|
||||
Residence.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled())
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, "ALL", ResidenceFlagChangeEvent.FlagType.RESIDENCE, FlagState.NEITHER, null);
|
||||
plugin.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
super.removeAllPlayerFlags(targetPlayer);
|
||||
player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("FlagSet"));
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("FlagSet"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -267,23 +313,25 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> save() {
|
||||
Map<String, Object> root = super.save();
|
||||
final Map<String, Object> root = super.save();
|
||||
root.put("Owner", owner);
|
||||
root.put("World", world);
|
||||
return root;
|
||||
}
|
||||
|
||||
public boolean setFlag(Player player, String flag, String flagstate, boolean resadmin) {
|
||||
if (validFlagGroups.containsKey(flag))
|
||||
public boolean setFlag(final Player player, final String flag, final String flagstate, final boolean resadmin) {
|
||||
if (validFlagGroups.containsKey(flag)) {
|
||||
return this.setFlagGroup(player, flag, flagstate, resadmin);
|
||||
FlagState state = FlagPermissions.stringToFlagState(flagstate);
|
||||
}
|
||||
final FlagState state = FlagPermissions.stringToFlagState(flagstate);
|
||||
if (checkCanSetFlag(player, flag, state, true, resadmin)) {
|
||||
ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, flag, ResidenceFlagChangeEvent.FlagType.RESIDENCE, state, null);
|
||||
Residence.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled())
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, flag, ResidenceFlagChangeEvent.FlagType.RESIDENCE, state, null);
|
||||
plugin.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
if (super.setFlag(flag, state)) {
|
||||
player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("FlagSet"));
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("FlagSet"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -291,100 +339,114 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setFlag(String flag, FlagState state) {
|
||||
ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, null, flag, ResidenceFlagChangeEvent.FlagType.RESIDENCE, state, null);
|
||||
Residence.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled())
|
||||
public boolean setFlag(final String flag, final FlagState state) {
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, null, flag, ResidenceFlagChangeEvent.FlagType.RESIDENCE, state, null);
|
||||
plugin.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
return super.setFlag(flag, state);
|
||||
}
|
||||
|
||||
public boolean setFlagGroup(Player player, String flaggroup, String state, boolean resadmin) {
|
||||
public boolean setFlagGroup(final Player player, final String flaggroup, final String state, final boolean resadmin) {
|
||||
if (ResidencePermissions.validFlagGroups.containsKey(flaggroup)) {
|
||||
ArrayList<String> flags = ResidencePermissions.validFlagGroups.get(flaggroup);
|
||||
final ArrayList<String> flags = ResidencePermissions.validFlagGroups.get(flaggroup);
|
||||
boolean changed = false;
|
||||
for (String flag : flags)
|
||||
if (this.setFlag(player, flag, state, resadmin))
|
||||
for (final String flag : flags) {
|
||||
if (this.setFlag(player, flag, state, resadmin)) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean setFlagGroupOnGroup(Player player, String flaggroup, String group, String state, boolean resadmin) {
|
||||
public boolean setFlagGroupOnGroup(final Player player, final String flaggroup, final String group, final String state, final boolean resadmin) {
|
||||
if (ResidencePermissions.validFlagGroups.containsKey(flaggroup)) {
|
||||
ArrayList<String> flags = ResidencePermissions.validFlagGroups.get(flaggroup);
|
||||
final ArrayList<String> flags = ResidencePermissions.validFlagGroups.get(flaggroup);
|
||||
boolean changed = false;
|
||||
for (String flag : flags)
|
||||
if (this.setGroupFlag(player, group, flag, state, resadmin))
|
||||
for (final String flag : flags) {
|
||||
if (this.setGroupFlag(player, group, flag, state, resadmin)) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean setFlagGroupOnPlayer(Player player, String target, String flaggroup, String state, boolean resadmin) {
|
||||
public boolean setFlagGroupOnPlayer(final Player player, final String target, final String flaggroup, final String state, final boolean resadmin) {
|
||||
if (ResidencePermissions.validFlagGroups.containsKey(flaggroup)) {
|
||||
ArrayList<String> flags = ResidencePermissions.validFlagGroups.get(flaggroup);
|
||||
final ArrayList<String> flags = ResidencePermissions.validFlagGroups.get(flaggroup);
|
||||
boolean changed = false;
|
||||
for (String flag : flags)
|
||||
if (this.setPlayerFlag(player, target, flag, state, resadmin))
|
||||
for (final String flag : flags) {
|
||||
if (this.setPlayerFlag(player, target, flag, state, resadmin)) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean setGroupFlag(Player player, String group, String flag, String flagstate, boolean resadmin) {
|
||||
public boolean setGroupFlag(final Player player, String group, final String flag, final String flagstate, final boolean resadmin) {
|
||||
group = group.toLowerCase();
|
||||
if (validFlagGroups.containsKey(flag))
|
||||
if (validFlagGroups.containsKey(flag)) {
|
||||
return this.setFlagGroupOnGroup(player, flag, group, flagstate, resadmin);
|
||||
FlagState state = FlagPermissions.stringToFlagState(flagstate);
|
||||
if (checkCanSetFlag(player, flag, state, false, resadmin))
|
||||
if (Residence.getPermissionManager().hasGroup(group)) {
|
||||
ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, flag, ResidenceFlagChangeEvent.FlagType.GROUP, state, group);
|
||||
Residence.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled())
|
||||
}
|
||||
final FlagState state = FlagPermissions.stringToFlagState(flagstate);
|
||||
if (checkCanSetFlag(player, flag, state, false, resadmin)) {
|
||||
if (plugin.getPermissionManager().hasGroup(group)) {
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, flag, ResidenceFlagChangeEvent.FlagType.GROUP, state, group);
|
||||
plugin.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
if (super.setGroupFlag(group, flag, state)) {
|
||||
player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("FlagSet"));
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("FlagSet"));
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidGroup"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidGroup"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setGroupFlag(String group, String flag, FlagState state) {
|
||||
ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, null, flag, ResidenceFlagChangeEvent.FlagType.GROUP, state, group);
|
||||
Residence.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled())
|
||||
public boolean setGroupFlag(final String group, final String flag, final FlagState state) {
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, null, flag, ResidenceFlagChangeEvent.FlagType.GROUP, state, group);
|
||||
plugin.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
return super.setGroupFlag(group, flag, state);
|
||||
}
|
||||
|
||||
public void setOwner(String newOwner, boolean resetFlags) {
|
||||
ResidenceOwnerChangeEvent ownerchange = new ResidenceOwnerChangeEvent(residence, newOwner);
|
||||
Residence.getServ().getPluginManager().callEvent(ownerchange);
|
||||
public void setOwner(final String newOwner, final boolean resetFlags) {
|
||||
final ResidenceOwnerChangeEvent ownerchange = new ResidenceOwnerChangeEvent(residence, newOwner);
|
||||
plugin.getServ().getPluginManager().callEvent(ownerchange);
|
||||
owner = newOwner;
|
||||
if (resetFlags)
|
||||
if (resetFlags) {
|
||||
this.applyDefaultFlags();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setPlayerFlag(Player player, String targetPlayer, String flag, String flagstate, boolean resadmin) {
|
||||
if (validFlagGroups.containsKey(flag))
|
||||
public boolean setPlayerFlag(final Player player, final String targetPlayer, final String flag, final String flagstate, final boolean resadmin) {
|
||||
if (validFlagGroups.containsKey(flag)) {
|
||||
return this.setFlagGroupOnPlayer(player, targetPlayer, flag, flagstate, resadmin);
|
||||
FlagState state = FlagPermissions.stringToFlagState(flagstate);
|
||||
}
|
||||
final FlagState state = FlagPermissions.stringToFlagState(flagstate);
|
||||
if (checkCanSetFlag(player, flag, state, false, resadmin)) {
|
||||
ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, flag, ResidenceFlagChangeEvent.FlagType.PLAYER, state, targetPlayer);
|
||||
Residence.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled())
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, flag, ResidenceFlagChangeEvent.FlagType.PLAYER, state, targetPlayer);
|
||||
plugin.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
if (super.setPlayerFlag(targetPlayer, flag, state)) {
|
||||
player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("FlagSet"));
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("FlagSet"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -392,38 +454,39 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setPlayerFlag(String player, String flag, FlagState state) {
|
||||
ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, null, flag, ResidenceFlagChangeEvent.FlagType.PLAYER, state, player);
|
||||
Residence.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled())
|
||||
public boolean setPlayerFlag(final String player, final String flag, final FlagState state) {
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, null, flag, ResidenceFlagChangeEvent.FlagType.PLAYER, state, player);
|
||||
plugin.getServ().getPluginManager().callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
return super.setPlayerFlag(player, flag, state);
|
||||
}
|
||||
|
||||
private boolean checkCanSetFlag(Player player, String flag, FlagState state, boolean globalflag, boolean resadmin) {
|
||||
private boolean checkCanSetFlag(final Player player, final String flag, final FlagState state, final boolean globalflag, final boolean resadmin) {
|
||||
if (!checkValidFlag(flag, globalflag)) {
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidFlag"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidFlag"));
|
||||
return false;
|
||||
}
|
||||
if (state == FlagState.INVALID) {
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidFlagState"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidFlagState"));
|
||||
return false;
|
||||
}
|
||||
if (!resadmin) {
|
||||
if (!this.hasResidencePermission(player, false)) {
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission"));
|
||||
return false;
|
||||
}
|
||||
if (!hasFlagAccess(owner, flag)) {
|
||||
player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("OwnerNoPermission"));
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("OwnerNoPermission"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasFlagAccess(String player, String flag) {
|
||||
PermissionGroup group = Residence.getPermissionManager().getGroup(player, world);
|
||||
private boolean hasFlagAccess(final String player, final String flag) {
|
||||
final PermissionGroup group = plugin.getPermissionManager().getGroup(player, world);
|
||||
return group.hasFlagAccess(flag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,34 +22,36 @@ import com.bekvon.bukkit.residence.Residence;
|
||||
* @author Administrator
|
||||
*/
|
||||
public class WorldFlagManager {
|
||||
protected FlagPermissions globaldefaults;
|
||||
protected Map<String, Map<String, FlagPermissions>> groupperms;
|
||||
protected Map<String, FlagPermissions> worldperms;
|
||||
protected FlagPermissions globaldefaults;
|
||||
Residence plugin;
|
||||
|
||||
public WorldFlagManager() {
|
||||
globaldefaults = new FlagPermissions();
|
||||
public WorldFlagManager(final Residence plugin) {
|
||||
this.plugin = plugin;
|
||||
globaldefaults = new FlagPermissions(plugin);
|
||||
worldperms = new HashMap<String, FlagPermissions>();
|
||||
groupperms = new HashMap<String, Map<String, FlagPermissions>>();
|
||||
}
|
||||
|
||||
public WorldFlagManager(FileConfiguration config) {
|
||||
this();
|
||||
public WorldFlagManager(final Residence plugin, final FileConfiguration config) {
|
||||
this(plugin);
|
||||
this.parsePerms(config);
|
||||
}
|
||||
|
||||
public FlagPermissions getPerms(Player player) {
|
||||
return this.getPerms(player.getWorld().getName(), Residence.getPermissionManager()
|
||||
.getGroupNameByPlayer(player));
|
||||
public FlagPermissions getPerms(final Player player) {
|
||||
return this.getPerms(player.getWorld().getName(), plugin.getPermissionManager().getGroupNameByPlayer(player));
|
||||
}
|
||||
|
||||
public FlagPermissions getPerms(String world) {
|
||||
world = world.toLowerCase();
|
||||
FlagPermissions list = worldperms.get(world);
|
||||
final FlagPermissions list = worldperms.get(world);
|
||||
if (list == null) {
|
||||
if (globaldefaults == null)
|
||||
return new FlagPermissions();
|
||||
else
|
||||
if (globaldefaults == null) {
|
||||
return new FlagPermissions(plugin);
|
||||
} else {
|
||||
return globaldefaults;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -57,76 +59,64 @@ public class WorldFlagManager {
|
||||
public FlagPermissions getPerms(String world, String group) {
|
||||
world = world.toLowerCase();
|
||||
group = group.toLowerCase();
|
||||
Map<String, FlagPermissions> groupworldperms = groupperms.get(group);
|
||||
if (groupworldperms == null)
|
||||
final Map<String, FlagPermissions> groupworldperms = groupperms.get(group);
|
||||
if (groupworldperms == null) {
|
||||
return this.getPerms(world);
|
||||
}
|
||||
FlagPermissions list = groupworldperms.get(world);
|
||||
if (list == null) {
|
||||
list = groupworldperms.get("global." + world);
|
||||
if (list == null) {
|
||||
list = groupworldperms.get("global");
|
||||
}
|
||||
if (list == null)
|
||||
if (list == null) {
|
||||
return this.getPerms(world);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void parsePerms(FileConfiguration config) {
|
||||
public void parsePerms(final FileConfiguration config) {
|
||||
try {
|
||||
|
||||
Set<String> keys = config.getConfigurationSection("Global.Flags").getKeys(false);
|
||||
if (keys != null) {
|
||||
for (String key : keys) {
|
||||
for (final String key : keys) {
|
||||
if (key.equalsIgnoreCase("Global")) {
|
||||
globaldefaults = FlagPermissions.parseFromConfigNode(key,
|
||||
config.getConfigurationSection("Global.Flags"));
|
||||
globaldefaults = FlagPermissions.parseFromConfigNode(key, config.getConfigurationSection("Global.Flags"));
|
||||
} else {
|
||||
worldperms.put(
|
||||
key.toLowerCase(),
|
||||
FlagPermissions.parseFromConfigNode(key,
|
||||
config.getConfigurationSection("Global.Flags")));
|
||||
worldperms.put(key.toLowerCase(), FlagPermissions.parseFromConfigNode(key, config.getConfigurationSection("Global.Flags")));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Entry<String, FlagPermissions> entry : worldperms.entrySet()) {
|
||||
for (final Entry<String, FlagPermissions> entry : worldperms.entrySet()) {
|
||||
entry.getValue().setParent(globaldefaults);
|
||||
}
|
||||
keys = config.getConfigurationSection("Groups").getKeys(false);
|
||||
if (keys != null) {
|
||||
for (String key : keys) {
|
||||
ConfigurationSection worldkeylist = config.getConfigurationSection("Groups."
|
||||
+ key + ".Flags.World");
|
||||
for (final String key : keys) {
|
||||
final ConfigurationSection worldkeylist = config.getConfigurationSection("Groups." + key + ".Flags.World");
|
||||
if (worldkeylist != null) {
|
||||
Set<String> worldkeys = config.getConfigurationSection(
|
||||
"Groups." + key + ".Flags.World").getKeys(false);
|
||||
final Set<String> worldkeys = config.getConfigurationSection("Groups." + key + ".Flags.World").getKeys(false);
|
||||
if (worldkeys != null) {
|
||||
Map<String, FlagPermissions> perms = new HashMap<String, FlagPermissions>();
|
||||
for (String wkey : worldkeys) {
|
||||
FlagPermissions list = FlagPermissions.parseFromConfigNode(
|
||||
wkey,
|
||||
config.getConfigurationSection("Groups." + key
|
||||
+ ".Flags.World"));
|
||||
final Map<String, FlagPermissions> perms = new HashMap<String, FlagPermissions>();
|
||||
for (final String wkey : worldkeys) {
|
||||
FlagPermissions list = FlagPermissions.parseFromConfigNode(wkey, config.getConfigurationSection("Groups." + key + ".Flags.World"));
|
||||
if (wkey.equalsIgnoreCase("global")) {
|
||||
list.setParent(globaldefaults);
|
||||
perms.put(wkey.toLowerCase(), list);
|
||||
for (Entry<String, FlagPermissions> worldperm : worldperms
|
||||
.entrySet()) {
|
||||
list = FlagPermissions.parseFromConfigNode(
|
||||
wkey,
|
||||
config.getConfigurationSection("Groups." + key
|
||||
+ ".Flags.World"));
|
||||
for (final Entry<String, FlagPermissions> worldperm : worldperms.entrySet()) {
|
||||
list = FlagPermissions.parseFromConfigNode(wkey, config.getConfigurationSection("Groups." + key + ".Flags.World"));
|
||||
list.setParent(worldperm.getValue());
|
||||
perms.put("global." + worldperm.getKey().toLowerCase(),
|
||||
list);
|
||||
perms.put("global." + worldperm.getKey().toLowerCase(), list);
|
||||
}
|
||||
} else {
|
||||
perms.put(wkey.toLowerCase(), list);
|
||||
}
|
||||
}
|
||||
for (Entry<String, FlagPermissions> entry : perms.entrySet()) {
|
||||
String wkey = entry.getKey();
|
||||
FlagPermissions list = entry.getValue();
|
||||
for (final Entry<String, FlagPermissions> entry : perms.entrySet()) {
|
||||
final String wkey = entry.getKey();
|
||||
final FlagPermissions list = entry.getValue();
|
||||
if (!wkey.startsWith("global.")) {
|
||||
list.setParent(perms.get("global." + wkey));
|
||||
if (list.getParent() == null) {
|
||||
@@ -142,7 +132,7 @@ public class WorldFlagManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
Logger.getLogger(WorldFlagManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user