Improved MLG handling
- Added blacklist for scenarios where MLG wouldn't block fall damage (or fail to place) -Water buckets now waterlog if possible Note: This still means that any non-solid blocks like signs are treated as air and are destroyed at MLG.
This commit is contained in:
@@ -17,6 +17,7 @@ import net.nuggetmc.tplus.api.utils.PlayerUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.block.data.type.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -337,26 +338,50 @@ public class LegacyAgent extends Agent {
|
||||
Material itemType;
|
||||
Material placeType;
|
||||
Sound sound;
|
||||
Location groundLoc = null;
|
||||
boolean nether = bot.getBukkitEntity().getWorld().getEnvironment() == World.Environment.NETHER;
|
||||
double yPos = bot.getBukkitEntity().getLocation().getY();
|
||||
|
||||
if (bot.getBukkitEntity().getWorld().getEnvironment() == World.Environment.NETHER) {
|
||||
if (nether) {
|
||||
itemType = Material.TWISTING_VINES;
|
||||
sound = Sound.BLOCK_WEEPING_VINES_PLACE;
|
||||
placeType = itemType;
|
||||
|
||||
for (Block block : event.getStandingOn()) {
|
||||
if (LegacyMats.canPlaceTwistingVines(block)) {
|
||||
groundLoc = block.getLocation();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
itemType = Material.WATER_BUCKET;
|
||||
sound = Sound.ITEM_BUCKET_EMPTY;
|
||||
placeType = Material.WATER;
|
||||
|
||||
for (Block block : event.getStandingOn()) {
|
||||
if (LegacyMats.canPlaceWater(block, yPos)) {
|
||||
groundLoc = block.getLocation();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Location loc = bot.getLocation();
|
||||
if (groundLoc == null) return;
|
||||
|
||||
if (!loc.clone().add(0, -1, 0).getBlock().getType().isSolid()) return;
|
||||
Location loc = !LegacyMats.shouldReplace(groundLoc.getBlock(), yPos, nether) ? groundLoc.add(0, 1, 0) : groundLoc;
|
||||
boolean waterloggable = loc.getBlock().getBlockData() instanceof Waterlogged;
|
||||
boolean waterlogged = waterloggable && ((Waterlogged)loc.getBlock().getBlockData()).isWaterlogged();
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (loc.getBlock().getType() != placeType) {
|
||||
if (loc.getBlock().getType() != placeType && !waterlogged) {
|
||||
bot.punch();
|
||||
loc.getBlock().setType(placeType);
|
||||
if (waterloggable) {
|
||||
Waterlogged data = (Waterlogged)loc.getBlock().getBlockData();
|
||||
data.setWaterlogged(true);
|
||||
loc.getBlock().setBlockData(data);
|
||||
} else
|
||||
loc.getBlock().setType(placeType);
|
||||
world.playSound(loc, sound, 1, 1);
|
||||
|
||||
if (itemType == Material.WATER_BUCKET) {
|
||||
@@ -365,11 +390,18 @@ public class LegacyAgent extends Agent {
|
||||
scheduler.runTaskLater(plugin, () -> {
|
||||
Block block = loc.getBlock();
|
||||
|
||||
if (block.getType() == Material.WATER) {
|
||||
boolean waterloggedNow = block.getBlockData() instanceof Waterlogged
|
||||
&& ((Waterlogged)block.getBlockData()).isWaterlogged();
|
||||
if (block.getType() == Material.WATER || waterloggedNow) {
|
||||
bot.look(BlockFace.DOWN);
|
||||
bot.setItem(new ItemStack(Material.WATER_BUCKET));
|
||||
world.playSound(loc, Sound.ITEM_BUCKET_FILL, 1, 1);
|
||||
block.setType(Material.AIR);
|
||||
if (waterloggedNow) {
|
||||
Waterlogged data = (Waterlogged)loc.getBlock().getBlockData();
|
||||
data.setWaterlogged(false);
|
||||
loc.getBlock().setBlockData(data);
|
||||
} else
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
}, 5);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package net.nuggetmc.tplus.api.agent.legacyagent;
|
||||
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.block.data.type.*;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -286,4 +290,179 @@ public class LegacyMats {
|
||||
&& !exclusions.contains(m) && !m.isLegacy()).toList());
|
||||
return materials;
|
||||
}
|
||||
|
||||
public static boolean canPlaceWater(Block block, double entityYPos) {
|
||||
if (block.getType().isSolid()) {
|
||||
if (block.getType() == Material.CHAIN && ((Chain)block.getBlockData()).getAxis() == Axis.Y
|
||||
&& !((Chain)block.getBlockData()).isWaterlogged())
|
||||
return false;
|
||||
if ((block.getType().data == Leaves.class || block.getType() == Material.MANGROVE_ROOTS
|
||||
|| block.getType() == Material.IRON_BARS || block.getType().name().endsWith("GLASS_PANE"))
|
||||
&& !((Waterlogged)block.getBlockData()).isWaterlogged())
|
||||
return false;
|
||||
if (block.getType().data == Slab.class && ((Slab)block.getBlockData()).getType() == Slab.Type.TOP
|
||||
&& !((Slab)block.getBlockData()).isWaterlogged())
|
||||
return false;
|
||||
if (block.getType().data == Stairs.class && ((Stairs)block.getBlockData()).getHalf() == Bisected.Half.TOP
|
||||
&& !((Stairs)block.getBlockData()).isWaterlogged())
|
||||
return false;
|
||||
if (block.getType().data == Stairs.class && ((Stairs)block.getBlockData()).getHalf() == Bisected.Half.BOTTOM
|
||||
&& !((Stairs)block.getBlockData()).isWaterlogged() && (int)entityYPos != block.getLocation().getBlockY())
|
||||
return false;
|
||||
if ((block.getType().data == Fence.class || block.getType().data == Wall.class)
|
||||
&& !((Waterlogged)block.getBlockData()).isWaterlogged())
|
||||
return false;
|
||||
if (block.getType() == Material.LIGHTNING_ROD && !((LightningRod)block.getBlockData()).isWaterlogged()
|
||||
&& (((LightningRod)block.getBlockData()).getFacing() == BlockFace.UP || ((LightningRod)block.getBlockData()).getFacing() == BlockFace.DOWN))
|
||||
return false;
|
||||
return true;
|
||||
} else {
|
||||
if (block.getType().name().endsWith("_CARPET"))
|
||||
return true;
|
||||
if (block.getType().data == Candle.class)
|
||||
return true;
|
||||
if (block.getType().name().startsWith("POTTED_"))
|
||||
return true;
|
||||
if ((block.getType().name().endsWith("_HEAD") || block.getType().name().endsWith("_SKULL"))
|
||||
&& !block.getType().name().equals("PISTON_HEAD"))
|
||||
return true;
|
||||
switch (block.getType()) {
|
||||
case SNOW:
|
||||
case AZALEA:
|
||||
case FLOWERING_AZALEA:
|
||||
case CHORUS_FLOWER:
|
||||
case CHORUS_PLANT:
|
||||
case COCOA:
|
||||
case LILY_PAD:
|
||||
case SEA_PICKLE:
|
||||
case END_ROD:
|
||||
case FLOWER_POT:
|
||||
case SCAFFOLDING:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean canPlaceTwistingVines(Block block) {
|
||||
if (block.getType().isSolid()) {
|
||||
if (block.getType().data == Leaves.class)
|
||||
return false;
|
||||
if (block.getType().name().endsWith("_CORAL_FAN") || block.getType().name().endsWith("_CORAL")
|
||||
|| block.getType().name().endsWith("_CORAL_WALL_FAN"))
|
||||
return false;
|
||||
if (block.getType().name().endsWith("GLASS_PANE"))
|
||||
return false;
|
||||
if (block.getType().data == Slab.class && ((Slab)block.getBlockData()).getType() == Slab.Type.BOTTOM)
|
||||
return false;
|
||||
if (block.getType().data == Stairs.class && ((Stairs)block.getBlockData()).getHalf() == Bisected.Half.BOTTOM)
|
||||
return false;
|
||||
if (block.getType().data == Fence.class || block.getType().data == Wall.class)
|
||||
return false;
|
||||
if (block.getType().name().endsWith("_BANNER"))
|
||||
return false;
|
||||
if (block.getType().name().endsWith("_WALL_BANNER"))
|
||||
return false;
|
||||
if (block.getType().data == Bed.class)
|
||||
return false;
|
||||
if (block.getType().name().endsWith("CANDLE_CAKE"))
|
||||
return false;
|
||||
if (block.getType().data == Door.class)
|
||||
return false;
|
||||
if (block.getType().data == Gate.class)
|
||||
return false;
|
||||
switch (block.getType()) {
|
||||
case POINTED_DRIPSTONE:
|
||||
case SMALL_AMETHYST_BUD:
|
||||
case MEDIUM_AMETHYST_BUD:
|
||||
case LARGE_AMETHYST_BUD:
|
||||
case AMETHYST_CLUSTER:
|
||||
case BAMBOO:
|
||||
case CACTUS:
|
||||
case DRAGON_EGG:
|
||||
case TURTLE_EGG:
|
||||
case CHAIN:
|
||||
case IRON_BARS:
|
||||
case LANTERN:
|
||||
case SOUL_LANTERN:
|
||||
case ANVIL:
|
||||
case BREWING_STAND:
|
||||
case CHEST:
|
||||
case ENDER_CHEST:
|
||||
case TRAPPED_CHEST:
|
||||
case ENCHANTING_TABLE:
|
||||
case GRINDSTONE:
|
||||
case LECTERN:
|
||||
case STONECUTTER:
|
||||
case BELL:
|
||||
case CAKE:
|
||||
case CAMPFIRE:
|
||||
case SOUL_CAMPFIRE:
|
||||
case CAULDRON:
|
||||
case COMPOSTER:
|
||||
case CONDUIT:
|
||||
case END_PORTAL_FRAME:
|
||||
case FARMLAND:
|
||||
case LADDER:
|
||||
case DAYLIGHT_DETECTOR:
|
||||
case HOPPER:
|
||||
case LIGHTNING_ROD:
|
||||
return false;
|
||||
default:
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
switch (block.getType()) {
|
||||
case CHORUS_FLOWER:
|
||||
case SCAFFOLDING:
|
||||
case AZALEA:
|
||||
case FLOWERING_AZALEA:
|
||||
return true;
|
||||
case SNOW:
|
||||
return ((Snow)block.getBlockData()).getLayers() == 1 || ((Snow)block.getBlockData()).getLayers() == 8;
|
||||
default:
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean shouldReplace(Block block, double entityYPos, boolean nether) {
|
||||
if ((int)entityYPos != block.getLocation().getBlockY())
|
||||
return false;
|
||||
if (nether) {
|
||||
return false;
|
||||
} else {
|
||||
if (block.getType().name().endsWith("_CORAL_FAN") || block.getType().name().endsWith("_CORAL")
|
||||
|| block.getType().name().endsWith("_CORAL_WALL_FAN"))
|
||||
return true;
|
||||
if (block.getType().data == Slab.class && ((Slab)block.getBlockData()).getType() == Slab.Type.BOTTOM)
|
||||
return true;
|
||||
if (block.getType().data == Stairs.class && !((Stairs)block.getBlockData()).isWaterlogged())
|
||||
return true;
|
||||
if (block.getType().data == Candle.class)
|
||||
return true;
|
||||
switch (block.getType()) {
|
||||
case POINTED_DRIPSTONE:
|
||||
case SMALL_AMETHYST_BUD:
|
||||
case MEDIUM_AMETHYST_BUD:
|
||||
case LARGE_AMETHYST_BUD:
|
||||
case AMETHYST_CLUSTER:
|
||||
case SEA_PICKLE:
|
||||
case LANTERN:
|
||||
case SOUL_LANTERN:
|
||||
case CHEST:
|
||||
case ENDER_CHEST:
|
||||
case TRAPPED_CHEST:
|
||||
case CAMPFIRE:
|
||||
case SOUL_CAMPFIRE:
|
||||
case CONDUIT:
|
||||
case LIGHTNING_ROD:
|
||||
return true;
|
||||
default:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,13 @@ public class BotUtils {
|
||||
Material.WATER,
|
||||
Material.LAVA,
|
||||
Material.TWISTING_VINES,
|
||||
Material.TWISTING_VINES_PLANT,
|
||||
Material.WEEPING_VINES,
|
||||
Material.WEEPING_VINES_PLANT,
|
||||
Material.SWEET_BERRY_BUSH,
|
||||
Material.POWDER_SNOW,
|
||||
Material.COBWEB
|
||||
Material.COBWEB,
|
||||
Material.VINE
|
||||
));
|
||||
|
||||
public static UUID randomSteveUUID() {
|
||||
|
||||
@@ -628,7 +628,9 @@ public class Bot extends ServerPlayer implements Terminator {
|
||||
private boolean canStandOn(Material mat) {
|
||||
if(mat == Material.END_ROD || mat == Material.FLOWER_POT || mat == Material.REPEATER || mat == Material.COMPARATOR
|
||||
|| mat == Material.SNOW || mat == Material.LADDER || mat == Material.VINE || mat == Material.SCAFFOLDING
|
||||
|| mat == Material.AZALEA || mat == Material.FLOWERING_AZALEA || mat == Material.BIG_DRIPLEAF)
|
||||
|| mat == Material.AZALEA || mat == Material.FLOWERING_AZALEA || mat == Material.BIG_DRIPLEAF
|
||||
|| mat == Material.CHORUS_FLOWER || mat == Material.CHORUS_PLANT || mat == Material.COCOA
|
||||
|| mat == Material.LILY_PAD || mat == Material.SEA_PICKLE)
|
||||
return true;
|
||||
|
||||
if(mat.name().endsWith("_CARPET"))
|
||||
|
||||
Reference in New Issue
Block a user