mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
Started work on WorldEdit protected area support.
This commit is contained in:
parent
18ed009ddd
commit
4cde6a53ba
@ -7,7 +7,6 @@ import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Pattern;
|
||||
import me.StevenLawson.TotalFreedomMod.*;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.EntryType;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -263,6 +262,11 @@ public class TFM_PlayerListener implements Listener
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getMaterial() == Material.WOOD_AXE)
|
||||
{
|
||||
TFM_WorldEditBridge.getInstance().validateSelection(player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
|
@ -12,6 +12,7 @@ import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class TFM_ProtectedArea implements Serializable
|
||||
{
|
||||
@ -49,6 +50,67 @@ public class TFM_ProtectedArea implements Serializable
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isInProtectedArea(Vector min, Vector max, String worldName)
|
||||
{
|
||||
for (Map.Entry<String, TFM_ProtectedArea> protectedArea : TFM_ProtectedArea.protectedAreas.entrySet())
|
||||
{
|
||||
Location protectedAreaCenter = SerializableLocation.returnLocation(protectedArea.getValue().center);
|
||||
if (protectedAreaCenter != null)
|
||||
{
|
||||
if (worldName.equals(protectedAreaCenter.getWorld().getName()))
|
||||
{
|
||||
double sphereRadius = protectedArea.getValue().radius;
|
||||
Vector sphereCenter = protectedAreaCenter.toVector();
|
||||
if (cubeIntersectsSphere(min, max, sphereCenter, sphereRadius))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
//
|
||||
|
||||
private static boolean cubeIntersectsSphere(Vector min, Vector max, Vector sphere, double radius)
|
||||
{
|
||||
double d = square(radius);
|
||||
|
||||
if (sphere.getX() < min.getX())
|
||||
{
|
||||
d -= square(sphere.getX() - min.getX());
|
||||
}
|
||||
else if (sphere.getX() > max.getX())
|
||||
{
|
||||
d -= square(sphere.getX() - max.getX());
|
||||
}
|
||||
if (sphere.getY() < min.getY())
|
||||
{
|
||||
d -= square(sphere.getY() - min.getY());
|
||||
}
|
||||
else if (sphere.getY() > max.getY())
|
||||
{
|
||||
d -= square(sphere.getY() - max.getY());
|
||||
}
|
||||
if (sphere.getZ() < min.getZ())
|
||||
{
|
||||
d -= square(sphere.getZ() - min.getZ());
|
||||
}
|
||||
else if (sphere.getZ() > max.getZ())
|
||||
{
|
||||
d -= square(sphere.getZ() - max.getZ());
|
||||
}
|
||||
|
||||
return d > 0;
|
||||
}
|
||||
|
||||
private static double square(double v)
|
||||
{
|
||||
return v * v;
|
||||
}
|
||||
|
||||
//
|
||||
public static void addProtectedArea(String label, Location location, double radius)
|
||||
{
|
||||
TFM_ProtectedArea.protectedAreas.put(label.toLowerCase(), new TFM_ProtectedArea(location, radius));
|
||||
|
@ -1,8 +1,10 @@
|
||||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -111,6 +113,35 @@ public class TFM_WorldEditBridge
|
||||
}
|
||||
}
|
||||
|
||||
public void validateSelection(Player player)
|
||||
{
|
||||
try
|
||||
{
|
||||
LocalSession session = getPlayerSession(player);
|
||||
if (session != null)
|
||||
{
|
||||
LocalWorld selectionWorld = session.getSelectionWorld();
|
||||
Region selection = session.getSelection(selectionWorld);
|
||||
if (TFM_ProtectedArea.isInProtectedArea(
|
||||
getBukkitVector(selection.getMinimumPoint()),
|
||||
getBukkitVector(selection.getMaximumPoint()),
|
||||
selectionWorld.getName()))
|
||||
{
|
||||
TFM_Util.bcastMsg("(DEBUG MSG: " + player.getName() + " has selected part of a protected area.");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TFM_Log.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static org.bukkit.util.Vector getBukkitVector(com.sk89q.worldedit.Vector worldEditVector)
|
||||
{
|
||||
return new org.bukkit.util.Vector(worldEditVector.getX(), worldEditVector.getY(), worldEditVector.getZ());
|
||||
}
|
||||
|
||||
public static TFM_WorldEditBridge getInstance()
|
||||
{
|
||||
return TFM_WorldEditBridgeHolder.INSTANCE;
|
||||
|
Loading…
Reference in New Issue
Block a user