|
|
|
@ -1,13 +1,17 @@
|
|
|
|
|
package net.theprogrammersworld.herobrine.AI.cores;
|
|
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
|
import org.bukkit.Material;
|
|
|
|
|
import org.bukkit.World;
|
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
|
import org.bukkit.block.Sign;
|
|
|
|
|
import org.bukkit.block.sign.Side;
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
|
|
import net.theprogrammersworld.herobrine.Herobrine;
|
|
|
|
|
import net.theprogrammersworld.herobrine.Support;
|
|
|
|
|
import net.theprogrammersworld.herobrine.AI.Core;
|
|
|
|
|
import net.theprogrammersworld.herobrine.AI.CoreResult;
|
|
|
|
|
|
|
|
|
@ -23,89 +27,53 @@ public class BuryPlayer extends Core {
|
|
|
|
|
public CoreResult CallCore(Object[] data) {
|
|
|
|
|
return FindPlace((Player) data[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CoreResult FindPlace(final Player player) {
|
|
|
|
|
if (Herobrine.getPluginCore().getSupport().checkBuild(player.getLocation())) {
|
|
|
|
|
final Location loc = player.getLocation();
|
|
|
|
|
if (isSolidBlock(
|
|
|
|
|
loc.getWorld().getBlockAt(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()).getType())
|
|
|
|
|
&& isSolidBlock(
|
|
|
|
|
loc.getWorld().getBlockAt(loc.getBlockX(), loc.getBlockY() - 2, loc.getBlockZ()).getType())
|
|
|
|
|
&& isSolidBlock(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ() - 1).getType())
|
|
|
|
|
&& isSolidBlock(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 2, loc.getBlockZ() - 1).getType())
|
|
|
|
|
&& isSolidBlock(
|
|
|
|
|
loc.getWorld().getBlockAt(loc.getBlockX(), loc.getBlockY() - 3, loc.getBlockZ()).getType())
|
|
|
|
|
&& isSolidBlock(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 3, loc.getBlockZ() - 1).getType())
|
|
|
|
|
&& isSolidBlock(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ() - 1).getType())
|
|
|
|
|
&& isSolidBlock(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 2, loc.getBlockZ() - 1).getType())
|
|
|
|
|
&& isSolidBlock(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ() - 2).getType())) {
|
|
|
|
|
if (Herobrine.getPluginCore().getSupport().checkBuild(
|
|
|
|
|
loc.getWorld().getBlockAt(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()).getLocation())
|
|
|
|
|
&& Herobrine.getPluginCore().getSupport().checkBuild(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 2, loc.getBlockZ()).getLocation())
|
|
|
|
|
&& Herobrine.getPluginCore().getSupport().checkBuild(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ() - 1).getLocation())
|
|
|
|
|
&& Herobrine.getPluginCore().getSupport().checkBuild(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 2, loc.getBlockZ() - 1).getLocation())
|
|
|
|
|
&& Herobrine.getPluginCore().getSupport().checkBuild(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 3, loc.getBlockZ()).getLocation())
|
|
|
|
|
&& Herobrine.getPluginCore().getSupport().checkBuild(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 3, loc.getBlockZ() - 1).getLocation())
|
|
|
|
|
&& Herobrine.getPluginCore().getSupport().checkBuild(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ() - 1).getLocation())
|
|
|
|
|
&& Herobrine.getPluginCore().getSupport().checkBuild(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 2, loc.getBlockZ() - 1).getLocation())
|
|
|
|
|
&& Herobrine.getPluginCore().getSupport().checkBuild(loc.getWorld()
|
|
|
|
|
.getBlockAt(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ() - 2).getLocation())) {
|
|
|
|
|
Bury(loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), player);
|
|
|
|
|
return new CoreResult(true, player.getDisplayName() + " was buried by Herobrine.");
|
|
|
|
|
} else {
|
|
|
|
|
return new CoreResult(false, player.getDisplayName() + " is in a protected area and cannot be buried.");
|
|
|
|
|
}
|
|
|
|
|
String resultMessage = null;
|
|
|
|
|
if (!hasNoProtection(player.getLocation())) {
|
|
|
|
|
resultMessage = player.getDisplayName() + " is in a protected area and cannot be buried.";
|
|
|
|
|
} else if (!isEnableBuildTomb(player.getLocation())) {
|
|
|
|
|
resultMessage = player.getDisplayName() + " could not be buried because a good burial location could not be found.";
|
|
|
|
|
} else {
|
|
|
|
|
Bury(player);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return new CoreResult(false, player.getDisplayName()
|
|
|
|
|
+ " could not be buried because a good burial location could not be found.");
|
|
|
|
|
}
|
|
|
|
|
return new CoreResult(false,
|
|
|
|
|
player.getDisplayName() + " could not be buried because a good burial location could not be found.");
|
|
|
|
|
return new CoreResult(resultMessage == null, Objects.toString(resultMessage, player.getDisplayName() + " could not be buried because a good burial location could not be found."));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Bury(World world, int X, int Y, int Z, Player player) {
|
|
|
|
|
|
|
|
|
|
Location loc = new Location(world, X, Y, Z);
|
|
|
|
|
|
|
|
|
|
loc.getWorld().getBlockAt(X, Y - 1, Z).breakNaturally();
|
|
|
|
|
loc.getWorld().getBlockAt(X, Y - 2, Z).breakNaturally();
|
|
|
|
|
loc.getWorld().getBlockAt(X, Y - 3, Z).breakNaturally();
|
|
|
|
|
loc.getWorld().getBlockAt(X, Y - 1, Z - 1).breakNaturally();
|
|
|
|
|
loc.getWorld().getBlockAt(X, Y - 2, Z - 1).breakNaturally();
|
|
|
|
|
loc.getWorld().getBlockAt(X, Y - 3, Z - 1).breakNaturally();
|
|
|
|
|
player.teleport(new Location(world, X, Y - 3, Z));
|
|
|
|
|
RegenBlocks(world, X, Y, Z, player.getName());
|
|
|
|
|
|
|
|
|
|
public void Bury(Player player) {
|
|
|
|
|
Stream.of(
|
|
|
|
|
player.getLocation().clone().add(0, -1, 0),
|
|
|
|
|
player.getLocation().clone().add(0, -2, 0),
|
|
|
|
|
player.getLocation().clone().add(0, -3, 0),
|
|
|
|
|
player.getLocation().clone().add(0, -1, -1),
|
|
|
|
|
player.getLocation().clone().add(0, -2, -1),
|
|
|
|
|
player.getLocation().clone().add(0, -3, -1)
|
|
|
|
|
).map(Location::getBlock).forEach(Block::breakNaturally);
|
|
|
|
|
player.teleport(player.getLocation().clone().add(0, -3, 0));
|
|
|
|
|
Block signBlock = player.getLocation().clone().add(0, 3, -2).getBlock();
|
|
|
|
|
signBlock.setType(Material.OAK_SIGN);
|
|
|
|
|
((Sign) signBlock.getState()).getSide(Side.FRONT).setLine(1, player.getDisplayName());
|
|
|
|
|
((Sign) signBlock.getState()).update();
|
|
|
|
|
player.getLocation().clone().add(0, 2, 0).getBlock().setType(Material.STONE_BRICKS, false);
|
|
|
|
|
player.getLocation().clone().add(0, 2, -1).getBlock().setType(Material.STONE_BRICKS, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegenBlocks(World world, int X, int Y, int Z, String playername) {
|
|
|
|
|
Location loc = new Location(world, X, Y, Z);
|
|
|
|
|
Location signloc = new Location(world, X, Y, Z - 2);
|
|
|
|
|
Block signblock = signloc.add(0, 0D, 0).getBlock();
|
|
|
|
|
signblock.setType(Material.OAK_SIGN);
|
|
|
|
|
Sign sign = (Sign) signblock.getState();
|
|
|
|
|
sign.setLine(1, playername);
|
|
|
|
|
sign.update();
|
|
|
|
|
loc.getWorld().getBlockAt(X, Y - 1, Z).setType(Material.STONE_BRICKS, false);
|
|
|
|
|
loc.getWorld().getBlockAt(X, Y - 1, Z - 1).setType(Material.STONE_BRICKS, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isSolidBlock(Material m) {
|
|
|
|
|
return m.isSolid();
|
|
|
|
|
}
|
|
|
|
|
private boolean hasNoProtection(final Location location) {
|
|
|
|
|
final Support support = Herobrine.getPluginCore().getSupport();
|
|
|
|
|
|
|
|
|
|
return location != null && Stream.of(location).flatMap((loc) -> Stream.of(/* @formatter:off */
|
|
|
|
|
loc,
|
|
|
|
|
loc.clone().add(0, -1, 0), loc.clone().add(0, -2, 0), loc.clone().add(0, -3, 0),
|
|
|
|
|
loc.clone().add(0, -1, -1), loc.clone().add(0, -2, -1), loc.clone().add(0, -3, -1),
|
|
|
|
|
loc.clone().add(0, -1, -2)
|
|
|
|
|
/* @formatter:on */)).allMatch(support::checkBuild);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isEnableBuildTomb(final Location location) {
|
|
|
|
|
return location != null && Stream.of(location).flatMap((loc) -> Stream.of(/* @formatter:off */
|
|
|
|
|
loc.clone().add(0, -1, 0), loc.clone().add(0, -2, 0), loc.clone().add(0, -3, 0),
|
|
|
|
|
loc.clone().add(0, -1, -1), loc.clone().add(0, -2, -1), loc.clone().add(0, -3, -1),
|
|
|
|
|
loc.clone().add(0, -1, -2)
|
|
|
|
|
/* @formatter:on */)).map(Location::getBlock).map(Block::getType).allMatch(Material::isSolid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|