PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java

86 lines
2.3 KiB
Java
Raw Normal View History

2015-01-26 05:16:10 +01:00
package com.intellectualcrafters.plot.object;
2015-01-26 06:05:56 +01:00
import java.util.HashSet;
2015-01-26 05:16:10 +01:00
import java.util.UUID;
2015-07-30 16:25:16 +02:00
import com.intellectualcrafters.plot.database.DBFunc;
2015-01-26 05:16:10 +01:00
public class PlotCluster {
2015-02-20 07:34:19 +01:00
public final String world;
public PlotSettings settings;
public UUID owner;
public HashSet<UUID> helpers = new HashSet<UUID>();
public HashSet<UUID> invited = new HashSet<UUID>();
private PlotId pos1;
private PlotId pos2;
2015-02-23 02:32:27 +01:00
2015-02-20 07:34:19 +01:00
public PlotId getP1() {
return this.pos1;
}
2015-02-23 02:32:27 +01:00
2015-02-20 07:34:19 +01:00
public PlotId getP2() {
return this.pos2;
}
2015-02-23 02:32:27 +01:00
2015-02-20 07:34:19 +01:00
public void setP1(final PlotId id) {
this.pos1 = id;
}
2015-02-23 02:32:27 +01:00
2015-02-20 07:34:19 +01:00
public void setP2(final PlotId id) {
this.pos2 = id;
}
2015-04-07 15:21:51 +02:00
2015-02-20 07:34:19 +01:00
public PlotCluster(final String world, final PlotId pos1, final PlotId pos2, final UUID owner) {
this.world = world;
this.pos1 = pos1;
this.pos2 = pos2;
this.owner = owner;
this.settings = new PlotSettings(null);
}
2015-02-23 02:32:27 +01:00
2015-04-07 15:21:51 +02:00
public boolean isAdded(final UUID uuid) {
2015-02-20 07:34:19 +01:00
return (this.owner.equals(uuid) || this.invited.contains(uuid) || this.invited.contains(DBFunc.everyone) || this.helpers.contains(uuid) || this.helpers.contains(DBFunc.everyone));
}
2015-02-23 02:32:27 +01:00
2015-02-20 07:34:19 +01:00
public boolean hasHelperRights(final UUID uuid) {
return (this.owner.equals(uuid) || this.helpers.contains(uuid) || this.helpers.contains(DBFunc.everyone));
}
2015-02-23 02:32:27 +01:00
2015-02-20 07:34:19 +01:00
public String getName() {
return this.settings.getAlias();
}
2015-08-28 08:28:55 +02:00
/**
* Get the area (in plots)
* @return
*/
public int getArea() {
return (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
}
2015-02-23 02:32:27 +01:00
2015-02-20 07:34:19 +01:00
@Override
public int hashCode() {
return this.pos1.hashCode();
}
2015-02-23 02:32:27 +01:00
2015-02-20 07:34:19 +01:00
@Override
public boolean equals(final Object obj) {
if (this == obj) {
2015-01-29 04:20:29 +01:00
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PlotCluster other = (PlotCluster) obj;
return (this.world.equals(other.world) && this.pos1.equals(other.pos1) && this.pos2.equals(other.pos2));
2015-02-20 07:34:19 +01:00
}
2015-02-23 02:32:27 +01:00
2015-02-20 07:34:19 +01:00
@Override
public String toString() {
return this.world + ";" + this.pos1.x + ";" + this.pos1.y + ";" + this.pos2.x + ";" + this.pos2.y;
}
2015-01-26 05:16:10 +01:00
}