mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-03 22:11:42 +01:00
Merge branch 'refs/heads/2.9' into release
This commit is contained in:
commit
610fae63d2
@ -285,6 +285,45 @@ public class Util
|
|||||||
}
|
}
|
||||||
return block.getLocation();
|
return block.getLocation();
|
||||||
}
|
}
|
||||||
|
public final static int RADIUS = 3;
|
||||||
|
public final static Vector3D[] VOLUME;
|
||||||
|
|
||||||
|
public static class Vector3D
|
||||||
|
{
|
||||||
|
public Vector3D(int x, int y, int z)
|
||||||
|
{
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
public int x;
|
||||||
|
public int y;
|
||||||
|
public int z;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
List<Vector3D> pos = new ArrayList<Vector3D>();
|
||||||
|
for (int x = -RADIUS; x <= RADIUS; x++)
|
||||||
|
{
|
||||||
|
for (int y = -RADIUS; y <= RADIUS; y++)
|
||||||
|
{
|
||||||
|
for (int z = -RADIUS; z <= RADIUS; z++)
|
||||||
|
{
|
||||||
|
pos.add(new Vector3D(x, y, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(pos, new Comparator<Vector3D>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int compare(Vector3D a, Vector3D b)
|
||||||
|
{
|
||||||
|
return (a.x * a.x + a.y * a.y + a.z * a.z) - (b.x * b.x + b.y * b.y + b.z * b.z);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
VOLUME = pos.toArray(new Vector3D[0]);
|
||||||
|
}
|
||||||
|
|
||||||
public static Location getSafeDestination(final Location loc) throws Exception
|
public static Location getSafeDestination(final Location loc) throws Exception
|
||||||
{
|
{
|
||||||
@ -296,7 +335,9 @@ public class Util
|
|||||||
int x = loc.getBlockX();
|
int x = loc.getBlockX();
|
||||||
int y = (int)Math.round(loc.getY());
|
int y = (int)Math.round(loc.getY());
|
||||||
int z = loc.getBlockZ();
|
int z = loc.getBlockZ();
|
||||||
|
final int origX = x;
|
||||||
final int origY = y;
|
final int origY = y;
|
||||||
|
final int origZ = z;
|
||||||
|
|
||||||
while (isBlockAboveAir(world, x, y, z))
|
while (isBlockAboveAir(world, x, y, z))
|
||||||
{
|
{
|
||||||
@ -308,41 +349,32 @@ public class Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (isBlockUnsafe(world, x, y, z))
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
if (i >= VOLUME.length)
|
||||||
|
{
|
||||||
|
x = origX;
|
||||||
|
y = origY + RADIUS;
|
||||||
|
z = origZ;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
x = origX + VOLUME[i].x;
|
||||||
|
y = origY + VOLUME[i].y;
|
||||||
|
z = origZ + VOLUME[i].z;
|
||||||
|
}
|
||||||
|
|
||||||
while (isBlockUnsafe(world, x, y, z))
|
while (isBlockUnsafe(world, x, y, z))
|
||||||
{
|
{
|
||||||
y += 1;
|
y += 1;
|
||||||
if (y >= world.getHighestBlockYAt(x, z))
|
if (y >= world.getHighestBlockYAt(x, z))
|
||||||
{
|
|
||||||
x -= 3;
|
|
||||||
z -= 3;
|
|
||||||
y = origY + 4;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (isBlockUnsafe(world, x, y, z))
|
|
||||||
{
|
|
||||||
y -= 1;
|
|
||||||
if (y + 4 < origY)
|
|
||||||
{
|
{
|
||||||
x += 1;
|
x += 1;
|
||||||
if (x - 3 > loc.getBlockX())
|
|
||||||
{
|
|
||||||
x = loc.getBlockX() - 3;
|
|
||||||
z += 1;
|
|
||||||
if (z - 3 > loc.getBlockZ())
|
|
||||||
{
|
|
||||||
x = loc.getBlockX() + 4;
|
|
||||||
z = loc.getBlockZ();
|
|
||||||
y = world.getHighestBlockYAt(x, z);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
y = origY + 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (isBlockUnsafe(world, x, y, z))
|
while (isBlockUnsafe(world, x, y, z))
|
||||||
{
|
{
|
||||||
y -= 1;
|
y -= 1;
|
||||||
@ -377,6 +409,11 @@ public class Util
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (below.getType() == Material.BED)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ((!AIR_MATERIALS.contains(world.getBlockAt(x, y, z).getType().getId()))
|
if ((!AIR_MATERIALS.contains(world.getBlockAt(x, y, z).getType().getId()))
|
||||||
|| (!AIR_MATERIALS.contains(world.getBlockAt(x, y + 1, z).getType().getId())))
|
|| (!AIR_MATERIALS.contains(world.getBlockAt(x, y + 1, z).getType().getId())))
|
||||||
{
|
{
|
||||||
|
@ -20,14 +20,19 @@ public class SignPlayerListener implements Listener
|
|||||||
this.ess = ess;
|
this.ess = ess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerInteract(final PlayerInteractEvent event)
|
public void onPlayerInteract(final PlayerInteractEvent event)
|
||||||
{
|
{
|
||||||
if (ess.getSettings().areSignsDisabled() || event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
if (ess.getSettings().areSignsDisabled() || (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Block block = event.getClickedBlock();
|
final Block block;
|
||||||
|
if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||||
|
block = event.getPlayer().getTargetBlock(null, 5);
|
||||||
|
} else {
|
||||||
|
block = event.getClickedBlock();
|
||||||
|
}
|
||||||
if (block == null)
|
if (block == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -3,6 +3,8 @@ package com.earth2me.essentials;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.plugin.InvalidDescriptionException;
|
import org.bukkit.plugin.InvalidDescriptionException;
|
||||||
@ -32,6 +34,33 @@ public class UtilTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSafeLocation()
|
||||||
|
{
|
||||||
|
Set<String> testSet = new HashSet<String>();
|
||||||
|
int count = 0;
|
||||||
|
int x, y, z, origX, origY, origZ;
|
||||||
|
x = y = z = origX = origY = origZ = 0;
|
||||||
|
int i = 0;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
testSet.add(x + ":" + y + ":" + z);
|
||||||
|
count++;
|
||||||
|
i++;
|
||||||
|
if (i >= Util.VOLUME.length)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
x = origX + Util.VOLUME[i].x;
|
||||||
|
y = origY + Util.VOLUME[i].y;
|
||||||
|
z = origZ + Util.VOLUME[i].z;
|
||||||
|
}
|
||||||
|
assertTrue(testSet.contains("0:0:0"));
|
||||||
|
assertTrue(testSet.contains("3:3:3"));
|
||||||
|
assertEquals(testSet.size(), count);
|
||||||
|
int diameter = Util.RADIUS * 2 + 1;
|
||||||
|
assertEquals(diameter * diameter * diameter, count);
|
||||||
|
}
|
||||||
|
|
||||||
public void testFDDnow()
|
public void testFDDnow()
|
||||||
{
|
{
|
||||||
Calendar c = new GregorianCalendar();
|
Calendar c = new GregorianCalendar();
|
||||||
|
Loading…
Reference in New Issue
Block a user