2011-07-18 22:06:02 +02:00
|
|
|
package com.massivecraft.factions;
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2011-04-08 21:01:46 +02:00
|
|
|
import java.util.HashSet;
|
2011-11-27 22:47:40 +01:00
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.Set;
|
2011-04-08 21:01:46 +02:00
|
|
|
|
2011-11-27 22:47:40 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2011-03-19 13:00:03 +01:00
|
|
|
import org.bukkit.Location;
|
2011-11-27 22:47:40 +01:00
|
|
|
import org.bukkit.World;
|
2011-03-19 13:00:03 +01:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
2011-07-18 22:06:02 +02:00
|
|
|
|
|
|
|
import com.massivecraft.factions.util.MiscUtil;
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public class FLocation
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
|
|
|
|
private String worldName = "world";
|
2011-03-22 17:20:21 +01:00
|
|
|
private int x = 0;
|
|
|
|
private int z = 0;
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2011-10-24 03:02:25 +02:00
|
|
|
// TODO: It would be wise to ask yourself is there is a better solution to creating loads of new object
|
|
|
|
// This object is create many times.
|
2011-03-19 13:00:03 +01:00
|
|
|
|
|
|
|
//----------------------------------------------//
|
|
|
|
// Constructors
|
|
|
|
//----------------------------------------------//
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public FLocation()
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public FLocation(String worldName, int x, int z)
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
this.worldName = worldName;
|
|
|
|
this.x = x;
|
|
|
|
this.z = z;
|
|
|
|
}
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public FLocation(Location location)
|
|
|
|
{
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
// this(location.getWorld().getName(), (int) Math.floor(location.getX() / cellSize) , (int) Math.floor(location.getZ() / cellSize));
|
|
|
|
// handy dandy rapid bitshifting instead of division
|
|
|
|
this(location.getWorld().getName(), location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
2011-03-19 13:00:03 +01:00
|
|
|
}
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public FLocation(Player player)
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
this(player.getLocation());
|
|
|
|
}
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public FLocation(FPlayer fplayer)
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
this(fplayer.getPlayer());
|
|
|
|
}
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public FLocation(Block block)
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
this(block.getLocation());
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------//
|
|
|
|
// Getters and Setters
|
|
|
|
//----------------------------------------------//
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public String getWorldName()
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
return worldName;
|
|
|
|
}
|
2011-11-27 22:47:40 +01:00
|
|
|
|
|
|
|
public World getWorld()
|
|
|
|
{
|
|
|
|
return Bukkit.getWorld(worldName);
|
|
|
|
}
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public void setWorldName(String worldName)
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
this.worldName = worldName;
|
|
|
|
}
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public long getX()
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public void setX(int x)
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
this.x = x;
|
|
|
|
}
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public long getZ()
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public void setZ(int z)
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
this.z = z;
|
|
|
|
}
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public String getCoordString()
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
return ""+x+","+z;
|
|
|
|
}
|
2011-03-23 12:45:21 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "["+this.getWorldName()+","+this.getCoordString()+"]";
|
|
|
|
}
|
2011-03-19 13:00:03 +01:00
|
|
|
|
|
|
|
//----------------------------------------------//
|
2011-04-08 21:01:46 +02:00
|
|
|
// Misc Geometry
|
2011-03-19 13:00:03 +01:00
|
|
|
//----------------------------------------------//
|
|
|
|
|
2011-11-27 22:47:40 +01:00
|
|
|
public FLocation getRelative(int dx, int dz)
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
return new FLocation(this.worldName, this.x + dx, this.z + dz);
|
|
|
|
}
|
2011-11-27 22:47:40 +01:00
|
|
|
|
|
|
|
public double getDistanceTo(FLocation that)
|
|
|
|
{
|
|
|
|
double dx = that.x - this.x;
|
|
|
|
double dz = that.z - this.z;
|
|
|
|
return Math.sqrt(dx*dx+dz*dz);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------//
|
|
|
|
// Some Geometry
|
|
|
|
//----------------------------------------------//
|
|
|
|
public Set<FLocation> getCircle(double radius)
|
|
|
|
{
|
|
|
|
Set<FLocation> ret = new LinkedHashSet<FLocation>();
|
|
|
|
if (radius <= 0) return ret;
|
|
|
|
|
|
|
|
int xfrom = (int) Math.floor(this.x - radius);
|
|
|
|
int xto = (int) Math.ceil(this.x + radius);
|
|
|
|
int zfrom = (int) Math.floor(this.z - radius);
|
|
|
|
int zto = (int) Math.ceil(this.z + radius);
|
|
|
|
|
|
|
|
for (int x=xfrom; x<=xto; x++)
|
|
|
|
{
|
|
|
|
for (int z=zfrom; z<=zto; z++)
|
|
|
|
{
|
|
|
|
FLocation potential = new FLocation(this.worldName, x, z);
|
|
|
|
if (this.getDistanceTo(potential) <= radius)
|
|
|
|
{
|
|
|
|
ret.add(potential);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
public static HashSet<FLocation> getArea(FLocation from, FLocation to)
|
|
|
|
{
|
2011-04-08 21:01:46 +02:00
|
|
|
HashSet<FLocation> ret = new HashSet<FLocation>();
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
for (long x : MiscUtil.range(from.getX(), to.getX()))
|
|
|
|
{
|
|
|
|
for (long z : MiscUtil.range(from.getZ(), to.getZ()))
|
|
|
|
{
|
2011-04-08 21:01:46 +02:00
|
|
|
ret.add(new FLocation(from.getWorldName(), (int)x, (int)z));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-19 13:00:03 +01:00
|
|
|
//----------------------------------------------//
|
|
|
|
// Comparison
|
|
|
|
//----------------------------------------------//
|
|
|
|
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
@Override
|
2011-10-09 18:35:39 +02:00
|
|
|
public int hashCode()
|
|
|
|
{
|
2011-03-23 12:00:38 +01:00
|
|
|
int hash = 3;
|
|
|
|
hash = 19 * hash + (this.worldName != null ? this.worldName.hashCode() : 0);
|
|
|
|
hash = 19 * hash + this.x;
|
|
|
|
hash = 19 * hash + this.z;
|
|
|
|
return hash;
|
|
|
|
};
|
|
|
|
|
2011-03-19 13:00:03 +01:00
|
|
|
@Override
|
2011-10-09 18:35:39 +02:00
|
|
|
public boolean equals(Object obj)
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
if (obj == this)
|
|
|
|
return true;
|
|
|
|
if (!(obj instanceof FLocation))
|
|
|
|
return false;
|
|
|
|
|
2011-03-23 12:00:38 +01:00
|
|
|
FLocation that = (FLocation) obj;
|
|
|
|
return this.x == that.x && this.z == that.z && ( this.worldName==null ? that.worldName==null : this.worldName.equals(that.worldName) );
|
2011-03-19 13:00:03 +01:00
|
|
|
}
|
|
|
|
}
|